| @@ -2,15 +2,15 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: WP Coder |
| 4 | 4 | * Plugin URI: https://wordpress.org/plugins/wp-coder/ |
| 5 | 5 | * Description: Adding custom HTML, CSS, JavaScript and PHP code to your WordPress site. |
| 6 | - * Version: 3.4 | |
| 6 | + * Version: 4.5.2 | |
| 7 | 7 | * Author: WPCoder |
| 8 | 8 | * Author URI: https://wpcoder.pro |
| 9 | - * Author Email: [email protected] | |
| 9 | + * Author Email: [email protected] | |
| 10 | 10 | * License: GPL-2.0+ |
| 11 | 11 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 12 | - * Text Domain: wpcoder | |
| 12 | + * Text Domain: wp-coder | |
| 13 | 13 | * Requires at least: 5.4 |
| 14 | 14 | * Requires PHP: 7.4 |
| 15 | 15 | */ |
| 16 | 16 | |
| @@ -16,8 +16,9 @@ | ||
| 16 | 16 | |
| 17 | 17 | namespace WPCoder; |
| 18 | 18 | |
| 19 | 19 | // Exit if accessed directly. |
| 20 | +use WPCoder\Block\WPCoder_Block; | |
| 20 | 21 | use WPCoder\Dashboard\DBManager; |
| 21 | 22 | use WPCoder\Dashboard\FolderManager; |
| 22 | 23 | use WPCoder\Update\UpdateDB; |
| 23 | 24 | |
| @@ -22,9 +23,9 @@ | ||
| 22 | 23 | use WPCoder\Update\UpdateDB; |
| 23 | 24 | |
| 24 | 25 | defined( 'ABSPATH' ) || exit; |
| 25 | 26 | |
| 26 | -if ( ! class_exists( 'WPCoder' ) ) : | |
| 27 | +if ( ! class_exists( 'wpcoder' ) ) : | |
| 27 | 28 | |
| 28 | 29 | final class WPCoder { |
| 29 | 30 | |
| 30 | 31 | // Plugin slug |
| @@ -59,9 +60,8 @@ | ||
| 59 | 60 | self::$instance->autoloader = new Autoloader( 'WPCoder' ); |
| 60 | 61 | self::$instance->dashboard = new WOWP_Dashboard(); |
| 61 | 62 | self::$instance->public = new WOWP_Public(); |
| 62 | 63 | |
| 63 | - | |
| 64 | 64 | register_activation_hook( __FILE__, [ self::$instance, 'plugin_activate' ] ); |
| 65 | 65 | add_action( 'plugins_loaded', [ self::$instance, 'loaded' ] ); |
| 66 | 66 | } |
| 67 | 67 | |
| @@ -89,8 +89,16 @@ | ||
| 89 | 89 | return plugin_dir_url( __FILE__ ); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | + // Capability required to access the plugin (it can execute PHP, so administrators only). | |
| 94 | + public const CAPABILITY = 'manage_options'; | |
| 95 | + | |
| 96 | + // Check if the current user can manage codes. On multisite, unfiltered_html is limited to super admins. | |
| 97 | + public static function user_can_manage(): bool { | |
| 98 | + return current_user_can( self::CAPABILITY ) && current_user_can( 'unfiltered_html' ); | |
| 99 | + } | |
| 100 | + | |
| 93 | 101 | // Get Plugin Info |
| 94 | 102 | public static function info( $show = '' ): string { |
| 95 | 103 | $data = [ |
| 96 | 104 | 'name' => 'Plugin Name', |
| @@ -99,11 +107,11 @@ | ||
| 99 | 107 | 'author' => 'Author', |
| 100 | 108 | 'email' => 'Author Email', |
| 101 | 109 | ]; |
| 102 | 110 | $plugin_data = get_file_data( __FILE__, $data, false ); |
| 111 | + $plugin_data['data'] = str_replace( ' ', '-', $plugin_data['name'] ); | |
| 103 | 112 | |
| 104 | 113 | return $plugin_data[ $show ] ?? ''; |
| 105 | - | |
| 106 | 114 | } |
| 107 | 115 | |
| 108 | 116 | /** |
| 109 | 117 | * Include required files. |
| @@ -128,9 +136,9 @@ | ||
| 128 | 136 | * @access protected |
| 129 | 137 | */ |
| 130 | 138 | public function __clone() { |
| 131 | 139 | // Cloning instances of the class is forbidden. |
| 132 | - _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wpcoder' ), '1.0' ); | |
| 140 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 133 | 141 | } |
| 134 | 142 | |
| 135 | 143 | /** |
| 136 | 144 | * Disable unserializing of the class. |
| @@ -139,15 +147,32 @@ | ||
| 139 | 147 | * @access protected |
| 140 | 148 | */ |
| 141 | 149 | public function __wakeup() { |
| 142 | 150 | // Unserializing instances of the class is forbidden. |
| 143 | - _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wpcoder' ), '1.0' ); | |
| 151 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 144 | 152 | } |
| 145 | 153 | |
| 146 | 154 | public function plugin_activate(): void { |
| 147 | - DBManager::create(); | |
| 155 | + $columns = " | |
| 156 | + id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 157 | + title VARCHAR(200) NOT NULL, | |
| 158 | + html_code LONGTEXT, | |
| 159 | + css_code LONGTEXT, | |
| 160 | + js_code LONGTEXT, | |
| 161 | + php_code LONGTEXT, | |
| 162 | + param LONGTEXT, | |
| 163 | + status BOOLEAN, | |
| 164 | + mode BOOLEAN, | |
| 165 | + tag TEXT, | |
| 166 | + php_include int(11) NOT NULL DEFAULT '0', | |
| 167 | + UNIQUE KEY id (id), | |
| 168 | + INDEX id_index (id) | |
| 169 | + "; | |
| 170 | + | |
| 171 | + | |
| 172 | + DBManager::create( $columns ); | |
| 148 | 173 | FolderManager::create(); |
| 149 | - update_option( self::PREFIX . '_db_version', '3.2' ); | |
| 174 | + update_option( self::PREFIX . '_db_version', '4.0' ); | |
| 150 | 175 | |
| 151 | 176 | include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 152 | 177 | if ( is_plugin_active( 'wp-coder-pro/wp-coder-pro.php' ) ) { |
| 153 | 178 | deactivate_plugins( 'wp-coder-pro/wp-coder-pro.php' ); |
| @@ -154,9 +179,8 @@ | ||
| 154 | 179 | } |
| 155 | 180 | if ( is_plugin_active( 'wpcoderpro/wpcoderpro.php' ) ) { |
| 156 | 181 | deactivate_plugins( 'wpcoderpro/wpcoderpro.php' ); |
| 157 | 182 | } |
| 158 | - | |
| 159 | 183 | } |
| 160 | 184 | |
| 161 | 185 | /** |
| 162 | 186 | * Download the folder with languages. |
| @@ -164,11 +188,12 @@ | ||
| 164 | 188 | * @access Publisher |
| 165 | 189 | * @return void |
| 166 | 190 | */ |
| 167 | 191 | public function loaded(): void { |
| 192 | + new WPCoder_Block(); | |
| 168 | 193 | UpdateDB::init(); |
| 169 | 194 | $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; |
| 170 | - load_plugin_textdomain( 'wpcoder', false, $languages_folder ); | |
| 195 | + load_plugin_textdomain( 'wp-coder', false, $languages_folder ); | |
| 171 | 196 | } |
| 172 | 197 | |
| 173 | 198 | } |
| 174 | 199 | |