expand_collapse_tabs(), array( $this, 'tabs_list' ), 'affwp_settings_affiliate_area_tabs', 'affwp_settings_affiliate_area_tabs' ); } /** * Add link to expand/collapse tabs * * @access private * @since 1.2 * * @return string */ private function expand_collapse_tabs() { ob_start(); $expand_text = __( 'Expand all tabs', 'affiliatewp-affiliate-area-tabs' ); $collapse_text = __( 'Collapse all tabs', 'affiliatewp-affiliate-area-tabs' ); ?>
$tab ) { /** * Reset any default tab's title based on the affiliate-wp * text domain. This ensures the tab title is correctly * translated again on save if the site's language is changed. */ $default_tabs = affiliatewp_affiliate_area_tabs()->functions->default_tabs(); if ( array_key_exists( $tab['slug'], $default_tabs ) ) { $new_value['affiliate_area_tabs'][$key]['title'] = $default_tabs[$tab['slug']]; } /** * Reset any add-on tab's title based on the add-on's text domain. * This ensures the tab title is correctly translated again on save * if the site's language is changed. */ $add_on_tabs = affiliatewp_affiliate_area_tabs()->functions->add_on_tabs(); if ( array_key_exists( $tab['slug'], $add_on_tabs ) ) { $new_value['affiliate_area_tabs'][$key]['title'] = $add_on_tabs[$tab['slug']]['title']; } // Skip sanitization on any non-custom tab. if ( 0 === $tab['id'] ) { continue; } // Tab's must have both a title and id assigned. if ( empty( $tab['title'] ) || ! isset( $tab['id'] ) ) { // Unset the tab unset( $new_value['affiliate_area_tabs'][$key] ); // Skip to the next tab. continue; } // Create an initial tab slug for custom tabs (core tabs already have a slug). if ( empty( $tab['slug'] ) ) { // Create a slug from the tab's title $new_value['affiliate_area_tabs'][$key]['slug'] = affiliatewp_affiliate_area_tabs()->functions->make_slug( $tab['title'] ); } // Force the tab ID to be an integer. $new_value['affiliate_area_tabs'][$key]['id'] = (int) $new_value['affiliate_area_tabs'][$key]['id']; // Determine if the tab is a custom tab. if ( isset( $tab['slug'] ) && affiliatewp_affiliate_area_tabs()->functions->is_custom_tab( $tab['slug'] ) ) { /** * Loop through the old values * * This is neccessary since custom tabs could have moved position via the admin interface. * * First we check if the custom tab exists in the old values. * If so, we then check its title. If the title changed, we attempt * To update its tab slug. */ foreach ( $old_value['affiliate_area_tabs'] as $old_key => $old_tab ) { // Found the custom slug, must be the same tab. if ( $old_tab['slug'] === $tab['slug'] ) { // Check to see if the tab's title was changed. if ( $old_tab['title'] !== $tab['title'] ) { // Create a new slug. $new_slug = affiliatewp_affiliate_area_tabs()->functions->make_slug( $tab['title'] ); /** * Check that the slug isn't already in-use. * AffiliateWP 2.17 or newer will look in the affwp_get_affiliate_area_tabs() function for the slug, * pre 2.1.7 will look in the currently saved tabs. * */ if ( ! array_key_exists( $new_slug, affiliatewp_affiliate_area_tabs()->functions->get_tabs() ) ) { // Slug isn't being used, use the new slug. $new_value['affiliate_area_tabs'][$key]['slug'] = $new_slug; } // If the new slug is already in-use, the slug will not change, and remain as its previous value. } } } } /** * Unset any tab if the page has the [affiliate_area] shotcode on it. */ if ( isset( $tab['id'] ) ) { $post = get_post( $tab['id'] ); $post_content = isset( $post->post_content ) ? $post->post_content : ''; if ( $post_content && has_shortcode( $post_content, 'affiliate_area' ) ) { unset( $new_value['affiliate_area_tabs'][$key] ); // Skip to the next tab. continue; } } } } return $new_value; } /** * Admin scripts. * * @access public * @since 1.2 */ public function admin_scripts() { // Admin CSS file. $screen = affwp_get_current_screen(); // Use minified libraries if SCRIPT_DEBUG is set to false. $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; // Register scripts. wp_register_style( 'aat-admin', AFFWP_AAT_PLUGIN_URL . 'assets/css/admin' . $suffix . '.css', array( 'dashicons' ), AFFWP_AAT_VERSION ); wp_register_script( 'aat-admin-scripts', AFFWP_AAT_PLUGIN_URL . 'assets/js/admin-scripts' . $suffix . '.js', array(), AFFWP_AAT_VERSION, false ); // Enqueue scripts. if ( $screen === 'affiliate-wp-settings' && isset( $_GET['tab'] ) && $_GET['tab'] === 'affiliate_area_tabs' ) { wp_enqueue_style( 'aat-admin' ); wp_enqueue_script( 'aat-admin-scripts' ); } } /** * Render the tabs list * * @since 1.0.0 */ public function tabs_list() { $tabs = affiliatewp_affiliate_area_tabs()->functions->get_tabs(); $count = count( $tabs ); $key = 0; ?>