AdminAjaxController.php
3 years ago
MetaController.php
3 years ago
NoticeController.php
3 years ago
PostTypeController.php
3 years ago
SettingsController.php
3 years ago
UpgradeController.php
3 years ago
UpgradeController.php
120 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Upgrade Controller class. |
| 4 | * |
| 5 | * @package RT_TPG |
| 6 | */ |
| 7 | |
| 8 | namespace RT\ThePostGrid\Controllers\Admin; |
| 9 | |
| 10 | // Do not allow directly accessing this file. |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 'This script cannot be accessed directly.' ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Upgrade Controller class. |
| 17 | */ |
| 18 | class UpgradeController { |
| 19 | /** |
| 20 | * Version compare |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | public static $compare_version; |
| 25 | |
| 26 | /** |
| 27 | * Class constructor |
| 28 | */ |
| 29 | public function __construct() { |
| 30 | self::$compare_version = '5.1.0'; |
| 31 | |
| 32 | if ( ! self::check_plugin_version() ) { |
| 33 | add_filter( 'plugin_row_meta', [ $this, 'show_update_notification' ], 10, 2 ); |
| 34 | $this->version_notice(); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Plugin version check |
| 40 | * |
| 41 | * @return bool |
| 42 | */ |
| 43 | public static function check_plugin_version() { |
| 44 | $tpg_version = self::get_pro_plugin_info( 'Version' ); |
| 45 | |
| 46 | if ( version_compare( $tpg_version, self::$compare_version, '<' ) ) { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Notice |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function version_notice() { |
| 59 | if ( class_exists( 'RtTpgPro' ) || class_exists( 'rtTPGP' ) ) { |
| 60 | add_action( |
| 61 | 'admin_notices', |
| 62 | function () { |
| 63 | $class = 'notice notice-error'; |
| 64 | $text = esc_html__( 'The Post Grid Pro', 'the-post-grid' ); |
| 65 | $link_pro = 'https://www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/'; |
| 66 | |
| 67 | printf( |
| 68 | '<div class="%1$s"><p><a target="_blank" href="%2$s"><strong>The Post Grid Pro</strong></a> is not working properly, You need to update <strong>%3$s</strong> version to 5.1.0 or more to get the pro features.</p></div>', |
| 69 | esc_attr( $class ), |
| 70 | esc_url( $link_pro ), |
| 71 | esc_html( $text ) |
| 72 | ); |
| 73 | } |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Get TPG Pro Plugin Info |
| 80 | * |
| 81 | * @param string $parameter Parameter. |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | public static function get_pro_plugin_info( $parameter ) { |
| 86 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 87 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 88 | } |
| 89 | |
| 90 | $tpg_free_path = WP_PLUGIN_DIR . '/the-post-grid-pro/the-post-grid-pro.php'; |
| 91 | |
| 92 | if ( file_exists( $tpg_free_path ) ) { |
| 93 | $plugin_path = get_plugin_data( $tpg_free_path ); |
| 94 | |
| 95 | if ( isset( $plugin_path[ $parameter ] ) ) { |
| 96 | return $plugin_path[ $parameter ]; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | return ''; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Notification |
| 105 | * |
| 106 | * @param array $links Link. |
| 107 | * @param string $file File. |
| 108 | * @return array |
| 109 | */ |
| 110 | public function show_update_notification( $links, $file ) { |
| 111 | if ( $file == 'the-post-grid-pro/the-post-grid-pro.php' ) { |
| 112 | $row_meta['tpg_update'] = '<span style="color: red">The Plugin is not compatible with the post grid free. Please update the plugin to ' . self::$compare_version . ' or more otherwise it will not activate.</span>'; |
| 113 | |
| 114 | return array_merge( $links, $row_meta ); |
| 115 | } |
| 116 | |
| 117 | return (array) $links; |
| 118 | } |
| 119 | } |
| 120 |