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-admin-dashboard.php +132 -129 4.2.04.4.8 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +
3 +use LearnPress\Helpers\Template;
4 +use LearnPress\Models\UserModel;
5 +use LearnPress\TemplateHooks\TemplateAJAX;
6 +
2 7 if ( ! class_exists( 'LP_Admin_Dashboard' ) ) {
3 8 /**
4 9 * Class LP_Admin_Dashboard
5 10 *
@@ -5,36 +10,39 @@
5 10 *
6 11 * Displays widgets in admin.
7 12 */
8 13 class LP_Admin_Dashboard {
9 -
10 14 /**
11 15 * LP_Admin_Dashboard constructor.
12 16 */
13 17 public function __construct() {
18 + // Ignore heartbeat requests.
19 + if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) {
20 + return;
21 + }
22 +
14 23 add_action( 'wp_dashboard_setup', array( $this, 'register' ) );
15 24 }
16 25
17 26 public function register() {
18 - if ( current_user_can( 'manage_options' ) || current_user_can( 'publish_lp_orders' ) ) {
27 + $screens = [
28 + 'learn_press_dashboard_order_statuses' => [
29 + 'label' => esc_html__( 'LearnPress order status', 'learnpress' ),
30 + 'callback' => [ $this, 'order_statuses' ],
31 + ],
32 + 'learn_press_dashboard_plugin_status' => [
33 + 'label' => esc_html__( 'LearnPress status', 'learnpress' ),
34 + 'callback' => [ $this, 'plugin_status' ],
35 + ],
36 + ];
37 +
38 + foreach ( $screens as $id => $screen ) {
19 39 wp_add_dashboard_widget(
20 - 'learn_press_dashboard_order_statuses',
21 - esc_html__( 'LearnPress order status', 'learnpress' ),
22 - array(
23 - $this,
24 - 'order_statuses',
25 - )
40 + $id,
41 + $screen['label'],
42 + $screen['callback']
26 43 );
27 44 }
28 -
29 - wp_add_dashboard_widget(
30 - 'learn_press_dashboard_plugin_status',
31 - esc_html__( 'LearnPress status', 'learnpress' ),
32 - array(
33 - $this,
34 - 'plugin_status',
35 - )
36 - );
37 45 }
38 46
39 47 /**
40 48 * Order status widget
@@ -39,142 +47,137 @@
39 47 /**
40 48 * Order status widget
41 49 */
42 50 public function order_statuses() {
43 - ?>
44 - <ul class="lp-order-statuses lp_append_data">
45 - <?php lp_skeleton_animation_html( 4, 100, 'height: 30px;border-radius:4px;' ); ?>
46 - </ul>
47 - <?php
48 - $eduma_data = $this->_get_theme_info( 14058034 );
49 - if ( ! empty( $eduma_data ) ) {
50 - $eduma_data['url'] = learn_press_get_item_referral( 14058034 );
51 - ?>
52 - <div class="featured-theme">
53 - <?php if ( isset( $eduma_data['name'] ) && isset( $eduma_data['price_cents'] ) ) : ?>
54 - <p>
55 - <a href="<?php echo esc_url_raw( $eduma_data['url'] ); ?>">
56 - <?php echo esc_html( $eduma_data['name'] ); ?>
57 - </a> - <?php printf( '%s%s', '$', $eduma_data['price_cents'] / 100 ); ?>
58 - </p>
59 - <?php endif; ?>
51 + $args = [
52 + 'id_url' => 'order-statistic-dashboard',
53 + ];
60 54
61 - <?php if ( isset( $eduma_data['rating']['count'] ) && isset( $eduma_data['rating']['rating'] ) ) : ?>
62 - <div>
63 - <?php
64 - wp_star_rating(
65 - array(
66 - 'rating' => $eduma_data['rating']['rating'],
67 - 'type' => 'rating',
68 - 'number' => $eduma_data['rating']['count'],
69 - )
70 - );
71 - ?>
72 - <span class="count-rating">(<?php echo esc_html( $eduma_data['rating']['count'] ); ?>)</span>
73 - <span>
74 - - <?php echo sprintf( '%d %s', esc_html( $eduma_data['number_of_sales'] ), esc_html__( ' sales', 'learnpress' ) ); ?>
75 - </span>
76 - </div>
77 - <?php endif; ?>
55 + /**
56 + * @uses order_statistic
57 + */
58 + $callback = [
59 + 'class' => self::class,
60 + 'method' => 'order_statistic',
61 + ];
78 62
79 - <?php if ( isset( $eduma_data['author_username'] ) ) : ?>
80 - <p>
81 - <?php esc_html_e( 'Created by: ', 'learnpress' ); ?>
82 - <a href="https://thimpress.com/" class="author"><?php echo esc_html( $eduma_data['author_username'] ); ?></a>
83 - </p>
84 - <?php endif; ?>
85 - </div>
86 - <?php
87 - }
63 + echo TemplateAJAX::load_content_via_ajax( $args, $callback );
88 64 }
89 65
90 66 /**
91 - * Get total value of LP orders has completed.
67 + * Get order statistic content
92 68 *
93 - * @return int|string
94 - * @deprecated 4.2.0
69 + * @return stdClass
95 70 */
96 - private function _get_order_total_raised() {
97 - _deprecated_function( __METHOD__, '4.2.0' );
98 - /*$orders = learn_press_get_orders( array( 'post_status' => 'lp-completed' ) );
99 - $total = 0;
71 + public static function order_statistic(): stdClass {
72 + // Check permission
73 + if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) ) {
74 + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learnpress' ) );
75 + }
100 76
101 - if ( $orders ) {
102 - foreach ( $orders as $order ) {
103 - $order = learn_press_get_order( $order->ID );
104 - $total = $total + floatval( $order->order_total );
105 - }
106 - }
77 + $order_statuses = LP_Order::get_order_statuses();
78 + $lp_order_icons = LP_Order::get_icons_status();
107 79
108 - return learn_press_format_price( $total, true );*/
80 + ob_start();
81 + $data = compact( 'order_statuses', 'lp_order_icons' );
82 + Template::instance()->get_admin_template( 'dashboard/html-orders', $data );
83 + $content = new stdClass();
84 + $content->content = sprintf(
85 + '<ul class="lp-order-statuses lp_append_data">%s</ul>',
86 + ob_get_clean()
87 + );
88 + return $content;
109 89 }
110 90
111 91 /**
112 - * @param String $item_id - The ID of an Envato Marketplace item
113 - *
114 - * @returns mixed
92 + * Plugin status widget
115 93 */
116 - private function _get_theme_info( $item_id ) {
117 - $alls = LP_Plugins_Helper::get_related_themes();
94 + public function plugin_status() {
95 + $args = [
96 + 'id_url' => 'plugin-status-dashboard',
97 + ];
118 98
119 - if ( empty( $alls ) ) {
120 - return false;
121 - }
99 + /**
100 + * @uses plugin_status_content
101 + */
102 + $callback = [
103 + 'class' => self::class,
104 + 'method' => 'plugin_status_content',
105 + ];
122 106
123 - foreach ( $alls as $k => $types ) {
124 - if ( isset( $types[ $item_id ] ) ) {
125 - return $types[ $item_id ];
126 - }
107 + echo TemplateAJAX::load_content_via_ajax( $args, $callback );
108 + }
109 +
110 + public static function plugin_status_content() {
111 + if ( ! current_user_can( UserModel::ROLE_ADMINISTRATOR ) ) {
112 + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'learnpress' ) );
127 113 }
128 114
129 - return false;
130 - }
131 -
132 - /**
133 - * Get data from wordpress.org
134 - *
135 - * @since 2.0
136 - */
137 - private function _get_data() {
138 115 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
139 116 require_once ABSPATH . 'wp-admin/includes/plugin.php';
140 117
141 - $api = get_transient( 'lp_plugin_status' );
118 + $api = plugins_api(
119 + 'plugin_information',
120 + array(
121 + 'slug' => 'learnpress',
122 + 'fields' => array(
123 + 'active_installs' => true,
124 + 'short_description' => true,
125 + 'description' => true,
126 + 'ratings' => true,
127 + 'downloaded' => true,
128 + ),
129 + )
130 + );
142 131
143 - if ( false === $api || is_wp_error( $api ) ) {
144 - $api = plugins_api(
145 - 'plugin_information',
146 - array(
147 - 'slug' => 'learnpress',
148 - 'fields' => array(
149 - 'active_installs' => true,
150 - 'short_description' => true,
151 - 'description' => true,
152 - 'ratings' => true,
153 - 'downloaded' => true,
154 - ),
155 - )
156 - );
132 + $section = [
133 + 'wrap' => '<div class="lp-plugin-status-wrap">',
134 + 'banner' => sprintf(
135 + '<image class="lp-plugin-banner" src="%s" style="%s" />',
136 + $api->banners ? ( $api->banners['low'] ?? '' ) : '',
137 + 'max-width:100%;height:auto;'
138 + ),
139 + 'active_installs' => sprintf(
140 + '<div class="lp-plugin-active-installs">%s: <strong>%s</strong></div>',
141 + esc_html__( 'Active Installations', 'learnpress' ),
142 + number_format_i18n( $api->active_installs )
143 + ),
144 + 'downloaded' => sprintf(
145 + '<div class="lp-plugin-downloaded">%s: <strong>%s</strong></div>',
146 + esc_html__( 'Total Downloads', 'learnpress' ),
147 + number_format_i18n( $api->downloaded )
148 + ),
149 + 'ratings' => sprintf(
150 + '<div class="lp-plugin-ratings">%s <strong>%s</strong></div>',
151 + esc_html__( 'Ratings 5 stars is:', 'learnpress' ),
152 + $api->ratings[5] ?? '0'
153 + ),
154 + 'requires' => sprintf(
155 + '<div class="lp-plugin-requires">%s %s</div>',
156 + esc_html__( 'Required WordPress version:', 'learnpress' ),
157 + $api->requires ?? esc_html__( 'N/A', 'learnpress' )
158 + ),
159 + 'requires_php' => sprintf(
160 + '<div class="lp-plugin-requires_php">%s %s</div>',
161 + esc_html__( 'Required PHP version:', 'learnpress' ),
162 + $api->requires_php ?? esc_html__( 'N/A', 'learnpress' )
163 + ),
164 + 'tested' => sprintf(
165 + '<div class="lp-plugin-tested">%s %s</div>',
166 + esc_html__( 'Tested with WordPress version:', 'learnpress' ),
167 + $api->tested ?? esc_html__( 'N/A', 'learnpress' )
168 + ),
169 + 'last_updated' => sprintf(
170 + '<div class="lp-plugin-last_updated">%s %s</div>',
171 + esc_html__( 'Latest updated:', 'learnpress' ),
172 + $api->last_updated ?? esc_html__( 'N/A', 'learnpress' )
173 + ),
174 + 'wrap-end' => '</div>',
175 + ];
157 176
158 - if ( ! is_wp_error( $api ) ) {
159 - set_transient( 'lp_plugin_status', $api, 12 * HOUR_IN_SECONDS );
160 - }
161 - }
162 -
163 - return $api;
164 - }
165 -
166 - /**
167 - * Plugin status widget
168 - */
169 - public function plugin_status() {
170 - $plugin_data = $this->_get_data();
171 -
172 - if ( ! $plugin_data || is_wp_error( $plugin_data ) ) {
173 - learn_press_admin_view( 'dashboard/plugin-status/html-no-data' );
174 - } else {
175 - learn_press_admin_view( 'dashboard/plugin-status/html-results', array( 'plugin_data' => $plugin_data ) );
176 - }
177 + $content = new stdClass();
178 + $content->content = Template::combine_components( $section );
179 + return $content;
177 180 }
178 181 }
179 182 }
180 183 new LP_Admin_Dashboard();