| @@ -1,116 +1,198 @@ | ||
| 1 | -<?php | |
| 2 | - /** | |
| 3 | - * Plugin Name: WP Coder | |
| 4 | - * Plugin URI: https://wordpress.org/plugins/wp-coder/ | |
| 5 | - * Description: Add custom CSS, HTML, JavaScript on your website page | |
| 6 | - * Version: 2.3.1 | |
| 7 | - * Author: Wow-Company | |
| 8 | - * Author URI: https://wow-estore.com/ | |
| 9 | - * License: GPL-2.0+ | |
| 10 | - * License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
| 11 | - * Text Domain: wpcoder | |
| 12 | - */ | |
| 13 | - | |
| 14 | - namespace wpcoder; | |
| 15 | - | |
| 16 | - if ( ! defined( 'ABSPATH' ) ) exit; | |
| 17 | - | |
| 18 | - | |
| 19 | - if( !class_exists( 'Wow_Plugin_Class' ) ) { | |
| 20 | - | |
| 21 | - final class Wow_Plugin_Class { | |
| 22 | - | |
| 23 | - private static $instance; | |
| 24 | - | |
| 25 | - const PREF = 'coder'; | |
| 26 | - | |
| 27 | - public static function instance() { | |
| 28 | - | |
| 29 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Wow_Plugin_Class ) ) { | |
| 30 | - | |
| 31 | - $info = array( | |
| 32 | - 'plugin_name' => 'WP Coder', | |
| 33 | - 'plugin_menu' => 'WP Coder', | |
| 34 | - 'plugin_home_url' => 'https://wordpress.org/plugins/wp-coder/', | |
| 35 | - 'plugin_version' => '2.3.1', | |
| 36 | - 'plugin_file' => basename( __FILE__ ), | |
| 37 | - 'plugin_slug' => dirname( plugin_basename( __FILE__ ) ), | |
| 38 | - 'plugin_dir' => plugin_dir_path( __FILE__ ), | |
| 39 | - 'plugin_url' => plugin_dir_url( __FILE__ ), | |
| 40 | - 'plugin_pref' => self::PREF, | |
| 41 | - 'author_url' => 'https://wow-estore.com', | |
| 42 | - 'pro_url' => 'https://wow-estore.com/item/wp-coder-extension/', | |
| 43 | - 'shortcode' => 'WP-Coder', | |
| 44 | - ); | |
| 45 | - | |
| 46 | - self::$instance = new Wow_Plugin_Class; | |
| 47 | - | |
| 48 | - register_activation_hook( __FILE__, array( self::$instance, 'plugin_activate' ) ); | |
| 49 | - register_deactivation_hook( __FILE__, array( self::$instance, 'plugin_deactivate' ) ); | |
| 50 | - | |
| 51 | - add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) ); | |
| 52 | - | |
| 53 | - add_action('admin_init', array( self::$instance, 'create_field') ); | |
| 54 | - | |
| 55 | - self::$instance->includes(); | |
| 56 | - | |
| 57 | - self::$instance->admin = new Wow_Admin_Class( $info ); | |
| 58 | - self::$instance->public = new Wow_Public_Class( $info ); | |
| 59 | - | |
| 60 | - | |
| 61 | - } | |
| 62 | - return self::$instance; | |
| 63 | - } | |
| 64 | - | |
| 65 | - public function __clone() { | |
| 66 | - // Cloning instances of the class is forbidden. | |
| 67 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wpcoder' ), '1.0' ); | |
| 68 | - } | |
| 69 | - | |
| 70 | - public function __wakeup() { | |
| 71 | - // Unserializing instances of the class is forbidden. | |
| 72 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wpcoder' ), '1.0' ); | |
| 73 | - } | |
| 74 | - | |
| 75 | - | |
| 76 | - private function includes() { | |
| 77 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-js-packer.php'; | |
| 78 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-db-update.php'; | |
| 79 | - require_once plugin_dir_path( __FILE__ ) . 'admin/class-admin.php'; | |
| 80 | - require_once plugin_dir_path( __FILE__ ) . 'public/class-public.php'; | |
| 81 | - } | |
| 82 | - | |
| 83 | - public function plugin_activate() { | |
| 84 | - $field = dirname( plugin_basename( __FILE__ ) ); | |
| 85 | - require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php'; | |
| 86 | - } | |
| 87 | - public function plugin_deactivate() { | |
| 88 | - require_once plugin_dir_path( __FILE__ ) . 'includes/deactivator.php'; | |
| 89 | - } | |
| 90 | - | |
| 91 | - public function create_field() { | |
| 92 | - if( get_option( 'wp_coder_create_field') === false ) { | |
| 93 | - $upload = wp_upload_dir(); | |
| 94 | - $field = dirname( plugin_basename( __FILE__ ) ); | |
| 95 | - $basedir = $upload['basedir'] . '/' . $field . '/'; | |
| 96 | - if ( !file_exists( $basedir ) ) { | |
| 97 | - wp_mkdir_p( $basedir ); | |
| 98 | - } | |
| 99 | - update_option( 'wp_coder_create_field', '2.0' ); | |
| 100 | - } | |
| 101 | - } | |
| 102 | - | |
| 103 | - public function load_textdomain() { | |
| 104 | - load_plugin_textdomain( self::PREF, FALSE, dirname( plugin_basename(__FILE__) ).'/languages/' ); | |
| 105 | - } | |
| 106 | - | |
| 107 | - } | |
| 108 | - | |
| 109 | - } | |
| 110 | - | |
| 111 | - function wow_plugin_run() { | |
| 112 | - return Wow_Plugin_Class::instance(); | |
| 113 | - } | |
| 114 | - | |
| 115 | - // Get Running. | |
| 116 | - wow_plugin_run(); | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Plugin Name: WP Coder | |
| 4 | + * Plugin URI: https://wordpress.org/plugins/wp-coder/ | |
| 5 | + * Description: Adding custom HTML, CSS, JavaScript and PHP code to your WordPress site. | |
| 6 | + * Version: 4.5.1 | |
| 7 | + * Author: WPCoder | |
| 8 | + * Author URI: https://wpcoder.pro | |
| 9 | + * Author Email: hey@wow-company.com | |
| 10 | + * License: GPL-2.0+ | |
| 11 | + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt | |
| 12 | + * Text Domain: wp-coder | |
| 13 | + * Requires at least: 5.4 | |
| 14 | + * Requires PHP: 7.4 | |
| 15 | + */ | |
| 16 | + | |
| 17 | +namespace WPCoder; | |
| 18 | + | |
| 19 | +// Exit if accessed directly. | |
| 20 | +use WPCoder\Block\WPCoder_Block; | |
| 21 | +use WPCoder\Dashboard\DBManager; | |
| 22 | +use WPCoder\Dashboard\FolderManager; | |
| 23 | +use WPCoder\Update\UpdateDB; | |
| 24 | + | |
| 25 | +defined( 'ABSPATH' ) || exit; | |
| 26 | + | |
| 27 | +if ( ! class_exists( 'wpcoder' ) ) : | |
| 28 | + | |
| 29 | + final class WPCoder { | |
| 30 | + | |
| 31 | + // Plugin slug | |
| 32 | + public const SLUG = 'wp-coder'; | |
| 33 | + | |
| 34 | + // Plugin prefix | |
| 35 | + public const PREFIX = 'wow_coder'; | |
| 36 | + | |
| 37 | + public const FOLDER = 'wp-coder'; | |
| 38 | + | |
| 39 | + public const SHORTCODE = 'wp_code'; | |
| 40 | + | |
| 41 | + // Plugin ULR | |
| 42 | + public const PluginURL = 'https://wordpress.org/plugins/wp-coder/'; | |
| 43 | + | |
| 44 | + private static $instance; | |
| 45 | + /** | |
| 46 | + * @var Autoloader | |
| 47 | + */ | |
| 48 | + private $autoloader; | |
| 49 | + /** | |
| 50 | + * @var Wow_Dashboard | |
| 51 | + */ | |
| 52 | + private $dashboard; | |
| 53 | + private $public; | |
| 54 | + | |
| 55 | + public static function instance(): WPCoder { | |
| 56 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPCoder ) ) { | |
| 57 | + self::$instance = new self; | |
| 58 | + | |
| 59 | + self::$instance->includes(); | |
| 60 | + self::$instance->autoloader = new Autoloader( 'WPCoder' ); | |
| 61 | + self::$instance->dashboard = new WOWP_Dashboard(); | |
| 62 | + self::$instance->public = new WOWP_Public(); | |
| 63 | + | |
| 64 | + register_activation_hook( __FILE__, [ self::$instance, 'plugin_activate' ] ); | |
| 65 | + add_action( 'plugins_loaded', [ self::$instance, 'loaded' ] ); | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + return self::$instance; | |
| 70 | + } | |
| 71 | + | |
| 72 | + // Plugin Root File. | |
| 73 | + public static function file(): string { | |
| 74 | + return __FILE__; | |
| 75 | + } | |
| 76 | + | |
| 77 | + // Plugin Base Name. | |
| 78 | + public static function basename(): string { | |
| 79 | + return plugin_basename( __FILE__ ); | |
| 80 | + } | |
| 81 | + | |
| 82 | + // Plugin Folder Path. | |
| 83 | + public static function dir(): string { | |
| 84 | + return plugin_dir_path( __FILE__ ); | |
| 85 | + } | |
| 86 | + | |
| 87 | + // Plugin Folder URL. | |
| 88 | + public static function url(): string { | |
| 89 | + return plugin_dir_url( __FILE__ ); | |
| 90 | + } | |
| 91 | + | |
| 92 | + | |
| 93 | + // Get Plugin Info | |
| 94 | + public static function info( $show = '' ): string { | |
| 95 | + $data = [ | |
| 96 | + 'name' => 'Plugin Name', | |
| 97 | + 'version' => 'Version', | |
| 98 | + 'url' => 'Plugin URI', | |
| 99 | + 'author' => 'Author', | |
| 100 | + 'email' => 'Author Email', | |
| 101 | + ]; | |
| 102 | + $plugin_data = get_file_data( __FILE__, $data, false ); | |
| 103 | + $plugin_data['data'] = str_replace( ' ', '-', $plugin_data['name'] ); | |
| 104 | + | |
| 105 | + return $plugin_data[ $show ] ?? ''; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Include required files. | |
| 110 | + * | |
| 111 | + * @access private | |
| 112 | + * @since 1.0 | |
| 113 | + */ | |
| 114 | + private function includes(): void { | |
| 115 | + require_once self::dir() . 'includes/safe-mode.php'; | |
| 116 | + require_once self::dir() . 'includes/snippets.php'; | |
| 117 | + require_once self::dir() . 'classes/Autoloader.php'; | |
| 118 | + require_once self::dir() . 'includes/class-wowp-dashboard.php'; | |
| 119 | + require_once self::dir() . 'includes/class-wowp-public.php'; | |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Throw error on object clone. | |
| 124 | + * The whole idea of the singleton design pattern is that there is a single | |
| 125 | + * object therefore, we don't want the object to be cloned. | |
| 126 | + * | |
| 127 | + * @return void | |
| 128 | + * @access protected | |
| 129 | + */ | |
| 130 | + public function __clone() { | |
| 131 | + // Cloning instances of the class is forbidden. | |
| 132 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Disable unserializing of the class. | |
| 137 | + * | |
| 138 | + * @return void | |
| 139 | + * @access protected | |
| 140 | + */ | |
| 141 | + public function __wakeup() { | |
| 142 | + // Unserializing instances of the class is forbidden. | |
| 143 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 144 | + } | |
| 145 | + | |
| 146 | + public function plugin_activate(): void { | |
| 147 | + $columns = " | |
| 148 | + id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 149 | + title VARCHAR(200) NOT NULL, | |
| 150 | + html_code LONGTEXT, | |
| 151 | + css_code LONGTEXT, | |
| 152 | + js_code LONGTEXT, | |
| 153 | + php_code LONGTEXT, | |
| 154 | + param LONGTEXT, | |
| 155 | + status BOOLEAN, | |
| 156 | + mode BOOLEAN, | |
| 157 | + tag TEXT, | |
| 158 | + php_include int(11) NOT NULL DEFAULT '0', | |
| 159 | + UNIQUE KEY id (id), | |
| 160 | + INDEX id_index (id) | |
| 161 | + "; | |
| 162 | + | |
| 163 | + | |
| 164 | + DBManager::create( $columns ); | |
| 165 | + FolderManager::create(); | |
| 166 | + update_option( self::PREFIX . '_db_version', '4.0' ); | |
| 167 | + | |
| 168 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
| 169 | + if ( is_plugin_active( 'wp-coder-pro/wp-coder-pro.php' ) ) { | |
| 170 | + deactivate_plugins( 'wp-coder-pro/wp-coder-pro.php' ); | |
| 171 | + } | |
| 172 | + if ( is_plugin_active( 'wpcoderpro/wpcoderpro.php' ) ) { | |
| 173 | + deactivate_plugins( 'wpcoderpro/wpcoderpro.php' ); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + /** | |
| 178 | + * Download the folder with languages. | |
| 179 | + * | |
| 180 | + * @access Publisher | |
| 181 | + * @return void | |
| 182 | + */ | |
| 183 | + public function loaded(): void { | |
| 184 | + new WPCoder_Block(); | |
| 185 | + UpdateDB::init(); | |
| 186 | + $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; | |
| 187 | + load_plugin_textdomain( 'wp-coder', false, $languages_folder ); | |
| 188 | + } | |
| 189 | + | |
| 190 | + } | |
| 191 | + | |
| 192 | +endif; | |
| 193 | + | |
| 194 | +function wp_coder_run() { | |
| 195 | + return WPCoder::instance(); | |
| 196 | +} | |
| 197 | + | |
| 198 | +wp_coder_run(); | |