PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / trunk
Shortcoder — Create Shortcodes for Anything vtrunk
6.5.4 trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / tools.php
shortcoder / admin Last commit date
css 1 month ago font 1 month ago images 1 month ago js 1 month ago admin.php 1 month ago edit.php 1 month ago form.php 1 month ago insert.php 1 month ago manage.php 1 month ago settings.php 1 month ago tools.php 1 month ago
tools.php
129 lines
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit;
4
5 class SC_Admin_Tools{
6
7 public static function init(){
8
9 // Register the action for admin ajax features
10 add_action( 'wp_ajax_sc_insert_window', array( __CLASS__, 'insert_window' ) );
11
12 // Add TinyMCE button
13 add_action( 'admin_init', array( __CLASS__, 'register_mce' ) );
14
15 add_action( 'wp_enqueue_editor', array( __CLASS__, 'enqueue_insert_scripts' ) );
16
17 // Gutenberg block
18 add_action( 'init', array( __CLASS__, 'register_block' ) );
19
20 }
21
22 public static function register_mce(){
23
24 // Show shortcoder button only for administrators
25 if( !current_user_can( 'manage_options' ) ){
26 return;
27 }
28
29 add_filter( 'mce_buttons', array( __CLASS__, 'register_mce_button' ) );
30
31 add_filter( 'mce_external_plugins', array( __CLASS__, 'register_mce_js' ) );
32
33 }
34
35 public static function register_mce_button( $buttons ){
36
37 if( self::is_sc_edit_page() )
38 return $buttons;
39
40 array_push( $buttons, 'separator', 'shortcoder' );
41 return $buttons;
42
43 }
44
45 public static function register_mce_js( $plugins ){
46
47 if( self::is_sc_edit_page() )
48 return $plugins;
49
50 $plugins[ 'shortcoder' ] = SC_ADMIN_URL . 'js/tinymce/editor_plugin.js';
51 return $plugins;
52
53 }
54
55 public static function register_block(){
56
57 if( !function_exists( 'register_block_type' ) ){
58 return false;
59 }
60
61 $asset_file = include( SC_PATH . 'admin/js/blocks/index.asset.php');
62
63 wp_register_script(
64 'shortcoder',
65 SC_ADMIN_URL . '/js/blocks/index.js',
66 $asset_file[ 'dependencies' ],
67 $asset_file[ 'version' ]
68 );
69
70 register_block_type( 'shortcoder/shortcoder', array(
71 'render_callback' => array( __CLASS__, 'render_block' ),
72 'editor_script' => 'shortcoder'
73 ));
74
75 }
76
77 public static function enqueue_insert_scripts(){
78
79 if( self::is_sc_edit_page() || !is_admin() )
80 return;
81
82 wp_enqueue_script( 'sc-tools-js', SC_ADMIN_URL . 'js/script-tools.js', array( 'jquery' ), SC_VERSION );
83
84 wp_enqueue_style( 'sc-tools-css', SC_ADMIN_URL . 'css/style-tools.css', array(), SC_VERSION );
85
86 wp_localize_script( 'sc-tools-js', 'SC_INSERT_VARS', array(
87 'insert_page' => admin_url( 'admin-ajax.php?action=sc_insert_window' ),
88 'popup_title' => __( 'Insert shortcode to editor', 'shortcoder' ),
89 'popup_opened' => false,
90 'block_editor' => false,
91 'block_inline_insert' => false
92 ));
93
94 }
95
96 public static function render_block( $attributes, $content ){
97 return wpautop( $content );
98 }
99
100 public static function insert_window(){
101
102 // Browse and insert popup should be available only for administrators
103 if( !current_user_can( 'manage_options' ) ){
104 wp_die( __( 'Not enough permissions to browse and insert shortcodes', 'shortcoder' ) );
105 }
106
107 include_once( 'insert.php' );
108 wp_die();
109
110 }
111
112 public static function is_sc_edit_page(){
113
114 if( !is_admin() ){
115 return false;
116 }
117
118 require_once( ABSPATH . 'wp-admin/includes/screen.php' );
119
120 $screen = get_current_screen();
121 return ( $screen && $screen->post_type == SC_POST_TYPE && $screen->base == 'post' );
122
123 }
124
125 }
126
127 SC_Admin_Tools::init();
128
129 ?>