PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.7.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.7.1
2.7.7 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 All 28 releases
← All changes | admin/boot.php +79 -109 2.4.42.7.1 View file →
@@ -1,11 +1,9 @@
1 1 <?php
2 2 /**
3 3 * Admin boot
4 4 *
5 - * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 - * @copyright Alex Kovalev 05.06.2018
7 - * @version 1.0
5 + * @package Woody_Code_Snippets
8 6 */
9 7
10 8 // Exit if accessed directly
11 9 if ( ! defined( 'ABSPATH' ) ) {
@@ -12,94 +10,20 @@
12 10 exit;
13 11 }
14 12
15 13 /**
16 - * Добавляет подсказку и кнопку в сообщение фатальной ошибки.
17 - *
18 - * С версии Wordpress 5.2, нам доступен специальный режим, перехвата php ошибок.
19 - * Если пользователь например допустит синтаксическую ошибку при редактировании
20 - * сниппета, то он вместо белого экрана (если php ошибки отключены на сервере)
21 - * увидит сообщение от Wordpress сгенерированное классом WP_Fatal_Error_Handler.
22 - *
23 - * Мы решили добавить в это сообщение кнопку для перехода в безопасный режим.
24 - */
25 -add_filter( 'wp_php_error_message', function ( $message ) {
26 - $safe_mode_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&wbcr-php-snippets-safe-mode' );
27 - $safe_mode_button = '<div style="margin:20px 0;padding:20px; background:#ffe8e8;">' . __( 'If you see this message after saving the snippet to the Woody Code Snippets plugin, please enable safe mode in the Woody plugin. Safe mode will allow you to continue working in the admin panel of your site and change the snippet in which you made a php error.', 'insert_php' ) . '</div>';
28 - $safe_mode_button .= '<a href="' . $safe_mode_url . '" class="button">' . __( 'Enable safe mode in Woody Code Snippets', 'insert_php' ) . '</a>';
29 -
30 - return $message . $safe_mode_button;
31 -} );
32 -
33 -/**
34 14 * Инициализации метабоксов и страницы "о плагине".
35 15 *
36 16 * Этот хук реализует условную логику, при которой пользователь переодически будет
37 17 * видет страницу "О плагине", а конкретно при активации и обновлении плагина.
38 18 */
39 -add_action( 'admin_init', function () {
19 +add_action(
20 + 'admin_init',
21 + function () {
22 + require_once WINP_PLUGIN_DIR . '/admin/metaboxes/snippet-metabox.php';
23 + }
24 +);
40 25
41 - $plugin = WINP_Plugin::app();
42 -
43 - // Register metaboxes
44 - require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/base-options.php' );
45 - WINP_Helper::register_factory_metaboxes( new WINP_BaseOptionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
46 -
47 - if ( ( defined( 'FACTORY_ADVERTS_DEBUG' ) && FACTORY_ADVERTS_DEBUG ) || ! WINP_Plugin::app()->premium->is_activate() ) {
48 - require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/info.php' );
49 - WINP_Helper::register_factory_metaboxes( new WINP_InfoMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
50 - }
51 -
52 - $snippet_type = WINP_Helper::get_snippet_type();
53 -
54 - if ( $snippet_type !== WINP_SNIPPET_TYPE_PHP ) {
55 - require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/view-options.php' );
56 - WINP_Helper::register_factory_metaboxes( new WINP_ViewOptionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
57 - }
58 -
59 - do_action( 'wbcr/inp/boot/metaboxes/revisions', '' );
60 -
61 - // If the user has updated the plugin or activated it for the first time,
62 - // you need to show the page "What's new?"
63 - /*
64 - if ( ! WINP_Plugin::app()->isNetworkAdmin() ) {
65 - $about_page_viewed = WINP_Plugin::app()->request->get( 'wbcr_inp_about_page_viewed', null );
66 - if ( is_null( $about_page_viewed ) ) {
67 - if ( WINP_Helper::is_need_show_about_page() && current_user_can( 'manage_options' ) ) {
68 - try {
69 - $redirect_url = '';
70 - if ( class_exists( 'Wbcr_FactoryPages452' ) ) {
71 - $redirect_url = WINP_Plugin::app()->getPluginPageUrl( 'about', [ 'wbcr_inp_about_page_viewed' => 1 ] );
72 - }
73 - if ( $redirect_url ) {
74 - wp_safe_redirect( $redirect_url );
75 - die();
76 - }
77 - } catch ( Exception $e ) {
78 - }
79 - }
80 - } else {
81 - if ( WINP_Helper::is_need_show_about_page() ) {
82 - delete_option( $plugin->getOptionName( 'what_new_210' ) );
83 - }
84 - }
85 - }
86 - */
87 -} );
88 -
89 -function wbcr_inp_admin_revisions() {
90 - $plugin = WINP_Plugin::app();
91 -
92 - require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/revisions.php' );
93 - WINP_Helper::register_factory_metaboxes( new WINP_RevisionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
94 -}
95 -
96 -add_action( 'wbcr/inp/boot/metaboxes/revisions', 'wbcr_inp_admin_revisions' );
97 -
98 -// ---
99 -// Editor
100 -//
101 -
102 26 /**
103 27 * Enqueue scripts
104 28 */
105 29 function wbcr_inp_enqueue_scripts() {
@@ -107,12 +31,17 @@
107 31
108 32 $screen = get_current_screen();
109 33
110 34 if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && WINP_SNIPPETS_POST_TYPE == $screen->post_type ) {
111 - wp_enqueue_script( 'wbcr-inp-admin-scripts', WINP_PLUGIN_URL . '/admin/assets/js/scripts.js', [
112 - 'jquery',
113 - 'jquery-ui-tooltip'
114 - ], WINP_Plugin::app()->getPluginVersion() );
35 + wp_enqueue_script(
36 + 'wbcr-inp-admin-scripts',
37 + WINP_PLUGIN_URL . '/admin/assets/js/scripts.js',
38 + [
39 + 'jquery',
40 + 'jquery-ui-tooltip',
41 + ],
42 + WINP_PLUGIN_VERSION
43 + );
115 44 }
116 45 }
117 46
118 47 /**
@@ -123,9 +52,9 @@
123 52 function wbcr_inp_enqueue_tinymce_assets( $hook ) {
124 53 $pages = [
125 54 'post.php',
126 55 'post-new.php',
127 - 'widgets.php'
56 + 'widgets.php',
128 57 ];
129 58
130 59 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) {
131 60 return;
@@ -130,9 +59,9 @@
130 59 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) {
131 60 return;
132 61 }
133 62
134 - wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_Plugin::app()->getPluginVersion(), true );
63 + wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_PLUGIN_VERSION, true );
135 64 }
136 65
137 66 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_tinymce_assets' );
138 67 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_scripts' );
@@ -154,26 +83,32 @@
154 83
155 84 $result = WINP_Helper::get_shortcode_data( true );
156 85 $shortcode_snippets_json = json_encode( $result );
157 86 ?>
158 - <!-- <?php echo WINP_Plugin::app()->getPluginTitle() ?> for tinymce -->
159 - <style>
160 - i.wbcr-inp-shortcode-icon {
161 - background: url("<?php echo $shortcode_icon ?>") center no-repeat;
162 - }
163 - </style>
164 - <script>
165 - var wbcr_inp_tinymce_snippets_button_title = '<?php echo $shortcode_title ?>';
166 - var wbcr_inp_post_tinymce_nonce = '<?php echo wp_create_nonce( 'wbcr_inp_tinymce_post_nonce' ) ?>';
167 - var wbcr_inp_shortcode_snippets = <?php echo $shortcode_snippets_json ?>;
168 - </script>
169 - <!-- /end <?php echo WINP_Plugin::app()->getPluginTitle() ?> for tinymce -->
87 + <!-- <?php echo esc_html__( 'Woody Code Snippets', 'insert-php' ); ?> for tinymce -->
88 + <style>
89 + i.wbcr-inp-shortcode-icon {
90 + background: url("<?php echo $shortcode_icon; ?>") center no-repeat;
91 + }
92 + </style>
93 + <script>
94 + var wbcr_inp_tinymce_snippets_button_title = '<?php echo $shortcode_title; ?>';
95 + var wbcr_inp_post_tinymce_nonce = '<?php echo wp_create_nonce( 'wbcr_inp_tinymce_post_nonce' ); ?>';
96 + var wbcr_inp_shortcode_snippets = <?php echo $shortcode_snippets_json; ?>;
97 + </script>
98 + <!-- /end <?php echo esc_html__( 'Woody Code Snippets', 'insert-php' ); ?> for tinymce -->
170 99 <?php
171 100 }
172 101
173 -add_action( 'admin_print_scripts-post.php', 'wbcr_inp_tinymce_data' );
174 -add_action( 'admin_print_scripts-post-new.php', 'wbcr_inp_tinymce_data' );
175 -add_action( 'admin_print_scripts-widgets.php', 'wbcr_inp_tinymce_data' );
102 +// Defer hook registration until init to prevent early translation loading (WP 6.7+)
103 +add_action(
104 + 'init',
105 + function () {
106 + add_action( 'admin_print_scripts-post.php', 'wbcr_inp_tinymce_data' );
107 + add_action( 'admin_print_scripts-post-new.php', 'wbcr_inp_tinymce_data' );
108 + add_action( 'admin_print_scripts-widgets.php', 'wbcr_inp_tinymce_data' );
109 + }
110 +);
176 111
177 112 /**
178 113 * Deactivate snippet on trashed
179 114 *
@@ -179,9 +114,8 @@
179 114 *
180 115 * @param $post_id
181 116 *
182 117 * @since 2.0.6
183 - *
184 118 */
185 119 function wbcr_inp_trash_post( $post_id ) {
186 120 $post_type = get_post_type( $post_id );
187 121 if ( $post_type == WINP_SNIPPETS_POST_TYPE ) {
@@ -197,9 +131,8 @@
197 131 * @param $menu
198 132 *
199 133 * @return mixed
200 134 * @see menu_order
201 - *
202 135 */
203 136 function wbcr_inp_remove_new_item( $menu ) {
204 137 global $submenu;
205 138
@@ -211,11 +144,48 @@
211 144 return $menu;
212 145 }
213 146
214 147 add_filter( 'custom_menu_order', '__return_true' );
215 -add_filter( 'admin_menu', 'wbcr_inp_remove_new_item' );
148 +add_filter( 'admin_menu', 'wbcr_inp_remove_new_item', 1 );
216 149
217 150 /**
151 + * Reorder submenu items to place '+ Add Snippet' as second item
152 + *
153 + * @param array<int|string, mixed> $menu Menu items.
154 + *
155 + * @return array<int|string, mixed>
156 + */
157 +function wbcr_inp_reorder_submenu_items( $menu ) {
158 + global $submenu;
159 +
160 + if ( ! isset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] ) ) {
161 + return $menu;
162 + }
163 +
164 + $snippet_submenu = $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ];
165 + $new_item_page = null;
166 + $new_item_key = null;
167 +
168 + foreach ( $snippet_submenu as $key => $item ) {
169 + if ( strpos( $item[2], 'new-item-' ) !== false ) {
170 + $new_item_page = $item;
171 + $new_item_key = $key;
172 + break;
173 + }
174 + }
175 +
176 + if ( null !== $new_item_page ) {
177 + unset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][ $new_item_key ] );
178 + $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][6] = $new_item_page; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
179 + ksort( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] );
180 + }
181 +
182 + return $menu;
183 +}
184 +
185 +add_filter( 'admin_menu', 'wbcr_inp_reorder_submenu_items', 999 );
186 +
187 +/**
218 188 * If the user tried to get access to the default 'new item',
219 189 * redirects forcibly to our page 'new item'.
220 190 *
221 191 * @see current_screen
@@ -229,14 +199,14 @@
229 199 if ( 'add' !== $screen->action || 'post' !== $screen->base || WINP_SNIPPETS_POST_TYPE !== $screen->post_type ) {
230 200 return;
231 201 }
232 202
233 - $winp_item = WINP_Plugin::app()->request->get( 'winp_item', null );
203 + $winp_item = WINP_HTTP::get( 'winp_item', null );
234 204 if ( ! is_null( $winp_item ) ) {
235 205 return;
236 206 }
237 207
238 - $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=new-item-' . WINP_Plugin::app()->getPluginName() );
208 + $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=winp-new-item' );
239 209
240 210 wp_safe_redirect( $url );
241 211
242 212 exit;