PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.5
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.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
← All changes | admin/boot.php +109 -42 trunk2.4.5 View file →
@@ -1,9 +1,11 @@
1 1 <?php
2 2 /**
3 3 * Admin boot
4 4 *
5 - * @package Woody_Code_Snippets
5 + * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 + * @copyright Alex Kovalev 05.06.2018
7 + * @version 1.0
6 8 */
7 9
8 10 // Exit if accessed directly
9 11 if ( ! defined( 'ABSPATH' ) ) {
@@ -10,20 +12,94 @@
10 12 exit;
11 13 }
12 14
13 15 /**
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 +/**
14 34 * Инициализации метабоксов и страницы "о плагине".
15 35 *
16 36 * Этот хук реализует условную логику, при которой пользователь переодически будет
17 37 * видет страницу "О плагине", а конкретно при активации и обновлении плагина.
18 38 */
19 -add_action(
20 - 'admin_init',
21 - function () {
22 - require_once WINP_PLUGIN_DIR . '/admin/metaboxes/snippet-metabox.php';
23 - }
24 -);
39 +add_action( 'admin_init', function () {
25 40
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_FactoryPages455' ) ) {
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 +
26 102 /**
27 103 * Enqueue scripts
28 104 */
29 105 function wbcr_inp_enqueue_scripts() {
@@ -31,17 +107,12 @@
31 107
32 108 $screen = get_current_screen();
33 109
34 110 if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && WINP_SNIPPETS_POST_TYPE == $screen->post_type ) {
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 - );
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() );
44 115 }
45 116 }
46 117
47 118 /**
@@ -52,9 +123,9 @@
52 123 function wbcr_inp_enqueue_tinymce_assets( $hook ) {
53 124 $pages = [
54 125 'post.php',
55 126 'post-new.php',
56 - 'widgets.php',
127 + 'widgets.php'
57 128 ];
58 129
59 130 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) {
60 131 return;
@@ -59,9 +130,9 @@
59 130 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) {
60 131 return;
61 132 }
62 133
63 - wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_PLUGIN_VERSION, true );
134 + wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_Plugin::app()->getPluginVersion(), true );
64 135 }
65 136
66 137 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_tinymce_assets' );
67 138 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_scripts' );
@@ -83,32 +154,26 @@
83 154
84 155 $result = WINP_Helper::get_shortcode_data( true );
85 156 $shortcode_snippets_json = json_encode( $result );
86 157 ?>
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 -->
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 -->
99 170 <?php
100 171 }
101 172
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 -);
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' );
111 176
112 177 /**
113 178 * Deactivate snippet on trashed
114 179 *
@@ -114,8 +179,9 @@
114 179 *
115 180 * @param $post_id
116 181 *
117 182 * @since 2.0.6
183 + *
118 184 */
119 185 function wbcr_inp_trash_post( $post_id ) {
120 186 $post_type = get_post_type( $post_id );
121 187 if ( $post_type == WINP_SNIPPETS_POST_TYPE ) {
@@ -131,8 +197,9 @@
131 197 * @param $menu
132 198 *
133 199 * @return mixed
134 200 * @see menu_order
201 + *
135 202 */
136 203 function wbcr_inp_remove_new_item( $menu ) {
137 204 global $submenu;
138 205
@@ -144,9 +211,9 @@
144 211 return $menu;
145 212 }
146 213
147 214 add_filter( 'custom_menu_order', '__return_true' );
148 -add_filter( 'admin_menu', 'wbcr_inp_remove_new_item', 1 );
215 +add_filter( 'admin_menu', 'wbcr_inp_remove_new_item' );
149 216
150 217 /**
151 218 * If the user tried to get access to the default 'new item',
152 219 * redirects forcibly to our page 'new item'.
@@ -162,14 +229,14 @@
162 229 if ( 'add' !== $screen->action || 'post' !== $screen->base || WINP_SNIPPETS_POST_TYPE !== $screen->post_type ) {
163 230 return;
164 231 }
165 232
166 - $winp_item = WINP_HTTP::get( 'winp_item', null );
233 + $winp_item = WINP_Plugin::app()->request->get( 'winp_item', null );
167 234 if ( ! is_null( $winp_item ) ) {
168 235 return;
169 236 }
170 237
171 - $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=winp-new-item' );
238 + $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=new-item-' . WINP_Plugin::app()->getPluginName() );
172 239
173 240 wp_safe_redirect( $url );
174 241
175 242 exit;