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 +183 -183 4.3.94.4.8 View file →
@@ -1,183 +1,183 @@
1 -<?php
2 -
3 -use LearnPress\Helpers\Template;
4 -use LearnPress\Models\UserModel;
5 -use LearnPress\TemplateHooks\TemplateAJAX;
6 -
7 -if ( ! class_exists( 'LP_Admin_Dashboard' ) ) {
8 - /**
9 - * Class LP_Admin_Dashboard
10 - *
11 - * Displays widgets in admin.
12 - */
13 - class LP_Admin_Dashboard {
14 - /**
15 - * LP_Admin_Dashboard constructor.
16 - */
17 - public function __construct() {
18 - // Ignore heartbeat requests.
19 - if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) {
20 - return;
21 - }
22 -
23 - add_action( 'wp_dashboard_setup', array( $this, 'register' ) );
24 - }
25 -
26 - public function register() {
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 ) {
39 - wp_add_dashboard_widget(
40 - $id,
41 - $screen['label'],
42 - $screen['callback']
43 - );
44 - }
45 - }
46 -
47 - /**
48 - * Order status widget
49 - */
50 - public function order_statuses() {
51 - $args = [
52 - 'id_url' => 'order-statistic-dashboard',
53 - ];
54 -
55 - /**
56 - * @uses order_statistic
57 - */
58 - $callback = [
59 - 'class' => self::class,
60 - 'method' => 'order_statistic',
61 - ];
62 -
63 - echo TemplateAJAX::load_content_via_ajax( $args, $callback );
64 - }
65 -
66 - /**
67 - * Get order statistic content
68 - *
69 - * @return stdClass
70 - */
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 - }
76 -
77 - $order_statuses = LP_Order::get_order_statuses();
78 - $lp_order_icons = LP_Order::get_icons_status();
79 -
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;
89 - }
90 -
91 - /**
92 - * Plugin status widget
93 - */
94 - public function plugin_status() {
95 - $args = [
96 - 'id_url' => 'plugin-status-dashboard',
97 - ];
98 -
99 - /**
100 - * @uses plugin_status_content
101 - */
102 - $callback = [
103 - 'class' => self::class,
104 - 'method' => 'plugin_status_content',
105 - ];
106 -
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' ) );
113 - }
114 -
115 - require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
116 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
117 -
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 - );
131 -
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 - ];
176 -
177 - $content = new stdClass();
178 - $content->content = Template::combine_components( $section );
179 - return $content;
180 - }
181 - }
182 -}
183 -new LP_Admin_Dashboard();
1 +<?php
2 +
3 +use LearnPress\Helpers\Template;
4 +use LearnPress\Models\UserModel;
5 +use LearnPress\TemplateHooks\TemplateAJAX;
6 +
7 +if ( ! class_exists( 'LP_Admin_Dashboard' ) ) {
8 + /**
9 + * Class LP_Admin_Dashboard
10 + *
11 + * Displays widgets in admin.
12 + */
13 + class LP_Admin_Dashboard {
14 + /**
15 + * LP_Admin_Dashboard constructor.
16 + */
17 + public function __construct() {
18 + // Ignore heartbeat requests.
19 + if ( isset( $_POST['action'] ) && 'heartbeat' === $_POST['action'] ) {
20 + return;
21 + }
22 +
23 + add_action( 'wp_dashboard_setup', array( $this, 'register' ) );
24 + }
25 +
26 + public function register() {
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 ) {
39 + wp_add_dashboard_widget(
40 + $id,
41 + $screen['label'],
42 + $screen['callback']
43 + );
44 + }
45 + }
46 +
47 + /**
48 + * Order status widget
49 + */
50 + public function order_statuses() {
51 + $args = [
52 + 'id_url' => 'order-statistic-dashboard',
53 + ];
54 +
55 + /**
56 + * @uses order_statistic
57 + */
58 + $callback = [
59 + 'class' => self::class,
60 + 'method' => 'order_statistic',
61 + ];
62 +
63 + echo TemplateAJAX::load_content_via_ajax( $args, $callback );
64 + }
65 +
66 + /**
67 + * Get order statistic content
68 + *
69 + * @return stdClass
70 + */
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 + }
76 +
77 + $order_statuses = LP_Order::get_order_statuses();
78 + $lp_order_icons = LP_Order::get_icons_status();
79 +
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;
89 + }
90 +
91 + /**
92 + * Plugin status widget
93 + */
94 + public function plugin_status() {
95 + $args = [
96 + 'id_url' => 'plugin-status-dashboard',
97 + ];
98 +
99 + /**
100 + * @uses plugin_status_content
101 + */
102 + $callback = [
103 + 'class' => self::class,
104 + 'method' => 'plugin_status_content',
105 + ];
106 +
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' ) );
113 + }
114 +
115 + require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
116 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
117 +
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 + );
131 +
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 + ];
176 +
177 + $content = new stdClass();
178 + $content->content = Template::combine_components( $section );
179 + return $content;
180 + }
181 + }
182 +}
183 +new LP_Admin_Dashboard();