PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.4.2
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.4.2
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.4.2, at admin/boot.php

249 lines 8.4 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 * @author Alex Kovalev <alex.kovalevv@gmail.com>
6 * @copyright Alex Kovalev 05.06.2018
7 * @version 1.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 /**
16 * Добавляет подсказку и кнопку в сообщение фатальной ошибки.
17 *
18 * С версии Wordpress 5.2, нам доступен специальный режим, пере�
19 вата php ошибок.
20 * Если пользователь например допустит синтаксическую ошибку при редактировании
21 * сниппета, то он вместо белого экрана (если php ошибки отключены на сервере)
22 * увидит сообщение от Wordpress сгенерированное классом WP_Fatal_Error_Handler.
23 *
24 * Мы решили добавить в это сообщение кнопку для пере�
25 ода в безопасный режим.
26 */
27 add_filter( 'wp_php_error_message', function ( $message ) {
28 $safe_mode_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&wbcr-php-snippets-safe-mode' );
29 $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>';
30 $safe_mode_button .= '<a href="' . $safe_mode_url . '" class="button">' . __( 'Enable safe mode in Woody Code Snippets', 'insert_php' ) . '</a>';
31
32 return $message . $safe_mode_button;
33 } );
34
35 /**
36 * Инициализации метабоксов и страницы "о плагине".
37 *
38 * Этот �
39 ук реализует условную логику, при которой пользователь переодически будет
40 * видет страницу "О плагине", а конкретно при активации и обновлении плагина.
41 */
42 add_action( 'admin_init', function () {
43
44 $plugin = WINP_Plugin::app();
45
46 // Register metaboxes
47 require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/base-options.php' );
48 WINP_Helper::register_factory_metaboxes( new WINP_BaseOptionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
49
50 if ( ( defined( 'FACTORY_ADVERTS_DEBUG' ) && FACTORY_ADVERTS_DEBUG ) || ! WINP_Plugin::app()->premium->is_activate() ) {
51 require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/info.php' );
52 WINP_Helper::register_factory_metaboxes( new WINP_InfoMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
53 }
54
55 $snippet_type = WINP_Helper::get_snippet_type();
56
57 if ( $snippet_type !== WINP_SNIPPET_TYPE_PHP ) {
58 require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/view-options.php' );
59 WINP_Helper::register_factory_metaboxes( new WINP_ViewOptionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
60 }
61
62 do_action( 'wbcr/inp/boot/metaboxes/revisions', '' );
63
64 // If the user has updated the plugin or activated it for the first time,
65 // you need to show the page "What's new?"
66 /*
67 if ( ! WINP_Plugin::app()->isNetworkAdmin() ) {
68 $about_page_viewed = WINP_Plugin::app()->request->get( 'wbcr_inp_about_page_viewed', null );
69 if ( is_null( $about_page_viewed ) ) {
70 if ( WINP_Helper::is_need_show_about_page() && current_user_can( 'manage_options' ) ) {
71 try {
72 $redirect_url = '';
73 if ( class_exists( 'Wbcr_FactoryPages449' ) ) {
74 $redirect_url = WINP_Plugin::app()->getPluginPageUrl( 'about', [ 'wbcr_inp_about_page_viewed' => 1 ] );
75 }
76 if ( $redirect_url ) {
77 wp_safe_redirect( $redirect_url );
78 die();
79 }
80 } catch ( Exception $e ) {
81 }
82 }
83 } else {
84 if ( WINP_Helper::is_need_show_about_page() ) {
85 delete_option( $plugin->getOptionName( 'what_new_210' ) );
86 }
87 }
88 }
89 */
90 } );
91
92 function wbcr_inp_admin_revisions() {
93 $plugin = WINP_Plugin::app();
94
95 require_once( WINP_PLUGIN_DIR . '/admin/metaboxes/revisions.php' );
96 WINP_Helper::register_factory_metaboxes( new WINP_RevisionsMetaBox( $plugin ), WINP_SNIPPETS_POST_TYPE, $plugin );
97 }
98
99 add_action( 'wbcr/inp/boot/metaboxes/revisions', 'wbcr_inp_admin_revisions' );
100
101 // ---
102 // Editor
103 //
104
105 /**
106 * Enqueue scripts
107 */
108 function wbcr_inp_enqueue_scripts() {
109 global $pagenow;
110
111 $screen = get_current_screen();
112
113 if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && WINP_SNIPPETS_POST_TYPE == $screen->post_type ) {
114 wp_enqueue_script( 'wbcr-inp-admin-scripts', WINP_PLUGIN_URL . '/admin/assets/js/scripts.js', [
115 'jquery',
116 'jquery-ui-tooltip'
117 ], WINP_Plugin::app()->getPluginVersion() );
118 }
119 }
120
121 /**
122 * Asset scripts for the tinymce editor
123 *
124 * @param string $hook
125 */
126 function wbcr_inp_enqueue_tinymce_assets( $hook ) {
127 $pages = [
128 'post.php',
129 'post-new.php',
130 'widgets.php'
131 ];
132
133 if ( ! in_array( $hook, $pages ) || ! current_user_can( 'manage_options' ) ) {
134 return;
135 }
136
137 wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_Plugin::app()->getPluginVersion(), true );
138 }
139
140 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_tinymce_assets' );
141 add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_scripts' );
142
143 /**
144 * Adds js variable required for shortcodes.
145 *
146 * @since 1.1.0
147 * @see before_wp_tiny_mce
148 */
149 function wbcr_inp_tinymce_data( $hook ) {
150 if ( ! current_user_can( 'manage_options' ) ) {
151 return;
152 }
153
154 // styles for the plugin shorcodes
155 $shortcode_icon = WINP_PLUGIN_URL . '/admin/assets/img/shortcode-icon5.png';
156 $shortcode_title = __( 'Woody Code Snippets', 'insert-php' );
157
158 $result = WINP_Helper::get_shortcode_data( true );
159 $shortcode_snippets_json = json_encode( $result );
160 ?>
161 <!-- <?php echo WINP_Plugin::app()->getPluginTitle() ?> for tinymce -->
162 <style>
163 i.wbcr-inp-shortcode-icon {
164 background: url("<?php echo $shortcode_icon ?>") center no-repeat;
165 }
166 </style>
167 <script>
168 var wbcr_inp_tinymce_snippets_button_title = '<?php echo $shortcode_title ?>';
169 var wbcr_inp_post_tinymce_nonce = '<?php echo wp_create_nonce( 'wbcr_inp_tinymce_post_nonce' ) ?>';
170 var wbcr_inp_shortcode_snippets = <?php echo $shortcode_snippets_json ?>;
171 </script>
172 <!-- /end <?php echo WINP_Plugin::app()->getPluginTitle() ?> for tinymce -->
173 <?php
174 }
175
176 add_action( 'admin_print_scripts-post.php', 'wbcr_inp_tinymce_data' );
177 add_action( 'admin_print_scripts-post-new.php', 'wbcr_inp_tinymce_data' );
178 add_action( 'admin_print_scripts-widgets.php', 'wbcr_inp_tinymce_data' );
179
180 /**
181 * Deactivate snippet on trashed
182 *
183 * @param $post_id
184 *
185 * @since 2.0.6
186 *
187 */
188 function wbcr_inp_trash_post( $post_id ) {
189 $post_type = get_post_type( $post_id );
190 if ( $post_type == WINP_SNIPPETS_POST_TYPE ) {
191 WINP_Helper::updateMetaOption( $post_id, 'snippet_activate', 0 );
192 }
193 }
194
195 add_action( 'wp_trash_post', 'wbcr_inp_trash_post' );
196
197 /**
198 * Removes the default 'new item' from the admin menu to add own page 'new item' later.
199 *
200 * @param $menu
201 *
202 * @return mixed
203 * @see menu_order
204 *
205 */
206 function wbcr_inp_remove_new_item( $menu ) {
207 global $submenu;
208
209 if ( ! isset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] ) ) {
210 return $menu;
211 }
212 unset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][10] );
213
214 return $menu;
215 }
216
217 add_filter( 'custom_menu_order', '__return_true' );
218 add_filter( 'admin_menu', 'wbcr_inp_remove_new_item' );
219
220 /**
221 * If the user tried to get access to the default 'new item',
222 * redirects forcibly to our page 'new item'.
223 *
224 * @see current_screen
225 */
226 function wbcr_inp_redirect_to_new_item() {
227 $screen = get_current_screen();
228
229 if ( empty( $screen ) ) {
230 return;
231 }
232 if ( 'add' !== $screen->action || 'post' !== $screen->base || WINP_SNIPPETS_POST_TYPE !== $screen->post_type ) {
233 return;
234 }
235
236 $winp_item = WINP_Plugin::app()->request->get( 'winp_item', null );
237 if ( ! is_null( $winp_item ) ) {
238 return;
239 }
240
241 $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=new-item-' . WINP_Plugin::app()->getPluginName() );
242
243 wp_safe_redirect( $url );
244
245 exit;
246 }
247
248 add_action( 'current_screen', 'wbcr_inp_redirect_to_new_item' );
249