← All changes
|
inc/rest-api/v1/admin/class-lp-admin-rest-tools-controller.php
+4
-116
4.4.3
→
4.4.9
View file →
| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | use LearnPress\Filters\Course\CourseJsonFilter; |
| 4 | -use LearnPress\Helpers\Template; | |
| 5 | 4 | use LearnPress\Models\Courses; |
| 6 | 5 | use LearnPress\Models\UserItems\UserCourseModel; |
| 7 | 6 | |
| 8 | 7 | /** |
| @@ -44,15 +43,15 @@ | ||
| 44 | 43 | 'callback' => array( $this, 'clean_tables' ), |
| 45 | 44 | 'permission_callback' => array( $this, 'check_permission' ), |
| 46 | 45 | ), |
| 47 | 46 | ), |
| 48 | - 'admin-notices' => array( | |
| 47 | + /*'admin-notices' => array( | |
| 49 | 48 | array( |
| 50 | 49 | 'methods' => WP_REST_Server::ALLMETHODS, |
| 51 | 50 | 'callback' => array( $this, 'admin_notices' ), |
| 52 | 51 | 'permission_callback' => array( $this, 'check_permission' ), |
| 53 | 52 | ), |
| 54 | - ), | |
| 53 | + ),*/ | |
| 55 | 54 | 'search-course' => array( |
| 56 | 55 | array( |
| 57 | 56 | 'methods' => WP_REST_Server::ALLMETHODS, |
| 58 | 57 | 'callback' => array( $this, 'search_courses' ), |
| @@ -245,119 +244,8 @@ | ||
| 245 | 244 | wp_send_json( $response ); |
| 246 | 245 | } |
| 247 | 246 | |
| 248 | 247 | /** |
| 249 | - * Show admin notices. | |
| 250 | - * | |
| 251 | - * @param WP_REST_Request $request | |
| 252 | - * | |
| 253 | - * @return void | |
| 254 | - * @since 4.1.7.3.2 | |
| 255 | - * @version 1.0.1 | |
| 256 | - */ | |
| 257 | - public function admin_notices( WP_REST_Request $request ) { | |
| 258 | - $response = new LP_REST_Response(); | |
| 259 | - $content = ''; | |
| 260 | - | |
| 261 | - try { | |
| 262 | - $params = $request->get_params(); | |
| 263 | - $admin_notices_dismiss = get_option( 'lp_admin_notices_dismiss', [] ); | |
| 264 | - $lp_beta_version_info = LP_Admin_Notice::check_lp_beta_version(); | |
| 265 | - | |
| 266 | - if ( isset( $params['dismiss'] ) ) { | |
| 267 | - if ( $lp_beta_version_info ) { | |
| 268 | - // Store version of LP beta to session. | |
| 269 | - learn_press_setcookie( 'lp_beta_version', $lp_beta_version_info['version'] ?? 0 ); | |
| 270 | - } | |
| 271 | - | |
| 272 | - $admin_notices_dismiss[ $params['dismiss'] ] = $params['dismiss']; | |
| 273 | - update_option( 'lp_admin_notices_dismiss', $admin_notices_dismiss ); | |
| 274 | - $response->message = __( 'Dismissed!', 'learnpress' ); | |
| 275 | - } else { | |
| 276 | - $show_notice_lp_beta_version = false; | |
| 277 | - /** | |
| 278 | - * Check if LP beta version is not dismissed or dismissed version lower than current version, will bet to show notice. | |
| 279 | - */ | |
| 280 | - if ( $lp_beta_version_info && ! isset( $_GET['tab'] ) && | |
| 281 | - ( ! isset( $_COOKIE['lp_beta_version'] ) || version_compare( $_COOKIE['lp_beta_version'], $lp_beta_version_info['version'], '<' ) ) ) { | |
| 282 | - $show_notice_lp_beta_version = true; | |
| 283 | - } | |
| 284 | - | |
| 285 | - $rules = apply_filters( | |
| 286 | - 'learn-press/admin-notices', | |
| 287 | - [ | |
| 288 | - // Check wp_remote call success. | |
| 289 | - 'check_wp_remote' => [ | |
| 290 | - 'template' => 'admin-notices/wp-remote.php', | |
| 291 | - 'check' => LP_Admin_Notice::check_wp_remote(), | |
| 292 | - ], | |
| 293 | - // Check name plugin base. | |
| 294 | - 'check_plugin_base' => [ | |
| 295 | - 'template' => 'admin-notices/plugin-base.php', | |
| 296 | - 'check' => LP_Admin_Notice::check_plugin_base(), | |
| 297 | - ], | |
| 298 | - // Show beta version of LP. | |
| 299 | - 'lp-beta-version' => [ | |
| 300 | - 'template' => 'admin-notices/beta-version.php', | |
| 301 | - 'check' => $show_notice_lp_beta_version, | |
| 302 | - 'info' => $lp_beta_version_info, | |
| 303 | - 'allow_dismiss' => 1, | |
| 304 | - ], | |
| 305 | - // Show message needs upgrades database compatible with LP version current. | |
| 306 | - 'lp-upgrade-db' => [ | |
| 307 | - 'template' => 'admin-notices/upgrade-db.php', | |
| 308 | - 'check' => LP_Updater::instance()->check_lp_db_need_upgrade(), | |
| 309 | - ], | |
| 310 | - // Show message wrong permalink structure. | |
| 311 | - 'lp-permalink' => [ | |
| 312 | - 'template' => 'admin-notices/permalink-wrong.php', | |
| 313 | - 'check' => ! get_option( 'permalink_structure' ), | |
| 314 | - ], | |
| 315 | - // Show notice setup wizard. | |
| 316 | - 'lp-setup-wizard' => [ | |
| 317 | - 'template' => 'admin-notices/setup-wizard.php', | |
| 318 | - 'check' => ! get_option( 'learn_press_setup_wizard_completed', false ) | |
| 319 | - && ! isset( $admin_notices_dismiss['lp-setup-wizard'] ), | |
| 320 | - 'allow_dismiss' => 1, | |
| 321 | - ], | |
| 322 | - // Show notification addons new version. | |
| 323 | - 'lp-addons-new-version' => [ | |
| 324 | - 'template' => 'admin-notices/addons-new-version.php', | |
| 325 | - 'addons' => LP_Manager_Addons::instance()->list_addon_new_version(), | |
| 326 | - 'allow_dismiss' => 1, | |
| 327 | - 'dismiss' => isset( $admin_notices_dismiss['lp-addons-new-version'] ), | |
| 328 | - ], | |
| 329 | - // Show notification addons purchased need extend. | |
| 330 | - 'lp-addons-purchased-extend' => [ | |
| 331 | - 'template' => 'admin-notices/addons-purchased-extend.php', | |
| 332 | - 'need-extend' => LP_Manager_Addons::instance()->check_addons_purchased_need_extend(), | |
| 333 | - 'allow_dismiss' => 1, | |
| 334 | - 'dismiss' => isset( $admin_notices_dismiss['lp-addons-purchased-extend'] ), | |
| 335 | - ], | |
| 336 | - ] | |
| 337 | - ); | |
| 338 | - | |
| 339 | - ob_start(); | |
| 340 | - foreach ( $rules as $template_data ) { | |
| 341 | - Template::instance()->get_admin_template( | |
| 342 | - $template_data['template'] ?? '', | |
| 343 | - [ 'data' => $template_data ] | |
| 344 | - ); | |
| 345 | - } | |
| 346 | - } | |
| 347 | - | |
| 348 | - $response->status = 'success'; | |
| 349 | - $response->data->content = ob_get_clean(); | |
| 350 | - } catch ( Exception $e ) { | |
| 351 | - ob_end_clean(); | |
| 352 | - $response->message = $e->getMessage(); | |
| 353 | - } | |
| 354 | - | |
| 355 | - wp_send_json( $response ); | |
| 356 | - } | |
| 357 | - | |
| 358 | - | |
| 359 | - /** | |
| 360 | 248 | * Search courses by title |
| 361 | 249 | * |
| 362 | 250 | * @param WP_REST_Request $request |
| 363 | 251 | * |
| @@ -567,9 +455,9 @@ | ||
| 567 | 455 | foreach ( $data as $user_course ) { |
| 568 | 456 | $user_id = $user_course['user_id'] ?? 0; |
| 569 | 457 | $course_id = $user_course['course_id'] ?? 0; |
| 570 | 458 | if ( ! $user_id || ! $course_id ) { |
| 571 | - throw new Exception( 'User or Course is invalid', 'learnpress' ); | |
| 459 | + throw new Exception( __( 'User or Course is invalid', 'learnpress' ) ); | |
| 572 | 460 | } |
| 573 | 461 | |
| 574 | 462 | $can_handle = apply_filters( |
| 575 | 463 | 'learn-press/assign-courses-to-users/can-handle', |
| @@ -646,9 +534,9 @@ | ||
| 646 | 534 | foreach ( $data as $user_course ) { |
| 647 | 535 | $user_id = $user_course['user_id'] ?? 0; |
| 648 | 536 | $course_id = $user_course['course_id'] ?? 0; |
| 649 | 537 | if ( ! $user_id || ! $course_id ) { |
| 650 | - throw new Exception( 'User or Course is invalid', 'learnpress' ); | |
| 538 | + throw new Exception( __( 'User or Course is invalid', 'learnpress' ) ); | |
| 651 | 539 | } |
| 652 | 540 | |
| 653 | 541 | // Delete data user who already enrolled this course. |
| 654 | 542 | LP_User_Items_DB::getInstance()->delete_user_items_old( $user_id, $course_id ); |