Pluginmeta.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backend\Pluginmeta; |
| 4 | |
| 5 | /* |
| 6 | * Admin Plugins Meta Data |
| 7 | */ |
| 8 | |
| 9 | // No Direct Access |
| 10 | if (!defined("WPINC")) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | use WPStaging\Core\WPStaging; |
| 15 | |
| 16 | |
| 17 | class Pluginmeta |
| 18 | { |
| 19 | // Link to Upgrade WP Staging |
| 20 | const UPGRADE_LINK = "https://wp-staging.com/premium-upgrade"; |
| 21 | |
| 22 | public function __construct() |
| 23 | { |
| 24 | $this->defineHooks(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Define Hooks |
| 29 | */ |
| 30 | public function defineHooks() |
| 31 | { |
| 32 | add_filter('plugin_row_meta', [$this, 'rowMeta'], 10, 2); |
| 33 | add_filter('plugin_action_links', [$this,'actionLinks'], 10, 2); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Plugins row action links |
| 38 | * |
| 39 | * @param array $links already defined action links |
| 40 | * @param string $file plugin file path and name being processed |
| 41 | * @return array $links |
| 42 | */ |
| 43 | public function actionLinks($links, $file) |
| 44 | { |
| 45 | $upgrade_link = '<a style="color: #27ae60;" target="_blank" href="' . self::UPGRADE_LINK . '">' . esc_html__('Upgrade to Premium', 'wp-staging') . '</a>'; |
| 46 | $freePlugins = [ |
| 47 | 'wp-staging/wp-staging.php', |
| 48 | 'wp-staging-1/wp-staging.php' |
| 49 | ]; |
| 50 | // show only for free version |
| 51 | // using static plugin paths allow us to show upgrade link even if the plugin is not activated |
| 52 | if (in_array($file, $freePlugins)) { |
| 53 | array_unshift($links, $upgrade_link); |
| 54 | } |
| 55 | |
| 56 | $settings_link = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>'; |
| 57 | // show on both free and pro version |
| 58 | // as WPSTG_PLUGIN_FILE is common for both free and pro version |
| 59 | // defined during requirement bootstrapping |
| 60 | // this will now work for wp-staging-dev/wp-staging-pro.php |
| 61 | // since the settings link will only work if the plugins is activated, it is good to show it this way |
| 62 | if (defined('WPSTG_PLUGIN_FILE') && $file == plugin_basename(WPSTG_PLUGIN_FILE)) { |
| 63 | array_unshift($links, $settings_link); |
| 64 | } |
| 65 | |
| 66 | return $links; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Plugin row meta links |
| 71 | * |
| 72 | * @author Michael Cannon <mc@aihr.us> |
| 73 | * @since 2.0 |
| 74 | * @param array $input already defined meta links |
| 75 | * @param string $file plugin file path and name being processed |
| 76 | * @return array $input |
| 77 | */ |
| 78 | public function rowMeta($input, $file) |
| 79 | { |
| 80 | if ($file != 'wp-staging/wp-staging.php' && $file != 'wp-staging-pro/wp-staging-pro.php') { |
| 81 | return $input; |
| 82 | } |
| 83 | |
| 84 | $links = [ |
| 85 | '<a href="' . admin_url('admin.php?page=wpstg_clone') . '">' . esc_html__('Start Now', 'wp-staging') . '</a>', |
| 86 | ]; |
| 87 | $input = array_merge($input, $links); |
| 88 | return $input; |
| 89 | } |
| 90 | } |
| 91 |