PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.5
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.5
2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 2.7.1 All 27 releases
insert-php / admin / boot.php

boot.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.7.5, at admin/boot.php

180 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin boot
4 *
5 * @package Woody_Code_Snippets
6 */
7
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Инициализации метабоксов и страницы "о плагине".
15 *
16 * Этот �
17 ук реализует условную логику, при которой пользователь переодически будет
18 * видет страницу "О плагине", а конкретно при активации и обновлении плагина.
19 */
20 add_action(
21 'admin_init',
22 function () {
23 require_once WINP_PLUGIN_DIR . '/admin/metaboxes/snippet-metabox.php';
24 }
25 );
26
27 /**
28 * Enqueue scripts
29 */
30 function wbcr_inp_enqueue_scripts() {
31 global $pagenow;
32
33 $screen = get_current_screen();
34
35 if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && WINP_SNIPPETS_POST_TYPE == $screen->post_type ) {
36 wp_enqueue_script(
37 'wbcr-inp-admin-scripts',
38 WINP_PLUGIN_URL . '/admin/assets/js/scripts.js',
39 [
40 'jquery',
41 'jquery-ui-tooltip',
42 ],
43 WINP_PLUGIN_VERSION
44 );
45 }
46 }
47
48 /**
49 * Asset scripts for the tinymce editor
50 *
51 * @param string $hook
52 */
53 function wbcr_inp_enqueue_tinymce_assets( $hook ) {
54 $pages = [
55 'post.php',
56 'post-new.php',
57 'widgets.php',
58 ];
59
60 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) {
61 return;
62 }
63
64 wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_PLUGIN_VERSION, true );
65 }
66
67 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_tinymce_assets' );
68 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_scripts' );
69
70 /**
71 * Adds js variable required for shortcodes.
72 *
73 * @since 1.1.0
74 * @see before_wp_tiny_mce
75 */
76 function wbcr_inp_tinymce_data( $hook ) {
77 if ( ! current_user_can( 'edit_posts' ) ) {
78 return;
79 }
80
81 // styles for the plugin shorcodes
82 $shortcode_icon = WINP_PLUGIN_URL . '/admin/assets/img/shortcode-icon5.png';
83 $shortcode_title = __( 'Woody Code Snippets', 'insert-php' );
84
85 $result = WINP_Helper::get_shortcode_data( true );
86 $shortcode_snippets_json = json_encode( $result );
87 ?>
88 <!-- <?php echo esc_html__( 'Woody Code Snippets', 'insert-php' ); ?> for tinymce -->
89 <style>
90 i.wbcr-inp-shortcode-icon {
91 background: url("<?php echo $shortcode_icon; ?>") center no-repeat;
92 }
93 </style>
94 <script>
95 var wbcr_inp_tinymce_snippets_button_title = '<?php echo $shortcode_title; ?>';
96 var wbcr_inp_post_tinymce_nonce = '<?php echo wp_create_nonce( 'wbcr_inp_tinymce_post_nonce' ); ?>';
97 var wbcr_inp_shortcode_snippets = <?php echo $shortcode_snippets_json; ?>;
98 </script>
99 <!-- /end <?php echo esc_html__( 'Woody Code Snippets', 'insert-php' ); ?> for tinymce -->
100 <?php
101 }
102
103 // Defer hook registration until init to prevent early translation loading (WP 6.7+)
104 add_action(
105 'init',
106 function () {
107 add_action( 'admin_print_scripts-post.php', 'wbcr_inp_tinymce_data' );
108 add_action( 'admin_print_scripts-post-new.php', 'wbcr_inp_tinymce_data' );
109 add_action( 'admin_print_scripts-widgets.php', 'wbcr_inp_tinymce_data' );
110 }
111 );
112
113 /**
114 * Deactivate snippet on trashed
115 *
116 * @param $post_id
117 *
118 * @since 2.0.6
119 */
120 function wbcr_inp_trash_post( $post_id ) {
121 $post_type = get_post_type( $post_id );
122 if ( $post_type == WINP_SNIPPETS_POST_TYPE ) {
123 WINP_Helper::updateMetaOption( $post_id, 'snippet_activate', 0 );
124 }
125 }
126
127 add_action( 'wp_trash_post', 'wbcr_inp_trash_post' );
128
129 /**
130 * Removes the default 'new item' from the admin menu to add own page 'new item' later.
131 *
132 * @param $menu
133 *
134 * @return mixed
135 * @see menu_order
136 */
137 function wbcr_inp_remove_new_item( $menu ) {
138 global $submenu;
139
140 if ( ! isset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] ) ) {
141 return $menu;
142 }
143 unset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][10] );
144
145 return $menu;
146 }
147
148 add_filter( 'custom_menu_order', '__return_true' );
149 add_filter( 'admin_menu', 'wbcr_inp_remove_new_item', 1 );
150
151 /**
152 * If the user tried to get access to the default 'new item',
153 * redirects forcibly to our page 'new item'.
154 *
155 * @see current_screen
156 */
157 function wbcr_inp_redirect_to_new_item() {
158 $screen = get_current_screen();
159
160 if ( empty( $screen ) ) {
161 return;
162 }
163 if ( 'add' !== $screen->action || 'post' !== $screen->base || WINP_SNIPPETS_POST_TYPE !== $screen->post_type ) {
164 return;
165 }
166
167 $winp_item = WINP_HTTP::get( 'winp_item', null );
168 if ( ! is_null( $winp_item ) ) {
169 return;
170 }
171
172 $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=winp-new-item' );
173
174 wp_safe_redirect( $url );
175
176 exit;
177 }
178
179 add_action( 'current_screen', 'wbcr_inp_redirect_to_new_item' );
180