AdminAjaxController.php
4 years ago
MetaController.php
4 years ago
NoticeController.php
4 years ago
PostTypeController.php
4 years ago
SettingsController.php
4 years ago
UpgradeController.php
4 years ago
UpgradeController.php
77 lines
| 1 | <?php |
| 2 | |
| 3 | namespace RT\ThePostGrid\Controllers\Admin; |
| 4 | |
| 5 | class UpgradeController { |
| 6 | |
| 7 | public static $compare_version; |
| 8 | |
| 9 | public function __construct() { |
| 10 | self::$compare_version = '5.1.0'; |
| 11 | if ( ! self::check_plugin_version() ) { |
| 12 | add_filter( 'plugin_row_meta', [ $this, 'show_update_notification' ], 10, 2 ); |
| 13 | $this->version_notice(); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | public static function check_plugin_version() { |
| 18 | $tpg_version = self::get_pro_plugin_info( 'Version' ); |
| 19 | if ( version_compare( $tpg_version, self::$compare_version, '<' ) ) { |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | return true; |
| 24 | } |
| 25 | |
| 26 | public function version_notice() { |
| 27 | if ( class_exists( 'RtTpgPro' ) || class_exists( 'rtTPGP' ) ) { |
| 28 | add_action( 'admin_notices', |
| 29 | function () { |
| 30 | $class = 'notice notice-error'; |
| 31 | $text = esc_html__( 'The Post Grid Pro', 'the-post-grid' ); |
| 32 | $link_pro = 'https://www.radiustheme.com/downloads/the-post-grid-pro-for-wordpress/'; |
| 33 | |
| 34 | printf( '<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>', |
| 35 | $class, |
| 36 | $link_pro, |
| 37 | $text ); |
| 38 | } ); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get TPG Pro Plugin Info |
| 44 | * |
| 45 | * @param $parameter |
| 46 | * |
| 47 | * @return string |
| 48 | */ |
| 49 | public static function get_pro_plugin_info( $parameter ): string { |
| 50 | if ( ! function_exists( 'get_plugin_data' ) ) { |
| 51 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 52 | } |
| 53 | |
| 54 | $tpg_free_path = WP_PLUGIN_DIR . '/the-post-grid-pro/the-post-grid-pro.php'; |
| 55 | |
| 56 | if ( file_exists( $tpg_free_path ) ) { |
| 57 | $plugin_path = get_plugin_data( $tpg_free_path ); |
| 58 | |
| 59 | if ( isset( $plugin_path[ $parameter ] ) ) { |
| 60 | return $plugin_path[ $parameter ]; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return ''; |
| 65 | } |
| 66 | |
| 67 | public function show_update_notification( $links, $file ) { |
| 68 | if ( $file == 'the-post-grid-pro/the-post-grid-pro.php' ) { |
| 69 | $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>'; |
| 70 | |
| 71 | return array_merge( $links, $row_meta ); |
| 72 | } |
| 73 | |
| 74 | return (array) $links; |
| 75 | } |
| 76 | } |
| 77 |