input( 'tab', 'get', 'general' ) ); /** * Filter: adfuz/settings/tabs * Allows Pro (or other plugins) to register additional tabs. * * @param array $tabs [ slug => [ 'label' => '', 'icon' => '' ] ] */ $tabs = apply_filters( 'adfuz/settings/tabs', array( 'general' => array( 'label' => __( 'General', 'ad-fuz' ), 'icon' => 'dashicons-admin-settings', ), 'geolite' => array( 'label' => __( 'GeoLite2', 'ad-fuz' ), 'icon' => 'dashicons-location-alt', ), 'ai' => array( 'label' => __( 'AI Settings', 'ad-fuz' ), 'icon' => 'dashicons-superhero-alt', ), ) ); // Fallback to first tab if the requested tab is not registered if ( ! array_key_exists( $active_tab, $tabs ) ) { $active_tab = array_key_first( $tabs ); } /** * Action: adfuz_settings_before_render_{tab} * Allows Pro to inject data for its own tabs before render. */ $tab_data = array(); $tab_data = apply_filters( "adfuz/settings/tab/data/{$active_tab}", $tab_data ); /** * Filter: adfuz/settings/tab/template/dir * Allows Pro (or any plugin) to override the template base directory * for a specific tab so templates can live outside the Free plugin. * * @param string $template_dir Default: ADFUZ_TEMPLATE_DIR (Free plugin) * @param string $active_tab The current active tab slug */ $template_dir = apply_filters( 'adfuz/settings/tab/template/dir', ADFUZ_TEMPLATE_DIR, $active_tab ); Template::load( 'admin/settings/index', compact( 'active_tab', 'tabs', 'tab_data', 'template_dir' ) ); } /** * AJAX: Save settings. * Hook: wp_ajax_adfuz_settings_save * Each tab save is delegated via action hook so Pro can handle its own tabs. */ public static function save(): void { Common::checkCapability( static::get_capabilities() ); Common::verifyNonce(); $request = ( new Request() ); // Common::checkCapability() and Common::verifyNonce() are called at the top for capability and nonce check. // phpcs:ignore WordPress.Security.NonceVerification.Recommended $tab = sanitize_key( wp_unslash( $request->input( 'tab', 'post', $request->input( 'tab', 'get', 'general' ) ) ) ); /** * Action: adfuz/settings/save/{tab} * Pro hooks in here to handle saving its own tab data. * Must call wp_send_json_success/error itself. */ do_action( "adfuz/settings/save/{$tab}" ); // Fallback if no handler called a response. wp_send_json_error( array( 'message' => __( 'No handler for this tab.', 'ad-fuz' ) ) ); } }