Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move capability into constant and make it configurable #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions includes/Admin/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public function __construct()
public function get_wildcard()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
wp_send_json_success(get_option('301_redirects_wildcard'));
wp_die();
}
public function wildcard()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
update_option('301_redirects_wildcard', sanitize_text_field($_POST['toggle']));
wp_send_json_success($_POST['toggle']);
wp_die();
}
public function install_plugin()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$slug = isset($_POST['slug']) ? sanitize_text_field($_POST['slug']) : '';
$result = \Simple301Redirects\Helper::install_plugin($slug);
if (is_wp_error($result)) {
Expand All @@ -45,7 +45,7 @@ public function install_plugin()
public function activate_plugin()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$basename = isset($_POST['basename']) ? sanitize_text_field($_POST['basename']) : '';
$result = activate_plugin($basename, '', false );
if (is_wp_error($result)) {
Expand All @@ -60,7 +60,7 @@ public function activate_plugin()
public function hide_notice()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$hide = isset($_POST['hide']) ? sanitize_text_field($_POST['hide']) : false;
update_option('simple301redirects_hide_btl_notice', $hide);
wp_send_json_success($hide);
Expand All @@ -70,15 +70,15 @@ public function hide_notice()
public function fetch_all_links()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
wp_send_json_success(get_option('301_redirects'));
wp_die();
}

public function create_new_link()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$key = (isset($_POST['key']) ? sanitize_text_field($_POST['key']) : '');
$value = (isset($_POST['value']) ? sanitize_text_field($_POST['value']) : '');
$links = get_option('301_redirects');
Expand All @@ -92,7 +92,7 @@ public function create_new_link()
public function update_link()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$key = (isset($_POST['key']) ? sanitize_text_field($_POST['key']) : '');
$oldKey = (isset($_POST['oldKey']) ? sanitize_text_field($_POST['oldKey']) : '');
$value = (isset($_POST['value']) ? sanitize_text_field($_POST['value']) : '');
Expand All @@ -111,7 +111,7 @@ public function update_link()
public function delete_link()
{
check_ajax_referer('simple301redirects', 'security');
if( ! current_user_can( 'manage_options' ) ) wp_die();
if( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) wp_die();
$key = (isset($_POST['key']) ? sanitize_text_field($_POST['key']) : '');
$links = get_option('301_redirects');
if(isset($links[$key])){
Expand Down
2 changes: 1 addition & 1 deletion includes/Admin/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct()
* @return void
*/
public function create_menu() {
add_options_page('301 Redirects', '301 Redirects', 'manage_options', '301options', array($this,'load_main_template'));
add_options_page('301 Redirects', '301 Redirects', SIMPLE301REDIRECTS_CAPABILITY, '301options', array($this,'load_main_template'));
}

public function load_main_template()
Expand Down
4 changes: 2 additions & 2 deletions includes/Admin/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function export_data()
{
$page = isset($_GET['page']) ? $_GET['page'] : '';
$export = isset($_REQUEST['export']) ? $_REQUEST['export'] : false;
if ($page === '301options' && $export == true && current_user_can('manage_options')) {
if ($page === '301options' && $export == true && current_user_can(SIMPLE301REDIRECTS_CAPABILITY)) {
check_ajax_referer('simple301redirects', 'security');
$content = get_option(SIMPLE301REDIRECTS_SETTINGS_NAME);
$content = $this->prepare_csv_file_data(get_option(SIMPLE301REDIRECTS_SETTINGS_NAME));
Expand Down Expand Up @@ -45,7 +45,7 @@ public function import_data()
{
$page = isset($_GET['page']) ? $_GET['page'] : '';
$import = isset($_REQUEST['import']) ? $_REQUEST['import'] : false;
if ($page === '301options' && $import == true && current_user_can('manage_options')) {
if ($page === '301options' && $import == true && current_user_can(SIMPLE301REDIRECTS_CAPABILITY)) {
check_ajax_referer('simple301redirects', 'security');
$file = $_FILES['upload_file'];
if (!empty($file['tmp_name']) && 'csv' === pathinfo($file['name'])[ 'extension' ]) {
Expand Down
2 changes: 1 addition & 1 deletion includes/Admin/WPDev/PluginUsageTracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public function notice() {
if( isset( $block_notice[$this->plugin_name] ) ) {
return;
}
if ( ! current_user_can( 'manage_options' ) ) {
if ( ! current_user_can( SIMPLE301REDIRECTS_CAPABILITY ) ) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions wp-simple-301-redirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public function define_constants()
define('SIMPLE301REDIRECTS_ROOT_DIR_PATH', plugin_dir_path(__FILE__));
define('SIMPLE301REDIRECTS_ASSETS_DIR_PATH', SIMPLE301REDIRECTS_ROOT_DIR_PATH . 'assets/');
define('SIMPLE301REDIRECTS_ASSETS_URI', SIMPLE301REDIRECTS_PLUGIN_ROOT_URI . 'assets/');
if (!defined('SIMPLE301REDIRECTS_CAPABILITY')) {
define('SIMPLE301REDIRECTS_CAPABILITY', 'manage_options');
}
}

/**
Expand Down