| @@ -2,115 +2,132 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Plugin Name: WP Coder |
| 4 | 4 | * Plugin URI: https://wordpress.org/plugins/wp-coder/ |
| 5 | 5 | * Description: Add custom CSS, HTML, JavaScript on your website page |
| 6 | - * Version: 2.3.2 | |
| 6 | + * Version: 1.1 | |
| 7 | 7 | * Author: Wow-Company |
| 8 | 8 | * Author URI: https://wow-estore.com/ |
| 9 | 9 | * License: GPL-2.0+ |
| 10 | 10 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 11 | - * Text Domain: wpcoder | |
| 12 | 11 | */ |
| 13 | 12 | |
| 14 | - namespace wpcoder; | |
| 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 | + } | |
| 15 | 24 | |
| 16 | - if ( ! defined( 'ABSPATH' ) ) exit; | |
| 25 | + // Plugin Folder Path. | |
| 26 | + if ( ! defined( 'WPCODER_PLUGIN_DIR' ) ) { | |
| 27 | + define( 'WPCODER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); | |
| 28 | + } | |
| 17 | 29 | |
| 30 | + // Plugin Folder URL. | |
| 31 | + if ( ! defined( 'WPCODER_PLUGIN_URL' ) ) { | |
| 32 | + define( 'WPCODER_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | |
| 33 | + } | |
| 18 | 34 | |
| 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.2', | |
| 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 ); | |
| 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'; | |
| 59 | 54 | |
| 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' ); | |
| 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 | + | |
| 68 | 72 | } |
| 69 | - | |
| 70 | - public function __wakeup() { | |
| 71 | - // Unserializing instances of the class is forbidden. | |
| 72 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'wpcoder' ), '1.0' ); | |
| 73 | + // Activate & diactivate | |
| 74 | + function plugin_activate() { | |
| 75 | + require_once plugin_dir_path( __FILE__ ) . 'include/activator.php'; | |
| 73 | 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 | + } | |
| 74 | 98 | |
| 75 | 99 | |
| 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'; | |
| 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; | |
| 81 | 106 | } |
| 82 | - | |
| 83 | - public function plugin_activate() { | |
| 84 | - $field = dirname( plugin_basename( __FILE__ ) ); | |
| 85 | - require_once plugin_dir_path( __FILE__ ) . 'includes/activator.php'; | |
| 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; | |
| 86 | 113 | } |
| 87 | - public function plugin_deactivate() { | |
| 88 | - require_once plugin_dir_path( __FILE__ ) . 'includes/deactivator.php'; | |
| 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 | + } | |
| 89 | 120 | } |
| 90 | 121 | |
| 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 | 122 | } |
| 123 | + | |
| 124 | + } | |
| 108 | 125 | |
| 109 | - } | |
| 110 | - | |
| 111 | - function wow_plugin_run() { | |
| 112 | - return Wow_Plugin_Class::instance(); | |
| 126 | + function wow_coder() { | |
| 127 | + $plugin = new Coder_Class(); | |
| 128 | + return $plugin; | |
| 113 | 129 | } |
| 114 | - | |
| 115 | 130 | // Get Running. |
| 116 | - wow_plugin_run(); | |
| 131 | + wow_coder(); | |
| 132 | + | |
| 133 | + | |