|
16 | 16 | * Plugin Name: CBX PhpSpreadSheet Library |
17 | 17 | * Plugin URI: https://codeboxr.com/php-spreadsheet-library-wordpress-plugin/ |
18 | 18 | * Description: A pure PHP library for reading and writing spreadsheet files https://phpspreadsheet.readthedocs.io/ |
19 | | - * Version: 1.0.6 |
20 | | - * Requires PHP: 7.4 |
| 19 | + * Version: 1.0.8 |
| 20 | + * Requires PHP: 8.1.99 |
21 | 21 | * Author: Codeboxr |
22 | 22 | * Author URI: https://github.com/PHPOffice/PhpSpreadsheet |
23 | 23 | * License: GPL-2.0+ |
|
26 | 26 | * Domain Path: /languages |
27 | 27 | */ |
28 | 28 |
|
29 | | -use Cbx\Phpspreadsheet\Hooks; |
30 | 29 |
|
31 | | -if (!defined('WPINC')) { |
32 | | - die; |
| 30 | + |
| 31 | +if ( ! defined( 'WPINC' ) ) { |
| 32 | + die; |
33 | 33 | } |
34 | 34 |
|
35 | | -defined('CBXPHPSPREADSHEET_PLUGIN_NAME') or define('CBXPHPSPREADSHEET_PLUGIN_NAME', 'cbxphpspreadsheet'); |
36 | | -defined('CBXPHPSPREADSHEET_PLUGIN_VERSION') or define('CBXPHPSPREADSHEET_PLUGIN_VERSION', '1.0.6'); |
37 | | -defined('CBXPHPSPREADSHEET_BASE_NAME') or define('CBXPHPSPREADSHEET_BASE_NAME', plugin_basename(__FILE__)); |
38 | | -defined('CBXPHPSPREADSHEET_ROOT_PATH') or define('CBXPHPSPREADSHEET_ROOT_PATH', plugin_dir_path(__FILE__)); |
39 | | -defined('CBXPHPSPREADSHEET_ROOT_URL') or define('CBXPHPSPREADSHEET_ROOT_URL', plugin_dir_url(__FILE__)); |
| 35 | +defined( 'CBXPHPSPREADSHEET_PLUGIN_NAME' ) or define( 'CBXPHPSPREADSHEET_PLUGIN_NAME', 'cbxphpspreadsheet' ); |
| 36 | +defined( 'CBXPHPSPREADSHEET_PLUGIN_VERSION' ) or define( 'CBXPHPSPREADSHEET_PLUGIN_VERSION', '1.0.8' ); |
| 37 | +defined( 'CBXPHPSPREADSHEET_BASE_NAME' ) or define( 'CBXPHPSPREADSHEET_BASE_NAME', plugin_basename( __FILE__ ) ); |
| 38 | +defined( 'CBXPHPSPREADSHEET_ROOT_PATH' ) or define( 'CBXPHPSPREADSHEET_ROOT_PATH', plugin_dir_path( __FILE__ ) ); |
| 39 | +defined( 'CBXPHPSPREADSHEET_ROOT_URL' ) or define( 'CBXPHPSPREADSHEET_ROOT_URL', plugin_dir_url( __FILE__ ) ); |
40 | 40 |
|
41 | | -register_activation_hook(__FILE__, ['CBXPhpSpreadSheet', 'activation']); |
42 | | -require_once CBXPHPSPREADSHEET_ROOT_PATH . "lib/vendor/autoload.php"; |
| 41 | +register_activation_hook( __FILE__, [ 'CBXPhpSpreadSheet', 'activation' ] ); |
43 | 42 |
|
44 | | -add_action('admin_notices', ['CBXPhpSpreadSheet', 'activation_error_display']); |
45 | 43 |
|
46 | 44 | /** |
47 | 45 | * Class CBXPhpSpreadSheet |
48 | 46 | */ |
49 | | -class CBXPhpSpreadSheet |
50 | | -{ |
51 | | - public function __construct() |
52 | | - { |
53 | | - // Load text domain |
54 | | - load_plugin_textdomain('cbxphpspreadsheet', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
55 | | - |
56 | | - // Add custom row meta links |
57 | | - add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2); |
| 47 | +class CBXPhpSpreadSheet { |
| 48 | + public function __construct() { |
| 49 | + // Load text domain |
| 50 | + load_plugin_textdomain( 'cbxphpspreadsheet', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
58 | 51 |
|
59 | | - new Hooks(); |
60 | | - }//end constructor |
| 52 | + // Add custom row meta links |
| 53 | + add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 ); |
| 54 | + add_action( 'admin_notices', [ $this, 'activation_error_display' ] ); |
| 55 | + }//end constructor |
61 | 56 |
|
62 | 57 | /** |
63 | 58 | * Activation hook |
64 | 59 | * |
65 | 60 | * @return void |
66 | 61 | */ |
67 | | - public static function activation() |
68 | | - { |
69 | | - $errors = []; |
70 | | - |
71 | | - if (!self::php_version_check()) { |
72 | | - $errors[] = __('This plugin requires PHP version 7.4 or newer.', 'cbxphpspreadsheet'); |
73 | | - } |
| 62 | + public static function activation() { |
| 63 | + $errors = []; |
| 64 | + |
| 65 | + if ( ! self::php_version_check() ) { |
| 66 | + $errors[] = esc_html__( 'CBX PhpSpreadSheet Library plugin requires PHP version 8.1.99 or newer.', 'cbxphpspreadsheet' ); |
| 67 | + } |
74 | 68 |
|
75 | | - if (!self::extension_check(['zip', 'xml', 'gd'])) { |
76 | | - $errors[] = __('This plugin requires PHP extensions: Zip, XML, and GD2.', 'cbxphpspreadsheet'); |
77 | | - } |
| 69 | + if ( ! self::extension_check( [ 'zip', 'xml', 'gd' ] ) ) { |
| 70 | + $errors[] = esc_html__( 'CBX PhpSpreadSheet Library plugin requires PHP extensions: Zip, XML, and GD2.', 'cbxphpspreadsheet' ); |
| 71 | + } |
78 | 72 |
|
79 | | - if (sizeof($errors) > 0) { |
80 | | - update_option('cbxphpspreadsheet_activation_error', $errors); |
81 | | - deactivate_plugins(plugin_basename(__FILE__)); |
| 73 | + if ( sizeof( $errors ) > 0 ) { |
| 74 | + update_option( 'cbxphpspreadsheet_activation_error', $errors ); |
| 75 | + //deactivate_plugins(plugin_basename(__FILE__)); |
82 | 76 |
|
83 | | - //wp_die('Plugin not activated due to dependency not fulfilled.'); |
| 77 | + //wp_die('Plugin not activated due to dependency not fulfilled.'); |
84 | 78 |
|
85 | | - //die(); |
86 | | - } |
87 | | - }//end method activation |
| 79 | + //die(); |
| 80 | + } |
| 81 | + }//end method activation |
88 | 82 |
|
89 | 83 | /** |
90 | 84 | * Show error |
91 | 85 | * |
92 | 86 | * @return void |
93 | 87 | */ |
94 | | - public static function activation_error_display(){ |
| 88 | + public function activation_error_display() { |
95 | 89 | // Only display on specific admin pages (e.g., plugins page) |
96 | 90 | $screen = get_current_screen(); |
97 | | - if ($screen && $screen->id === 'plugins') { |
98 | | - $errors = get_option('cbxphpspreadsheet_activation_error'); |
99 | | - if ($errors) { |
100 | | - if(is_array($errors) && sizeof($errors) > 0){ |
101 | | - foreach ($errors as $error){ |
102 | | - echo '<div class="notice notice-error is-dismissible"><p>' . esc_html($error) . '</p></div>'; |
| 91 | + if ( $screen && $screen->id === 'plugins' ) { |
| 92 | + $errors = get_option( 'cbxphpspreadsheet_activation_error' ); |
| 93 | + if ( $errors ) { |
| 94 | + if ( is_array( $errors ) && sizeof( $errors ) > 0 ) { |
| 95 | + foreach ( $errors as $error ) { |
| 96 | + echo '<div class="notice notice-error is-dismissible"><p>' . esc_html( $error ) . '</p></div>'; |
103 | 97 | } |
104 | 98 | } |
105 | 99 |
|
106 | | - delete_option('cbxphpspreadsheet_activation_error'); |
107 | | - deactivate_plugins('cbxphpspreadsheet/cbxphpspreadsheet.php'); |
| 100 | + delete_option( 'cbxphpspreadsheet_activation_error' ); |
| 101 | + //deactivate_plugins('cbxphpspreadsheet/cbxphpspreadsheet.php'); |
108 | 102 | } |
109 | 103 | } |
110 | 104 | }//end method activation_error_display |
111 | 105 |
|
112 | | - /** |
113 | | - * Check PHP version compatibility |
114 | | - * |
115 | | - * @return bool |
116 | | - */ |
117 | | - private static function php_version_check() |
118 | | - { |
119 | | - return version_compare(PHP_VERSION, '7.4.0', '>='); |
120 | | - }//end method php_version_check |
121 | | - |
122 | | - /** |
123 | | - * Check if required PHP extensions are enabled |
124 | | - * |
125 | | - * @param array $extensions |
126 | | - * @return bool |
127 | | - */ |
128 | | - private static function extension_check($extensions) |
129 | | - { |
130 | | - foreach ($extensions as $extension) { |
131 | | - if (!extension_loaded($extension)) { |
132 | | - return false; |
133 | | - } |
134 | | - } |
135 | | - return true; |
136 | | - }//end method extension_check |
137 | | - |
138 | | - /** |
139 | | - * Add support and documentation links to the plugin row meta |
140 | | - * |
141 | | - * @param array $links |
142 | | - * @param string $file |
143 | | - * @return array |
144 | | - */ |
145 | | - public function plugin_row_meta($links, $file) |
146 | | - { |
147 | | - if (strpos($file, 'cbxphpspreadsheet.php') !== false) { |
148 | | - $new_links = [ |
149 | | - 'support' => '<a href="https://codeboxr.com/php-spreadsheet-library-wordpress-plugin/" target="_blank">' . esc_html__('Support', 'cbxphpspreadsheet') . '</a>', |
150 | | - 'doc' => '<a href="https://phpspreadsheet.readthedocs.io/en/latest/" target="_blank">' . esc_html__('PHP Spreadsheet Doc', 'cbxphpspreadsheet') . '</a>', |
151 | | - ]; |
152 | | - |
153 | | - $links = array_merge($links, $new_links); |
154 | | - } |
155 | | - |
156 | | - return $links; |
157 | | - } |
158 | | -} |
| 106 | + /** |
| 107 | + * Check PHP version compatibility |
| 108 | + * |
| 109 | + * @return bool |
| 110 | + */ |
| 111 | + private static function php_version_check() { |
| 112 | + //return version_compare( PHP_VERSION, '8.1.99', '>=' ); |
| 113 | + return false; |
| 114 | + }//end method php_version_check |
| 115 | + |
| 116 | + /** |
| 117 | + * Check if required PHP extensions are enabled |
| 118 | + * |
| 119 | + * @param array $extensions |
| 120 | + * |
| 121 | + * @return bool |
| 122 | + */ |
| 123 | + private static function extension_check( $extensions ) { |
| 124 | + foreach ( $extensions as $extension ) { |
| 125 | + if ( ! extension_loaded( $extension ) ) { |
| 126 | + return false; |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + return true; |
| 131 | + }//end method extension_check |
| 132 | + |
| 133 | + /** |
| 134 | + * Is the environment ready for the phpspreadsheet package |
| 135 | + * |
| 136 | + * @return bool |
| 137 | + */ |
| 138 | + public static function environment_ready() { |
| 139 | + return self::php_version_check() && self::extension_check( [ 'zip', 'xml', 'gd' ]); |
| 140 | + }//end method environment_ready |
| 141 | + |
| 142 | + /** |
| 143 | + * Add support and documentation links to the plugin row meta |
| 144 | + * |
| 145 | + * @param array $links |
| 146 | + * @param string $file |
| 147 | + * |
| 148 | + * @return array |
| 149 | + */ |
| 150 | + public function plugin_row_meta( $links, $file ) { |
| 151 | + if ( strpos( $file, 'cbxphpspreadsheet.php' ) !== false ) { |
| 152 | + $new_links = [ |
| 153 | + 'support' => '<a href="https://codeboxr.com/php-spreadsheet-library-wordpress-plugin/" target="_blank">' . esc_html__( 'Support', 'cbxphpspreadsheet' ) . '</a>', |
| 154 | + 'doc' => '<a href="https://phpspreadsheet.readthedocs.io/en/latest/" target="_blank">' . esc_html__( 'PHP Spreadsheet Doc', 'cbxphpspreadsheet' ) . '</a>', |
| 155 | + ]; |
| 156 | + |
| 157 | + $links = array_merge( $links, $new_links ); |
| 158 | + } |
| 159 | + |
| 160 | + return $links; |
| 161 | + } |
| 162 | +}//end class CBXPhpSpreadSheet |
159 | 163 |
|
160 | 164 | /** |
161 | 165 | * Initialize the plugin |
162 | 166 | */ |
163 | | -function cbxphpspreadsheet_load_plugin() |
164 | | -{ |
165 | | - new CBXPhpSpreadSheet(); |
| 167 | +function cbxphpspreadsheet_load_plugin() { |
| 168 | + new CBXPhpSpreadSheet(); |
| 169 | +} |
| 170 | + |
| 171 | +add_action( 'plugins_loaded', 'cbxphpspreadsheet_load_plugin', 5 ); |
| 172 | + |
| 173 | + |
| 174 | +if(!function_exists('cbxphpspreadsheet_loadable')){ |
| 175 | + /** |
| 176 | + * Check if the enviroment ready for phpspreadsheet library |
| 177 | + * |
| 178 | + * @return bool |
| 179 | + */ |
| 180 | + function cbxphpspreadsheet_loadable(){ |
| 181 | + return CBXPhpSpreadSheet::environment_ready(); |
| 182 | + }//end function cbxphpspreadsheet_loadable |
| 183 | +} |
| 184 | + |
| 185 | +if(!function_exists('cbxphpspreadsheet_load')){ |
| 186 | + /** |
| 187 | + * If the enviroment is ready then load the autoloaded |
| 188 | + * |
| 189 | + * @return void |
| 190 | + */ |
| 191 | + function cbxphpspreadsheet_load(){ |
| 192 | + if(CBXPhpSpreadSheet::environment_ready()){ |
| 193 | + require_once CBXPHPSPREADSHEET_ROOT_PATH . "lib/vendor/autoload.php"; |
| 194 | + } |
| 195 | + }//end function cbxphpspreadsheet_load |
166 | 196 | } |
167 | 197 |
|
168 | | -add_action('plugins_loaded', 'cbxphpspreadsheet_load_plugin', 5); |
|
0 commit comments