PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.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
178 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 $settingsLink = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>';
95 array_unshift($links, $settingsLink);
96
97 $freeRequireNotice = '<span style="color: #32373c;">' . esc_html__('Required by WP Staging Pro', 'wp-staging') . '</span>';
98 array_unshift($links, $freeRequireNotice);
99 }
100
101 if (wpstgIsProActiveInNetworkOrInCurrentSite() && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
102 unset($links['activate']);
103 }
104
105 return $links;
106 }
107
108 /**
109 * @return bool
110 */
111 private function canShowFreeRequiredNotice(): bool
112 {
113 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
114 if (stripos($pluginBasename, 'wp-staging-pro.php') === false) {
115 return false;
116 }
117
118 if (defined('WPSTGPRO_MINIMUM_FREE_VERSION') && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
119 return false;
120 }
121
122 if (is_network_admin() && !wpstgIsFreeVersionActiveInNetwork()) {
123 return false;
124 }
125
126 if (!is_network_admin() && !wpstgIsFreeVersionActive()) {
127 return false;
128 }
129
130 return true;
131 }
132
133 /**
134 * @param $file
135 * @return bool
136 */
137 private function canShowSettingsLink($file): bool
138 {
139 if (!defined('WPSTG_PLUGIN_FILE')) {
140 return false;
141 }
142
143 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
144 if ($file !== $pluginBasename) {
145 return false;
146 }
147
148 if (!$this->pluginInfo->canShowAdminMenu()) {
149 return false;
150 }
151
152 return true;
153 }
154
155 /**
156 * Plugin row meta links
157 *
158 * @param array $input already defined meta links
159 * @param string $file plugin file path and name being processed
160 * @return array
161 */
162 public function rowMeta(array $input, string $file): array
163 {
164 if ($file != 'wp-staging/wp-staging.php' && $file != 'wp-staging-pro/wp-staging-pro.php') {
165 return $input;
166 }
167
168 if (!$this->canShowSettingsLink($file)) {
169 return $input;
170 }
171
172 $links = [
173 '<a href="' . admin_url('admin.php?page=wpstg_clone') . '">' . esc_html__('Start Now', 'wp-staging') . '</a>',
174 ];
175 return array_merge($input, $links);
176 }
177 }
178