PluginProbe
PixCodes / 2.3.9
PixCodes v2.3.9
2.3.9 trunk 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8
pixcodes / pixcodes.php

pixcodes.php in PixCodes 2.3.9, at pixcodes.php

171 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: PixCodes
4 Plugin URI: https://pixelgrade.com
5 Description: WordPress shortcodes plugin everywhere. Loaded with shortcodes, awesomeness and more.
6 Version: 2.3.9
7 Author: Pixelgrade
8 Author URI: https://pixelgrade.com
9 Author Email: hello@pixelgrade.com
10 License: GPL-2.0-or-later
11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
12 Text Domain: pixcodes
13 Domain Path: /lang
14 Requires at least: 5.9.0
15 Tested up to: 7.1
16 Requires PHP: 7.4
17 */
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 die( '-1' );
21 }
22
23 class WpGradeShortcodes {
24
25 protected static $plugin_dir;
26 public $plugin_url;
27
28 function __construct() {
29 self::$plugin_dir = dirname( plugin_basename( __FILE__ ) );
30 $this->plugin_url = plugin_dir_url( dirname( __FILE__ ) . '/plugin.php' );
31
32 add_action( 'admin_init', array( $this, 'wpgrade_init_plugin' ) );
33 // Register admin styles and scripts
34 add_action( 'mce_buttons_2', array( $this, 'register_admin_assets' ) );
35
36 // Register site styles and scripts
37 // not used right now
38 //add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) );
39 //add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) );
40
41 // Run our plugin along with wordpress init
42 add_action( 'init', array( $this, 'create_wpgrade_shortcodes' ) );
43
44 add_filter( 'the_content', array( $this, 'wpgrade_remove_spaces_around_shortcodes' ) );
45
46 // ajax load for modal
47 if ( is_admin() ) {
48 add_action( 'wp_ajax_wpgrade_get_shortcodes_modal', array( $this, 'wpgrade_get_shortcodes_modal' ) );
49 }
50
51 //prevent certain shortcodes from getting their content texturized
52 add_filter( 'no_texturize_shortcodes', array( $this, 'wpgrade_shortcodes_to_exempt_from_wptexturize' ) );
53
54 } // end constructor
55
56 public function wpgrade_init_plugin() {
57 $this->plugin_textdomain();
58 $this->add_wpgrade_shortcodes_button();
59 }
60
61 public function plugin_textdomain() {
62 // WordPress.org loads PixCodes language packs automatically.
63 } // end plugin_textdomain
64
65 /**
66 * Registers and enqueues admin-specific styles.
67 */
68 public function register_admin_assets( $buttons ) {
69 wp_enqueue_style( 'wpgrade-shortcodes-reveal-styles', $this->plugin_url . 'css/base.css', array( 'wp-color-picker' ), '2.3.9' );
70 wp_enqueue_script( 'select2-js', $this->plugin_url . 'js/select2/select2.js', array(
71 'jquery',
72 'jquery-ui-tabs'
73 ), '2.3.9', true );
74 wp_enqueue_script( 'wp-color-picker' );
75
76 return $buttons;
77 } // end register_admin_assets
78
79 /**
80 * Registers and enqueues plugin-specific styles.Usually we base on the theme style and this is empty
81 */
82 public function register_plugin_styles() {
83 } // end register_plugin_styles
84
85 /**
86 * Registers and enqueues plugin-specific scripts..Usually we base on theme front-end scripts and this is empty.
87 */
88 public function register_plugin_scripts() {
89 } // end register_plugin_scripts
90
91 /*--------------------------------------------*
92 * Core Functions
93 *---------------------------------------------*/
94
95 function add_wpgrade_shortcodes_button() {
96 //make sure the user has correct permissions
97 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
98 return;
99 }
100
101 // add to the visual mode only
102 if ( get_user_option( 'rich_editing' ) == 'true' ) {
103 add_filter( 'mce_external_plugins', array( $this, 'addto_mce_wpgrade_shortcodes' ) );
104 add_filter( 'mce_buttons', array( $this, 'register_wpgrade_shortcodes_button' ) );
105 }
106 } // end action_method_name
107
108 function register_wpgrade_shortcodes_button( $buttons ) {
109 array_push( $buttons, "wpgrade" );
110
111 return $buttons;
112 } // end filter_method_name
113
114 function addto_mce_wpgrade_shortcodes( $plugin_array ) {
115 $plugin_array['wpgrade'] = $this->plugin_url . 'js/add_shortcode.js';
116 wp_localize_script(
117 'editor',
118 'pixcodesModal',
119 array(
120 'nonce' => wp_create_nonce( 'pixcodes_shortcode_modal' ),
121 )
122 );
123
124 return $plugin_array;
125 }
126
127 public function wpgrade_get_shortcodes_modal() {
128 check_ajax_referer( 'pixcodes_shortcode_modal', 'nonce' );
129
130 if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
131 wp_send_json_error( esc_html__( 'You are not allowed to access this shortcode modal.', 'pixcodes' ), 403 );
132 }
133
134 ob_start();
135 include( 'views/shortcodes-modal.php' );
136 wp_send_json_success( ob_get_clean() );
137 }
138
139 public function create_wpgrade_shortcodes() {
140 include_once( 'shortcodes.php' );
141 }
142
143 function wpgrade_remove_spaces_around_shortcodes( $content ) {
144 $array = array(
145 '<p>[' => '[',
146 ']</p>' => ']',
147 ']<br />' => ']'
148 );
149
150 $content = strtr( $content, $array );
151
152 return $content;
153 }
154
155 /**
156 * Add some of our own shortcodes to the list of shortcodes that won't have their content texturized.
157 *
158 * @param array $shortcodes
159 *
160 * @return array
161 */
162 function wpgrade_shortcodes_to_exempt_from_wptexturize( $shortcodes ) {
163 $shortcodes[] = 'restaurantmenu';
164
165 return $shortcodes;
166 }
167
168 } // end class
169
170 $WpGradeShortcodes = new WpGradeShortcodes();
171