tabs ) { return $this->tabs; } $tabs = apply_filters( 'learn-press/admin/settings-tabs-array', array( 'general' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-general.php', 'courses' => new LP_Settings_Courses(), 'profile' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-profile.php', 'payments' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-payments.php', 'emails' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-emails.php', 'permalink' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-permalink.php', 'advanced' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-advanced.php', 'open-ai' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-open-ai.php', 'addons' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-addons.php', ) ); // Check if no addon config on tab addons then remove it. if ( isset( $tabs['addons'] ) && $tabs['addons'] instanceof LP_Settings_Addons && ! $tabs['addons']->has_sections() ) { unset( $tabs['addons'] ); } $this->tabs = apply_filters( 'learn-press/submenu-' . self::PAGE_ID . '-heading-tabs', $tabs ); return $this->tabs; } /** * Get active tab by checking ?tab=tab-name. * * @return bool|string */ public function get_active_tab() { $tabs = $this->get_tabs(); if ( ! $tabs ) { return false; } $tab = LP_Helper::sanitize_params_submitted( $_REQUEST['tab'] ?? '' ); if ( empty( $tab ) || empty( $tabs[ $tab ] ) ) { $tab_keys = array_keys( $tabs ); $tab = reset( $tab_keys ); } return $tab; } /** * Get sections of the active tab. * * @return array */ public function get_sections(): array { $tabs = $this->get_tabs(); $active_tab = $this->get_active_tab(); $sections = array(); if ( ! empty( $tabs[ $active_tab ] ) && is_callable( array( $tabs[ $active_tab ], 'get_sections' ) ) ) { $sections = call_user_func( array( $tabs[ $active_tab ], 'get_sections' ) ); } return apply_filters( 'learn-press/submenu-sections', $sections ); } /** * Get active section by checking ?section=section-name. * * @return bool|string */ public function get_active_section() { $sections = $this->get_sections(); if ( ! $sections ) { return false; } $section = LP_Helper::sanitize_params_submitted( $_REQUEST['section'] ?? '' ); if ( empty( $section ) || empty( $sections[ $section ] ) ) { $section_keys = array_keys( $sections ); $section = reset( $section_keys ); } return $section; } /** * Output section navigation. Hooked to 'learn-press/admin/page-content-sections'. * * @return void */ public function output_section_nav() { if ( self::PAGE_ID !== LP_Request::get_param( 'page' ) ) { return; } $active_section = $this->get_active_section(); $sections = $this->get_sections(); if ( ! $sections ) { return; } ?> get_tabs(); $active_tab = $this->get_active_tab(); $section = $this->get_active_section(); if ( 'permalink' === $active_tab && isset( $_GET['lp-user-slug-generated'] ) ) { $processed = absint( $_GET['lp-user-slug-processed'] ?? 0 ); $generated = absint( $_GET['lp-user-slug-generated'] ?? 0 ); $skipped = absint( $_GET['lp-user-slug-skipped'] ?? 0 ); $failed = absint( $_GET['lp-user-slug-failed'] ?? 0 ); ?>

admin_page_settings( $section, $this->get_sections() ); $hide_save_button = false; if ( 'advanced' === $active_tab && 'mcp' === $section && class_exists( 'LP_Settings_Advanced' ) ) { $hide_save_button = ! learn_press_is_mcp_available(); } ?>

'; if ( $this->get_tabs() ) { $tab = $this->get_active_tab(); do_action( 'learn-press/admin/before-page-content-sections', 'settings', $tab ); do_action( 'learn-press/admin/page-content-settings', $tab ); do_action( 'learn-press/admin/page-content-settings/' . $tab ); do_action( 'learn-press/admin/after-page-content-sections', 'settings', $tab ); } echo ''; } /** * Main callback for the Settings admin page. Used as 'callback' in * config/wp-menus.php, same pattern as the other menus. * * @return void */ public function html_page() { $tabs = $this->get_tabs(); $active_tab = $this->get_active_tab(); $flat_tabs = array(); foreach ( $tabs as $tab_slug => $tab_obj ) { $tab_id = $tab_obj->id ?? $tab_slug; $tab_title = $tab_obj->text ?? $tab_slug; $flat_tabs[ $tab_id ] = apply_filters( 'learn-press/admin/submenu-heading-tab-title', $tab_title, $tab_id ); } ob_start(); do_action( 'learn-press/admin/heading-icon', $active_tab ); echo esc_html__( 'Settings', 'learnpress' ); do_action( 'learn-press/admin/heading-title', $active_tab ); $title = ob_get_clean(); $classes = array( 'lp-admin-tabs' ); $sections = $this->get_sections(); $has_sections = $sections && sizeof( $sections ) > 1; $has_sections = apply_filters( 'learn-press/admin/submenu-has-sections', $has_sections, $sections, $active_tab ); if ( $has_sections ) { $classes[] = 'has-sections'; } ob_start(); $this->page_content(); $page_content = ob_get_clean(); $wrapper = array( sprintf( '
', esc_attr( implode( ' ', $classes ) ) ) => '
', ); echo AdminTemplate::html_on_wp_admin_screen( array( 'tabs' => $flat_tabs, 'content' => Template::instance()->nest_elements( $wrapper, $page_content ), 'title' => $title, 'id' => self::PAGE_ID, ) ); } /** * Save settings of the active tab. Hooked to 'admin_init'. * * @return void */ public function save_settings() { if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) || ! is_admin() || ! isset( $_GET['page'] ) || self::PAGE_ID !== $_GET['page'] ) { return; } $nonce = learn_press_get_request( 'lp-settings-nonce' ); if ( ! wp_verify_nonce( $nonce, 'lp-settings' ) ) { return; } $tabs = $this->get_tabs(); $active_tab = $this->get_active_tab(); $tabs[ $active_tab ]->save_settings( $this->get_active_section(), $this->get_sections() ); $redirect_args = array(); if ( 'permalink' === $active_tab && 'yes' === LP_Request::get_param( 'lp_generate_user_slug' ) ) { $result = UserService::instance()->generate_users_pretty_slug(); $redirect_args = array( 'lp-user-slug-generated' => $result['generated'], 'lp-user-slug-processed' => $result['processed'], 'lp-user-slug-skipped' => $result['skipped'], 'lp-user-slug-failed' => $result['failed'], ); } do_action( 'learn-press/update-settings/updated' ); // Clear cache settings. $lp_settings_cache = new LP_Settings_Cache( true ); $lp_settings_cache->clean_lp_settings(); // Flush rewrite rules after save settings. if ( isset( $_REQUEST['tab'] ) && 'permalink' === $_REQUEST['tab'] ) { flush_rewrite_rules(); } // Filter redirect. $redirect = apply_filters( 'learn-press/update-settings/redirect', esc_url_raw( add_query_arg( array_merge( array( 'settings-updated' => 'yes' ), $redirect_args ) ) ) ); if ( $redirect ) { wp_safe_redirect( $redirect ); exit(); } } }