Warning! The settings below are meant for debugging/development only. Do not use them on a live website!' , 'woocommerce-pdf-invoices-packing-slips' ) ); } /** * Custom fields section callback. * * @return void. */ public function custom_fields_section() { echo wp_kses_post( __( 'These are used for the (optional) footer columns in the Modern (Premium) template, but can also be used for other elements in your custom template' , 'woocommerce-pdf-invoices-packing-slips' ) ); } /** * HTML section callback. * * @return void. */ public function html_section( $args ) { extract( $this->normalize_settings_args( $args ) ); // output HTML echo wp_kses_post( $html ); } /** * Checkbox callback. * * args: * option_name - name of the main option * id - key of the setting * value - value if not 1 (optional) * default - default setting (optional) * description - description (optional) * * @return void. */ public function checkbox( $args ) { extract( $this->normalize_settings_args( $args ) ); // output checkbox printf( '', esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $value ), checked( $value, $current, false ), ! empty( $disabled ) ? 'disabled="disabled"' : '' ); // print store empty input if true if( $store_unchecked ) { printf( '', $option_name, esc_attr( $id ) ); } // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Text input callback. * * args: * option_name - name of the main option * id - key of the setting * size - size of the text input (em) * default - default setting (optional) * description - description (optional) * type - type (optional) * * @return void. */ public function text_input( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( empty( $type ) ) { $type = 'text'; } $size = ! empty( $size ) ? sprintf( 'size="%s"', esc_attr( $size ) ) : ''; printf( '', esc_attr( $type ), esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $current ), $size, esc_attr( $placeholder ), ! empty( $disabled ) ? 'disabled="disabled"' : '' ); // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * URL input callback. * * args: * option_name - name of the main option * id - key of the setting * size - size of the text input (em) * default - default setting (optional) * description - description (optional) * type - type (optional) * * @return void. */ public function url_input( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( empty( $type ) ) { $type = 'url'; } $size = ! empty( $size ) ? sprintf( 'size="%s"', esc_attr( $size ) ) : ''; printf( '', esc_attr( $type ), esc_attr( $id ), esc_attr( $setting_name ), sanitize_url( $current ), $size, esc_attr( $placeholder ), ! empty( $disabled ) ? 'disabled="disabled"' : '' ); // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Combined checkbox & text input callback. * * args: * option_name - name of the main option * id - key of the setting * value - value if not 1 (optional) * default - default setting (optional) * description - description (optional) * * @return void. */ public function checkbox_text_input( $args ) { $args = $this->normalize_settings_args( $args ); extract( $args ); unset( $args['description'] ); // already extracted, should only be used here // get checkbox ob_start(); $this->checkbox( $args ); $checkbox = ob_get_clean(); // get text input for insertion in wrapper $input_args = array( 'id' => $args['text_input_id'], 'default' => isset( $args['text_input_default'] ) ? (string) $args['text_input_default'] : NULL, 'size' => isset( $args['text_input_size'] ) ? $args['text_input_size'] : NULL, ) + $args; unset( $input_args['current'] ); unset( $input_args['setting_name'] ); ob_start(); $this->text_input( $input_args ); $text_input = ob_get_clean(); if (! empty( $text_input_wrap ) ) { printf( "{$checkbox} {$text_input_wrap}", $text_input); } else { echo "{$checkbox} {$text_input}"; } // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } // Single text option (not part of any settings array) public function singular_text_element( $args ) { $option_name = $args['option_name']; $id = $args['id']; $size = isset( $args['size'] ) ? $args['size'] : '25'; $class = isset( $args['translatable'] ) && $args['translatable'] === true ? 'translatable' : ''; $option = get_option( $option_name ); if ( isset( $option ) ) { $current = $option; } else { $current = isset( $args['default'] ) ? $args['default'] : ''; } printf( '', esc_attr( $id ), esc_attr( $option_name ), esc_attr( $current ), esc_attr( $size ), esc_attr( $class ) ); // output description. if ( isset( $args['description'] ) ) { printf( '

%s

