settings = get_option( $this->option, [] ); // Hook into main pdf plugin settings add_filter( 'wpo_wcpdf_settings_tabs', array( $this, 'settings_tab' ) ); add_action( 'admin_init', array( $this, 'init_settings' ) ); add_action( 'wpo_wcpdf_before_settings', array( $this, 'column_editor' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts_styles' ), 99 ); // Fix compatibility issues with YIT themes and other plugins loading jquery-ui styles everywhere add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_jquery_ui_styles' ), 999 ); // Footer height settings (also initiated in the template functions but registered here too for backwards compatibility) add_filter( 'wpo_wcpdf_settings_fields_general', array( $this, 'add_footer_height_setting' ), 10, 4 ); // Replace extra fields description based on selected template add_filter( 'wpo_wcpdf_settings_fields_general', array( $this, 'extra_fields_description_replacement' ), 10, 4 ); // Add field to columns or totals add_action( 'wp_ajax_wcpdf_templates_add_totals_columns_field', array( $this, 'add_totals_columns_field' ) ); // Add custom block add_action( 'wp_ajax_wcpdf_templates_add_custom_block', array( $this, 'add_custom_block' ) ); // remove single use query arg for restoring defaults add_action( 'updated_option', array( $this, 'remove_load_defaults_after_updating_option' ), 10, 3 ); // update editor columns/totals positions add_action( 'updated_option', array( $this, 'update_totals_columns_positions' ), 99, 3 ); // show notice when the Simple template is active add_action( 'wpo_wcpdf_before_settings_page', array( $this, 'simple_template_notice' ), 1 ); // import/export customizer settings add_filter( 'wpo_wcpdf_setting_types', array( $this, 'customizer_setting_types' ), 10, 1 ); add_filter( 'wpo_wcpdf_export_settings', array( $this, 'customizer_settings_export' ), 10, 2 ); add_filter( 'wpo_wcpdf_import_settings_option', array( $this, 'customizer_settings_import_option' ), 10, 3 ); } /** * Display notification when the Simple theme is selected */ public function simple_template_notice ( $active_tab ) { if ( $active_tab == 'editor' ) { $settings = get_option( 'wpo_wcpdf_settings_general', array() ); if ( is_array( $settings ) && isset( $settings['template_path'] ) ) { if ( $settings['template_path'] == 'default/Simple' ) { ?>
Simple template has limited compatibilty with the Customizer. You will need to switch your template to a premium one, e.g. Simple Premium, if you want to take full advantage of the Customizer.', 'wpo_wcpdf_templates' ) ); ?>
__('Text', 'wpo_wcpdf_templates'), 'custom_field' => __('Custom Field', 'wpo_wcpdf_templates'), 'user_meta' => __('User Meta', 'wpo_wcpdf_templates'), ); $option_key = 'type'; $this->select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => $types, 'current' => !empty($current[$option_key]) ? $current[$option_key] : '', 'class' => "custom-block-type", )); ?> | |
__('Before document', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_shop_name' => __('Before the shop name', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_shop_name' => __('After the shop name', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_shop_address' => __('Before the shop address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_shop_address' => __('After the shop address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_document_label' => __('Before the document label', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_document_label' => __('After the document label', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_billing_address' => __('Before the billing address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_billing_address' => __('After the billing address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_shipping_address' => __('Before the shipping address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_shipping_address' => __('After the shipping address', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_order_data' => __('Before the order data (invoice number, order date, etc.)', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_order_data' => __('After the order data', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_customer_notes' => __('Before the customer notes', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_customer_notes' => __('After the customer notes', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_order_details' => __('Before the order details table with all items', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_order_details' => __('After the order details table', 'wpo_wcpdf_templates'), 'wpo_wcpdf_before_footer' => __('Before the footer', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_footer' => __('After the footer', 'wpo_wcpdf_templates'), 'wpo_wcpdf_after_document' => __('After document', 'wpo_wcpdf_templates'), ); $option_key = 'position'; $this->select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => $positions, 'current' => !empty($current[$option_key]) ? $current[$option_key] : '', )); ?> | |
input_element(array( 'option_name' => "{$name}[{$option_key}]", 'current' => !empty($current[$option_key]) ? $current[$option_key] : '', )); ?> | |
"> input_element(array( 'option_name' => "{$name}[{$option_key}]", 'current' => !empty($current[$option_key]) ? $current[$option_key] : '', // 'class' => 'meta_key', )); ?> | |
textarea_element(array( 'option_name' => "{$name}[{$option_key}]", 'current' => !empty($current[$option_key]) ? $current[$option_key] : '', // 'class' => 'custom_text', 'rows' => 8, )); ?> |
select_element(array( 'class' => 'select-requirements', 'options' => array( '' => __('Select additional requirements for displaying this custom block', 'wpo_wcpdf_templates') . '…' ), 'current' => 'requirement', 'css' => 'width:100%;', )); ?> |
select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => wc_get_order_statuses(), 'current' => !empty($current[$option_key]) ? $current[$option_key] : array(), 'enhanced_select' => true, 'multiple' => true, 'placeholder' => __( 'Select one or more statuses', 'wpo_wcpdf_templates' ), 'css' => 'width:90%', )); ?> |
payment_gateways->payment_gateways() as $gateway) { $payment_gateways[$gateway->id] = $gateway->get_title(); } $this->select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => $payment_gateways, 'current' => !empty($current[$option_key]) ? $current[$option_key] : array(), 'enhanced_select' => true, 'multiple' => true, 'placeholder' => __( 'Select one or more payment methods', 'wpo_wcpdf_templates' ), 'class' => 'wc-enhanced-select wpo-wcpdf-enhanced-select', 'css' => 'width:90%', )); ?> |
select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => $countries, 'current' => !empty($current[$option_key]) ? $current[$option_key] : array(), 'enhanced_select' => true, 'multiple' => true, 'placeholder' => __( 'Select one or more countries', 'wpo_wcpdf_templates' ), 'class' => 'wc-enhanced-select wpo-wcpdf-enhanced-select', 'css' => 'width:90%', )); ?> |
select_element(array( 'option_name' => "{$name}[{$option_key}]", 'options' => $countries, 'current' => !empty($current[$option_key]) ? $current[$option_key] : array(), 'enhanced_select' => true, 'multiple' => true, 'placeholder' => __( 'Select one or more countries', 'wpo_wcpdf_templates' ), 'class' => 'wc-enhanced-select wpo-wcpdf-enhanced-select', 'css' => 'width:90%', )); ?> |
', $option_key, $option_name, checked( 1, $current_vat_reverse_charge, false ) ); ?> |
', $option_key, $option_name, checked( 1, $current_hide_if_empty, false ) ); ?> |
', $option_key, $option_name, checked( 1, $current_html_mode, false ) ); ?> |
{{wpo_wcpdf_%2$s}}
placeholder within the customizer to display the content from this field.', 'wpo_wcpdf_templates' ),
$template_name,
$settings['id']
);
}
if( ! empty( $setting['id'] ) && $setting['id'] == 'extra_1' ) {
if( $template_name == 'Business' ) {
$settings['args']['description'] = sprintf(
/* translators: template name */
__( 'This shows in the %s (Premium) template header', 'wpo_wcpdf_templates' ),
$template_name
);
} else {
$settings['args']['description'] = $not_used_description;
}
} elseif( ! empty( $setting['id'] ) && in_array( $setting['id'], array( 'extra_2', 'extra_3' ) ) ) {
$settings['args']['description'] = $not_used_description;
}
}
}
}
}
return $settings_fields;
}
public function insert_after_setting( $settings, $new_setting, $insert_after_id ) {
// search setting with $insert_after_id
foreach ($settings as $key => $setting) {
if ($setting['type'] == 'setting' && $setting['id'] == $insert_after_id) {
$insert_pos = array_search($key, array_keys($settings)) + 1;
}
}
// simply append if position not found
if (empty($insert_pos)) {
return array_merge( $settings, array( $new_setting ) );
}
// splicemup!
array_splice( $settings, $insert_pos, 0, array( $new_setting ) );
return $settings;
}
/**
* Validate options.
*
* @param array $input options to valid.
*
* @return array validated options.
*/
public function validate_options( $input ) {
// no validation required at this point!
$output = $input;
// Return the array processing any additional functions filtered by this action.
return apply_filters( 'wpo_wcpdf_templates_validate_settings', $output, $input );
}
/**
* Remove load-defaults query variable after option is updated (to prevent loading the defaults again)
*/
public function remove_load_defaults_after_updating_option( $option, $old_value, $value ) {
if ( $option == $this->option ) {
add_filter( 'wp_redirect', function( $location, $status ) {
return esc_url_raw( remove_query_arg( 'load-defaults', $location ) );
}, 10, 2 );
}
}
public function select_element( $args ) {
$defaults = array(
'option_name' => '',
'options' => array(),
'current' => null,
'enhanced_select' => false,
'multiple' => false,
'placeholder' => '',
'title' => '',
'id' => '',
'class' => '',
'css' => '',
);
$args = wp_parse_args( $args, $defaults );
extract($args);
if ( $enhanced_select ) {
if ( $multiple ) {
$option_name = "{$option_name}[]";
$multiple = 'multiple=multiple';
} else {
$multiple = '';
}
$placeholder = isset($placeholder) ? esc_attr( $placeholder ) : '';
$title = isset($title) ? esc_attr( $title ) : '';
$class .= ' wc-enhanced-select wpo-wcpdf-enhanced-select';
// $css = 'width:400px';
printf( '