__init_modules( $type ); } /** * Init modules. */ public function __init_modules( $type = 'module' ) { add_filter( 'aiow_settings_sections', array( $this, 'settings_section' ) ); add_filter( 'aiow_settings_' . $this->id, array( $this, 'get_settings' ), 100 ); $this->type = $type; if ( 'module' === $this->type ) { $this->parent_id = ''; } if ( 'no' === aiow_option( 'aiow_load_modules_on_init', 'no' ) ) { add_action( 'init', array( $this, 'add_settings' ) ); add_action( 'init', array( $this, 'reset_settings' ), PHP_INT_MAX ); } else { if ( 'init' === current_filter() ) { $this->add_settings(); $this->reset_settings(); } } // Handle WPML hooks if ( $this->is_enabled() ) { add_action( 'aiow_before_get_terms', array( $this, 'remove_wpml_functions_before_get_terms' ) ); add_action( 'aiow_after_get_terms', array( $this, 'restore_wpml_functions_after_get_terms' ) ); add_action( 'aiow_before_get_products', array( $this, 'add_wpml_args_on_get_products' ) ); add_action( 'aiow_after_get_products', array( $this, 'restore_wpml_args_on_get_products' ) ); add_action( 'admin_init', array( $this, 'remove_wpml_hooks' ) ); } // Handle Price Functions add_filter( 'wc_price', array( $this, 'handle_price' ), 10, 4 ); } /** * handle_price. * * @param $return * @param $price * @param $args * @param $unformatted_price * * @return mixed */ function handle_price( $return, $price, $args, $unformatted_price ) { if ( isset( $args['add_html_on_price'] ) && ! filter_var( $args['add_html_on_price'], FILTER_VALIDATE_BOOLEAN ) ) { $return = $price; } return $return; } /** * remove_wpml_hooks. */ function remove_wpml_hooks() { if ( 'no' === aiow_option( 'aiow_' . $this->id . '_wpml_get_products_all_lang', 'no' ) ) { return; } // Remove a WPML filter that filters products by language aiow_remove_class_filter( 'woocommerce_json_search_found_products', 'WCML_Products', 'filter_wc_searched_products_on_admin' ); } /** * restore_wpml_args_on_get_products. * * @param null $module_id */ function restore_wpml_args_on_get_products( $module_id = null ){ if ( 'no' === aiow_option( 'aiow_' . $this->id . '_wpml_get_products_all_lang', 'no' ) ) { return; } remove_action( 'pre_get_posts', array( $this, 'suppress_filters' ) ); } /** * add_wpml_args_on_get_products. * * It's necessary to take 2 steps: * 1. Add `do_action('aiow_before_get_products', $this->id )` before get_product, aiow_get_products, or wp_query. * 2. Add a setting using `$this->get_wpml_products_in_all_languages_setting()` * * @param null $module_id */ function add_wpml_args_on_get_products( $module_id = null ) { if ( 'no' === aiow_option( 'aiow_' . $this->id . '_wpml_get_products_all_lang', 'no' ) ) { return; } add_action( 'pre_get_posts', array( $this, 'suppress_filters' ) ); } /** * Query filter. * * @param object $query WP_Query */ function suppress_filters( $query ) { $query->query_vars['suppress_filters'] = true; } /** * Get all WPML product language setting. * * @return array */ function get_wpml_terms_in_all_languages_setting() { return array( 'title' => __( 'WPML: Get Terms in All Languages', 'all-in-one-wc' ), 'desc' => __( 'Enable', 'all-in-one-wc' ), 'desc_tip' => __( 'Get tags and taxonomies in all languages', 'all-in-one-wc' ), 'id' => 'aiow_' . $this->id . '_wpml_get_terms_all_lang', 'default' => 'no', 'type' => 'checkbox', ); } /** * Get all WPML product language setting. * * @return array */ function get_wpml_products_in_all_languages_setting() { return array( 'title' => __( 'WPML: Get Products in All Languages', 'all-in-one-wc' ), 'desc' => __( 'Enable', 'all-in-one-wc' ), 'desc_tip' => __( 'Get products in all languages', 'all-in-one-wc' ), 'id' => 'aiow_' . $this->id . '_wpml_get_products_all_lang', 'default' => 'no', 'type' => 'checkbox', ); } /** * Restore WPML function before get terms. * * @param string $module_id Module ID. * @return string */ function remove_wpml_functions_before_get_terms( $module_id = null ) { if ( 'no' === aiow_option( 'aiow_' . $this->id . '_wpml_get_terms_all_lang', 'no' ) ) { return; } aiow_remove_wpml_terms_filters(); } /** * Restore WPML function after get terms. * * @param string $module_id Module ID. * @return string */ function restore_wpml_functions_after_get_terms( $module_id = null ) { if ( 'no' === aiow_option( 'aiow_' . $this->id . '_wpml_get_terms_all_lang', 'no' ) ) { return; } aiow_add_wpml_terms_filters(); } /** * Get deprecated options. * * @return bool */ function get_deprecated_options() { return false; } /** * Handle deprecated options. */ function handle_deprecated_options() { if ( $deprecated_options = $this->get_deprecated_options() ) { foreach ( $deprecated_options as $new_option => $old_options ) { $new_value = aiow_option( $new_option, array() ); foreach ( $old_options as $new_key => $old_option ) { if ( null !== ( $old_value = aiow_option( $old_option, null ) ) ) { $new_value[ $new_key ] = $old_value; delete_option( $old_option ); } } update_option( $new_option, $new_value ); } } } /** * Save metabox. * * @param mixed $option_value Setting value. * @param string $option_name Option name. * @param string $module_id Module ID. * @return string */ function save_meta_box_validate_value( $option_value, $option_name, $module_id ) { if ( true === apply_filters( 'aiow_option', false, true ) ) { return $option_value; } if ( 'no' === $option_value ) { return $option_value; } if ( $this->id === $module_id && $this->meta_box_validate_value === $option_name ) { $args = array( 'post_type' => 'product', 'post_status' => 'any', 'posts_per_page' => 1, 'meta_key' => '_' . $this->meta_box_validate_value, 'meta_value' => 'yes', 'post__not_in' => array( get_the_ID() ), ); $loop = new WP_Query( $args ); $c = $loop->found_posts + 1; if ( $c >= 2 ) { add_filter( 'redirect_post_location', array( $this, 'validate_value_add_notice_query_var' ), 99 ); return 'no'; } } return $option_value; } /** * Validate notice. * * @param string $location Location URL. * @return string */ function validate_value_add_notice_query_var( $location ) { remove_filter( 'redirect_post_location', array( $this, 'validate_value_add_notice_query_var' ), 99 ); return add_query_arg( array( 'aiow_' . $this->id . '_meta_box_admin_notice' => true ), $location ); } /** * Get metabox options. */ function get_meta_box_options() { $filename = aiow_plugin_path() . '/includes/settings/meta-box/aiow-settings-meta-box-' . str_replace( '_', '-', $this->id ) . '.php'; return ( file_exists ( $filename ) ? require( $filename ) : array() ); } /** * Maybe fix settings. * * @param array $settings Setting. * @return array */ function maybe_fix_settings( $settings ) { if ( ! AIOW_IS_WC_VERSION_BELOW_3_2_0 ) { foreach ( $settings as &$setting ) { if ( isset( $setting['type'] ) && 'select' === $setting['type'] ) { if ( ! isset( $setting['ignore_enhanced_select_class'] ) || ( isset( $setting['ignore_enhanced_select_class'] ) && false === $setting['ignore_enhanced_select_class'] ) ) { if ( ! isset( $setting['class'] ) || '' === $setting['class'] ) { $setting['class'] = 'wc-enhanced-select'; } else { $setting['class'] .= ' ' . 'wc-enhanced-select'; } } } if ( isset( $setting['type'] ) && 'text' === $setting['type'] && isset( $setting['class'] ) && 'widefat' === $setting['class'] ) { if ( ! isset( $setting['css'] ) || '' === $setting['css'] ) { $setting['css'] = 'width:100%;'; } else { $setting['css'] .= ' ' . 'width:100%;'; } } } } return $settings; } /** * Add setting from file. * * @param array $settings Settings. * @return array */ function add_settings_from_file( $settings ) { $filename = str_replace( '_', '-', $this->id ); if ( isset( $_GET['aiow-cat'] ) && 'shipping_and_orders' === $_GET['aiow-cat'] ) { $filename = 'shipping/' . $filename; } $filename = aiow_plugin_path() . '/includes/Modules/custom-fields/' . $filename . '.php'; $settings = ( file_exists ( $filename ) ? require( $filename ) : $settings ); return $this->maybe_fix_settings( $settings ); } /** * Add setting panel. */ function add_settings() { add_filter( 'aiow_' . $this->id . '_settings', array( $this, 'add_settings_from_file' ) ); } /** * Save meta box. * * @param mixed $option_value option value. * @param string $option_name Option name. * @param mixed $module_id Module ID. * @return string */ function save_meta_box_value( $option_value, $option_name, $module_id ) { if ( true === apply_filters( 'aiow_option', false, true ) ) { return $option_value; } if ( 'no' === $option_value ) { return $option_value; } if ( $this->id === $module_id && $this->co === $option_name ) { $args = array( 'post_type' => 'product', 'post_status' => 'any', 'posts_per_page' => 3, 'meta_key' => '_' . $this->co, 'meta_value' => 'yes', 'post__not_in' => array( get_the_ID() ), ); $loop = new WP_Query( $args ); $c = $loop->found_posts + 1; if ( $c >= 4 ) { add_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 ); return 'no'; } } return $option_value; } /** * Add notice query var. * * @param string $location Url location. * @return string */ function add_notice_query_var( $location ) { remove_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 ); return add_query_arg( array( 'aiow_' . $this->id . '_admin_notice' => true ), $location ); } /** * Display admin notice. */ function admin_notices() { if ( ! isset( $_GET[ 'aiow_' . $this->id . '_admin_notice' ] ) ) { return; } echo '
| ' . $option['title'] . ' | '; $html .= '' . $option['title'] . $maybe_tooltip . ' | '; if ( isset( $option['desc'] ) && '' != $option['desc'] ) { $html .= '' . $option['desc'] . ' | '; } $html .= '' . $field_html . ' | '; $html .= ''; } } } $html .= '
|---|
' . $this->get_back_to_settings_link_html() . '
'; $html .= '' . $this->tools_array[ $tool_id ]['desc'] . '
'; } return $html; } /** * Add module tool. * * @param array $tools_array Tools. * @param array $args Arguments. */ function add_tools( $tools_array, $args = array() ) { $this->tools_array = $tools_array; add_action( 'aiow_module_tools_' . $this->id, array( $this, 'add_tool_link' ), PHP_INT_MAX ); $hook_priority = isset( $args['tools_dashboard_hook_priority'] ) ? $args['tools_dashboard_hook_priority'] : 10; if ( $this->is_enabled() ) { add_filter( 'aiow_tools_tabs', array( $this, 'add_module_tools_tabs' ), $hook_priority ); foreach ( $this->tools_array as $tool_id => $tool_data ) { add_action( 'aiow_tools_' . $tool_id, array( $this, 'create_' . $tool_id . '_tool' ) ); } } add_action( 'aiow_tools_dashboard', array( $this, 'add_module_tools_info_to_tools_dashboard' ), $hook_priority ); } /** * Add module tab. * * @param arrau $tabs Setting tab. * @return array */ function add_module_tools_tabs( $tabs ) { foreach ( $this->tools_array as $tool_id => $tool_data ) { $tool_title = ( isset( $tool_data['tab_title'] ) ) ? $tool_data['tab_title'] : $tool_data['title']; $tabs[] = array( 'id' => $tool_id, 'title' => $tool_title, ); } return $tabs; } /** * Add module info in dashboard. */ function add_module_tools_info_to_tools_dashboard() { $is_enabled_html = ( $this->is_enabled() ) ? '' . __( 'enabled', 'all-in-one-wc' ) . '' : '' . __( 'disabled', 'all-in-one-wc' ) . ''; foreach ( $this->tools_array as $tool_id => $tool_data ) { $tool_title = $tool_data['title']; $tool_desc = $tool_data['desc']; $additional_style_html = ''; $additional_info_html = ''; if ( isset( $tool_data['deprecated'] ) && true === $tool_data['deprecated'] ) { $additional_style_html = 'color:gray;font-style:italic;'; $additional_info_html = ' - ' . __( 'Deprecated', 'all-in-one-wc' ); } echo '';
echo ( $this->is_enabled() ) ?
'' . $tool_title . '' :
'' . $tool_title . '';
echo '