PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.6.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.6.1
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 / includes / class.notices.php

class.notices.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.6.1, at admin/includes/class.notices.php

201 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 * Warning notices
4 *
5 * @author Webcraftic <WordPress.webraftic@gmail.com>
6 * @copyright (c) 11.12.2018, Webcraftic
7 * @version 1.0
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 class WINP_WarningNotices {
16
17 /**
18 * @var string
19 */
20 private $prefix = 'inp_';
21
22 /**
23 * @var array
24 */
25 private $notices = [];
26
27 public function __construct() {
28 /**
29 * @since 2.2.8 Filter Name Changed
30 */
31 add_filter( 'wbcr/factory/admin_notices', [ $this, 'register_notices' ], 10, 2 );
32 }
33
34 /**
35 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
36 *
37 * @param array $notices
38 * @param string $plugin_name
39 *
40 * @return array
41 * @throws \Exception
42 */
43 public function register_notices( $notices, $plugin_name ) {
44 if ( $plugin_name !== WINP_Plugin::app()->getPluginName() ) {
45 return $notices;
46 }
47
48 if ( ! WINP_Plugin::app()->currentUserCan() ) {
49 return $notices;
50 }
51
52 $this->add_notice( 'warning_security_notice', $this->get_warning_notice(), 'warning' );
53
54 if ( WINP_Plugin::app()->getOption( 'need_show_attention_notice' ) ) {
55 $this->add_notice( 'upgrade_plugin2', $this->get_upgrade_notice(), 'warning' );
56 }
57
58 $this->add_notice( 'safe_mode', $this->get_safe_mode_notice(), 'success', false );
59 $this->add_notice( 'result_error', $this->get_throw_php_error_notice(), 'error', false, 0, [
60 'post',
61 'post-new',
62 'edit',
63 ] );
64 /*
65 $this->add_notice( 'leave_feedback', $this->get_leave_feedback_notice(), 'success', true, time() + 3600 * 60, [
66 'post',
67 'post-new',
68 'edit'
69 ] );*/
70
71 return array_merge( $notices, $this->notices );
72 }
73
74 /**
75 * This warning is for users of the old version 1.3.0. The plugin has changed the way it works
76 * and requires user actions to continue working with plugin.
77 *
78 * @return string
79 */
80 public function get_warning_notice() {
81 if ( is_multisite() ) {
82 $notice = '<b>' . WINP_Plugin::app()->getPluginTitle() . '</b>: ' . sprintf( __( "ATTENTION! Use this plugin with care! Check your php scripts before inserting on your site. If you don't understand how the php script you are using works, try to avoid using it. Using unverified or outdated php scripts can damage the security of your site! Using the plugin on multisites can be dangerous as it will allow all administrators to insert php, js code. If you cannot control the work of administrators, we recommend that you do not use this plugin for security reasons. We are constantly working to improve the security of the plugin, but unfortunately we cannot check the code scripts you use that may violate the security of your site!", 'insert-php' ), WINP_Plugin::app()->getPluginVersion() );
83 } else {
84 $notice = '<b>' . WINP_Plugin::app()->getPluginTitle() . '</b>: ' . sprintf( __( "ATTENTION! Use this plugin with care! Check your php scripts before inserting on your site. If you don't understand how the php script you are using works, try to avoid using it. Using unverified or outdated php scripts can damage the security of your site!", 'insert-php' ), WINP_Plugin::app()->getPluginVersion() );
85 }
86 return $notice;
87 }
88
89 /**
90 * A small line that asks for feedback from user
91 *
92 * @return string
93 */
94 /*
95 public function get_leave_feedback_notice() {
96 $post_type = WINP_Plugin::app()->request->get( 'post_type' );
97 if ( ! empty( $post_type ) && WINP_SNIPPETS_POST_TYPE == $post_type ) {
98 return '<strong>' . __( 'Have feedback on Woody ad Snippets?', 'insert-php' ) . '</strong> ' . __( 'Please take the time to answer a short survey on how you use this plugin and what you\'d like to see changed or added in the future.', 'insert-php' ) . '
99 <a href="http://bit.ly/2MpVokA" class="button secondary" target="_blank" style="margin: auto .5em;">' . __( 'Take the survey now', 'insert-php' ) . '</a>';
100 }
101 }*/
102
103 /**
104 * Show error notification after saving snippet. We can also show this message when the snippet is activated.
105 * We must warn the user that we can not perform the spippet due to an error.
106 *
107 * @return string|null
108 */
109 public function get_throw_php_error_notice() {
110 $save_snippet_result = WINP_Plugin::app()->request->get( 'wbcr_inp_save_snippet_result' );
111 $post_id = WINP_Plugin::app()->request->get( 'post' );
112
113 if ( ! empty( $save_snippet_result ) && 'code-error' == $save_snippet_result ) {
114 $post_id = ! empty( $post_id ) ? intval( $post_id ) : null;
115
116 if ( $post_id ) {
117 $error = WINP_Plugin::app()->getExecuteObject()->getSnippetError( $post_id );
118
119 if ( false !== $error ) {
120 return sprintf( '<p>%s</p><p><strong>%s</strong></p>', sprintf( __( 'The snippet has been deactivated due to an error on line %d:', 'insert-php' ), $error['line'] ), $error['message'] );
121 }
122 }
123 }
124
125 return null;
126 }
127
128 /**
129 * This warning is for users of the old version 1.3.0. The plugin has changed the way it works
130 * and requires user actions to continue working with plugin.
131 *
132 * @return string
133 */
134 public function get_upgrade_notice() {
135 $create_notice_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE );
136
137 $notice = '<b>' . WINP_Plugin::app()->getPluginTitle() . '</b>: ' . sprintf( __( 'Attention! If you have previously used version 1.3.0 of plugin Insert php. This new %s plugin version, we added the ability to insert php code using snippets. This is a more convenient and secure way than using shortcodes [insert_php] code execute [/ insert_php]. However, for compatibility reasons, we left support for [insert_php] shortcodes until March 2019, after that we will stop supporting shortcodes [insert_php].', 'insert-php' ), WINP_Plugin::app()->getPluginVersion() );
138
139 $notice .= '<br><br>' . __( 'We strongly recommend you to porting your php code to snippets and call them in your posts/pages and widgets using [wbcr_php_snippet id = "000"] shortcodes.', 'insert-php' );
140 $notice .= ' ' . sprintf( __( 'For more information on porting code and using snippets, see our plugin <a href="%s" target="_blank">documentation</a>', 'insert-php' ), WINP_Plugin::app()->get_support()->get_docs_url( true, 'admin-notice' ) );
141 $notice .= '<br><br><a href="' . $create_notice_url . '" class="button button-default">' . __( 'Create new php snippet', 'insert-php' ) . '</a> ';
142 $notice .= '<a href="https://downloads.wordpress.org/plugin/insert-php.1.3.zip" class="button button-default">' . __( 'Download old version', 'insert-php' ) . '</a>';
143 $notice .= '<br><br>' . sprintf( __( 'If you still want to use the old shortcodes [insert_php] and you don’t have time to upgrade to the new version, you can enable support for old shortcodes in the plugin <a href="%s">settings</a>.', 'insert-php' ), WINP_Plugin::app()->getPluginPageUrl( 'settings' ) );
144 $notice .= '<br>' . sprintf( __( 'If you have issues with the plugin new version or any suggestions, please contact us on <a href="%s" target="_blank">our forum</a>.', 'insert-php' ), 'https://wordpress.org/support/plugin/insert-php/' );
145
146 return $notice;
147 }
148
149 /**
150 * When the safe mode of the plugin is enabled, this notification will remind
151 * the user to exit safe mode so that the user's snippets are available publicly.
152 *
153 * @return string
154 */
155 public function get_safe_mode_notice() {
156 if ( ! WINP_Helper::is_safe_mode() ) {
157 return null;
158 }
159
160 $disable_safe_mode_url = esc_url( add_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' => 1 ] ) );
161
162 $notice = WINP_Plugin::app()->getPluginTitle() . ': ' . __( 'Running in safe mode. This mode your snippets will not be started.', 'insert-php' );
163 $notice .= ' <a href="' . $disable_safe_mode_url . '" class="button button-default">' . __( 'Disable Safe Mode', 'insert-php' ) . '</a>';
164
165 return $notice;
166 }
167
168 /**
169 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
170 *
171 * @param string $id
172 * @param string $message
173 * @param string $type
174 * @param bool $dismissible
175 * @param int $dismiss_expires
176 * @param array $where
177 */
178 protected function add_notice( $id, $message, $type = 'warning', $dismissible = true, $dismiss_expires = 0, $where = [] ) {
179 if ( is_null( $message ) ) {
180 return;
181 }
182
183 if ( ! empty( $this->notices ) ) {
184 foreach ( $this->notices as $notice ) {
185 if ( $notice['id'] == $this->prefix . $id ) {
186 return;
187 }
188 }
189 }
190
191 $this->notices[] = [
192 'id' => $this->prefix . $id,
193 'type' => $type,
194 'dismissible' => (bool) $dismissible,
195 'dismiss_expires' => (int) $dismiss_expires,
196 'where' => $where,
197 'text' => '<p>' . $message . '</p>',
198 ];
199 }
200 }
201