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

156 lines 6.1 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 add_filter( 'wbcr_factory_notices_000_list', [ $this, 'register_notices' ], 10, 2 );
29 }
30
31 public function register_notices( $notices, $plugin_name ) {
32 if ( $plugin_name !== WINP_Plugin::app()->getPluginName() ) {
33 return $notices;
34 }
35
36 if ( WINP_Plugin::app()->getOption( 'need_show_attention_notice' ) ) {
37 $this->add_notice( 'upgrade_plugin2', $this->get_upgrade_notice(), 'warning' );
38 }
39
40 $this->add_notice( 'safe_mode', $this->get_safe_mode_notice(), 'success', false );
41 $this->add_notice( 'result_error', $this->get_throw_php_error_notice(), 'error', false, 0, [
42 'post',
43 'post-new',
44 'edit'
45 ] );
46 $this->add_notice( 'leave_feedback', $this->get_leave_feedback_notice(), 'success', true, time() + 3600 * 60, [
47 'post',
48 'post-new',
49 'edit'
50 ] );
51
52 return array_merge( $notices, $this->notices );
53 }
54
55 /**
56 * A small line that asks for feedback from user
57 *
58 * @return string
59 */
60 public function get_leave_feedback_notice() {
61 $post_type = WINP_Plugin::app()->request->get( 'post_type' );
62 if ( ! empty( $post_type ) && WINP_SNIPPETS_POST_TYPE == $post_type ) {
63 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' ) . '
64 <a href="http://bit.ly/2MpVokA" class="button secondary" target="_blank" style="margin: auto .5em;">' . __( 'Take the survey now', 'insert-php' ) . '</a>';
65 }
66 }
67
68 /**
69 * Show error notification after saving snippet. We can also show this message when the snippet is activated.
70 * We must warn the user that we can not perform the spippet due to an error.
71 *
72 * @return string|null
73 */
74 public function get_throw_php_error_notice() {
75 $save_snippet_result = WINP_Plugin::app()->request->get( 'wbcr_inp_save_snippet_result' );
76 $post_id = WINP_Plugin::app()->request->get( 'post' );
77
78 if ( ! empty( $save_snippet_result ) && 'code-error' == $save_snippet_result ) {
79 $post_id = ! empty( $post_id ) ? intval( $post_id ) : null;
80
81 if ( $post_id ) {
82 $error = WINP_Plugin::app()->getExecuteObject()->getSnippetError( $post_id );
83
84 if ( false !== $error ) {
85 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'] );
86 }
87 }
88 }
89
90 return null;
91 }
92
93 /**
94 * This warning is for users of the old version 1.3.0. The plugin has changed the way it works
95 * and requires user actions to continue working with plugin.
96 *
97 * @return string
98 */
99 public function get_upgrade_notice() {
100 $create_notice_url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE );
101
102 $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() );
103
104 $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' );
105 $notice .= ' ' . sprintf( __( 'For more information on porting code and using snippets, see our plugin <a href="%s" target="_blank">documentation</a>', 'insert-php' ), 'http://woody-ad-snippets.webcraftic.com/getting-started-with-woody-ad-snippets/' );
106
107 $notice .= '<br><br><a href="' . $create_notice_url . '" class="button button-default">' . __( 'Create new php snippet', 'insert-php' ) . '</a> ';
108
109 $notice .= '<a href="https://downloads.wordpress.org/plugin/insert-php.1.3.zip" class="button button-default">' . __( 'Download old version', 'insert-php' ) . '</a><br><br>';
110 $notice .= 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' ), 'http://forum.webcraftic.com' );
111
112 return $notice;
113 }
114
115 /**
116 * When the safe mode of the plugin is enabled, this notification will remind
117 * the user to exit safe mode so that the user's snippets are available publicly.
118 *
119 * @return string
120 */
121 public function get_safe_mode_notice() {
122 if ( ! WINP_Helper::is_safe_mode() ) {
123 return null;
124 }
125
126 $disable_safe_mode_url = add_query_arg( [ 'wbcr-php-snippets-disable-safe-mode' => 1 ] );
127
128 $notice = WINP_Plugin::app()->getPluginTitle() . ': ' . __( 'Running in safe mode. This mode your snippets will not be started.', 'insert-php' );
129 $notice .= ' <a href="' . $disable_safe_mode_url . '" class="button button-default">' . __( 'Disable Safe Mode', 'insert-php' ) . '</a>';
130
131 return $notice;
132 }
133
134 protected function add_notice( $id, $message, $type = 'warning', $dismissible = true, $dismiss_expires = 0, $where = [] ) {
135 if ( is_null( $message ) ) {
136 return;
137 }
138
139 if ( ! empty( $this->notices ) ) {
140 foreach ( $this->notices as $notice ) {
141 if ( $notice['id'] == $this->prefix . $id ) {
142 return;
143 }
144 }
145 }
146
147 $this->notices[] = [
148 'id' => $this->prefix . $id,
149 'type' => $type,
150 'dismissible' => (bool) $dismissible,
151 'dismiss_expires' => (int) $dismiss_expires,
152 'where' => $where,
153 'text' => '<p>' . $message . '</p>'
154 ];
155 }
156 }