', wp_kses_post( $args['description'] ) ); } } /** * Textarea callback. * * args: * option_name - name of the main option * id - key of the setting * width - width of the text input (em) * height - height of the text input (lines) * default - default setting (optional) * description - description (optional) * * @return void. */ public function textarea( $args ) { extract( $this->normalize_settings_args( $args ) ); printf( '', esc_attr( $id ), esc_attr( $setting_name ), esc_textarea( $current ), esc_attr( $width ), esc_attr( $height ), esc_attr( $placeholder ) ); // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Select element callback. * * @param array $args Field arguments. * * @return void */ public function select( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( ! empty( $enhanced_select ) ) { if ( ! empty( $multiple ) ) { $setting_name = "{$setting_name}[]"; $multiple = 'multiple=multiple'; } else { $multiple = ''; } $placeholder = ! empty( $placeholder ) ? esc_attr( $placeholder ) : ''; $title = ! empty( $title ) ? esc_attr( $title ) : ''; $class = 'wc-enhanced-select wpo-wcpdf-enhanced-select'; $css = 'width:400px'; printf( '', esc_attr( $id ), esc_attr( $setting_name ) ); } if ( ! empty( $options_callback ) ) { $options = isset( $options_callback_args ) ? call_user_func_array( $options_callback, $options_callback_args ) : call_user_func( $options_callback ); } foreach ( $options as $key => $label ) { if ( ! empty( $multiple ) && is_array( $current ) ) { $selected = in_array( $key, $current ) ? ' selected="selected"' : ''; printf( '', esc_attr( $key ), esc_attr( $selected ), esc_html( $label ) ); } else { printf( '', esc_attr( $key ), esc_attr( selected( $current, $key, false ) ), esc_html( $label ) ); } } echo ''; if ( ! empty( $custom ) ) { printf( '
', esc_attr( $id ) ); if ( is_callable( array( $this, $custom['type'] ) ) ) { $this->{$custom['type']}( $custom['args'] ); } echo '
'; $custom_option = ! empty( $custom['custom_option'] ) ? $custom['custom_option'] : 'custom'; ?> %s

