PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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
← All changes | inc/admin/class-lp-setup-wizard.php +51 -160 4.1.6.94.4.8 View file →
@@ -21,48 +21,11 @@
21 21 protected function __construct() {
22 22 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
23 23 add_action( 'admin_init', array( $this, 'setup_wizard' ) );
24 24 add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
25 -
26 - $actions = array(
27 - 'setup-create-pages' => 'create_pages',
28 - 'get-price-format' => 'get_price_format',
29 - );
30 -
31 - foreach ( $actions as $action => $callback ) {
32 - LP_Request::register_ajax( $action, array( $this, $callback ) );
33 - }
34 25 }
35 26
36 27 /**
37 - * Create static pages action
38 - */
39 - public function create_pages() {
40 - if ( ! wp_verify_nonce( LP_Request::get_string( '_wpnonce', 'setup-create-pages' ) ) ) {
41 - die();
42 - }
43 -
44 - $settings = LP_Request::get( 'settings' );
45 - foreach ( $settings['pages'] as $page => $page_id ) {
46 - if ( empty( $page_id ) ) {
47 - $_REQUEST['settings']['pages'][ $page ] = $this->create_page( $page );
48 - }
49 - }
50 -
51 - LP_Request::$ajax_shutdown = false;
52 - }
53 -
54 - /**
55 - * Get sample format price
56 - */
57 - public static function get_price_format() {
58 - self::instance()->save();
59 - // LP_Settings::instance()->refresh();
60 - echo learn_press_format_price( 1234.56, true );
61 - die();
62 - }
63 -
64 - /**
65 28 * Create page by type.
66 29 *
67 30 * @param string $page
68 31 *
@@ -69,17 +32,19 @@
69 32 * @return int|WP_Error
70 33 */
71 34 public function create_page( $page ) {
72 35 $page_titles = array(
73 - 'courses_page_id' => _x( 'LP Courses', 'static-page', 'learnpress' ),
74 - 'profile_page_id' => _x( 'LP Profile', 'static-page', 'learnpress' ),
75 - 'checkout_page_id' => _x( 'LP Checkout', 'static-page', 'learnpress' ),
76 - 'become_a_teacher_page_id' => _x( 'LP Become Teacher', 'static-page', 'learnpress' ),
77 - 'term_conditions_page_id' => _x( 'LP Terms and Conditions', 'static-page', 'learnpress' ),
36 + 'courses_page_id' => _x( 'LP Courses', 'static-page', 'learnpress' ),
37 + 'profile_page_id' => _x( 'LP Profile', 'static-page', 'learnpress' ),
38 + 'checkout_page_id' => _x( 'LP Checkout', 'static-page', 'learnpress' ),
39 + 'become_a_teacher_page_id' => _x( 'LP Become a Teacher', 'static-page', 'learnpress' ),
40 + 'term_conditions_page_id' => _x( 'LP Terms and Conditions', 'static-page', 'learnpress' ),
41 + 'instructors_page_id' => _x( 'Instructors', 'static-page', 'learnpress' ),
42 + 'single_instructor_page_id' => _x( 'Instructor', 'static-page', 'learnpress' ),
78 43 );
79 44
80 45 if ( $page === 'profile_page_id' ) {
81 - $page_content = '<!-- wp:shortcode -->[' . apply_filters( 'learn-press/shortcode/profile/tag', 'learn_press_profile' ) . ']<!-- /wp:shortcode -->';
46 + $page_content = '<!-- wp:shortcode -->[learn_press_profile]<!-- /wp:shortcode -->';
82 47 } else {
83 48 $page_content = '';
84 49 }
85 50
@@ -84,12 +49,12 @@
84 49 }
85 50
86 51 return wp_insert_post(
87 52 array(
88 - 'post_title' => $page_titles[ $page ],
53 + 'post_title' => $page_titles[ $page ] ?? $page,
89 54 'post_status' => 'publish',
90 55 'post_type' => 'page',
91 - 'post_content' => isset( $page_content ) ? $page_content : '',
56 + 'post_content' => $page_content,
92 57 )
93 58 );
94 59 }
95 60
@@ -96,11 +61,13 @@
96 61 /**
97 62 * Add an empty menu item for validating page.
98 63 */
99 64 public function admin_menu() {
100 - if ( 'lp-setup' !== LP_Request::get_string( 'page' ) || ! current_user_can( 'install_plugins' ) ) {
65 + if ( 'lp-setup' !== LP_Request::get_param( 'page' )
66 + || ! current_user_can( 'install_plugins' ) ) {
101 67 return;
102 68 }
69 +
103 70 add_dashboard_page( '', '', 'manage_options', 'lp-setup', '' );
104 71 }
105 72
106 73 /**
@@ -106,52 +73,13 @@
106 73 /**
107 74 * Display setup page a ignore anything else in the rest
108 75 */
109 76 public function setup_wizard() {
110 - if ( 'lp-setup' !== LP_Request::get_string( 'page' ) || ! current_user_can( 'install_plugins' ) ) {
77 + if ( 'lp-setup' !== LP_Request::get_param( 'page' )
78 + || ! current_user_can( 'install_plugins' ) ) {
111 79 return;
112 80 }
113 81
114 - if ( 'finish' === LP_Request::get_string( 'step' ) ) {
115 -
116 - // LP_Install::create_options();
117 -
118 - update_option( 'learn_press_setup_wizard_completed', 'yes' );
119 - }
120 -
121 - // LP_Install::create_tables();
122 -
123 - $this->save();
124 -
125 - // Refresh new changes
126 - // LP_Settings::instance()->refresh();
127 -
128 - $assets = learn_press_admin_assets();
129 -
130 - // tungnx: fix error with Woocommerce
131 - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Loader', 'register_scripts' ) );
132 - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Loader', 'load_scripts' ), 15 );
133 - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Features\Features', 'load_scripts' ), 15 );
134 - // End fix
135 - // @do_action( 'admin_enqueue_scripts' );
136 -
137 - wp_enqueue_style( 'buttons' );
138 - wp_enqueue_style( 'common' );
139 - wp_enqueue_style( 'forms' );
140 - wp_enqueue_style( 'themes' );
141 - wp_enqueue_style( 'dashboard' );
142 - wp_enqueue_style( 'widgets' );
143 - wp_enqueue_style( 'lp-admin', $assets->url( 'css/admin/admin.css' ) );
144 - wp_enqueue_style( 'lp-setup', $assets->url( 'css/admin/setup.css' ) );
145 - wp_enqueue_style( 'lp-select2', $assets->url( 'src/css/vendor/select2.min.css' ) );
146 -
147 - wp_enqueue_script( 'lp-select2', $assets->url( 'src/js/vendor/select2.full.min.js' ) );
148 - wp_enqueue_script( 'lp-utils', $assets->url( 'js/dist/utils.js' ) );
149 - wp_enqueue_script( 'lp-admin', $assets->url( 'src/js/admin/admin.js' ), uniqid(), true );
150 - wp_enqueue_script( 'drop-down-page', $assets->url( 'src/js/admin/share/dropdown-pages.js' ), uniqid(), true );
151 - wp_register_script( 'lp-setup', $assets->url( 'js/dist/admin/pages/setup.js' ), array( 'jquery', 'lp-admin' ), uniqid(), true );
152 - wp_localize_script( 'lp-setup', 'lpGlobalSettings', learn_press_global_script_params() );
153 - wp_enqueue_script( 'lp-setup' );
154 82 learn_press_admin_view( 'setup/header' );
155 83 learn_press_admin_view( 'setup/content', array( 'steps' => $this->get_steps() ) );
156 84 learn_press_admin_view( 'setup/footer' );
157 85
@@ -157,51 +85,8 @@
157 85
158 86 die();
159 87 }
160 88
161 - public function save() {
162 - $step = LP_Request::get_string( 'lp-setup-step' );
163 -
164 - if ( ! wp_verify_nonce( LP_Request::get_string( 'lp-setup-nonce' ), 'lp-setup-step-' . $step ) ) {
165 - return;
166 - }
167 -
168 - $postdata = LP_Request::get_array( 'settings' );
169 - $steps = array( 'payment', 'pages', 'currency', 'emails' );
170 -
171 - if ( ( 'yes' !== LP_Request::get( 'skip' ) ) && in_array( $step, $steps ) ) {
172 - if ( array_key_exists( 'paypal', $postdata ) ) {
173 - update_option( 'learn_press_paypal', $postdata['paypal'] );
174 - }
175 -
176 - if ( array_key_exists( 'currency', $postdata ) ) {
177 - foreach ( $postdata['currency'] as $k => $v ) {
178 - update_option( 'learn_press_' . $k, $v );
179 - }
180 - }
181 -
182 - if ( array_key_exists( 'pages', $postdata ) ) {
183 - foreach ( $postdata['pages'] as $k => $v ) {
184 - update_option( 'learn_press_' . $k, $v );
185 - }
186 - }
187 -
188 - if ( array_key_exists( 'emails', $postdata ) ) {
189 - if ( ! empty( $postdata['emails']['enable'] ) && ( $postdata['emails']['enable'] === 'yes' ) ) {
190 - $emails = LP_Emails::instance()->emails;
191 -
192 - if ( $emails ) {
193 - foreach ( $emails as $email ) {
194 - $response[ $email->id ] = $email->enable( true );
195 - }
196 - }
197 - }
198 - }
199 - }
200 -
201 - do_action( 'learn-press/setup-wizard/update-settings', $postdata, $step );
202 - }
203 -
204 89 /**
205 90 * Return array of all steps are available when running setup wizard.
206 91 *
207 92 * @return array
@@ -206,40 +91,38 @@
206 91 *
207 92 * @return array
208 93 */
209 94 public function get_steps() {
210 - static $steps = false;
211 - if ( ! $steps ) {
95 + static $steps;
96 + if ( is_null( $steps ) ) {
212 97 $steps = apply_filters(
213 98 'learn-press/setup-wizard/steps',
214 99 array(
215 - 'welcome' => array(
100 + 'welcome' => array(
216 101 'title' => __( 'Welcome', 'learnpress' ),
217 102 'callback' => array( $this, 'step_welcome' ),
218 - 'next_button' => __( 'Run Setup Wizard', 'learnpress' ),
103 + 'next_button' => __( 'Get Started', 'learnpress' ),
219 104 ),
220 - 'pages' => array(
105 + 'learning-experience' => array(
106 + 'title' => __( 'Learning Experience', 'learnpress' ),
107 + 'callback' => array( $this, 'step_learning_experience' ),
108 + ),
109 + 'pages' => array(
221 110 'title' => __( 'Pages', 'learnpress' ),
222 111 'callback' => array( $this, 'step_pages' ),
223 112 ),
224 - // 'currency' => array(
225 - // 'title' => __( 'Currency', 'learnpress' ),
226 - // 'callback' => array( $this, 'step_currency' ),
227 - // 'back_button' => false,
228 - // 'skip_prev_button' => false
229 - // ),
230 - 'payment' => array(
231 - 'title' => __( 'Payment', 'learnpress' ),
232 - 'callback' => array( $this, 'step_payment' ),
233 - ),
234 - // 'emails' => array(
235 - // 'title' => __( 'Emails', 'learnpress' ),
236 - // 'callback' => array( $this, 'step_emails' )
237 - // ),
238 - 'finish' => array(
239 - 'title' => __( 'Finish', 'learnpress' ),
240 - 'callback' => array( $this, 'step_finish' ),
241 - ),
113 + 'payment' => array(
114 + 'title' => __( 'Payment & Currency', 'learnpress' ),
115 + 'callback' => array( $this, 'step_payment' ),
116 + ),
117 + 'emails' => array(
118 + 'title' => __( 'Emails', 'learnpress' ),
119 + 'callback' => array( $this, 'step_emails' ),
120 + ),
121 + 'finish' => array(
122 + 'title' => __( 'Finish', 'learnpress' ),
123 + 'callback' => array( $this, 'step_finish' ),
124 + ),
242 125 )
243 126 );
244 127 }
245 128
@@ -262,9 +145,9 @@
262 145 *
263 146 * @return mixed|string
264 147 */
265 148 public function get_current_step( $key = true ) {
266 - $current = LP_Request::get_string( 'step' );
149 + $current = LP_Request::get_param( 'step' );
267 150 $steps = $this->get_steps();
268 151
269 152 if ( empty( $steps[ $current ] ) ) {
270 153 $key_steps = array_keys( $steps );
@@ -310,9 +193,9 @@
310 193 $current = $this->get_current_step();
311 194 $steps = $this->get_step_keys();
312 195 $at = array_search( $current, $steps );
313 196 if ( $at < sizeof( $steps ) - 1 ) {
314 - $at ++;
197 + ++$at;
315 198 }
316 199
317 200 return esc_url_raw( add_query_arg( 'step', $steps[ $at ], admin_url( $this->_base_url ) ) );
318 201 }
@@ -326,9 +209,9 @@
326 209 $current = $this->get_current_step();
327 210 $steps = $this->get_step_keys();
328 211 $at = array_search( $current, $steps );
329 212 if ( $at > 0 ) {
330 - $at --;
213 + --$at;
331 214 }
332 215
333 216 return esc_url_raw( add_query_arg( 'step', $steps[ $at ], admin_url( $this->_base_url ) ) );
334 217 }
@@ -353,9 +236,9 @@
353 236 public function get_payments() {
354 237 return array(
355 238 'paypal' => array(
356 239 'name' => __( 'PayPal', 'learnpress' ),
357 - 'icon' => LP()->plugin_url( '/assets/images/paypal-2.png' ),
240 + 'icon' => LearnPress::instance()->plugin_url( 'assets/images/paypal-logo-preview.png' ),
358 241 'callback' => array( $this, 'setup_paypal' ),
359 242 ),
360 243 );
361 244 }
@@ -375,8 +258,15 @@
375 258 learn_press_admin_view( 'setup/steps/welcome' );
376 259 }
377 260
378 261 /**
262 + * Learning Experience step content.
263 + */
264 + public function step_learning_experience() {
265 + learn_press_admin_view( 'setup/steps/learning-experience' );
266 + }
267 +
268 + /**
379 269 * Currency step content.
380 270 */
381 271 public function step_currency() {
382 272 learn_press_admin_view( 'setup/steps/currency' );
@@ -395,8 +285,9 @@
395 285 }
396 286
397 287 public function step_finish() {
398 288 learn_press_admin_view( 'setup/steps/finish' );
289 + update_option( 'learn_press_setup_wizard_completed', 'yes' );
399 290 }
400 291
401 292 public function scripts() {
402 293 }
@@ -406,11 +297,10 @@
406 297 *
407 298 * @return bool|LP_Setup_Wizard
408 299 */
409 300 public static function instance() {
410 - static $instance = false;
411 -
412 - if ( ! $instance ) {
301 + static $instance;
302 + if ( is_null( $instance ) ) {
413 303 $instance = new self();
414 304 }
415 305
416 306 return $instance;
@@ -415,5 +305,6 @@
415 305
416 306 return $instance;
417 307 }
418 308 }
309 +
419 310 return LP_Setup_Wizard::instance();