PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.3.2
Admin Columns v4.3.2
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Dependencies.php
codepress-admin-columns / classes Last commit date
Admin 5 years ago Ajax 5 years ago Asset 5 years ago Autoloader 5 years ago Capabilities 5 years ago Check 5 years ago Column 5 years ago ColumnRepository 5 years ago Controller 5 years ago Deprecated 5 years ago Exception 5 years ago Form 5 years ago Helper 5 years ago Integration 5 years ago ListScreen 5 years ago ListScreenRepository 5 years ago ListTable 5 years ago Message 5 years ago Meta 5 years ago Plugin 5 years ago Preferences 5 years ago Promo 5 years ago Relation 5 years ago Request 5 years ago Response 5 years ago Sanitize 5 years ago Screen 5 years ago Settings 5 years ago Storage 5 years ago Table 5 years ago ThirdParty 5 years ago Transient 5 years ago Type 5 years ago Addon.php 5 years ago AdminColumns.php 5 years ago AdminFactoryInterface.php 5 years ago ApplyFilter.php 5 years ago ArrayIterator.php 5 years ago Autoloader.php 5 years ago Builder.php 5 years ago Capabilities.php 5 years ago Collection.php 5 years ago Column.php 5 years ago ColumnGroups.php 5 years ago ColumnRepository.php 5 years ago Config.php 5 years ago DefaultColumnsRepository.php 5 years ago Dependencies.php 5 years ago EncodedListScreenData.php 5 years ago EncodedListScreenDataFactory.php 5 years ago Expirable.php 5 years ago Groups.php 5 years ago Helper.php 5 years ago Installer.php 5 years ago Integration.php 5 years ago Integrations.php 5 years ago ListScreen.php 5 years ago ListScreenCollection.php 5 years ago ListScreenFactory.php 5 years ago ListScreenGroups.php 5 years ago ListScreenPost.php 5 years ago ListScreenRepository.php 5 years ago ListScreenRepositoryWritable.php 5 years ago ListScreenTypes.php 5 years ago ListScreenWP.php 5 years ago ListScreens.php 5 years ago ListTable.php 5 years ago ListTableFactory.php 5 years ago Message.php 5 years ago MetaType.php 5 years ago Middleware.php 5 years ago NoticeChecks.php 5 years ago OpCacheInvalidateTrait.php 5 years ago PermissionChecker.php 5 years ago Plugin.php 5 years ago PluginActionLinks.php 5 years ago PluginInformation.php 5 years ago Preferences.php 5 years ago Promo.php 5 years ago PromoCollection.php 5 years ago Registrable.php 5 years ago Relation.php 5 years ago Renderable.php 5 years ago Request.php 5 years ago Sanitize.php 5 years ago Screen.php 5 years ago ScreenController.php 5 years ago Transient.php 5 years ago TypedArrayIterator.php 5 years ago View.php 5 years ago WpListTableFactory.php 5 years ago
Dependencies.php
269 lines
1 <?php
2
3 namespace AC;
4
5 /**
6 * Show a notice when plugin dependencies are not met
7 * @version 1.5
8 */
9 final class Dependencies {
10
11 const ACP_PLUGIN = 'Admin Columns Pro';
12
13 /**
14 * Basename of this plugin
15 * @var string
16 */
17 private $basename;
18
19 /**
20 * @var string
21 */
22 private $version;
23
24 /**
25 * Missing dependency messages
26 * @var string[]
27 */
28 private $messages = [];
29
30 /**
31 * @param string $basename
32 * @param string $version
33 */
34 public function __construct( $basename, $version ) {
35 $this->basename = $basename;
36 $this->version = $version;
37 }
38
39 /**
40 * @return string
41 */
42 public function get_basename() {
43 return $this->basename;
44 }
45
46 /**
47 * @return string
48 */
49 public function get_version() {
50 return $this->version;
51 }
52
53 /**
54 * Register hooks
55 */
56 private function register() {
57 add_action( 'after_plugin_row_' . $this->basename, [ $this, 'display_notice' ], 5 );
58 add_action( 'admin_head', [ $this, 'display_notice_css' ] );
59 }
60
61 /**
62 * Add missing dependency
63 *
64 * @param string $message
65 * @param string $key
66 */
67 public function add_missing( $message, $key ) {
68 if ( ! $this->has_missing() ) {
69 $this->register();
70 }
71
72 $this->messages[ $key ] = $this->sanitize_message( $message );
73 }
74
75 /**
76 * Add missing dependency
77 *
78 * @param string $plugin
79 * @param string $url
80 * @param string $version
81 */
82 public function add_missing_plugin( $plugin, $url = null, $version = null ) {
83 $this->add_missing(
84 $this->get_missing_plugin_message( $plugin, $url, $version ),
85 $plugin
86 );
87 }
88
89 /**
90 * @param string $plugin
91 * @param null $url
92 * @param null $version
93 *
94 * @return string
95 */
96 private function get_missing_plugin_message( $plugin, $url = null, $version = null ) {
97 $plugin = esc_html( $plugin );
98
99 if ( $url ) {
100 $plugin = sprintf( '<a href="%s">%s</a>', esc_url( $url ), $plugin );
101 }
102
103 if ( $version ) {
104 $plugin .= ' ' . sprintf( 'version %s+', esc_html( $version ) );
105 }
106
107 return sprintf( '%s needs to be installed and activated.', $plugin );
108 }
109
110 /**
111 * @return bool
112 */
113 public function has_missing() {
114 return ! empty( $this->messages );
115 }
116
117 /**
118 * @param string $message
119 *
120 * @return string
121 */
122 private function sanitize_message( $message ) {
123 return wp_kses( $message, [
124 'a' => [
125 'href' => true,
126 'target' => true,
127 ],
128 ] );
129 }
130
131 /**
132 * @return string
133 */
134 private function get_download_acp_message() {
135 return sprintf(
136 'Download the latest version from <a target="_blank" href="%s">your account.</a>',
137 esc_url( 'https://www.admincolumns.com/my-account' )
138 );
139 }
140
141 /**
142 * Check if Admin Columns Pro is installed
143 *
144 * @param $version
145 *
146 * @return bool
147 */
148 public function requires_acp( $version ) {
149 if ( ! function_exists( 'ACP' ) ) {
150 $this->add_missing(
151 $this->get_missing_plugin_message( self::ACP_PLUGIN ) . ' ' . $this->get_download_acp_message(),
152 self::ACP_PLUGIN
153 );
154
155 return false;
156 }
157
158 if ( ! ACP()->is_version_gte( $version ) || ! acp_is_addon_compatible( __NAMESPACE__, $this->version ) ) {
159 $message = sprintf(
160 'this plugin is not compatible with the current version of %1$s. Make sure this plugin and %1$s are updated to the most recent version.',
161 self::ACP_PLUGIN
162 );
163
164 $this->add_missing( $message, self::ACP_PLUGIN );
165
166 return false;
167 }
168
169 return true;
170 }
171
172 /**
173 * Check current PHP version
174 *
175 * @param string $version
176 *
177 * @return bool
178 */
179 public function requires_php( $version ) {
180 if ( ! version_compare( PHP_VERSION, $version, '>=' ) ) {
181 $message = sprintf(
182 'PHP %s+ is required. Your server currently runs PHP %s. <a href="%s" target="_blank">Learn more about requirements.</a>',
183 $version,
184 PHP_VERSION,
185 esc_url( 'https://www.admincolumns.com/documentation/getting-started/requirements/' )
186 );
187
188 $this->add_missing( $message, 'PHP Version' );
189
190 return false;
191 }
192
193 return true;
194 }
195
196 /**
197 * URL that performs a search in the WordPress repository
198 *
199 * @param string $keywords
200 *
201 * @return string
202 */
203 public function get_search_url( $keywords ) {
204 $url = add_query_arg( [
205 'tab' => 'search',
206 's' => $keywords,
207 ], admin_url( 'plugin-install.php' ) );
208
209 return $url;
210 }
211
212 /**
213 * @return bool
214 */
215 private function is_plugin_active() {
216 return is_multisite() && is_network_admin()
217 ? is_plugin_active_for_network( $this->basename )
218 : is_plugin_active( $this->basename );
219 }
220
221 /**
222 * Show a warning when dependencies are not met
223 */
224 public function display_notice() {
225 $intro = "This plugin can't load because";
226 ?>
227
228 <tr class="plugin-update-tr <?= $this->is_plugin_active() ? 'active' : 'inactive'; ?>">
229 <td colspan="3" class="plugin-update colspanchange">
230 <div class="update-message notice inline notice-error notice-alt">
231 <?php if ( count( $this->messages ) > 1 ) : ?>
232 <p>
233 <?php echo $intro . ':' ?>
234 </p>
235
236 <ul>
237 <?php foreach ( $this->messages as $message ) : ?>
238 <li><?php echo $message; ?></li>
239 <?php endforeach; ?>
240 </ul>
241 <?php else : ?>
242 <p>
243 <?php echo $intro . ' ' . current( $this->messages ); ?>
244 </p>
245 <?php endif; ?>
246 </div>
247 </td>
248 </tr>
249
250 <?php
251 }
252
253 /**
254 * Load additional CSS for the warning
255 */
256 public function display_notice_css() {
257 ?>
258
259 <style>
260 .plugins tr[data-plugin='<?php echo $this->basename; ?>'] th,
261 .plugins tr[data-plugin='<?php echo $this->basename; ?>'] td {
262 box-shadow: none;
263 }
264 </style>
265
266 <?php
267 }
268
269 }