PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.2
Shortcoder — Create Shortcodes for Anything v6.2
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 3 years ago font 3 years ago images 3 years ago js 3 years ago admin.php 3 years ago edit.php 3 years ago form.php 3 years ago insert.php 3 years ago manage.php 3 years ago settings.php 3 years ago tools.php 3 years ago
tools.php
119 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 if( !function_exists( 'register_block_type' ) ){
53 return false;
54 }
55
56 $asset_file = include( SC_PATH . 'admin/js/blocks/index.asset.php');
57
58 wp_register_script(
59 'shortcoder',
60 SC_ADMIN_URL . '/js/blocks/index.js',
61 $asset_file[ 'dependencies' ],
62 $asset_file[ 'version' ]
63 );
64
65 register_block_type( 'shortcoder/shortcoder', array(
66 'render_callback' => array( __CLASS__, 'render_block' ),
67 'editor_script' => 'shortcoder'
68 ));
69
70 }
71
72 public static function enqueue_insert_scripts(){
73
74 if( self::is_sc_edit_page() || !is_admin() )
75 return;
76
77 wp_enqueue_script( 'sc-tools-js', SC_ADMIN_URL . 'js/script-tools.js', array( 'jquery' ), SC_VERSION );
78
79 wp_enqueue_style( 'sc-tools-css', SC_ADMIN_URL . 'css/style-tools.css', array(), SC_VERSION );
80
81 wp_localize_script( 'sc-tools-js', 'SC_INSERT_VARS', array(
82 'insert_page' => admin_url( 'admin-ajax.php?action=sc_insert_window' ),
83 'popup_title' => __( 'Insert shortcode to editor', 'shortcoder' ),
84 'popup_opened' => false,
85 'block_editor' => false,
86 'block_inline_insert' => false
87 ));
88
89 }
90
91 public static function render_block( $attributes, $content ){
92 return wpautop( $content );
93 }
94
95 public static function insert_window(){
96
97 include_once( 'insert.php' );
98 die(0);
99
100 }
101
102 public static function is_sc_edit_page(){
103
104 if( !is_admin() ){
105 return false;
106 }
107
108 require_once( ABSPATH . 'wp-admin/includes/screen.php' );
109
110 $screen = get_current_screen();
111 return ( $screen->post_type == SC_POST_TYPE && $screen->base == 'post' );
112
113 }
114
115 }
116
117 SC_Admin_Tools::init();
118
119 ?>