PluginProbe
Black Bar / 2.1.2
Black Bar v2.1.2
trunk 1.0.0 1.1.0 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.2.0 2.2.1 3.0.0 3.1.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0
blackbar / activate.php

activate.php in Black Bar 2.1.2, at activate.php

144 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'WPINC' ) || die;
4
5 /**
6 * Check for minimum system requirments on plugin activation
7 * @version 3.0.0
8 */
9 class GL_Plugin_Check_v3
10 {
11 const MIN_PHP_VERSION = '5.6.0';
12 const MIN_WORDPRESS_VERSION = '4.7.0';
13
14 /**
15 * @var string
16 */
17 protected $file;
18
19 /**
20 * @var array
21 */
22 protected $versions;
23
24 /**
25 * @param string $file
26 */
27 public function __construct( $file, array $versions = array() )
28 {
29 $this->file = realpath( $file );
30 $this->versions = wp_parse_args( $versions, array(
31 'php' => static::MIN_PHP_VERSION,
32 'wordpress' => static::MIN_WORDPRESS_VERSION,
33 ));
34 }
35
36 /**
37 * @return bool
38 */
39 public function canProceed()
40 {
41 if( $this->isValid() ) {
42 return true;
43 }
44 add_action( 'activated_plugin', array( $this, 'deactivate' ));
45 add_action( 'admin_notices', array( $this, 'deactivate' ));
46 return false;
47 }
48
49 /**
50 * @return bool
51 */
52 public function isPhpValid()
53 {
54 return !version_compare( PHP_VERSION, $this->versions['php'], '<' );
55 }
56
57 /**
58 * @return bool
59 */
60 public function isValid()
61 {
62 return $this->isPhpValid() && $this->isWpValid();
63 }
64
65 /**
66 * @return bool
67 */
68 public function isWpValid()
69 {
70 global $wp_version;
71 return !version_compare( $wp_version, $this->versions['wordpress'], '<' );
72 }
73
74 /**
75 * @param string $plugin
76 * @return void
77 */
78 public function deactivate( $plugin )
79 {
80 if( $this->isValid() )return;
81 $pluginSlug = plugin_basename( $this->file );
82 if( $plugin == $pluginSlug ) {
83 $this->redirect(); //exit
84 }
85 $pluginData = get_file_data( $this->file, array( 'name' => 'Plugin Name' ), 'plugin' );
86 deactivate_plugins( $pluginSlug );
87 $this->printNotice( $pluginData['name'] );
88 }
89
90 /**
91 * @return array
92 */
93 protected function getMessages()
94 {
95 return array(
96 __( 'The %s plugin was deactivated.', 'blackbar' ),
97 __( 'This plugin requires %s or greater in order to work properly.', 'blackbar' ),
98 __( 'Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'blackbar' ),
99 __( 'PHP version', 'blackbar' ),
100 __( 'WordPress version', 'blackbar' ),
101 __( 'Update WordPress', 'blackbar' ),
102 __( 'You can use the %s plugin to restore %s to the previous version.', 'blackbar' ),
103 );
104 }
105
106 /**
107 * @param string $pluginName
108 * @return void
109 */
110 protected function printNotice( $pluginName )
111 {
112 $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
113 $messages = $this->getMessages();
114 $rollbackMessage = sprintf( '<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName );
115 if( !$this->isPhpValid() ) {
116 printf( $noticeTemplate,
117 sprintf( $messages[0], $pluginName ),
118 sprintf( $messages[1], $messages[3].' '.$this->versions['php'] ),
119 sprintf( $messages[2], PHP_VERSION ).'</p><p>'.$rollbackMessage
120 );
121 }
122 else if( !$this->isWpValid() ) {
123 printf( $noticeTemplate,
124 sprintf( $messages[0], $pluginName ),
125 sprintf( $messages[1], $messages[4].' '.$this->versions['wordpress'] ),
126 $rollbackMessage.'</p><p>'.sprintf( '<a href="%s">%s</a>', admin_url( 'update-core.php' ), $messages[5] )
127 );
128 }
129 }
130
131 /**
132 * @return void
133 */
134 protected function redirect()
135 {
136 wp_safe_redirect( self_admin_url( sprintf( 'plugins.php?plugin_status=%s&paged=%s&s=%s',
137 filter_input( INPUT_GET, 'plugin_status' ),
138 filter_input( INPUT_GET, 'paged' ),
139 filter_input( INPUT_GET, 's' )
140 )));
141 exit;
142 }
143 }
144