PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.9.5
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.9.5
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 2 days ago
Pluginmeta.php
188 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\Language\Language;
9 use WPStaging\Framework\Utils\PluginInfo;
10
11 class Pluginmeta
12 {
13 /** @var PluginInfo */
14 private $pluginInfo;
15
16 public function __construct()
17 {
18 $this->pluginInfo = WPStaging::make(PluginInfo::class);
19 $this->defineHooks();
20 }
21
22 /**
23 * Define Hooks
24 */
25 public function defineHooks()
26 {
27 add_filter('plugin_row_meta', [$this, 'rowMeta'], 10, 2);
28 add_filter('plugin_action_links', [$this, 'actionLinks'], 10, 2);
29 add_filter('network_admin_plugin_action_links', [$this, 'editFreeActionRow'], 10, 2);
30 }
31
32 /**
33 * Plugins row action links for the free version
34 *
35 * @param array $links already defined action links
36 * @param string $file plugin file path and name being processed
37 * @return array $links
38 */
39 public function actionLinks(array $links, string $file): array
40 {
41 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
42
43 if ($this->isFreePluginSlug($file) && stripos($pluginBasename, 'wp-staging-pro.php') === false) {
44 $upgradeLink = '<a style="color: #27ae60;" target="_blank" href="' . esc_url(Language::getUpgradeUrl('plugin_row')) . '">' . esc_html__('Upgrade to Premium', 'wp-staging') . '</a>';
45 array_unshift($links, $upgradeLink);
46 }
47
48 // show on both free and pro version
49 // as WPSTG_PLUGIN_FILE is common for both free and pro version
50 // defined during requirement bootstrapping
51 // this will now work for wp-staging-dev/wp-staging-pro.php
52 // since the settings link will only work if the plugins is activated, it is good to show it this way
53 if ($this->canShowSettingsLink($file)) {
54 $settingsLink = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>';
55 array_unshift($links, $settingsLink);
56 }
57
58 if (stripos($file, 'wp-staging-pro.php')) {
59 $updateLink = '<a href="' . esc_url('https://wp-staging.com/quick-start-guide/') . '" target="_blank">' . esc_html__('Quick Guide', 'wp-staging') . '</a>';
60 array_push($links, $updateLink);
61
62 $updateLink = '<a href="' . esc_url('https://wp-staging.com/contact-us-presale-and-premium-support/') . '" target="_blank">' . esc_html__('Contact Support', 'wp-staging') . '</a>';
63 array_push($links, $updateLink);
64 }
65
66 return $this->editFreeActionRow($links, $file);
67 }
68
69 /**
70 * Check if it's a free plugin slug
71 * Checking against hardcoded plugin paths allow us to show an upgrade link even if the plugin is not activated
72 *
73 * @param $pluginSlug
74 * @return bool
75 */
76 private function isFreePluginSlug($pluginSlug): bool
77 {
78 $freePluginSlugs = [
79 'wp-staging/wp-staging.php',
80 'wp-staging-1/wp-staging.php',
81 'wp-staging-2/wp-staging.php',
82 ];
83 return in_array($pluginSlug, $freePluginSlugs);
84 }
85
86 /**
87 * @param array $links
88 * @param string $file
89 * @return array
90 */
91 public function editFreeActionRow(array $links, string $file): array
92 {
93 if (stripos($file, 'wp-staging.php') === false) {
94 return $links;
95 }
96
97 if ($this->canShowFreeRequiredNotice()) {
98 unset($links['deactivate']);
99
100 $settingsLink = '<a href="' . admin_url('admin.php?page=wpstg-settings') . '">' . esc_html__('Settings', 'wp-staging') . '</a>';
101 array_unshift($links, $settingsLink);
102
103 $freeRequireNotice = '<span style="color: #32373c;">' . esc_html__('Required by WP Staging Pro', 'wp-staging') . '</span>';
104 array_unshift($links, $freeRequireNotice);
105 }
106
107 if (wpstgIsFreeVersionRequiredForPro() && wpstgIsProActiveInNetworkOrInCurrentSite() && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
108 unset($links['activate']);
109 }
110
111 return $links;
112 }
113
114 /**
115 * @return bool
116 */
117 private function canShowFreeRequiredNotice(): bool
118 {
119 if (!wpstgIsFreeVersionRequiredForPro()) {
120 return false;
121 }
122
123 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
124 if (stripos($pluginBasename, 'wp-staging-pro.php') === false) {
125 return false;
126 }
127
128 if (defined('WPSTGPRO_MINIMUM_FREE_VERSION') && version_compare(wpstgGetFreeVersionNumberIfInstalled(), WPSTGPRO_MINIMUM_FREE_VERSION, '<')) {
129 return false;
130 }
131
132 if (is_network_admin() && !wpstgIsFreeVersionActiveInNetwork()) {
133 return false;
134 }
135
136 if (!is_network_admin() && !wpstgIsFreeVersionActive()) {
137 return false;
138 }
139
140 return true;
141 }
142
143 /**
144 * @param $file
145 * @return bool
146 */
147 private function canShowSettingsLink($file): bool
148 {
149 if (!defined('WPSTG_PLUGIN_FILE')) {
150 return false;
151 }
152
153 $pluginBasename = plugin_basename(WPSTG_PLUGIN_FILE);
154 if ($file !== $pluginBasename) {
155 return false;
156 }
157
158 if (!$this->pluginInfo->canShowAdminMenu()) {
159 return false;
160 }
161
162 return true;
163 }
164
165 /**
166 * Plugin row meta links
167 *
168 * @param array $input already defined meta links
169 * @param string $file plugin file path and name being processed
170 * @return array
171 */
172 public function rowMeta(array $input, string $file): array
173 {
174 if ($file != 'wp-staging/wp-staging.php' && $file != 'wp-staging-pro/wp-staging-pro.php') {
175 return $input;
176 }
177
178 if (!$this->canShowSettingsLink($file)) {
179 return $input;
180 }
181
182 $links = [
183 '<a href="' . admin_url('admin.php?page=wpstg_clone') . '">' . esc_html__('Start Now', 'wp-staging') . '</a>',
184 ];
185 return array_merge($input, $links);
186 }
187 }
188