| @@ -1,133 +1,196 @@ | ||
| 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: 1.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 | - */ | |
| 12 | - | |
| 13 | - if ( ! defined( 'WPINC' ) ) {die;} | |
| 14 | - // Declaration Wow-Company class | |
| 15 | - if( !class_exists( 'Wow_Company' )) { | |
| 16 | - require_once plugin_dir_path( __FILE__ ) . 'asset/class-wow-company.php'; | |
| 17 | - } | |
| 18 | - if( !class_exists( 'WOW_DATA' )) { | |
| 19 | - require_once plugin_dir_path( __FILE__ ) . 'include/class/data.php'; | |
| 20 | - } | |
| 21 | - if( !class_exists( 'JavaScriptPacker' )) { | |
| 22 | - require_once plugin_dir_path( __FILE__ ) . 'include/class/packer.php'; | |
| 23 | - } | |
| 24 | - | |
| 25 | - // Plugin Folder Path. | |
| 26 | - if ( ! defined( 'WPCODER_PLUGIN_DIR' ) ) { | |
| 27 | - define( 'WPCODER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
| 28 | - } | |
| 29 | - | |
| 30 | - // Plugin Folder URL. | |
| 31 | - if ( ! defined( 'WPCODER_PLUGIN_URL' ) ) { | |
| 32 | - define( 'WPCODER_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | |
| 33 | - } | |
| 34 | - | |
| 35 | - // Uninstall plugin | |
| 36 | - register_uninstall_hook( __FILE__, array( 'Coder_Class', 'uninstall' ) ); | |
| 37 | - // Declaration of the plugin class | |
| 38 | - if( !class_exists( 'Coder_Class' ) ) { | |
| 39 | - class Coder_Class | |
| 40 | - { | |
| 41 | - const PREF = 'coder'; | |
| 42 | - public static function uninstall() { | |
| 43 | - global $wpdb; | |
| 44 | - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wow_".self::PREF ); | |
| 45 | - } | |
| 46 | - function __construct() { | |
| 47 | - $this->name = 'WP Coder'; | |
| 48 | - $this->menuname = 'WP Coder'; | |
| 49 | - $this->version = '1.0'; | |
| 50 | - $this->pluginname = dirname(plugin_basename(__FILE__)); | |
| 51 | - $this->plugindir = plugin_dir_path( __FILE__ ); | |
| 52 | - $this->pluginurl = plugin_dir_url( __FILE__ ); | |
| 53 | - $this->shortcode = 'WP-Coder'; | |
| 54 | - | |
| 55 | - // activate & diactivate | |
| 56 | - register_activation_hook( __FILE__, array($this, 'plugin_activate' ) ); | |
| 57 | - register_deactivation_hook( __FILE__, array($this, 'plugin_deactivate') ); | |
| 58 | - // admin pages | |
| 59 | - add_action( 'admin_menu', array($this, 'add_menu_page') ); | |
| 60 | - // show on front end | |
| 61 | - | |
| 62 | - if( !class_exists( 'Coder_Class_Extension' ) ) { | |
| 63 | - add_shortcode($this->shortcode, array($this, 'shortcode') ); | |
| 64 | - } | |
| 65 | - | |
| 66 | - // admin links | |
| 67 | - add_filter( 'plugin_row_meta', array($this, 'row_meta'), 10, 4 ); | |
| 68 | - add_filter( 'plugin_action_links', array($this, 'action_links'), 10, 2 ); | |
| 69 | - // check asset folder | |
| 70 | - add_filter( 'admin_init', array($this, 'asset_folder') ); | |
| 71 | - | |
| 72 | - } | |
| 73 | - // Activate & diactivate | |
| 74 | - function plugin_activate() { | |
| 75 | - require_once plugin_dir_path( __FILE__ ) . 'include/activator.php'; | |
| 76 | - } | |
| 77 | - function plugin_deactivate() { | |
| 78 | - require_once plugin_dir_path( __FILE__ ) . 'include/deactivator.php'; | |
| 79 | - } | |
| 80 | - // AdminPanel | |
| 81 | - function add_menu_page() { | |
| 82 | - add_submenu_page('wow-company', $this->name.' version '.$this->version, $this->menuname, 'manage_options', $this->pluginname, array( $this, 'plugin_admin' )); | |
| 83 | - } | |
| 84 | - function plugin_admin() { | |
| 85 | - require_once plugin_dir_path( __FILE__ ) . 'admin/index.php'; | |
| 86 | - } | |
| 87 | - // Show on Front end | |
| 88 | - function shortcode($atts) { | |
| 89 | - ob_start(); | |
| 90 | - require plugin_dir_path( __FILE__ ) . 'public/shortcode.php'; | |
| 91 | - $shortcode = ob_get_contents(); | |
| 92 | - ob_end_clean(); | |
| 93 | - return $shortcode; | |
| 94 | - } | |
| 95 | - function display() { | |
| 96 | - require plugin_dir_path( __FILE__ ) . 'public/display.php'; | |
| 97 | - } | |
| 98 | - | |
| 99 | - | |
| 100 | - // Admin links | |
| 101 | - function row_meta( $meta, $plugin_file ){ | |
| 102 | - if( false === strpos( $plugin_file, basename(__FILE__) ) ) | |
| 103 | - return $meta; | |
| 104 | - $meta[] = '<a href="https://www.facebook.com/wowaffect/" target="_blank">Join us on Facebook</a>'; | |
| 105 | - return $meta; | |
| 106 | - } | |
| 107 | - function action_links( $actions, $plugin_file ){ | |
| 108 | - if( false === strpos( $plugin_file, basename(__FILE__) ) ) | |
| 109 | - return $actions; | |
| 110 | - $settings_link = '<a href="admin.php?page='. $this->pluginname .'">Settings</a>'; | |
| 111 | - array_unshift( $actions, $settings_link ); | |
| 112 | - return $actions; | |
| 113 | - } | |
| 114 | - // check asset folder | |
| 115 | - function asset_folder(){ | |
| 116 | - $path = plugin_dir_path( __FILE__ ).'asset'; | |
| 117 | - if (!is_writable($path)) { | |
| 118 | - echo "<div class='error' id='message'><p>Please set the 775 access rights (chmod 775) for the '".$path."</p> </div>"; | |
| 119 | - } | |
| 120 | - } | |
| 121 | - | |
| 122 | - } | |
| 123 | - | |
| 124 | - } | |
| 125 | - | |
| 126 | - function wow_coder() { | |
| 127 | - $plugin = new Coder_Class(); | |
| 128 | - return $plugin; | |
| 129 | - } | |
| 130 | - // Get Running. | |
| 131 | - wow_coder(); | |
| 132 | - | |
| 133 | - | |
| 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.3 | |
| 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\Dashboard\DBManager; | |
| 21 | +use WPCoder\Dashboard\FolderManager; | |
| 22 | +use WPCoder\Update\UpdateDB; | |
| 23 | + | |
| 24 | +defined( 'ABSPATH' ) || exit; | |
| 25 | + | |
| 26 | +if ( ! class_exists( 'wpcoder' ) ) : | |
| 27 | + | |
| 28 | + final class WPCoder { | |
| 29 | + | |
| 30 | + // Plugin slug | |
| 31 | + public const SLUG = 'wp-coder'; | |
| 32 | + | |
| 33 | + // Plugin prefix | |
| 34 | + public const PREFIX = 'wow_coder'; | |
| 35 | + | |
| 36 | + public const FOLDER = 'wp-coder'; | |
| 37 | + | |
| 38 | + public const SHORTCODE = 'wp_code'; | |
| 39 | + | |
| 40 | + // Plugin ULR | |
| 41 | + public const PluginURL = 'https://wordpress.org/plugins/wp-coder/'; | |
| 42 | + | |
| 43 | + private static $instance; | |
| 44 | + /** | |
| 45 | + * @var Autoloader | |
| 46 | + */ | |
| 47 | + private $autoloader; | |
| 48 | + /** | |
| 49 | + * @var Wow_Dashboard | |
| 50 | + */ | |
| 51 | + private $dashboard; | |
| 52 | + private $public; | |
| 53 | + | |
| 54 | + public static function instance(): WPCoder { | |
| 55 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WPCoder ) ) { | |
| 56 | + self::$instance = new self; | |
| 57 | + | |
| 58 | + self::$instance->includes(); | |
| 59 | + self::$instance->autoloader = new Autoloader( 'WPCoder' ); | |
| 60 | + self::$instance->dashboard = new WOWP_Dashboard(); | |
| 61 | + self::$instance->public = new WOWP_Public(); | |
| 62 | + | |
| 63 | + register_activation_hook( __FILE__, [ self::$instance, 'plugin_activate' ] ); | |
| 64 | + add_action( 'plugins_loaded', [ self::$instance, 'loaded' ] ); | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | + return self::$instance; | |
| 69 | + } | |
| 70 | + | |
| 71 | + // Plugin Root File. | |
| 72 | + public static function file(): string { | |
| 73 | + return __FILE__; | |
| 74 | + } | |
| 75 | + | |
| 76 | + // Plugin Base Name. | |
| 77 | + public static function basename(): string { | |
| 78 | + return plugin_basename( __FILE__ ); | |
| 79 | + } | |
| 80 | + | |
| 81 | + // Plugin Folder Path. | |
| 82 | + public static function dir(): string { | |
| 83 | + return plugin_dir_path( __FILE__ ); | |
| 84 | + } | |
| 85 | + | |
| 86 | + // Plugin Folder URL. | |
| 87 | + public static function url(): string { | |
| 88 | + return plugin_dir_url( __FILE__ ); | |
| 89 | + } | |
| 90 | + | |
| 91 | + | |
| 92 | + // Get Plugin Info | |
| 93 | + public static function info( $show = '' ): string { | |
| 94 | + $data = [ | |
| 95 | + 'name' => 'Plugin Name', | |
| 96 | + 'version' => 'Version', | |
| 97 | + 'url' => 'Plugin URI', | |
| 98 | + 'author' => 'Author', | |
| 99 | + 'email' => 'Author Email', | |
| 100 | + ]; | |
| 101 | + $plugin_data = get_file_data( __FILE__, $data, false ); | |
| 102 | + $plugin_data['data'] = str_replace( ' ', '-', $plugin_data['name'] ); | |
| 103 | + | |
| 104 | + return $plugin_data[ $show ] ?? ''; | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Include required files. | |
| 109 | + * | |
| 110 | + * @access private | |
| 111 | + * @since 1.0 | |
| 112 | + */ | |
| 113 | + private function includes(): void { | |
| 114 | + require_once self::dir() . 'includes/safe-mode.php'; | |
| 115 | + require_once self::dir() . 'includes/snippets.php'; | |
| 116 | + require_once self::dir() . 'classes/Autoloader.php'; | |
| 117 | + require_once self::dir() . 'includes/class-wowp-dashboard.php'; | |
| 118 | + require_once self::dir() . 'includes/class-wowp-public.php'; | |
| 119 | + } | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Throw error on object clone. | |
| 123 | + * The whole idea of the singleton design pattern is that there is a single | |
| 124 | + * object therefore, we don't want the object to be cloned. | |
| 125 | + * | |
| 126 | + * @return void | |
| 127 | + * @access protected | |
| 128 | + */ | |
| 129 | + public function __clone() { | |
| 130 | + // Cloning instances of the class is forbidden. | |
| 131 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * Disable unserializing of the class. | |
| 136 | + * | |
| 137 | + * @return void | |
| 138 | + * @access protected | |
| 139 | + */ | |
| 140 | + public function __wakeup() { | |
| 141 | + // Unserializing instances of the class is forbidden. | |
| 142 | + _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin’ huh?', 'wp-coder' ), '1.0' ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + public function plugin_activate(): void { | |
| 146 | + $columns = " | |
| 147 | + id mediumint(9) NOT NULL AUTO_INCREMENT, | |
| 148 | + title VARCHAR(200) NOT NULL, | |
| 149 | + html_code LONGTEXT, | |
| 150 | + css_code LONGTEXT, | |
| 151 | + js_code LONGTEXT, | |
| 152 | + php_code LONGTEXT, | |
| 153 | + param LONGTEXT, | |
| 154 | + status BOOLEAN, | |
| 155 | + mode BOOLEAN, | |
| 156 | + tag TEXT, | |
| 157 | + php_include int(11) NOT NULL DEFAULT '0', | |
| 158 | + UNIQUE KEY id (id), | |
| 159 | + INDEX id_index (id) | |
| 160 | + "; | |
| 161 | + | |
| 162 | + | |
| 163 | + DBManager::create( $columns ); | |
| 164 | + FolderManager::create(); | |
| 165 | + update_option( self::PREFIX . '_db_version', '4.0' ); | |
| 166 | + | |
| 167 | + include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
| 168 | + if ( is_plugin_active( 'wp-coder-pro/wp-coder-pro.php' ) ) { | |
| 169 | + deactivate_plugins( 'wp-coder-pro/wp-coder-pro.php' ); | |
| 170 | + } | |
| 171 | + if ( is_plugin_active( 'wpcoderpro/wpcoderpro.php' ) ) { | |
| 172 | + deactivate_plugins( 'wpcoderpro/wpcoderpro.php' ); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + /** | |
| 177 | + * Download the folder with languages. | |
| 178 | + * | |
| 179 | + * @access Publisher | |
| 180 | + * @return void | |
| 181 | + */ | |
| 182 | + public function loaded(): void { | |
| 183 | + UpdateDB::init(); | |
| 184 | + $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/'; | |
| 185 | + load_plugin_textdomain( 'wp-coder', false, $languages_folder ); | |
| 186 | + } | |
| 187 | + | |
| 188 | + } | |
| 189 | + | |
| 190 | +endif; | |
| 191 | + | |
| 192 | +function wp_coder_run() { | |
| 193 | + return WPCoder::instance(); | |
| 194 | +} | |
| 195 | + | |
| 196 | +wp_coder_run(); | |