PluginProbe
Code Snippets / 2.14.6
Code Snippets v2.14.6
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / class-admin.php

class-admin.php in Code Snippets 2.14.6, at php/class-admin.php

228 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Functions specific to the administration interface
5 *
6 * @package Code_Snippets
7 */
8 class Code_Snippets_Admin {
9
10 public $menus = array();
11
12 public function __construct() {
13
14 if ( is_admin() ) {
15 $this->run();
16 }
17 }
18
19 public function load_classes() {
20 $this->menus['manage'] = new Code_Snippets_Manage_Menu();
21 $this->menus['edit'] = new Code_Snippets_Edit_Menu();
22 $this->menus['import'] = new Code_Snippets_Import_Menu();
23
24 if ( is_network_admin() === code_snippets_unified_settings() ) {
25 $this->menus['settings'] = new Code_Snippets_Settings_Menu();
26 }
27
28 foreach ( $this->menus as $menu ) {
29 $menu->run();
30 }
31 }
32
33 public function run() {
34 add_action( 'init', array( $this, 'load_classes' ), 11 );
35
36 add_filter( 'mu_menu_items', array( $this, 'mu_menu_items' ) );
37 add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), array( $this, 'plugin_settings_link' ) );
38 add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 2 );
39 add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );
40 add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_menu_icon' ) );
41
42 if ( isset( $_POST['save_snippet'] ) && $_POST['save_snippet'] ) {
43 add_action( 'code_snippets/allow_execute_snippet', array( $this, 'prevent_exec_on_save' ), 10, 3 );
44 }
45 }
46
47 /**
48 * @return bool
49 */
50 public function is_compact_menu() {
51 return ! is_network_admin() && apply_filters( 'code_snippets_compact_menu', false );
52 }
53
54 /**
55 * Allow super admins to control site admin access to
56 * snippet admin menus
57 *
58 * Adds a checkbox to the *Settings > Network Settings*
59 * network admin menu
60 *
61 * @param array $menu_items The current mu menu items
62 *
63 * @return array The modified mu menu items
64 * @since 1.7.1
65 *
66 */
67 public function mu_menu_items( $menu_items ) {
68 $menu_items['snippets'] = __( 'Snippets', 'code-snippets' );
69 $menu_items['snippets_settings'] = __( 'Snippets &raquo; Settings', 'code-snippets' );
70
71 return $menu_items;
72 }
73
74 /**
75 * Load the stylesheet for the admin menu icon
76 */
77 public function load_admin_menu_icon() {
78
79 wp_enqueue_style(
80 'menu-icon-snippets',
81 plugins_url( 'css/min/menu-icon.css', code_snippets()->file ),
82 array(),
83 code_snippets()->version
84 );
85 }
86
87 /**
88 * Prevent the snippet currently being saved from being executed
89 * so it is not run twice (once normally, once
90 *
91 * @param bool $exec Whether the snippet will be executed
92 * @param int $exec_id The ID of the snippet being executed
93 * @param string $table_name
94 *
95 * @return bool Whether the snippet will be executed
96 */
97 public function prevent_exec_on_save( $exec, $exec_id, $table_name ) {
98
99 if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
100 return $exec;
101 }
102
103 if ( code_snippets()->db->get_table_name() !== $table_name ) {
104 return $exec;
105 }
106
107 $id = intval( $_POST['snippet_id'] );
108
109 if ( $id === $exec_id ) {
110 return false;
111 }
112
113 return $exec;
114 }
115
116 /**
117 * Adds a link pointing to the Manage Snippets page
118 *
119 * @param array $links The existing plugin action links
120 *
121 * @return array The modified plugin action links
122 * @since 2.0
123 *
124 */
125 public function plugin_settings_link( $links ) {
126 array_unshift(
127 $links,
128 sprintf(
129 '<a href="%1$s" title="%2$s">%3$s</a>',
130 esc_url( code_snippets()->get_menu_url() ),
131 esc_attr__( 'Manage your existing snippets', 'code-snippets' ),
132 esc_html__( 'Snippets', 'code-snippets' )
133 )
134 );
135
136 return $links;
137 }
138
139 /**
140 * Adds extra links related to the plugin
141 *
142 * @param array $links The existing plugin info links
143 * @param string $file The plugin the links are for
144 *
145 * @return array The modified plugin info links
146 * @since 2.0
147 *
148 */
149 public function plugin_meta_links( $links, $file ) {
150
151 /* We only want to affect the Code Snippets plugin listing */
152 if ( plugin_basename( CODE_SNIPPETS_FILE ) !== $file ) {
153 return $links;
154 }
155
156 $format = '<a href="%1$s" title="%2$s">%3$s</a>';
157
158 /* array_merge appends the links to the end */
159
160 return array_merge(
161 $links,
162 array(
163 sprintf( $format,
164 'https://wordpress.org/plugins/code-snippets/',
165 esc_attr__( 'Visit the WordPress.org plugin page', 'code-snippets' ),
166 esc_html__( 'About', 'code-snippets' )
167 ),
168 sprintf( $format,
169 'https://wordpress.org/support/plugin/code-snippets/',
170 esc_attr__( 'Visit the support forums', 'code-snippets' ),
171 esc_html__( 'Support', 'code-snippets' )
172 ),
173 sprintf( $format,
174 'https://sheabunge.com/donate/',
175 esc_attr__( "Support this plugin's development", 'code-snippets' ),
176 esc_html__( 'Donate', 'code-snippets' )
177 ),
178 )
179 );
180 }
181
182 /**
183 * Print a notice inviting people to participate in the Code Snippets Survey
184 *
185 * @return void
186 * @since 1.9
187 */
188 public function survey_message() {
189 global $current_user;
190
191 $key = 'ignore_code_snippets_survey_message';
192
193 /* Bail now if the user has dismissed the message */
194 if ( get_user_meta( $current_user->ID, $key ) ) {
195 return;
196 } elseif ( isset( $_GET[ $key ], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $key ) ) {
197 add_user_meta( $current_user->ID, $key, true, true );
198
199 return;
200 }
201
202 ?>
203
204 <br/>
205
206 <div class="updated code-snippets-survey-message">
207 <p>
208
209 <?php echo wp_kses(
210 __( "<strong>Have feedback on Code Snippets?</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.", 'code-snippets' ),
211 array( 'strong' => array() )
212 );
213 ?>
214
215 <a href="https://codesnippets.pro/survey/" class="button secondary"
216 target="_blank" style="margin: auto .5em;">
217 <?php esc_html_e( 'Take the survey now', 'code-snippets' ); ?>
218 </a>
219
220 <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( $key, true ), $key ) ); ?>"><?php esc_html_e( 'Dismiss', 'code-snippets' ); ?></a>
221
222 </p>
223 </div>
224
225 <?php
226 }
227 }
228