PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 3.1.2
WP STAGING – WordPress Backups, Restore, Migration & Clone v3.1.2
4.11.2 4.11.1 4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backend / Pluginmeta / Pluginmeta.php
wp-staging / Backend / Pluginmeta Last commit date
Meta.php 5 years ago Pluginmeta.php 2 years ago
Pluginmeta.php
169 lines
1 <?php
2
3 namespace WPStaging\Backend\Pluginmeta;
4
5 /* Admin Plugins Meta Data */
6
7 use WPStaging\Core\WPStaging;
8 use WPStaging\Framework\Utils\PluginInfo;
9
10 class Pluginmeta
11 {
12 // Link to Upgrade WP Staging
13 const UPGRADE_LINK = "https://wp-staging.com/premium-upgrade";
14
15 /** @var PluginInfo */
16 private $pluginInfo;
17
18 public function __construct()
19 {
20 $this->pluginInfo = WPStaging::make(PluginInfo::class);
21 $this->defineHooks();
22 }
23
24 /**
25 * Define Hooks
26 */
27 public function defineHooks()
28 {
29 add_filter('plugin_row_meta', [$this, 'rowMeta'], 10, 2);
30 add_filter('plugin_action_links', [$this, 'actionLinks'], 10, 2);
31 add_filter('network_admin_plugin_action_links', [$this, 'editFreeActionRow'], 10, 2);
32 }
33
34 /**
35 * Plugins row action links for the free version
36 *
37 * @param array $links already defined action links
38 * @param string $file plugin file path and name being processed
39 * @return array $links
40 */
41 public function actionLinks(array $links, string $file): array
42 {
43 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
44
45 if ($this->isFreePluginSlug($file) && stripos($pluginBasename, 'wp-staging-pro.php') === false) {
46 $upgradeLink = '<a style="color: #27ae60;" target="_blank" href="' . self::UPGRADE_LINK . '">' . esc_html__('Upgrade to Premium', 'wp-staging') . '</a>';
47 array_unshift($links, $upgradeLink);
48 }
49
50 // show on both free and pro version
51 // as WPSTG_PLUGIN_FILE is common for both free and pro version
52 // defined during requirement bootstrapping
53 // this will now work for wp-staging-dev/wp-staging-pro.php
54 // since the settings link will only work if the plugins is activated, it is good to show it this way
55 if ($this->canShowSettingsLink($file)) {
56 $settingsLink = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>';
57 array_unshift($links, $settingsLink);
58 }
59
60 return $this->editFreeActionRow($links, $file);
61 }
62
63 /**
64 * Check if it's a free plugin slug
65 * Checking against hardcoded plugin paths allow us to show an upgrade link even if the plugin is not activated
66 *
67 * @param $pluginSlug
68 * @return bool
69 */
70 private function isFreePluginSlug($pluginSlug): bool
71 {
72 $freePluginSlugs = [
73 'wp-staging/wp-staging.php',
74 'wp-staging-1/wp-staging.php',
75 'wp-staging-2/wp-staging.php'
76 ];
77 return in_array($pluginSlug, $freePluginSlugs);
78 }
79
80 /**
81 * @param array $links
82 * @param string $file
83 * @return array
84 */
85 public function editFreeActionRow(array $links, string $file): array
86 {
87 if (stripos($file, 'wp-staging.php') === false) {
88 return $links;
89 }
90
91 if ($this->canShowFreeRequiredNotice()) {
92 unset($links['deactivate']);
93
94 $freeRequireNotice = '<span style="color: #afb3b7;">' . esc_html__('Must be active for WP STAGING | PRO plugin', 'wp-staging') . '</span>';
95 array_unshift($links, $freeRequireNotice);
96 }
97
98 if (wpstgIsProActiveInNetworkOrInCurrentSite() && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
99 unset($links['activate']);
100 }
101
102 return $links;
103 }
104
105 /**
106 * @return bool
107 */
108 private function canShowFreeRequiredNotice(): bool
109 {
110 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
111 if (stripos($pluginBasename, 'wp-staging-pro.php') === false) {
112 return false;
113 }
114
115 if (defined('WPSTGPRO_MINIMUM_FREE_VERSION') && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
116 return false;
117 }
118
119 if (!wpstgIsFreeActiveInNetworkOrCurrentSite()) {
120 return false;
121 }
122
123 return true;
124 }
125
126 /**
127 * @param $file
128 * @return bool
129 */
130 private function canShowSettingsLink($file): bool
131 {
132 if (!defined('WPSTG_PLUGIN_FILE')) {
133 return false;
134 }
135
136 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
137 if ($file !== $pluginBasename) {
138 return false;
139 }
140
141 if (!$this->pluginInfo->canShowAdminMenu()) {
142 return false;
143 }
144
145 return true;
146 }
147
148 /**
149 * Plugin row meta links
150 *
151 * @param array $input already defined meta links
152 * @param string $file plugin file path and name being processed
153 * @return array $input
154 * @since 2.0
155 * @author Michael Cannon <mc@aihr.us>
156 */
157 public function rowMeta(array $input, string $file): array
158 {
159 if ($file != 'wp-staging/wp-staging.php' && $file != 'wp-staging-pro/wp-staging-pro.php') {
160 return $input;
161 }
162
163 $links = [
164 '<a href="' . admin_url('admin.php?page=wpstg_clone') . '">' . esc_html__('Start Now', 'wp-staging') . '</a>',
165 ];
166 return array_merge($input, $links);
167 }
168 }
169