Skip to content

Commit 52b0c8d

Browse files
committed
Add capability check to site importer
Add additional capability checks for menus Bump plugin version
1 parent bee817f commit 52b0c8d

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.9.1.1
4+
* Add capability check to site snippets importer
5+
36
## 1.9.1
47
* Use an icon font for menu icon instead of embedded SVG
58
* Use Sass (libsass) instead of Compass

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
* __Requires at least:__ [WordPress 3.3](http://wordpress.org/download/) or later
55
* __Tested up to:__ WordPress 3.8
6-
* __Stable version:__ [1.9.1](http://downloads.wordpress.org/plugin/code-snippets.latest-stable.zip)
6+
* __Stable version:__ [1.9.1.1](http://downloads.wordpress.org/plugin/code-snippets.latest-stable.zip)
77
* __License:__ [MIT](license.txt)
88

99
An easy, clean and simple way to add code snippets to your site.

code-snippets.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* contribute to the localization, please see http://code-snippets.bungeshea.com
88
*
99
* @package Code_Snippets
10-
* @version 1.9.1
10+
* @version 1.9.1.1
1111
* @author Shea Bunge <http://bungeshea.com/>
1212
* @copyright Copyright (c) 2012-2014, Shea Bunge
1313
* @link http://code-snippets.bungeshea.com
@@ -20,7 +20,7 @@
2020
Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
2121
Author: Shea Bunge
2222
Author URI: http://bungeshea.com
23-
Version: 1.9.1
23+
Version: 1.9.1.1
2424
License: MIT
2525
License URI: license.txt
2626
Text Domain: code-snippets
@@ -58,7 +58,7 @@ final class Code_Snippets {
5858
* @access public
5959
* @var string A PHP-standardized version number string
6060
*/
61-
public $version = '1.9.1';
61+
public $version = '1.9.1.1';
6262

6363
/**
6464
* Variables to hold plugin paths

includes/class-admin.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,19 @@ function mu_menu_items( $menu_items ) {
164164
* @return void
165165
*/
166166
function load_importer() {
167+
global $code_snippets;
167168

168-
if ( defined( 'WP_LOAD_IMPORTERS' ) ) {
169+
/* Only register the importer if the current user can manage snippets */
170+
if ( defined( 'WP_LOAD_IMPORTERS' ) && current_user_can( $code_snippets->get_cap() ) ) {
169171

170172
/* Load Importer API */
171173
require_once ABSPATH . 'wp-admin/includes/import.php';
172174

173175
if ( ! class_exists( 'WP_Importer' ) ) {
174176
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
175-
if ( file_exists( $class_wp_importer ) )
177+
if ( file_exists( $class_wp_importer ) ) {
176178
require_once $class_wp_importer;
179+
}
177180
}
178181

179182
/* Register the Code Snippets importer with WordPress */
@@ -228,6 +231,22 @@ public function get_messages( $slug ) {
228231
require $code_snippets->plugin_dir . "admin/messages/{$slug}.php";
229232
}
230233

234+
/**
235+
* Check if the current user can manage snippets.
236+
* If not, display an error message
237+
*
238+
* @since 1.9.1.1
239+
* @access public
240+
* @return void
241+
*/
242+
public function check_perms() {
243+
global $code_snippets;
244+
245+
if ( ! current_user_can( $code_snippets->get_cap() ) ) {
246+
wp_die( __( 'You are not access this page.', 'code-snippets' ) );
247+
}
248+
}
249+
231250
/**
232251
* Add the dashboard admin menu and subpages
233252
*
@@ -350,6 +369,9 @@ function load_admin_icon_style() {
350369
function load_manage_menu() {
351370
global $code_snippets;
352371

372+
/* Make sure the user has permission to be here */
373+
$this->check_perms();
374+
353375
/* Create the snippet tables if they don't exist */
354376
$code_snippets->maybe_create_tables( true, true );
355377

@@ -376,6 +398,9 @@ function load_single_menu() {
376398
global $code_snippets;
377399
$screen = get_current_screen();
378400

401+
/* Make sure the user has permission to be here */
402+
$this->check_perms();
403+
379404
/* Create the snippet tables if they don't exist */
380405
$code_snippets->maybe_create_tables( true, true );
381406

@@ -561,6 +586,9 @@ function single_menu_enqueue_scripts( $hook ) {
561586
function load_import_menu() {
562587
global $code_snippets;
563588

589+
/* Make sure the user has permission to be here */
590+
$this->check_perms();
591+
564592
/* Create the snippet tables if they don't exist */
565593
$code_snippets->maybe_create_tables( true, true );
566594

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: http://code-snippets.bungeshea.com/donate/
44
Tags: code-snippets, snippets, code, php, network, multisite
55
Requires at least: 3.3
66
Tested up to: 3.8
7-
Stable tag: 1.9.1
7+
Stable tag: 1.9.1.1
88
License: MIT
99
License URI: license.txt
1010

@@ -120,6 +120,9 @@ That's fantastic! Join me on [GitHub](https://github.com/bungeshea/code-snippets
120120

121121
== Changelog ==
122122

123+
= 1.9.1.1
124+
* Add capability check to site snippets importer
125+
123126
= 1.9.1 =
124127
* Use an icon font for menu icon instead of embedded SVG
125128
* Use Sass (libsass) instead of Compass
@@ -268,6 +271,9 @@ Plugin updates will be posted on the [plugin's homepage](http://code-snippets.bu
268271

269272
== Upgrade Notice ==
270273

274+
= 1.9.1.1 =
275+
Add capability check to snippets importer
276+
271277
= 1.9.1 =
272278
UI improvements for WordPress 3.8
273279

0 commit comments

Comments
 (0)