| @@ -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 a 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,47 +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 | - update_option( 'learn_press_setup_wizard_completed', 'yes' ); | |
| 116 | - } | |
| 117 | - | |
| 118 | - $this->save(); | |
| 119 | - | |
| 120 | - // Refresh new changes | |
| 121 | - // LP_Settings::instance()->refresh(); | |
| 122 | - | |
| 123 | - $assets = learn_press_admin_assets(); | |
| 124 | - | |
| 125 | - // tungnx: fix error with Woocommerce | |
| 126 | - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Loader', 'register_scripts' ) ); | |
| 127 | - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Loader', 'load_scripts' ), 15 ); | |
| 128 | - remove_action( 'admin_enqueue_scripts', array( 'Automattic\WooCommerce\Admin\Features\Features', 'load_scripts' ), 15 ); | |
| 129 | - // End fix | |
| 130 | - // @do_action( 'admin_enqueue_scripts' ); | |
| 131 | - | |
| 132 | - wp_enqueue_style( 'buttons' ); | |
| 133 | - wp_enqueue_style( 'common' ); | |
| 134 | - wp_enqueue_style( 'forms' ); | |
| 135 | - wp_enqueue_style( 'themes' ); | |
| 136 | - wp_enqueue_style( 'dashboard' ); | |
| 137 | - wp_enqueue_style( 'widgets' ); | |
| 138 | - wp_enqueue_style( 'lp-admin', $assets->url( 'css/admin/admin.css' ) ); | |
| 139 | - wp_enqueue_style( 'lp-setup', $assets->url( 'css/admin/setup.css' ) ); | |
| 140 | - wp_enqueue_style( 'lp-select2', $assets->url( 'src/css/vendor/select2.min.css' ) ); | |
| 141 | - | |
| 142 | - wp_enqueue_script( 'lp-select2', $assets->url( 'src/js/vendor/select2.full.min.js' ) ); | |
| 143 | - wp_enqueue_script( 'lp-utils', $assets->url( 'js/dist/utils.js' ) ); | |
| 144 | - wp_enqueue_script( 'lp-admin', $assets->url( 'src/js/admin/admin.js' ), uniqid(), true ); | |
| 145 | - wp_enqueue_script( 'drop-down-page', $assets->url( 'src/js/admin/share/dropdown-pages.js' ), uniqid(), true ); | |
| 146 | - wp_register_script( 'lp-setup', $assets->url( 'js/dist/admin/pages/setup.js' ), array( 'jquery', 'lp-admin' ), uniqid(), true ); | |
| 147 | - wp_localize_script( 'lp-setup', 'lpGlobalSettings', learn_press_global_script_params() ); | |
| 148 | - wp_enqueue_script( 'lp-setup' ); | |
| 149 | 82 | learn_press_admin_view( 'setup/header' ); |
| 150 | 83 | learn_press_admin_view( 'setup/content', array( 'steps' => $this->get_steps() ) ); |
| 151 | 84 | learn_press_admin_view( 'setup/footer' ); |
| 152 | 85 | |
| @@ -153,91 +86,43 @@ | ||
| 153 | 86 | die(); |
| 154 | 87 | } |
| 155 | 88 | |
| 156 | 89 | /** |
| 157 | - * @TODO tungnx - need review | |
| 158 | - */ | |
| 159 | - public function save() { | |
| 160 | - $step = LP_Request::get_string( 'lp-setup-step' ); | |
| 161 | - | |
| 162 | - if ( ! wp_verify_nonce( LP_Request::get_string( 'lp-setup-nonce' ), 'lp-setup-step-' . $step ) ) { | |
| 163 | - return; | |
| 164 | - } | |
| 165 | - | |
| 166 | - $postdata = LP_Request::get_array( 'settings' ); | |
| 167 | - $steps = array( 'payment', 'pages', 'currency', 'emails' ); | |
| 168 | - | |
| 169 | - if ( ( 'yes' !== LP_Request::get( 'skip' ) ) && in_array( $step, $steps ) ) { | |
| 170 | - if ( array_key_exists( 'paypal', $postdata ) ) { | |
| 171 | - update_option( 'learn_press_paypal', $postdata['paypal'] ); | |
| 172 | - } | |
| 173 | - | |
| 174 | - if ( array_key_exists( 'currency', $postdata ) ) { | |
| 175 | - foreach ( $postdata['currency'] as $k => $v ) { | |
| 176 | - update_option( 'learn_press_' . $k, $v ); | |
| 177 | - } | |
| 178 | - } | |
| 179 | - | |
| 180 | - if ( array_key_exists( 'pages', $postdata ) ) { | |
| 181 | - foreach ( $postdata['pages'] as $k => $v ) { | |
| 182 | - update_option( 'learn_press_' . $k, $v ); | |
| 183 | - } | |
| 184 | - } | |
| 185 | - | |
| 186 | - if ( array_key_exists( 'emails', $postdata ) ) { | |
| 187 | - if ( ! empty( $postdata['emails']['enable'] ) && ( $postdata['emails']['enable'] === 'yes' ) ) { | |
| 188 | - $emails = LP_Emails::instance()->emails; | |
| 189 | - | |
| 190 | - if ( $emails ) { | |
| 191 | - foreach ( $emails as $email ) { | |
| 192 | - $response[ $email->id ] = $email->enable( true ); | |
| 193 | - } | |
| 194 | - } | |
| 195 | - } | |
| 196 | - } | |
| 197 | - } | |
| 198 | - | |
| 199 | - do_action( 'learn-press/setup-wizard/update-settings', $postdata, $step ); | |
| 200 | - } | |
| 201 | - | |
| 202 | - /** | |
| 203 | 90 | * Return array of all steps are available when running setup wizard. |
| 204 | 91 | * |
| 205 | 92 | * @return array |
| 206 | 93 | */ |
| 207 | 94 | public function get_steps() { |
| 208 | - static $steps = false; | |
| 209 | - if ( ! $steps ) { | |
| 95 | + static $steps; | |
| 96 | + if ( is_null( $steps ) ) { | |
| 210 | 97 | $steps = apply_filters( |
| 211 | 98 | 'learn-press/setup-wizard/steps', |
| 212 | 99 | array( |
| 213 | - 'welcome' => array( | |
| 100 | + 'welcome' => array( | |
| 214 | 101 | 'title' => __( 'Welcome', 'learnpress' ), |
| 215 | 102 | 'callback' => array( $this, 'step_welcome' ), |
| 216 | - 'next_button' => __( 'Run Setup Wizard', 'learnpress' ), | |
| 103 | + 'next_button' => __( 'Get Started', 'learnpress' ), | |
| 217 | 104 | ), |
| 218 | - 'pages' => array( | |
| 105 | + 'learning-experience' => array( | |
| 106 | + 'title' => __( 'Learning Experience', 'learnpress' ), | |
| 107 | + 'callback' => array( $this, 'step_learning_experience' ), | |
| 108 | + ), | |
| 109 | + 'pages' => array( | |
| 219 | 110 | 'title' => __( 'Pages', 'learnpress' ), |
| 220 | 111 | 'callback' => array( $this, 'step_pages' ), |
| 221 | 112 | ), |
| 222 | - // 'currency' => array( | |
| 223 | - // 'title' => __( 'Currency', 'learnpress' ), | |
| 224 | - // 'callback' => array( $this, 'step_currency' ), | |
| 225 | - // 'back_button' => false, | |
| 226 | - // 'skip_prev_button' => false | |
| 227 | - // ), | |
| 228 | - 'payment' => array( | |
| 229 | - 'title' => __( 'Payment', 'learnpress' ), | |
| 230 | - 'callback' => array( $this, 'step_payment' ), | |
| 231 | - ), | |
| 232 | - // 'emails' => array( | |
| 233 | - // 'title' => __( 'Emails', 'learnpress' ), | |
| 234 | - // 'callback' => array( $this, 'step_emails' ) | |
| 235 | - // ), | |
| 236 | - 'finish' => array( | |
| 237 | - 'title' => __( 'Finish', 'learnpress' ), | |
| 238 | - 'callback' => array( $this, 'step_finish' ), | |
| 239 | - ), | |
| 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 | + ), | |
| 240 | 125 | ) |
| 241 | 126 | ); |
| 242 | 127 | } |
| 243 | 128 | |
| @@ -260,9 +145,9 @@ | ||
| 260 | 145 | * |
| 261 | 146 | * @return mixed|string |
| 262 | 147 | */ |
| 263 | 148 | public function get_current_step( $key = true ) { |
| 264 | - $current = LP_Request::get_string( 'step' ); | |
| 149 | + $current = LP_Request::get_param( 'step' ); | |
| 265 | 150 | $steps = $this->get_steps(); |
| 266 | 151 | |
| 267 | 152 | if ( empty( $steps[ $current ] ) ) { |
| 268 | 153 | $key_steps = array_keys( $steps ); |
| @@ -308,9 +193,9 @@ | ||
| 308 | 193 | $current = $this->get_current_step(); |
| 309 | 194 | $steps = $this->get_step_keys(); |
| 310 | 195 | $at = array_search( $current, $steps ); |
| 311 | 196 | if ( $at < sizeof( $steps ) - 1 ) { |
| 312 | - $at ++; | |
| 197 | + ++$at; | |
| 313 | 198 | } |
| 314 | 199 | |
| 315 | 200 | return esc_url_raw( add_query_arg( 'step', $steps[ $at ], admin_url( $this->_base_url ) ) ); |
| 316 | 201 | } |
| @@ -324,9 +209,9 @@ | ||
| 324 | 209 | $current = $this->get_current_step(); |
| 325 | 210 | $steps = $this->get_step_keys(); |
| 326 | 211 | $at = array_search( $current, $steps ); |
| 327 | 212 | if ( $at > 0 ) { |
| 328 | - $at --; | |
| 213 | + --$at; | |
| 329 | 214 | } |
| 330 | 215 | |
| 331 | 216 | return esc_url_raw( add_query_arg( 'step', $steps[ $at ], admin_url( $this->_base_url ) ) ); |
| 332 | 217 | } |
| @@ -351,9 +236,9 @@ | ||
| 351 | 236 | public function get_payments() { |
| 352 | 237 | return array( |
| 353 | 238 | 'paypal' => array( |
| 354 | 239 | 'name' => __( 'PayPal', 'learnpress' ), |
| 355 | - 'icon' => LearnPress::instance()->plugin_url( '/assets/images/paypal-2.png' ), | |
| 240 | + 'icon' => LearnPress::instance()->plugin_url( 'assets/images/paypal-logo-preview.png' ), | |
| 356 | 241 | 'callback' => array( $this, 'setup_paypal' ), |
| 357 | 242 | ), |
| 358 | 243 | ); |
| 359 | 244 | } |
| @@ -373,8 +258,15 @@ | ||
| 373 | 258 | learn_press_admin_view( 'setup/steps/welcome' ); |
| 374 | 259 | } |
| 375 | 260 | |
| 376 | 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 | + /** | |
| 377 | 269 | * Currency step content. |
| 378 | 270 | */ |
| 379 | 271 | public function step_currency() { |
| 380 | 272 | learn_press_admin_view( 'setup/steps/currency' ); |
| @@ -393,8 +285,9 @@ | ||
| 393 | 285 | } |
| 394 | 286 | |
| 395 | 287 | public function step_finish() { |
| 396 | 288 | learn_press_admin_view( 'setup/steps/finish' ); |
| 289 | + update_option( 'learn_press_setup_wizard_completed', 'yes' ); | |
| 397 | 290 | } |
| 398 | 291 | |
| 399 | 292 | public function scripts() { |
| 400 | 293 | } |
| @@ -404,11 +297,10 @@ | ||
| 404 | 297 | * |
| 405 | 298 | * @return bool|LP_Setup_Wizard |
| 406 | 299 | */ |
| 407 | 300 | public static function instance() { |
| 408 | - static $instance = false; | |
| 409 | - | |
| 410 | - if ( ! $instance ) { | |
| 301 | + static $instance; | |
| 302 | + if ( is_null( $instance ) ) { | |
| 411 | 303 | $instance = new self(); |
| 412 | 304 | } |
| 413 | 305 | |
| 414 | 306 | return $instance; |
| @@ -413,5 +305,6 @@ | ||
| 413 | 305 | |
| 414 | 306 | return $instance; |
| 415 | 307 | } |
| 416 | 308 | } |
| 309 | + | |
| 417 | 310 | return LP_Setup_Wizard::instance(); |