', wp_kses_post( $description ) ); } } public function radio_button( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( ! empty( $options_callback ) ) { $options = isset( $options_callback_args ) ? call_user_func_array( $options_callback, $options_callback_args ) : call_user_func( $options_callback ); } foreach ( $options as $key => $label ) { printf( '', esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $key ), checked( $current, $key, false ) ); printf( '
', esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $key ), esc_html( $label ) ); } // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Multiple text element callback. * @param array $args Field arguments. * @return void */ public function multiple_text_input( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( ! empty( $fields_callback ) ) { $fields = isset( $fields_callback_args ) ? call_user_func_array( $fields_callback, $fields_callback_args ) : call_user_func( $fields_callback ); } printf( '', esc_attr( $id ) ); if ( ! empty( $header ) ) { echo wp_kses_post( "" ); } foreach ($fields as $name => $field) { echo ''; $size = $field['size']; $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; $field_description = ! empty( $field['description'] ) ? $field['description']: ''; // output field label if ( isset( $field['label'] ) ) { printf( '', esc_attr( $id ), esc_attr( $name ), esc_html( $field['label'] ) ); } else { echo ''; } // output field $field_current = isset( $current[$name] ) ? $current[$name] : ''; $type = isset( $field['type'] ) ? $field['type'] : 'text'; printf( '', esc_attr( $type ), esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $name ), esc_attr( $field_current ), esc_attr( $size ), esc_attr( $placeholder ) ); // field description. if ( ! empty( $field_description ) ) { echo ''; } else { echo ''; } echo ''; } echo "
{$header}:
' . wc_help_tip( $field_description, true ) . '
"; // group description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Multiple text element callback. * @param array $args Field arguments. * @return void */ public function multiple_checkboxes( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( ! empty( $fields_callback ) ) { $fields = isset( $fields_callback_args ) ? call_user_func_array( $fields_callback, $fields_callback_args ) : call_user_func( $fields_callback ); } foreach ( $fields as $name => $label ) { // output checkbox $field_current = isset( $current[$name] ) ? $current[$name] : ''; printf( '', esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $name ), esc_attr( $value ), checked( $value, $field_current, false ) ); // output field label printf( '
', esc_attr( $id ), esc_attr( $name ), esc_html( $label ) ); } // output description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Media upload callback. * * @param array $args Field arguments. * @return void */ public function media_upload( $args ) { extract( $this->normalize_settings_args( $args ) ); if( ! empty( $current ) && $attachment = wp_get_attachment_image_src( $current, 'full', false ) ) { $general_settings = get_option('wpo_wcpdf_settings_general'); $attachment_src = $attachment[0]; $attachment_width = $attachment[1]; $attachment_height = $attachment[2]; // check if we have the height saved on settings $header_logo_height = !empty( $general_settings['header_logo_height'] ) ? $general_settings['header_logo_height'] : '3cm'; if ( stripos( $header_logo_height, 'mm' ) != false ) { $in_height = floatval( $header_logo_height )/25.4; } elseif ( stripos( $header_logo_height, 'cm' ) != false ) { $in_height = floatval( $header_logo_height )/2.54; } elseif ( stripos( $header_logo_height, 'in' ) != false ) { $in_height = floatval( $header_logo_height ); } else { // don't display resolution } /* * .webp support can be disabled but still showing the image in settings. * We should add a notice because this will display an error when redering the PDF using DOMPDF. */ if ( 'webp' === wp_check_filetype( $attachment_src )['ext'] && ! function_exists( 'imagecreatefromwebp' ) ) { printf( '

%s

', wp_kses_post( 'File type webp is not supported by your server! Please check your System Configurations under the Advanced tab.', 'woocommerce-pdf-invoices-packing-slips' ) ); } printf( '', esc_attr( $attachment_src ), esc_attr( $id ) ); if ( ! empty( $attachment_height ) && ! empty( $in_height ) ) { $attachment_resolution = round( absint( $attachment_height ) / $in_height ); printf( '

%s: %sdpi

', esc_html__( 'Image resolution', 'woocommerce-pdf-invoices-packing-slips' ), $attachment_resolution ); // warn the user if the image is unnecessarily large if ( $attachment_resolution > 600 ) { printf( '

%s

', esc_html__( 'The image resolution exceeds the recommended maximum of 600dpi. This will unnecessarily increase the size of your PDF files and could negatively affect performance.', 'woocommerce-pdf-invoices-packing-slips' ) ); } } printf('%2$s ', esc_attr( $id ), esc_attr( $remove_button_text ) ); } printf( '', esc_attr( $id ), esc_attr( $setting_name ), esc_attr( $current ), esc_attr( json_encode( $args ) ), wp_create_nonce( "wpo_wcpdf_get_media_upload_setting_html" ) ); printf( '%2$s', esc_attr( $uploader_title ), esc_attr( $uploader_button_text ), esc_attr( $remove_button_text ), esc_attr( $id ) ); // Displays option description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Next document number edit callback. * * @param array $args Field arguments. */ public function next_number_edit( $args ) { extract( $args ); // $store, $size, $description if ( ! empty( $store_callback ) ) { $store = isset( $store_callback_args ) ? call_user_func_array( $store_callback, $store_callback_args ) : call_user_func( $store_callback ); } // Sequential_Number_Store object if( is_object( $store ) ) { $next_number = $store->get_next(); $store = $store->store_name; // legacy } else { $number_store_method = WPO_WCPDF()->settings->get_sequential_number_store_method(); $number_store = new Sequential_Number_Store( $store, $number_store_method ); $next_number = $number_store->get_next(); } $nonce = wp_create_nonce( "wpo_wcpdf_next_{$store}" ); printf( ' ', esc_attr( $store ), esc_attr( $size ), esc_attr( $next_number ), esc_attr( $nonce ), esc_html__( 'Save', 'woocommerce-pdf-invoices-packing-slips' ) ); // Displays option description. if ( ! empty( $description ) ) { printf( '

%s

', wp_kses_post( $description ) ); } } /** * Wrapper function to create tabs for settings in different languages * @param array $args * @return void */ public function i18n_wrap ( $args ) { extract( $this->normalize_settings_args( $args ) ); if ( $languages = $this->get_languages() ) { printf( '
', esc_attr( $option_name ), esc_attr( $id ) ); ?> $language_name ) { $translation_id = "{$option_name}_{$id}_{$lang_code}"; printf( '
', esc_attr( $translation_id ) ); $args['lang'] = $lang_code; // don't use internationalized placeholders since they're not translated, // to avoid confusion (user thinking they're all the same) if ( $callback == 'multiple_text_input' ) { foreach ( $fields as $key => $field_args ) { if ( ! empty( $field_args['placeholder'] ) && isset( $field_args['i18n_placeholder'] ) ) { $args['fields'][$key]['placeholder'] = ''; } } } else { if ( !empty( $args['placeholder'] ) && isset( $args['i18n_placeholder'] ) ) { $args['placeholder'] = ''; } } // specific description for internationalized fields (to compensate for missing placeholder) if ( ! empty( $args['i18n_description'] ) ) { $args['description'] = $args['i18n_description']; } if ( is_array( $callback ) ) { call_user_func( $callback, $args ); } else { call_user_func( array( $this, $callback ), $args ); } echo '
'; } ?>
$data) { $languages[$data['language_code']] = $data['native_name']; } } else { return false; } return $languages; } public function normalize_settings_args ( $args ) { $args['value'] = isset( $args['value'] ) ? $args['value'] : 1; $args['placeholder'] = isset( $args['placeholder'] ) ? $args['placeholder'] : ''; $args['store_unchecked'] = isset( $args['store_unchecked'] ) && $args['store_unchecked'] ? true : false; // get main settings array $option = get_option( $args['option_name'] ); if ( empty ( $args['setting_name'] ) ) { $args['setting_name'] = "{$args['option_name']}[{$args['id']}]"; } if ( !isset($args['lang']) && !empty($args['translatable']) ) { $args['lang'] = 'default'; } if ( ! array_key_exists( 'current', $args ) ) { if (isset($args['lang'])) { // i18n settings name $args['setting_name'] = "{$args['setting_name']}[{$args['lang']}]"; // copy current option value if set if ( $args['lang'] == 'default' && !empty($option[$args['id']]) && !isset( $option[$args['id']]['default'] ) ) { // we're switching back from WPML to normal // try english first if ( isset( $option[$args['id']]['en'] ) ) { $args['current'] = $option[$args['id']]['en']; } elseif ( is_array( $option[$args['id']] ) ) { // fallback to the first language if english not found $first = array_shift($option[$args['id']]); if (!empty($first)) { $args['current'] = $first; } } elseif ( is_string( $option[$args['id']] ) ) { $args['current'] = $option[$args['id']]; } else { // nothing, really? $args['current'] = ''; } } else { if ( isset( $option[$args['id']][$args['lang']] ) ) { $args['current'] = $option[$args['id']][$args['lang']]; } elseif (isset( $option[$args['id']]['default'] )) { $args['current'] = $option[$args['id']]['default']; } } } else { // copy current option value if set if ( isset( $option[$args['id']] ) ) { $args['current'] = $option[$args['id']]; } } } // falback to default or empty if no value in option if ( !isset($args['current']) ) { $args['current'] = isset( $args['default'] ) ? $args['default'] : ''; } elseif ( empty($args['current']) && isset($args['default_if_empty']) && $args['default_if_empty'] == true ) { // force fallback if empty 'current' and 'default_if_empty' equals to true $args['current'] = isset( $args['default'] ) ? $args['default'] : ''; } return $args; } /** * Validate options. * * @param array $input options to valid. * * @return array validated options. */ public function validate( $input ) { // Create our array for storing the validated options. $output = array(); if ( empty( $input ) || ! is_array( $input ) ) { return $input; } if ( ! empty( $input['wpo_wcpdf_setting_store_empty'] ) ) { //perhaps we should use a more unique/specific name for this foreach ( $input['wpo_wcpdf_setting_store_empty'] as $key ) { if ( empty( $input[$key] ) ) { $output[$key] = 0; } } unset($input['wpo_wcpdf_setting_store_empty']); } // Loop through each of the incoming options. foreach ( $input as $key => $value ) { // Check to see if the current option has a value. If so, process it. if ( isset( $input[$key] ) ) { if ( is_array( $input[$key] ) ) { foreach ( $input[$key] as $sub_key => $sub_value ) { $output[$key][$sub_key] = $input[$key][$sub_key]; } } else { $output[$key] = $input[$key]; } } } // Return the array processing any additional functions filtered by this action. return apply_filters( 'wpo_wcpdf_validate_input', $output, $input ); } } endif; // class_exists