PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.3.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.3.9.1
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / admin / sub-menus / class-lp-submenu-settings.php

class-lp-submenu-settings.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.3.9.1, at inc/admin/sub-menus/class-lp-submenu-settings.php

185 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use LearnPress\Models\UserModel;
4 use LearnPress\Services\UserService;
5
6 defined( 'ABSPATH' ) || exit();
7
8 /**
9 * Class LP_Submenu_Settings
10 */
11 class LP_Submenu_Settings extends LP_Abstract_Submenu {
12 /**
13 * @var LP_Abstract_Settings_Page[]
14 */
15 protected $tabs = array();
16
17 /**
18 * LP_Submenu_Settings constructor.
19 */
20 public function __construct() {
21 $this->id = 'learn-press-settings';
22 $this->menu_title = esc_html__( 'Settings', 'learnpress' );
23 $this->page_title = esc_html__( 'LearnPress Settings', 'learnpress' );
24 $this->priority = 30;
25 $this->callback = [ $this, 'display' ];
26
27 $this->tabs = apply_filters(
28 'learn-press/admin/settings-tabs-array',
29 array(
30 'general' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-general.php',
31 'courses' => new LP_Settings_Courses(),
32 'profile' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-profile.php',
33 'payments' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-payments.php',
34 'emails' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-emails.php',
35 'permalink' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-permalink.php',
36 'advanced' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-advanced.php',
37 'open-ai' => include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-open-ai.php',
38 )
39 );
40
41 if ( learn_press_is_mcp_available() ) {
42 $this->tabs['mcp'] = include_once LP_PLUGIN_PATH . 'inc/admin/settings/class-lp-settings-mcp.php';
43 }
44
45 add_action( 'learn-press/admin/page-content-settings', array( $this, 'page_contents' ) );
46 add_action( 'learn-press/admin/page-' . $this->_get_page() . '/section-content', array( $this, 'section_content' ) );
47
48 /** Save metabox in LP4 */
49 add_action( 'admin_init', array( $this, 'save_settings' ) );
50
51 parent::__construct();
52 }
53
54 /**
55 * Display menu content
56 */
57 public function page_content() {
58 parent::page_content();
59 }
60
61 public function page_contents() {
62 $active_tab = $this->get_active_tab();
63 $section = $this->get_active_section();
64
65 if ( 'permalink' === $active_tab && isset( $_GET['lp-user-slug-generated'] ) ) {
66 $processed = absint( $_GET['lp-user-slug-processed'] ?? 0 );
67 $generated = absint( $_GET['lp-user-slug-generated'] ?? 0 );
68 $skipped = absint( $_GET['lp-user-slug-skipped'] ?? 0 );
69 $failed = absint( $_GET['lp-user-slug-failed'] ?? 0 );
70 ?>
71 <div class="notice notice-success">
72 <p>
73 <?php
74 echo esc_html(
75 sprintf(
76 /* translators: 1: processed users, 2: generated slugs, 3: skipped users, 4: failed users */
77 __( 'User slug generation finished. Processed: %1$d, Generated: %2$d, Skipped: %3$d, Failed: %4$d.', 'learnpress' ),
78 $processed,
79 $generated,
80 $skipped,
81 $failed
82 )
83 );
84 ?>
85 </p>
86 </div>
87 <?php
88 }
89
90 $this->tabs[ $active_tab ]->admin_page_settings( $section, $this->get_sections() );
91
92 $hide_save_button = false;
93 if ( 'mcp' === $active_tab ) {
94 $hide_save_button = ! learn_press_is_mcp_available();
95 }
96 ?>
97
98 <?php if ( ! $hide_save_button ) : ?>
99 <input type="hidden" name="lp-settings-nonce" value="<?php echo wp_create_nonce( 'lp-settings' ); ?>">
100 <p class="lp-admin-settings-buttons">
101 <button class="button button-primary"><?php esc_html_e( 'Save settings', 'learnpress' ); ?></button>
102 </p>
103 <?php endif; ?>
104
105 <?php
106 }
107
108 public function section_content( $section ) {
109 }
110
111 /**
112 * Update metabox setting
113 *
114 * @return void
115 * @version 4.0.1
116 * @author ThimPress <nhamdv>
117 */
118 public function save_settings() {
119 if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR )
120 | ! is_admin() || ! isset( $_GET['page'] )
121 || 'learn-press-settings' !== $_GET['page'] ) {
122 return;
123 }
124
125 $nonce = learn_press_get_request( 'lp-settings-nonce' );
126
127 if ( ! wp_verify_nonce( $nonce, 'lp-settings' ) ) {
128 return;
129 }
130
131 $active_tab = $this->get_active_tab();
132
133 $this->tabs[ $active_tab ]->save_settings( $this->get_active_section(), $this->get_sections() );
134
135 $redirect_args = array();
136 if ( 'permalink' === $active_tab &&
137 'yes' === LP_Request::get_param( 'lp_generate_user_slug' ) ) {
138 $result = UserService::instance()->generate_users_pretty_slug();
139 $redirect_args = array(
140 'lp-user-slug-generated' => $result['generated'],
141 'lp-user-slug-processed' => $result['processed'],
142 'lp-user-slug-skipped' => $result['skipped'],
143 'lp-user-slug-failed' => $result['failed'],
144 );
145 }
146
147 do_action( 'learn-press/update-settings/updated', $this );
148
149 // Clear cache settings
150 $lp_settings_cache = new LP_Settings_Cache( true );
151 $lp_settings_cache->clean_lp_settings();
152
153 // Clear cache lp rewrite rules
154 //$lp_settings_cache->clean_lp_rewrite_rules();
155
156 // Flush rewrite rules after save settings.
157 if ( isset( $_REQUEST['tab'] ) && 'permalink' === $_REQUEST['tab'] ) {
158 flush_rewrite_rules();
159 }
160
161 // Filter redirect
162 $redirect = apply_filters(
163 'learn-press/update-settings/redirect',
164 esc_url_raw(
165 add_query_arg(
166 array_merge(
167 array( 'settings-updated' => 'yes' ),
168 $redirect_args
169 )
170 )
171 ),
172 $this
173 );
174 if ( $redirect ) {
175 wp_safe_redirect( $redirect );
176 exit();
177 }
178 }
179
180 public function save() {
181 }
182 }
183
184 return new LP_Submenu_Settings();
185