plugin_url . '/assets/plugin/chosen/chosen.min.css', array(), AFTERSHIP_VERSION ); } /** * Inject javascripts */ public function library_scripts() { $plugin_url = aftership()->plugin_url; wp_enqueue_script( 'aftership_styles_chosen_jquery', $plugin_url . '/assets/plugin/chosen/chosen.jquery.min.js', array(), AFTERSHIP_VERSION ); wp_enqueue_script( 'aftership_styles_chosen_proto', $plugin_url . '/assets/plugin/chosen/chosen.proto.min.js', array(), AFTERSHIP_VERSION ); wp_enqueue_script( 'aftership_script_util', $plugin_url . '/assets/js/util.js', array(), AFTERSHIP_VERSION ); wp_enqueue_script( 'aftership_script_couriers', $plugin_url . '/assets/js/couriers.js', array(), AFTERSHIP_VERSION ); wp_enqueue_script( 'aftership_script_show_order_actions', $plugin_url . '/assets/js/order-status.js', array(), AFTERSHIP_VERSION ); wp_enqueue_script( 'aftership_script_setting', $plugin_url . '/assets/js/setting.js', array(), AFTERSHIP_VERSION ); } /** * Register and add settings */ public function page_init() { $this->options = get_option( 'aftership_option_name' ); register_setting( 'aftership_option_group', 'aftership_option_name', array( $this, 'sanitize' ) ); add_settings_section( 'aftership_setting_section_id', '', array( $this, 'print_section_info' ), 'aftership-setting-admin' ); add_settings_field( $this->dom_id_couriers, '', array( $this, 'couriers_callback' ), 'aftership-setting-admin', 'aftership_setting_section_id' ); add_settings_field( 'use_track_button', '', array( $this, 'track_button_callback' ), 'aftership-setting-admin', 'aftership_setting_section_id' ); add_settings_field( 'custom_domain', '', array( $this, 'custom_domain_callback' ), 'aftership-setting-admin', 'aftership_setting_section_id' ); add_settings_field( 'enable_import_tracking', '', array( $this, 'enable_import_tracking_callback' ), 'aftership-setting-admin', 'aftership_setting_section_id' ); // CNT-34475 下掉相关的选项 // add_settings_field( // 'save_notes_to_meta_data', // '', // array( $this, 'save_notes_to_meta_data_callback' ), // 'aftership-setting-admin', // 'aftership_setting_section_id' // ); add_settings_field( $this->dom_id_show_order_actions, '', array( $this, 'show_order_actions_callback' ), 'aftership-setting-admin', 'aftership_setting_section_id' ); } /** * Sanitize each setting field as needed * * @param array $input Contains all settings fields as array keys. * @return array */ public function sanitize( $input ) { $new_input = array(); if ( isset( $input['couriers'] ) ) { $new_input['couriers'] = sanitize_text_field( $input['couriers'] ); } if ( isset( $input['custom_domain'] ) ) { $new_input['custom_domain'] = sanitize_text_field( $input['custom_domain'] ); } if ( isset( $input['use_track_button'] ) ) { $new_input['use_track_button'] = true; } if ( isset( $input['connected'] ) ) { $new_input['connected'] = boolval( $input['connected'] ); } if ( isset( $input['enable_import_tracking'] ) ) { if ($input['enable_import_tracking'] == 'on' || $input['enable_import_tracking'] === true || intval($input['enable_import_tracking']) === 1 ) { $new_input['enable_import_tracking'] = 1; } } if ( isset( $input['save_notes_to_meta_data'] ) ) { if ($input['save_notes_to_meta_data'] == 'on' || $input['save_notes_to_meta_data'] === true || intval($input['save_notes_to_meta_data']) === 1 ) { $new_input['save_notes_to_meta_data'] = 1; } } if ( isset( $input['show_orders_actions'] ) ) { $new_input['show_orders_actions'] = sanitize_text_field( $input['show_orders_actions'] ); } return $new_input; } /** * Print the Section text */ public function print_section_info() { // print 'Enter your settings below:';. } /** * Normalize custom domain. * * @param string $url input url. * @return string */ public function normalize_custom_domain( $url ) { if ( filter_var( $url, FILTER_VALIDATE_URL ) === false ) { return $url; } $domain = parse_url( $url, PHP_URL_HOST ); return $domain; } /** * Call this func before shown on pages. */ public function couriers_callback() { $couriers = array(); if ( isset( $this->options['couriers'] ) ) { $couriers = explode( ',', $this->options['couriers'] ); } echo '