PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.7.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.7.0
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 1 year ago Pluginmeta.php 10 months ago
Pluginmeta.php
190 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 if (stripos($file, 'wp-staging-pro.php')) {
61 $updateLink = '<a href="' . esc_url('https://wp-staging.com/quick-start-guide/') . '" target="_blank">' . esc_html__('Quick Guide', 'wp-staging') . '</a>';
62 array_push($links, $updateLink);
63
64 $updateLink = '<a href="' . esc_url('https://wp-staging.com/contact-us-presale-and-premium-support/') . '" target="_blank">' . esc_html__('Contact Support', 'wp-staging') . '</a>';
65 array_push($links, $updateLink);
66 }
67
68 return $this->editFreeActionRow($links, $file);
69 }
70
71 /**
72 * Check if it's a free plugin slug
73 * Checking against hardcoded plugin paths allow us to show an upgrade link even if the plugin is not activated
74 *
75 * @param $pluginSlug
76 * @return bool
77 */
78 private function isFreePluginSlug($pluginSlug): bool
79 {
80 $freePluginSlugs = [
81 'wp-staging/wp-staging.php',
82 'wp-staging-1/wp-staging.php',
83 'wp-staging-2/wp-staging.php',
84 ];
85 return in_array($pluginSlug, $freePluginSlugs);
86 }
87
88 /**
89 * @param array $links
90 * @param string $file
91 * @return array
92 */
93 public function editFreeActionRow(array $links, string $file): array
94 {
95 if (stripos($file, 'wp-staging.php') === false) {
96 return $links;
97 }
98
99 if ($this->canShowFreeRequiredNotice()) {
100 unset($links['deactivate']);
101
102 $settingsLink = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>';
103 array_unshift($links, $settingsLink);
104
105 $freeRequireNotice = '<span style="color: #32373c;">' . esc_html__('Required by WP Staging Pro', 'wp-staging') . '</span>';
106 array_unshift($links, $freeRequireNotice);
107 }
108
109 if (wpstgIsFreeVersionRequiredForPro() && wpstgIsProActiveInNetworkOrInCurrentSite() && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
110 unset($links['activate']);
111 }
112
113 return $links;
114 }
115
116 /**
117 * @return bool
118 */
119 private function canShowFreeRequiredNotice(): bool
120 {
121 if (!wpstgIsFreeVersionRequiredForPro()) {
122 return false;
123 }
124
125 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
126 if (stripos($pluginBasename, 'wp-staging-pro.php') === false) {
127 return false;
128 }
129
130 if (defined('WPSTGPRO_MINIMUM_FREE_VERSION') && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
131 return false;
132 }
133
134 if (is_network_admin() && !wpstgIsFreeVersionActiveInNetwork()) {
135 return false;
136 }
137
138 if (!is_network_admin() && !wpstgIsFreeVersionActive()) {
139 return false;
140 }
141
142 return true;
143 }
144
145 /**
146 * @param $file
147 * @return bool
148 */
149 private function canShowSettingsLink($file): bool
150 {
151 if (!defined('WPSTG_PLUGIN_FILE')) {
152 return false;
153 }
154
155 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
156 if ($file !== $pluginBasename) {
157 return false;
158 }
159
160 if (!$this->pluginInfo->canShowAdminMenu()) {
161 return false;
162 }
163
164 return true;
165 }
166
167 /**
168 * Plugin row meta links
169 *
170 * @param array $input already defined meta links
171 * @param string $file plugin file path and name being processed
172 * @return array
173 */
174 public function rowMeta(array $input, string $file): array
175 {
176 if ($file != 'wp-staging/wp-staging.php' && $file != 'wp-staging-pro/wp-staging-pro.php') {
177 return $input;
178 }
179
180 if (!$this->canShowSettingsLink($file)) {
181 return $input;
182 }
183
184 $links = [
185 '<a href="' . admin_url('admin.php?page=wpstg_clone') . '">' . esc_html__('Start Now', 'wp-staging') . '</a>',
186 ];
187 return array_merge($input, $links);
188 }
189 }
190