Skip to content

Commit

Permalink
= 4.2.2.4 =
Browse files Browse the repository at this point in the history
~ Show note: addons has new version.
  • Loading branch information
tungnxt89 committed Mar 29, 2023
1 parent 9f39899 commit 6888175
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 12 deletions.
5 changes: 5 additions & 0 deletions inc/admin/sub-menus/class-lp-submenu-addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function __construct() {

public function display() {
echo '<h1>' . __( 'LearnPress Addons' ) . '</h1>';
echo '<p><strong><i>* If you use premium theme and theme include addons, you can go to tab Plugins to download/update</strong></i></p>';
echo sprintf(
'<p>* If you buy premium addon separately, you can enter purchase code( %s ) and download/update addons on here</p>',
'<a href="https://thimpress.com/my-account/" target="_blank">get from your account</a>'
);
echo '<div class="lp-addons-page">';
lp_skeleton_animation_html( 20 );
echo '</div>';
Expand Down
35 changes: 35 additions & 0 deletions inc/admin/views/admin-notices/addons-new-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Template for display error wrong permalink structure.
*
* @version 1.0.1
* @since 3.0.0
*/

use LearnPress\Helpers\Template;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! isset( $data ) || empty( $data['addons'] ) ) {
return;
}
?>
<div id="notice-install" class="lp-notice notice notice-info">
<?php
Template::instance()->get_admin_template( 'admin-notices/button-dismiss.php', array( 'key' => 'lp-addons-new-version' ) );
?>
<p><?php echo sprintf( '<strong>%s</strong>', __( 'LearnPress has new version Addons.', 'learnpress' ) ); ?></p>
<p style="display: flex;gap: 5px">
<?php
foreach ( $data['addons'] as $addon ) {
echo sprintf(
'<a href="%s" class="button button-primary">%s</a>',
admin_url( 'admin.php?page=learn-press-addons&tab=update' ),
$addon->name
);
}
?>
</p>
</div>
12 changes: 6 additions & 6 deletions inc/admin/views/admin-notices/beta-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Template for display beta version of LP.
*/

use LearnPress\Helpers\Template;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
Expand All @@ -24,10 +26,8 @@
<h3><?php echo wp_kses_post( $data_info['title'] ?? '' ); ?></h3>
<?php echo wp_kses_post( $data_info['description'] ?? '' ); ?>
<?php
if ( isset( $data['dismiss'] ) ) :
?>
<button type="button" class="notice-dismiss btn-lp-notice-dismiss" data-dismiss="lp-beta-version" title="Dismiss notice">
<span class="screen-reader-text">Dismiss this notice.</span>
</button>
<?php endif; ?>
if ( isset( $data['dismiss'] ) ) {
Template::instance()->get_admin_template( 'admin-notices/button-dismiss.php', array( 'key' => 'lp-beta-version' ) );
}
?>
</div>
17 changes: 17 additions & 0 deletions inc/admin/views/admin-notices/button-dismiss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Template button dismiss notice.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}

if ( ! isset( $key ) ) {
return;
}
?>

<button type="button" class="notice-dismiss btn-lp-notice-dismiss" data-dismiss="<?php echo $key; ?>" title="Dismiss notice">
<span class="screen-reader-text">Dismiss this notice.</span>
</button>
28 changes: 28 additions & 0 deletions inc/class-lp-manager-addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,33 @@ public function active_site( $addon_slug, $purchase_code ) {
error_log( $e->getMessage() );
}
}

/**
* Get list addon have new version.
*
* @return array
*/
public function list_addon_new_version(): array {
$addon_contr = new LP_REST_Addon_Controller();
$request = new WP_REST_Request();
$request->set_param( 'return_obj', true );
$addons_rs = $addon_contr->list_addons( $request );
$addons_new_version = [];
if ( 'success' === $addons_rs->status ) {
$addons = $addons_rs->data;
$plugins = get_plugins();

foreach ( $addons as $addon ) {
if ( isset( $plugins[ $addon->basename ] ) ) {
$version = $plugins[ $addon->basename ]['Version'];
if ( version_compare( $version, $addon->version, '<' ) ) {
$addons_new_version[] = $addon;
}
}
}
}

return $addons_new_version;
}
}

18 changes: 12 additions & 6 deletions inc/rest-api/v1/admin/class-lp-admin-rest-tools-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,38 +231,44 @@ public function admin_notices( WP_REST_Request $request ) {
'learn-press/admin-notices',
[
// Check wp_remote call success.
'check_wp_remote' => [
'check_wp_remote' => [
'template' => 'admin-notices/wp-remote.php',
'check' => LP_Admin_Notice::check_wp_remote(),
],
// Check name plugin base.
'check_plugin_base' => [
'check_plugin_base' => [
'template' => 'admin-notices/plugin-base.php',
'check' => LP_Admin_Notice::check_plugin_base(),
],
// Show beta version of LP.
'lp-beta-version' => [
'lp-beta-version' => [
'template' => 'admin-notices/beta-version.php',
'check' => $show_notice_lp_beta_version,
'info' => $lp_beta_version_info,
'dismiss' => 1,
],
// Show message needs upgrades database compatible with LP version current.
'lp-upgrade-db' => [
'lp-upgrade-db' => [
'template' => 'admin-notices/upgrade-db.php',
'check' => LP_Updater::instance()->check_lp_db_need_upgrade(),
],
// Show message wrong permalink structure.
'lp-permalink' => [
'lp-permalink' => [
'template' => 'admin-notices/permalink-wrong.php',
'check' => ! get_option( 'permalink_structure' ),
],
// Show notice setup wizard.
'lp-setup-wizard' => [
'lp-setup-wizard' => [
'template' => 'admin-notices/setup-wizard.php',
'check' => ! get_option( 'learn_press_setup_wizard_completed', false ) && ! isset( $admin_notices['lp-setup-wizard'] ),
'dismiss' => 1,
],
// Show notification addons new version.
'lp-addons-new-version' => [
'template' => 'admin-notices/addons-new-version.php',
'addons' => LP_Manager_Addons::instance()->list_addon_new_version(),
'dismiss' => 1,
],
]
);

Expand Down
7 changes: 7 additions & 0 deletions inc/rest-api/v1/frontend/class-lp-rest-addon-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function list_addons( WP_REST_Request $request ): LP_REST_Response {
$response = new LP_REST_Response();

try {
$params = $request->get_params();
$lp_addon = LP_Manager_Addons::instance();
$res = wp_remote_get( $lp_addon->url_list_addons );
if ( is_wp_error( $res ) ) {
Expand All @@ -75,6 +76,12 @@ public function list_addons( WP_REST_Request $request ): LP_REST_Response {
throw new Exception( json_last_error_msg() );
}

if ( isset( $params['return_obj'] ) ) {
$response->status = 'success';
$response->data = $addons;
return $response;
}

ob_start();
Template::instance()->get_admin_template( 'addons.php', compact( 'addons' ) );
$response->data->html = ob_get_clean();
Expand Down

0 comments on commit 6888175

Please sign in to comment.