parse_args( $args ); } /** * Implement magic __set to avoid PHP 8.2 dynamic property deprecation */ public function __set( $name, $value ) { $this->$name = $value; } /** * Implement magic __set to avoid PHP 8.2 dynamic property deprecation */ public function __get( $name ) { return $this->$name; } /** * Parse the arguments passed in the construction and assign them to * internal variables. * @since 1.1 */ private function parse_args( $args ) { foreach ( $args as $key => $val ) { switch ( $key ) { case 'id' : $this->{$key} = esc_attr( $val ); default : $this->{$key} = $val; } } } /** * Modify the capability required to save settings on this page * @since 2.0 */ public function modify_required_capability( $cap ) { return $this->capability; } /** * Add the page to the appropriate menu slot. * @note The default will be to post to the options page, but other classes * should override this function. * @since 1.0 */ public function add_admin_menu() { call_user_func( $this->setup_function, $this->title, $this->menu_title, $this->capability, $this->id, array( $this, 'display_admin_menu' ) ); } /** * Add a section to the page * @since 1.0 */ public function add_section( $section ) { if ( !$section ) { return; } $this->sections[ $section->id ] = $section; } /** * Register the settings and sanitization callbacks for each setting * @since 1.0 */ public function register_admin_menu() { foreach ( $this->sections as $section ) { $section->add_settings_section(); foreach ( $section->settings as $setting ) { $setting->add_settings_field( $section->id ); } } register_setting( $this->id, $this->id, array( $this, 'sanitize_callback' ) ); // Modify capability required to save the settings if it's not // the default `manage_options` if ( !empty( $this->capability ) && $this->capability !== 'manage_options') { add_filter( 'option_page_capability_' . $this->id, array( $this, 'modify_required_capability' ) ); } } /** * Loop through the settings and sanitize the data * @since 2.0 */ public function sanitize_callback( $value ) { if ( empty( $_POST['_wp_http_referer'] ) ) { return $value; } // Get the current page/tab so we only update those settings parse_str( sanitize_url( wp_unslash( $_POST['_wp_http_referer'] ) ), $referrer ); $current_page = $this->get_current_page( $referrer ); // Use a new empty value so only values for settings that were added are // passed to the db. $new_value = array(); foreach ( $this->sections as $section ) { foreach ( $section->settings as $setting ) { if ( $setting->tab == $current_page ) { $setting_value = isset( $value[$setting->id] ) ? $value[$setting->id] : ''; $new_value[$setting->id] = $setting->sanitize_callback_wrapper( $setting_value ); } } } // Pull in the existing values so we never overwrite values that were // on a different tab $old_value = get_option( $this->id ); if ( is_array( $old_value ) ) { return array_merge( $old_value, $new_value ); } else { return $new_value; } } /** * Get the current page/tab being viewed * @since 2.0 */ public function get_current_page( $request ) { if ( !empty( $request['tab'] ) ) { return sanitize_text_field( $request['tab'] ); } elseif ( !empty( $this->default_tab ) ) { return $this->default_tab; } else { return $this->id; } } /** * Output the settings passed to this page * @since 1.0 */ public function display_admin_menu() { if ( !$this->title && !count( $this->settings ) ) { return; } if ( !current_user_can( $this->capability ) ) { wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'simple-admin-pages') ); } $current_page = $this->get_current_page( $_GET ); // Fetch and Order sections/tabs $tab_list = []; $non_tab_list = []; $bottom = 1000; foreach( $this->sections as $section ) { if ( isset( $section->is_tab ) && $section->is_tab === true ) { if( property_exists( $section, 'rank' ) ) { // array start from 0, rank start from 1 $tab_list[ $section->rank - 1 ][] = $section; } else { $tab_list[$bottom][] = $section; } } else { $non_tab_list[] = $section; } } $this->sections = []; ksort($tab_list); foreach ($tab_list as $rank => $sub_list) { $this->sections = array_merge( $this->sections, $sub_list ); } $this->sections = array_merge( $this->sections, $non_tab_list ); ?>
display_page_title(); ?> default_tab ) ) : ?>
id ); ?> maybe_print_tutorial_div( $current_page ); ?> show_button ) { submit_button(); } ?>
title ) ) { return; } ?>

title ); ?>

sections as $section ) { if ( $current_page == $section->id and ! empty( $section->tutorial_yt_id ) ) { ?>