PluginProbe
WP Coder – Insert & Manage Code Snippets / 4.5.2
WP Coder – Insert & Manage Code Snippets v4.5.2
4.5.2 4.5.1 1.1 2.3.1 2.3.2 2.4.1 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1 3.1.1 3.2 3.2.1 3.3 3.4 3.5 All 40 releases
wp-coder / wp-coder.php

wp-coder.php in WP Coder – Insert & Manage Code Snippets 4.5.2, at wp-coder.php

206 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.2
7 * Author: WPCoder
8 * Author URI: https://wpcoder.pro
9 * Author Email: [email protected]
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 // 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
101 // Get Plugin Info
102 public static function info( $show = '' ): string {
103 $data = [
104 'name' => 'Plugin Name',
105 'version' => 'Version',
106 'url' => 'Plugin URI',
107 'author' => 'Author',
108 'email' => 'Author Email',
109 ];
110 $plugin_data = get_file_data( __FILE__, $data, false );
111 $plugin_data['data'] = str_replace( ' ', '-', $plugin_data['name'] );
112
113 return $plugin_data[ $show ] ?? '';
114 }
115
116 /**
117 * Include required files.
118 *
119 * @access private
120 * @since 1.0
121 */
122 private function includes(): void {
123 require_once self::dir() . 'includes/safe-mode.php';
124 require_once self::dir() . 'includes/snippets.php';
125 require_once self::dir() . 'classes/Autoloader.php';
126 require_once self::dir() . 'includes/class-wowp-dashboard.php';
127 require_once self::dir() . 'includes/class-wowp-public.php';
128 }
129
130 /**
131 * Throw error on object clone.
132 * The whole idea of the singleton design pattern is that there is a single
133 * object therefore, we don't want the object to be cloned.
134 *
135 * @return void
136 * @access protected
137 */
138 public function __clone() {
139 // Cloning instances of the class is forbidden.
140 _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin&#8217; huh?', 'wp-coder' ), '1.0' );
141 }
142
143 /**
144 * Disable unserializing of the class.
145 *
146 * @return void
147 * @access protected
148 */
149 public function __wakeup() {
150 // Unserializing instances of the class is forbidden.
151 _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin&#8217; huh?', 'wp-coder' ), '1.0' );
152 }
153
154 public function plugin_activate(): void {
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 );
173 FolderManager::create();
174 update_option( self::PREFIX . '_db_version', '4.0' );
175
176 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
177 if ( is_plugin_active( 'wp-coder-pro/wp-coder-pro.php' ) ) {
178 deactivate_plugins( 'wp-coder-pro/wp-coder-pro.php' );
179 }
180 if ( is_plugin_active( 'wpcoderpro/wpcoderpro.php' ) ) {
181 deactivate_plugins( 'wpcoderpro/wpcoderpro.php' );
182 }
183 }
184
185 /**
186 * Download the folder with languages.
187 *
188 * @access Publisher
189 * @return void
190 */
191 public function loaded(): void {
192 new WPCoder_Block();
193 UpdateDB::init();
194 $languages_folder = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
195 load_plugin_textdomain( 'wp-coder', false, $languages_folder );
196 }
197
198 }
199
200 endif;
201
202 function wp_coder_run() {
203 return WPCoder::instance();
204 }
205
206 wp_coder_run();