| 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.6 |
| 7 |
Author: PixelGrade |
| 8 |
Author URI: https://pixelgrade.com |
| 9 |
Author Email: contact@pixelgrade.com |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
die( '-1' ); |
| 14 |
} |
| 15 |
|
| 16 |
class WpGradeShortcodes { |
| 17 |
|
| 18 |
protected static $plugin_dir; |
| 19 |
public $plugin_url; |
| 20 |
|
| 21 |
function __construct() { |
| 22 |
self::$plugin_dir = dirname( plugin_basename( __FILE__ ) ); |
| 23 |
$this->plugin_url = plugin_dir_url( dirname( __FILE__ ) . '/plugin.php' ); |
| 24 |
|
| 25 |
add_action( 'admin_init', array( $this, 'wpgrade_init_plugin' ) ); |
| 26 |
// Register admin styles and scripts |
| 27 |
add_action( 'mce_buttons_2', array( $this, 'register_admin_assets' ) ); |
| 28 |
|
| 29 |
// Register site styles and scripts |
| 30 |
// not used right now |
| 31 |
//add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_styles' ) ); |
| 32 |
//add_action( 'wp_enqueue_scripts', array( $this, 'register_plugin_scripts' ) ); |
| 33 |
|
| 34 |
// Run our plugin along with wordpress init |
| 35 |
add_action( 'init', array( $this, 'create_wpgrade_shortcodes' ) ); |
| 36 |
|
| 37 |
add_filter( 'the_content', array( $this, 'wpgrade_remove_spaces_around_shortcodes' ) ); |
| 38 |
|
| 39 |
// ajax load for modal |
| 40 |
if ( is_admin() ) { |
| 41 |
add_action( 'wp_ajax_wpgrade_get_shortcodes_modal', array( $this, 'wpgrade_get_shortcodes_modal' ) ); |
| 42 |
} |
| 43 |
|
| 44 |
//prevent certain shortcodes from getting their content texturized |
| 45 |
add_filter( 'no_texturize_shortcodes', array( $this, 'wpgrade_shortcodes_to_exempt_from_wptexturize' ) ); |
| 46 |
|
| 47 |
} // end constructor |
| 48 |
|
| 49 |
public function wpgrade_init_plugin() { |
| 50 |
$this->plugin_textdomain(); |
| 51 |
$this->add_wpgrade_shortcodes_button(); |
| 52 |
} |
| 53 |
|
| 54 |
public function plugin_textdomain() { |
| 55 |
$domain = 'pixcodes_txtd'; |
| 56 |
$locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
| 57 |
load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
| 58 |
load_plugin_textdomain( $domain, false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); |
| 59 |
} // end plugin_textdomain |
| 60 |
|
| 61 |
/** |
| 62 |
* Registers and enqueues admin-specific styles. |
| 63 |
*/ |
| 64 |
public function register_admin_assets( $buttons ) { |
| 65 |
wp_enqueue_style( 'wpgrade-shortcodes-reveal-styles', $this->plugin_url . 'css/base.css', array( 'wp-color-picker' ) ); |
| 66 |
wp_enqueue_script( 'select2-js', $this->plugin_url . 'js/select2/select2.js', array( |
| 67 |
'jquery', |
| 68 |
'jquery-ui-tabs' |
| 69 |
) ); |
| 70 |
wp_enqueue_script( 'wp-color-picker' ); |
| 71 |
|
| 72 |
return $buttons; |
| 73 |
} // end register_admin_assets |
| 74 |
|
| 75 |
/** |
| 76 |
* Registers and enqueues plugin-specific styles.Usually we base on the theme style and this is empty |
| 77 |
*/ |
| 78 |
public function register_plugin_styles() { |
| 79 |
} // end register_plugin_styles |
| 80 |
|
| 81 |
/** |
| 82 |
* Registers and enqueues plugin-specific scripts..Usually we base on theme front-end scripts and this is empty. |
| 83 |
*/ |
| 84 |
public function register_plugin_scripts() { |
| 85 |
} // end register_plugin_scripts |
| 86 |
|
| 87 |
/*--------------------------------------------* |
| 88 |
* Core Functions |
| 89 |
*---------------------------------------------*/ |
| 90 |
|
| 91 |
function add_wpgrade_shortcodes_button() { |
| 92 |
//make sure the user has correct permissions |
| 93 |
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) { |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
// add to the visual mode only |
| 98 |
if ( get_user_option( 'rich_editing' ) == 'true' ) { |
| 99 |
add_filter( 'mce_external_plugins', array( $this, 'addto_mce_wpgrade_shortcodes' ) ); |
| 100 |
add_filter( 'mce_buttons', array( $this, 'register_wpgrade_shortcodes_button' ) ); |
| 101 |
} |
| 102 |
} // end action_method_name |
| 103 |
|
| 104 |
function register_wpgrade_shortcodes_button( $buttons ) { |
| 105 |
array_push( $buttons, "wpgrade" ); |
| 106 |
|
| 107 |
return $buttons; |
| 108 |
} // end filter_method_name |
| 109 |
|
| 110 |
function addto_mce_wpgrade_shortcodes( $plugin_array ) { |
| 111 |
$plugin_array['wpgrade'] = $this->plugin_url . 'js/add_shortcode.js'; |
| 112 |
|
| 113 |
return $plugin_array; |
| 114 |
} |
| 115 |
|
| 116 |
public function wpgrade_get_shortcodes_modal() { |
| 117 |
ob_start(); |
| 118 |
include( 'views/shortcodes-modal.php' ); |
| 119 |
echo json_encode( ob_get_clean() ); |
| 120 |
die(); |
| 121 |
} |
| 122 |
|
| 123 |
public function create_wpgrade_shortcodes() { |
| 124 |
include_once( 'shortcodes.php' ); |
| 125 |
} |
| 126 |
|
| 127 |
function wpgrade_remove_spaces_around_shortcodes( $content ) { |
| 128 |
$array = array( |
| 129 |
'<p>[' => '[', |
| 130 |
']</p>' => ']', |
| 131 |
']<br />' => ']' |
| 132 |
); |
| 133 |
|
| 134 |
$content = strtr( $content, $array ); |
| 135 |
|
| 136 |
return $content; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Add some of our own shortcodes to the list of shortcodes that won't have their content texturized. |
| 141 |
* |
| 142 |
* @param array $shortcodes |
| 143 |
* |
| 144 |
* @return array |
| 145 |
*/ |
| 146 |
function wpgrade_shortcodes_to_exempt_from_wptexturize( $shortcodes ) { |
| 147 |
$shortcodes[] = 'restaurantmenu'; |
| 148 |
|
| 149 |
return $shortcodes; |
| 150 |
} |
| 151 |
|
| 152 |
} // end class |
| 153 |
|
| 154 |
$WpGradeShortcodes = new WpGradeShortcodes(); |
| 155 |
|