PluginProbe
Code Snippets / 2.12.0
Code Snippets v2.12.0
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.0, at php/class-admin.php

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