PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.7
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.7
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 4.2.1 All 138 releases
learnpress / inc / admin / views / addons.php

addons.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.7, at inc/admin/views/addons.php

300 lines 10.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Template show list addons of LearnPress
4 *
5 * @version 1.0.1
6 * @since 4.2.1
7 */
8
9 use LearnPress\Helpers\Template;
10
11 defined( 'ABSPATH' ) || exit();
12
13 if ( ! isset( $addons ) ) {
14 return;
15 }
16
17 require_once ABSPATH . 'wp-admin/includes/plugin.php';
18
19 $total_addon_free = 0;
20 $total_addon_paid = 0;
21 $total_addon_installed = 0;
22 $total_addon_not_installed = 0;
23 $total_addon_activated = 0;
24 $total_addon_update = 0;
25 $total_addon_purchased = 0;
26 $plugins_installed = get_plugins();
27 $plugins_activated = get_option( 'active_plugins', '' );
28 $active_tab = ! empty( $_REQUEST['tab'] ) ? $_REQUEST['tab'] : 'all';
29 $keys_purchase = LP_Settings::get_option( LP_Manager_Addons::instance()->key_purchase_addons, [] );
30 ?>
31 <div class="lp-addons-wrapper">
32 <div id="lp-addons">
33 <?php
34 foreach ( $addons as $slug => $addon ) :
35 $addon->slug = $slug;
36 $is_installed = false;
37 $is_activated = false;
38 $is_updated = false;
39 $is_free = $addon->is_free ?? 0;
40 $addon_base = $addon->basename ?? '';
41 $version_latest = $addon->version ?? 0;
42 $version_current = $addon->version ?? 0;
43 $classes_status = [];
44 $addon_purchased = $addon->purchase_info ?? false;
45 // Addon is free or paid.
46 if ( 1 == $addon->is_free ) {
47 ++$total_addon_free;
48 } else {
49 ++$total_addon_paid;
50 }
51 // Addon is installed
52 if ( isset( $plugins_installed[ $addon_base ] ) ) {
53 $is_installed = true;
54 $classes_status[] = 'installed';
55 $version_current = $plugins_installed[ $addon_base ]['Version'];
56 ++$total_addon_installed;
57 } else {
58 $classes_status[] = 'not_installed';
59 ++$total_addon_not_installed;
60 }
61 // Addon is activated
62 if ( in_array( $addon_base, $plugins_activated ) ) {
63 $is_activated = true;
64 $classes_status[] = 'activated';
65 ++$total_addon_activated;
66 }
67 // Addon is having update
68 if ( $is_installed && version_compare( $version_current, $version_latest, '<' ) ) {
69 ++$total_addon_update;
70 $classes_status[] = 'update';
71 $is_updated = true;
72 }
73 // Addon is purchased
74 if ( $addon_purchased ) {
75 $classes_status[] = 'license';
76 ++$total_addon_purchased;
77 $date_expired_str = $addon_purchased->date_expire ?? '';
78 // Test
79 //$date_expired_str = '2024-02-01';
80 //$date_expired_str = '2023-01-12';
81 // End
82 $date_expired = new DateTime( $date_expired_str );
83 $date_now = new DateTime( gmdate( 'Y-m-d' ) );
84 $date_diff = date_diff( $date_now, $date_expired );
85 $number_days_remaining = $date_diff->days;
86 if ( $date_diff->invert ) {
87 $number_days_remaining = 0;
88 }
89 }
90 // Addon is paid on Thimpress
91 if ( ! $is_free ) {
92 $classes_status[] = 'purchase';
93 $purchase_code = $keys_purchase[ $addon->slug ] ?? '';
94 } else { // Addon is free
95 $classes_status[] = 'free';
96 }
97 // Show addons of tab.
98 if ( ! in_array( $active_tab, $classes_status ) && $active_tab != 'all' ) {
99 $classes_status[] = 'hide';
100 }
101 ?>
102 <div class="lp-addon-item <?php echo implode( ' ', $classes_status ); ?>"
103 data-slug="<?php echo $slug; ?>">
104 <div class="lp-addon-item__content">
105 <img src="<?php echo $addon->image; ?>" alt="<?php echo $addon->name; ?>"/>
106 <h3>
107 <a href="<?php echo $addon->link; ?>" target="_blank" rel="noopener">
108 <?php echo $addon->name; ?>
109 </a>
110 </h3>
111 <span style="display: block">
112 <?php
113 if ( $version_current ) {
114 echo "Version <span class='addon-version-current'>$version_current</span>";
115 }
116
117 if ( isset( $addon->link_doc ) && ! empty( $addon->link_doc ) ) {
118 echo " | <a href='{$addon->link_doc}' target='_blank' rel='noopener'>Documentation</a>";
119 }
120 ?>
121 </span>
122 <?php
123 // Show version latest.
124 if ( $is_updated ) {
125 echo sprintf(
126 '<span class="new-update" style="color:#27BF49;display: block">%s: %s</span>',
127 __( 'Latest version', 'learnpress' ),
128 $version_latest
129 );
130 }
131
132 if ( $addon_purchased ) {
133 $color_expire = '#27BF49';
134 $message = '';
135 $button_extends = sprintf(
136 '<p><a href="%s" target="_blank" rel="noopener" style="color: #E64B50;text-decoration: underline">%s</a></p>',
137 $addon->link,
138 __( 'Extends Now', 'learnpress' )
139 );
140
141 if ( $number_days_remaining === 0 ) {
142 $color_expire = 'red';
143 $message = __( 'Your update and support has expired!', 'learnpress' );
144
145 } elseif ( $number_days_remaining < 61 ) {
146 $color_expire = 'orange';
147 $message = sprintf(
148 __( 'You have a license of for this item with %s days of update & support remaining. Please extend the update & support license to keep updating the latest versions & receive customer support from ThimPress before it expires.', 'learnpress' ),
149 sprintf( '<strong style="color: #D93C65">%d</strong>', $number_days_remaining )
150 );
151 } else {
152 $button_extends = '';
153 }
154
155 echo sprintf(
156 '<span class="need-extend" style="display: block">%s %s</span>',
157 $message,
158 $button_extends
159 );
160 }
161
162 echo sprintf(
163 '<p>%s on %s</p>',
164 $addon->is_free ? __( 'Free', 'learnpress' ) : __( 'Paid', 'learnpress' ),
165 $addon->is_org ? __( 'WP.org', 'learnpress' ) : __( 'Thimpress', 'learnpress' )
166 );
167 ?>
168 <?php
169 if ( ! $is_free && $is_installed && empty( $purchase_code ) ) {
170 echo '<p style="color: red; display: none">Empty key purchase</p>';
171 }
172 ?>
173 <p title="<?php echo $addon->description; ?>"><?php echo $addon->description; ?></p>
174 </div>
175 <div class="lp-addon-item__actions">
176 <div class="lp-addon-item__actions__left">
177 <?php
178 if ( isset( $addon->setting ) && ! empty( $addon->setting ) ) {
179 ?>
180 <a href="<?php echo site_url( $addon->setting ); ?>" target="_blank" rel="noopener">
181 <button data-action="setting"><?php _e( 'Settings', 'learnpress' ); ?></button>
182 </a>
183 <?php
184 }
185 ?>
186 <button class="btn-addon-action" data-action="update"
187 title="<?php echo sprintf( '%s %s require LP version %s', $addon->name, $version_latest, $addon->require_lp ); ?>">
188 <span class="dashicons dashicons-update"></span><span class="text">Update</span>
189 </button>
190 <button class="btn-addon-action" data-action="update-purchase-code"
191 title="<?php _e( 'Change Purchase Code', 'learnpress' ); ?>">
192 <span class="dashicons dashicons-ellipsis"></span>
193 </button>
194 <button class="btn-addon-action" data-action="install"
195 <?php echo $is_free ? 'data-link="' . $addon->link . '"' : ''; ?>
196 >
197 <span class="dashicons dashicons-update"></span><span
198 class="text"><?php _e( 'Install', 'learnpress' ); ?></span>
199 </button>
200 <button class="btn-addon-action"
201 data-action="purchase"><?php _e( 'Install', 'learnpress' ); ?></button>
202 </div>
203 <div class="lp-addon-item__actions__right">
204 <button class="btn-addon-action" data-action="deactivate">
205 <span class="dashicons dashicons-update"></span><span
206 class="text"><?php _e( 'Deactivate', 'learnpress' ); ?></span>
207 </button>
208 <button class="btn-addon-action" data-action="activate">
209 <span class="dashicons dashicons-update"></span><span
210 class="text"><?php _e( 'Activate', 'learnpress' ); ?></span>
211 </button>
212 </div>
213 </div>
214 <div class="lp-addon-item__purchase">
215 <div class="lp-addon-item__purchase__wrapper">
216 <div class="purchase-install">
217 <label>
218 <?php _e( 'Purchase Code', 'learnpress' ); ?>
219 <input type="text" class="enter-purchase-code"
220 placeholder="<?php esc_attr_e( 'Enter Purchase Code', 'learnpress' ); ?>"
221 value="<?php echo $purchase_code ?? ''; ?>">
222 </label>
223 <button class="btn-addon-action" data-action="install">
224 <span class="dashicons dashicons-update"></span><span
225 class="text"><?php _e( 'Submit', 'learnpress' ); ?></span>
226 </button>
227 OR
228 <button class="btn-addon-action" data-action="buy" data-link="<?php echo $addon->link; ?>">
229 Buy
230 Now
231 </button>
232 <button class="btn-addon-action"
233 data-action="cancel">
234 <i class="lp-icon-close"></i>
235 </button>
236 </div>
237 <div class="purchase-update">
238 <label>
239 <?php _e( 'Purchase Code', 'learnpress' ); ?>
240 <input type="text" class="enter-purchase-code" placeholder="<?php esc_attr_e( 'Enter Purchase Code', 'learnpress' ); ?>"
241 value="<?php echo $purchase_code ?? ''; ?>">
242 </label>
243 <button class="btn-addon-action" data-action="update-purchase">
244 <span class="dashicons dashicons-update"></span><span
245 class="text"><?php _e( 'Save', 'learnpress' ); ?></span>
246 </button>
247 <button class="btn-addon-action"
248 data-action="cancel">
249 <i class="lp-icon-close"></i>
250 </button>
251 </div>
252 <input type="hidden" name="purchase-code"
253 value="<?php echo $purchase_code ?? ''; ?>">
254 </div>
255 </div>
256 </div>
257 <?php
258 endforeach;
259 ?>
260 </div>
261 <div class="lp-nav-tab-wrapper" style="display: none">
262 <?php
263 $tabs = array(
264 'all' => sprintf( '%s (<span>%d</span>)', __( 'All', 'learnpress' ), count( (array) $addons ) ),
265 'installed' => sprintf( '%s (<span>%d</span>)', __( 'Installed', 'learnpress' ), $total_addon_installed ),
266 'purchase' => sprintf( '%s (<span>%d</span>)', __( 'Paid', 'learnpress' ), $total_addon_paid ),
267 'free' => sprintf( '%s (<span>%d</span>)', __( 'Free', 'learnpress' ), $total_addon_free ),
268 'update' => sprintf( '%s (<span>%d</span>)', __( 'Update', 'learnpress' ), $total_addon_update ),
269 'license' => sprintf( '%s (<span>%d</span>)', __( 'License', 'learnpress' ), $total_addon_purchased ),
270 'not_installed' => sprintf( '%s (<span>%d</span>)', __( 'Not Installed', 'learnpress' ), $total_addon_not_installed ),
271 );
272 foreach ( $tabs as $tab => $name ) {
273 ?>
274 <?php
275
276 $active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';
277 $tab_title = apply_filters( 'learn-press/admin/submenu-heading-tab-title', $name, $tab );
278 ?>
279
280 <?php if ( $active_class ) { ?>
281 <a class="nav-tab<?php echo esc_attr( $active_class ); ?>"
282 data-tab="<?php echo esc_attr( $tab ); ?>" href="#">
283 <?php echo wp_kses_post( $tab_title ); ?>
284 </a>
285 <?php } else { ?>
286 <a class="nav-tab"
287 data-tab="<?php echo esc_attr( $tab ); ?>"
288 href="?page=learn-press-addons&tab=<?php echo esc_attr( $tab ); ?>">
289 <?php echo wp_kses_post( $tab_title ); ?>
290 </a>
291 <?php } ?>
292 <?php } ?>
293 <div class="lp-search-addons">
294 <label>
295 <input id="lp-search-addons__input" type="text" placeholder="<?php esc_attr_e( 'Search name addon', 'learnpress' ); ?>"/>
296 </label>
297 </div>
298 </div>
299 </div>
300