PluginProbe
Code Snippets / 2.12.1
Code Snippets v2.12.1
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.12.1, at php/class-admin.php

241 lines 6.4 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 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_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_stylesheet' ) );
38 add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), array( $this, 'plugin_settings_link' ) );
39 add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 2 );
40 add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );
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 * Allow super admins to control site admin access to
49 * snippet admin menus
50 *
51 * Adds a checkbox to the *Settings > Network Settings*
52 * network admin menu
53 *
54 * @since 1.7.1
55 *
56 * @param array $menu_items The current mu menu items
57 *
58 * @return array The modified mu menu items
59 */
60 function mu_menu_items( $menu_items ) {
61 $menu_items['snippets'] = __( 'Snippets', 'code-snippets' );
62 $menu_items['snippets_settings'] = __( 'Snippets &raquo; Settings', 'code-snippets' );
63
64 return $menu_items;
65 }
66
67 /**
68 * Enqueue the stylesheet for a snippet menu
69 *
70 * @since 2.2.0
71 * @uses wp_enqueue_style() to add the stylesheet to the queue
72 * @uses get_user_option() to check if MP6 mode is active
73 * @uses plugins_url() to retrieve a URL to assets
74 *
75 * @param string $hook the current page hook
76 */
77 function enqueue_admin_stylesheet( $hook ) {
78 $pages = array( 'manage', 'add', 'edit', 'settings' );
79 $hooks = array_map( 'code_snippets_get_menu_hook', $pages );
80
81 /* First, load the menu icon stylesheet */
82 wp_enqueue_style(
83 'menu-icon-snippets',
84 plugins_url( 'css/min/menu-icon.css', CODE_SNIPPETS_FILE ),
85 false,
86 CODE_SNIPPETS_VERSION
87 );
88
89 /* Only load the stylesheet on the right snippets page */
90 if ( ! in_array( $hook, $hooks ) ) {
91 return;
92 }
93
94 $hooks = array_combine( $hooks, $pages );
95 $page = $hooks[ $hook ];
96
97 // add snippet page uses edit stylesheet
98 'add' === $page && $page = 'edit';
99
100 $rtl = is_rtl() && ( 'edit' === $page || 'manage' === $page ) ? '-rtl' : '';
101
102 wp_enqueue_style(
103 "code-snippets-$page",
104 plugins_url( "css/min/{$page}{$rtl}.css", CODE_SNIPPETS_FILE ),
105 false,
106 CODE_SNIPPETS_VERSION
107 );
108 }
109
110 /**
111 * Prevent the snippet currently being saved from being executed
112 * so it is not run twice (once normally, once
113 *
114 * @param bool $exec Whether the snippet will be executed
115 * @param int $exec_id The ID of the snippet being executed
116 * @param string $table_name
117 *
118 * @return bool Whether the snippet will be executed
119 */
120 function prevent_exec_on_save( $exec, $exec_id, $table_name ) {
121
122 if ( ! isset( $_POST['save_snippet'], $_POST['snippet_id'] ) ) {
123 return $exec;
124 }
125
126 if ( code_snippets()->db->get_table_name() !== $table_name ) {
127 return $exec;
128 }
129
130 $id = intval( $_POST['snippet_id'] );
131
132 if ( $id === $exec_id ) {
133 return false;
134 }
135
136 return $exec;
137 }
138
139 /**
140 * Adds a link pointing to the Manage Snippets page
141 *
142 * @since 2.0
143 *
144 * @param array $links The existing plugin action links
145 *
146 * @return array The modified plugin action links
147 */
148 function plugin_settings_link( $links ) {
149 array_unshift( $links, sprintf(
150 '<a href="%1$s" title="%2$s">%3$s</a>',
151 code_snippets()->get_menu_url(),
152 __( 'Manage your existing snippets', 'code-snippets' ),
153 __( 'Snippets', 'code-snippets' )
154 ) );
155
156 return $links;
157 }
158
159 /**
160 * Adds extra links related to the plugin
161 *
162 * @since 2.0
163 *
164 * @param array $links The existing plugin info links
165 * @param string $file The plugin the links are for
166 *
167 * @return array The modified plugin info links
168 */
169 function plugin_meta_links( $links, $file ) {
170
171 /* We only want to affect the Code Snippets plugin listing */
172 if ( plugin_basename( CODE_SNIPPETS_FILE ) !== $file ) {
173 return $links;
174 }
175
176 $format = '<a href="%1$s" title="%2$s">%3$s</a>';
177
178 /* array_merge appends the links to the end */
179
180 return array_merge( $links, array(
181 sprintf( $format,
182 'http://wordpress.org/plugins/code-snippets/',
183 __( 'Visit the WordPress.org plugin page', 'code-snippets' ),
184 __( 'About', 'code-snippets' )
185 ),
186 sprintf( $format,
187 'http://wordpress.org/support/plugin/code-snippets/',
188 __( 'Visit the support forums', 'code-snippets' ),
189 __( 'Support', 'code-snippets' )
190 ),
191 sprintf( $format,
192 'http://bungeshea.com/donate/',
193 __( "Support this plugin's development", 'code-snippets' ),
194 __( 'Donate', 'code-snippets' )
195 ),
196 ) );
197 }
198
199 /**
200 * Print a notice inviting people to participate in the Code Snippets Survey
201 *
202 * @since 1.9
203 * @return void
204 */
205 function survey_message() {
206 global $current_user;
207
208 $key = 'ignore_code_snippets_survey_message';
209
210 /* Bail now if the user has dismissed the message */
211 if ( get_user_meta( $current_user->ID, $key ) ) {
212 return;
213 } elseif ( isset( $_GET[ $key ], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $key ) ) {
214 add_user_meta( $current_user->ID, $key, true, true );
215
216 return;
217 }
218
219 ?>
220
221 <br />
222
223 <div class="updated">
224 <p>
225
226 <?php _e( "<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' ); ?>
227
228 <a href="http://sheabunge.polldaddy.com/s/code-snippets-feedback" class="button secondary"
229 target="_blank" style="margin: auto .5em;">
230 <?php _e( 'Take the survey now', 'code-snippets' ); ?>
231 </a>
232
233 <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( $key, true ), $key ) ); ?>"><?php esc_html_e( 'Dismiss', 'code-snippets' ); ?></a>
234
235 </p>
236 </div>
237
238 <?php
239 }
240 }
241