filter_settings = get_option( 'twincaaf_woocommerce_filters', array() ); add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 50 ); add_action( 'woocommerce_settings_tabs_twincaaf_settings', array( $this, 'settings_page' ) ); add_action( 'woocommerce_update_options_twincaaf_settings', array( $this, 'save_settings' ) ); add_action( 'admin_init', array( $this, 'page_init' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); } /** * Add the AAF settings tab to the WooCommerce settings array. * * @param array $tabs Existing WooCommerce settings tabs. * @return array Modified tabs array with AAF included. */ public function add_settings_tab( $tabs ) { $tabs['twincaaf_settings'] = __( 'Attribute Filters', 'advanced-attribute-filters' ); return $tabs; } /** * Trigger the saving process for AAF settings. * * Manually saves the settings from the WooCommerce settings tab. * * @return void */ public function save_settings() { // Έλεγχος Nonce για ασφάλεια. if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'woocommerce-settings' ) ) { return; } if ( isset( $_POST['twincaaf_woocommerce_filters'] ) ) { $filters_post = wp_unslash( $_POST['twincaaf_woocommerce_filters'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $filters = $this->sanitize_tab2( $filters_post ); if ( update_option( 'twincaaf_woocommerce_filters', $filters ) ) { $this->filter_settings = $filters; } } } /** * Enqueue scripts and styles for the settings page. * * @param string $hook Page hook. */ public function enqueue_admin_scripts( $hook ) { $current_tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $is_aaf_settings = ( 'woocommerce_page_wc-settings' === $hook && 'twincaaf_settings' === $current_tab ); $is_term_edit = ( 'term.php' === $hook || 'edit-tags.php' === $hook ); if ( ! $is_aaf_settings && ! $is_term_edit ) { return; } wp_enqueue_style( 'twincaaf-admin-style', plugins_url( 'admin/css/advanced-attribute-filters.css', TWINCAAF_WC_ADVANCED_ATTRIBUTE_FILTERS_PATH ), array(), '1.0.1' ); wp_enqueue_script( 'twincaaf-admin-scripts', plugins_url( 'admin/js/advanced-attribute-filters.js', TWINCAAF_WC_ADVANCED_ATTRIBUTE_FILTERS_PATH ), array( 'jquery' ), '1.0.0', true ); } /** * Render the settings page. */ public function settings_page() { ?>
' . esc_html__( 'Select which product attributes should be available as filters on the frontend.', 'advanced-attribute-filters' ) . '
'; } /** * Callback for enabled attributes. */ public function enabled_attributes_callback() { $attributes = wc_get_attribute_taxonomies(); if ( empty( $attributes ) ) { echo '' . esc_html__( 'No product attributes found.', 'advanced-attribute-filters' ) . '
'; return; } echo '| ' . esc_html__( 'Attribute', 'advanced-attribute-filters' ) . ' | '; echo '' . esc_html__( 'Enable', 'advanced-attribute-filters' ) . ' | '; echo '
|---|---|
| ' . esc_html( wc_attribute_label( $attr_name ) ) . ' | '; echo ''; echo ' |