PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0.1
Shortcoder — Create Shortcodes for Anything v5.0.1
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 6 years ago font 6 years ago images 6 years ago js 6 years ago admin.php 6 years ago edit.php 6 years ago form.php 6 years ago insert.php 6 years ago manage.php 6 years ago tools.php 6 years ago
tools.php
102 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 add_filter( 'mce_buttons', array( __class__, 'register_mce_button' ) );
25
26 add_filter( 'mce_external_plugins', array( __class__, 'register_mce_js' ) );
27
28 }
29
30 public static function register_mce_button( $buttons ){
31
32 if( self::is_sc_edit_page() )
33 return $buttons;
34
35 array_push( $buttons, 'separator', 'shortcoder' );
36 return $buttons;
37
38 }
39
40 public static function register_mce_js( $plugins ){
41
42 if( self::is_sc_edit_page() )
43 return $plugins;
44
45 $plugins[ 'shortcoder' ] = SC_ADMIN_URL . '/js/tinymce/editor_plugin.js';
46 return $plugins;
47
48 }
49
50 public static function register_block(){
51
52 wp_register_script(
53 'shortcoder', SC_ADMIN_URL . '/js/blocks/shortcoder.js', array( 'wp-blocks', 'wp-element' )
54 );
55
56 register_block_type( 'shortcoder/shortcoder', array(
57 'editor_script' => 'shortcoder',
58 ));
59
60 }
61
62 public static function enqueue_insert_scripts(){
63
64 if( self::is_sc_edit_page() )
65 return;
66
67 wp_enqueue_script( 'sc-tools-js', SC_ADMIN_URL . 'js/script-tools.js', array( 'jquery' ), SC_VERSION );
68
69 wp_enqueue_style( 'sc-tools-css', SC_ADMIN_URL . 'css/style-tools.css', array(), SC_VERSION );
70
71 wp_localize_script( 'sc-tools-js', 'SC_INSERT_VARS', array(
72 'insert_page' => admin_url( 'admin-ajax.php?action=sc_insert_window' ),
73 'popup_title' => __( 'Insert shortcode to editor', 'shortcoder' ),
74 'popup_opened' => false,
75 'block_editor' => false
76 ));
77
78 }
79
80 public static function insert_window(){
81
82 include_once( 'insert.php' );
83 die(0);
84
85 }
86
87 public static function is_sc_edit_page(){
88
89 if( !is_admin() ){
90 return false;
91 }
92
93 $screen = get_current_screen();
94 return ( $screen->post_type == SC_POST_TYPE && $screen->base == 'post' );
95
96 }
97
98 }
99
100 SC_Admin_Tools::init();
101
102 ?>