PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
4.4.9 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 All 140 releases
learnpress / inc / Services / AdminNoticeService.php

AdminNoticeService.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.9, at inc/Services/AdminNoticeService.php

81 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin notice check service.
4 *
5 * Centralizes pure check/validation logic used by admin notices.
6 *
7 * @package LearnPress\Services
8 * @since 4.4.9 instead of LP_Admin_Notice
9 * @version 1.0.0
10 */
11
12 namespace LearnPress\Services;
13
14 use Exception;
15 use LP_Debug;
16 use LP_Helper;
17 use stdClass;
18 use Throwable;
19 use WP_Error;
20
21 defined( 'ABSPATH' ) || exit;
22
23 /**
24 * Class AdminNoticeService
25 */
26 class AdminNoticeService {
27 /**
28 * Check if the plugin base directory is correct.
29 *
30 * @return bool True if plugin base is NOT the expected value.
31 */
32 public static function check_plugin_base(): bool {
33 return 0 !== strcmp( LP_PLUGIN_BASENAME, 'learnpress/learnpress.php' );
34 }
35
36 /**
37 * Check wp_remote_get connectivity.
38 *
39 * @return array|WP_Error Response array on success, WP_Error on failure.
40 */
41 public static function check_wp_remote() {
42 $test_url = LP_PLUGIN_URL . 'assets/images/icon-128x128.png';
43 $args = [
44 'timeout' => 5,
45 ];
46
47 return wp_remote_get( $test_url, $args );
48 }
49
50 /**
51 * Check LP beta version from remote config.
52 *
53 * @return bool|array
54 */
55 public static function check_lp_beta_version() {
56 $url = 'https://learnpress.github.io/learnpress/lp-beta-version.json';
57 $config = new stdClass();
58
59 try {
60 $res = wp_remote_get( $url );
61 if ( is_wp_error( $res ) ) {
62 throw new Exception( $res->get_error_message() );
63 }
64
65 $config = LP_Helper::json_decode( wp_remote_retrieve_body( $res ) );
66 $version = $config->version ?? 0;
67 if ( ! $version ) {
68 throw new Exception( 'Version LP beta is invalid!' );
69 }
70
71 if ( ! version_compare( $version, LEARNPRESS_VERSION, '>' ) ) {
72 return false;
73 }
74 } catch ( Throwable $e ) {
75 LP_Debug::error_log( $e );
76 }
77
78 return $config;
79 }
80 }
81