From d0ad6ba7db282b31e7e286b1f65b45745136bfb2 Mon Sep 17 00:00:00 2001 From: Jesse Graupmann Date: Sun, 7 Sep 2014 17:46:20 -0400 Subject: [PATCH 1/4] Changing menu type and menu name. Changing 'CWv3 Options' to 'Content Warning v3' and moving the menu to Settings. --- inc/options.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inc/options.inc.php b/inc/options.inc.php index a8095ff..73efef9 100644 --- a/inc/options.inc.php +++ b/inc/options.inc.php @@ -10,9 +10,10 @@ foreach($cat_list as $cw_cat){ } $cwv3_op_data = array( 'plugin_title' => 'Content Warning v3', - 'prefix' => 'cwv3_', - 'menu_title' => 'CWv3 Options', - 'slug' => 'cwv3_options', + 'prefix' => 'cwv3_', + 'menu_title' => 'Content Warning v3', + 'menu_type' => 'option', + 'slug' => 'cwv3_options', 'opData' => array( 'sitewide' => array( 'name' => 'Sitewide', From 2469fed4ad7159b6cacbd8f9a1ed1c908b7a5e6f Mon Sep 17 00:00:00 2001 From: Jay Wood Date: Mon, 27 Oct 2014 19:09:30 -0400 Subject: [PATCH 2/4] Wordpress Coding Standards --- class/main.class.php | 202 +++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 114 deletions(-) diff --git a/class/main.class.php b/class/main.class.php index 819ab77..727fb3a 100644 --- a/class/main.class.php +++ b/class/main.class.php @@ -7,7 +7,7 @@ class CWV3 { add_action( 'init', array( &$this, 'register_frontend_data' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) ); - add_action( 'wp_footer', array( $this, 'renderDialog' ) ); + add_action( 'wp_footer', array( $this, 'render_dialog' ) ); // Post Meta Box for this. add_action( 'add_meta_boxes', array( $this, 'cw_meta' ) ); @@ -21,8 +21,6 @@ class CWV3 { add_filter( 'manage_page_posts_columns', array( $this, 'post_cols' ) ); add_filter( 'manage_post_posts_columns', array( $this, 'post_cols' ) ); - //add_action('quick_edit_custom_box', array(&$this, 'display_qe'), 10, 2); - // Post column info add_action( 'manage_posts_custom_column', array( $this, 'set_col_data' ) ); add_action( 'manage_pages_custom_column', array( $this, 'set_col_data' ) ); @@ -37,20 +35,17 @@ class CWV3 { $img = get_option( 'cwv3_bg_image', '' ); $color = get_option( 'cwv3_bg_color' ); ?>ID, 'cwv3_auth', true ) == 'yes' || $sw[0] == 'enabled' ) { + if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) || 'enabled' == $sw[0] ) { echo 'Yes'; }else { echo 'No'; @@ -75,7 +70,7 @@ class CWV3 { public function post_cols( $cols ) { - return array_slice( $cols, 0, 1, true )+array( 'cwv2'=> 'CW' )+array_slice( $cols, 1, count( $array )-1, true ); + return array_slice( $cols, 0, 1, true ) + array( 'cwv2' => 'CW' ) + array_slice( $cols, 1, count( $array ) - 1, true ); } @@ -93,20 +88,20 @@ class CWV3 { } public function cwv3_meta_save( $post_id ) { - // check isset before access (edit by @jgraup) - if ( isset($_POST['post_type']) && 'page' == $_POST['post_type'] ) - if ( !current_user_can( 'edit_page', $post_id ) ) + + // check isset before access (edit by @jgraup) + if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ){ + if ( ! current_user_can( 'edit_page', $post_id ) ){ return; - else - if ( !current_user_can( 'edit_post', $post_id ) ) - return; + } else { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } - if ( !isset( $_POST['cwv3_meta'] ) || ! wp_verify_nonce( $_POST['cwv3_meta'], plugin_basename( __FILE__ ) ) ) - return; + if ( ! isset( $_POST['cwv3_meta'] ) || ! wp_verify_nonce( $_POST['cwv3_meta'], plugin_basename( __FILE__ ) ) ) { return; } + } + } - // check isset before access (edit by @jgraup) - if(isset($_POST['cwv3_auth'])) - { + // check isset before access (edit by @jgraup) + if ( isset( $_POST['cwv3_auth'] ) ){ $mydata = sanitize_text_field( $_POST['cwv3_auth'] ); update_post_meta( $post_id, 'cwv3_auth', $mydata ); } @@ -117,12 +112,12 @@ class CWV3 { check_ajax_referer( 'cwv3_ajax_'.$post_id, 'nonce' ); - if ( $_POST['method'] == 'exit' ) { + if ( 'exit' == $_POST['method'] ) { $d = get_option( 'cwv3_denial' ); - if ( $d[0] == 'enabled' ) { + if ( 'enabled' == $d[0] ) { $resp = $this->set_cookie( $post_id, 3 ); } - $resp = "denied"; + $resp = 'denied'; }else { $resp = $this->set_cookie( $post_id, 1 ); } @@ -133,7 +128,7 @@ class CWV3 { public function load_dependancies() { global $post; - if ( current_user_can( 'manage_options' ) ) return; + if ( current_user_can( 'manage_options' ) ) { return; } wp_enqueue_style( 'cwv3_css' ); wp_enqueue_script( 'cwv3_js' ); @@ -147,9 +142,9 @@ class CWV3 { 'nonce' => wp_create_nonce( 'cwv3_ajax_'.$p_ID ), 'admin_url' => admin_url( 'admin-ajax.php' ), 'id' => $p_ID, - 'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && !empty( $d ) ) ) ? true : false, - 'enter' => !empty( $elink ) ? $elink : '#', - 'exit' => !empty( $exlink ) ? $exlink : 'http://google.com', + 'sd' => ( $this->check_data() == false || ( $this->check_data() == 3 && ! empty( $d ) ) ) ? true : false, + 'enter' => ! empty( $elink ) ? $elink : '#', + 'exit' => ! empty( $exlink ) ? $exlink : 'http://google.com', 'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ) ) ); } @@ -158,7 +153,7 @@ class CWV3 { // Colorbox w/ MIT License wp_register_style( 'colorbox', plugins_url( 'js/colorbox.1.5.10/colorbox.css', dirname( __FILE__ ) ), '', '1.4.14', 'ALL' ); - $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : ".min"; + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'colorbox_js', plugins_url( "js/colorbox.1.5.10/jquery.colorbox{$min}.js", dirname( __FILE__ ) ), array( 'jquery' ), '1.4.14', true ); // Main data @@ -175,30 +170,29 @@ class CWV3 { $mi = get_option( 'cwv3_misc' ); $cData = array( - // check isset before access (edit by @jgraup) - 'pages' => !isset($_COOKIE['cwv3_pages']) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_pages'] ) ), - 'posts' => !isset($_COOKIE['cwv3_posts']) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_posts'] ) ), - 'categories' => !isset($_COOKIE['cwv3_cats']) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_cats'] ) ) + // check isset before access (edit by @jgraup) + 'pages' => ! isset( $_COOKIE['cwv3_pages'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_pages'] ) ), + 'posts' => ! isset( $_COOKIE['cwv3_posts'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_posts'] ) ), + 'categories' => ! isset( $_COOKIE['cwv3_cats'] ) ? '' : json_decode( stripslashes( $_COOKIE['cwv3_cats'] ) ) ); // ensure we're using valid objects (edit by @jgraup) - foreach ($cData as $key => $value) { - if(is_scalar($value)){ - $cData[$key] = new stdClass; - } - } - - if ( !empty( $sw ) == 'enabled' ) { + foreach ( $cData as $key => $value ) { + if ( is_scalar( $value ) ) { + $cData[ $key ] = new stdClass; + } + } + if ( 'enabled' == ! empty( $sw ) ) { $cData['pages']->sitewide = $action; return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); } - if ( !empty( $hm ) == 'enabled' && $id == -1 ) { + if ( 'enabled' == ! empty( $hm ) && -1 == $id ) { $cData['pages']->home = $action; return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); } - if ( !empty( $mi ) == 'enabled' && $id == -2 ) { + if ( 'enabled' == ! empty( $mi ) && -2 == $id ) { $cData['pages']->other = $action; return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); } @@ -207,7 +201,7 @@ class CWV3 { if ( $type == 'post' ) { $catData = get_option( "cwv3_cat_list" ); $curCat = get_the_category( $id ); - if ( $this->inCat( $catData, $curCat ) ) { + if ( $this->in_cat( $catData, $curCat ) ) { $cData['categories']->$id = $action; return setcookie( 'cwv3_cats', json_encode( $cData['categories'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false ); }else if ( get_post_meta( $id, 'cwv3_auth', true ) == 'yes' ) { @@ -233,10 +227,10 @@ class CWV3 { } $cData = array( - // check isset before access (edit by @jgraup) - 'pages' => !isset($_COOKIE['cwv3_pages']) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_pages'] ), true ), - 'posts' => !isset($_COOKIE['cwv3_posts']) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_posts'] ), true ), - 'categories' => !isset($_COOKIE['cwv3_cats']) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_cats'] ), true ) + // check isset before access (edit by @jgraup) + 'pages' => ! isset( $_COOKIE['cwv3_pages'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_pages'] ), true ), + 'posts' => ! isset( $_COOKIE['cwv3_posts'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_posts'] ), true ), + 'categories' => ! isset( $_COOKIE['cwv3_cats'] ) ? '' : json_decode( stripslashes( @$_COOKIE['cwv3_cats'] ), true ) ); $sw = get_option( 'cwv3_sitewide' ); @@ -244,68 +238,83 @@ class CWV3 { $mi = get_option( 'cwv3_misc' ); if ( ! empty( $sw ) ) { - return !empty( $cData['pages']['sitewide'] ) ? $cData['pages']['sitewide'] : false; + return ! empty( $cData['pages']['sitewide'] ) ? $cData['pages']['sitewide'] : false; } - if ( is_front_page() && !empty( $hm ) ) { - return !empty( $cData['pages']['home'] ) ? $cData['pages']['home'] : false; + if ( is_front_page() && ! empty( $hm ) ) { + return ! empty( $cData['pages']['home'] ) ? $cData['pages']['home'] : false; } - if ( ( is_archive() || is_search() ) && !empty( $mi ) ) { + if ( ( is_archive() || is_search() ) && ! empty( $mi ) ) { // Protect misc pages aswell - return !empty( $cData['pages']['other'] ) ? $cData['pages']['other'] : false; + return ! empty( $cData['pages']['other'] ) ? $cData['pages']['other'] : false; } - if ( is_page() && get_post_meta( $post->ID, 'cwv3_auth', true ) == 'yes' ) { - $c = $cData['pages'][$post->ID]; - return !empty( $c ) ? $c : false; + if ( is_page() && 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) ) { + $c = $cData['pages'][ $post->ID ]; + return ! empty( $c ) ? $c : false; } $id = ( is_attachment() ? $post->post_parent : $post->ID ); // First see if categories are setup in the admin side. - $catData = get_option( "cwv3_cat_list" ); + $catData = get_option( 'cwv3_cat_list' ); $curCat = get_the_category( $id ); - if ( get_post_type( $id ) == 'post' && $this->inCat( $catData, $curCat ) ) { + if ( 'post' == get_post_type( $id ) && $this->in_cat( $catData, $curCat ) ) { // If the current category is selected in the admin page, that means the administrator wishes to protect it. // respect the admin's wishes and do it. - return !empty( $cData['categories'][$post->ID] ) ? $cData['categories'][$id] : false; + return ! empty( $cData['categories'][ $post->ID ] ) ? $cData['categories'][ $id ] : false; } // Since that's not the case, we need to check post_meta data and see if this post is protected. - if ( get_post_meta( $post->ID, 'cwv3_auth', true ) == 'yes' && !is_front_page() ) { - return !empty( $cData['posts'][$post->ID] ) ? $cData['posts'][$id] : false; + if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) && ! is_front_page() ) { + return ! empty( $cData['posts'][ $post->ID ] ) ? $cData['posts'][ $id ] : false; } return true; } - public function inCat( $catIDs, $catArray ) { - if ( !is_array( $catIDs ) ) { + public function in_cat( $catIDs, $catArray ) { + if ( ! is_array( $catIDs ) ) { $catIDs = array(); // Empty } foreach ( $catArray as $cat ) { - if ( in_array( $cat->term_id, $catIDs ) ) {return true;}else {continue;} + if ( in_array( $cat->term_id, $catIDs ) ) { + return true; + } else { + continue; + } } return false; } - public function renderDialog() { + public function render_dialog() { $d = get_option( 'cwv3_denial' ); - if ( $this->check_data() == 3 && $d[0] == 'enabled' ) { + if ( 3 == $this->check_data() && 'enabled' == $d[0] ) { $dtype = true; }else { $dtype = false; } - $etxt = get_option( 'cwv3_enter_txt' ); - $extxt = get_option( 'cwv3_exit_txt' ); + $etxt = get_option( 'cwv3_enter_txt', 'Enter' ); + $extxt = get_option( 'cwv3_exit_txt', 'Exit' ); + + $cwv3_title = ( true == $dtype ) ? get_option( 'cwv3_den_title' ) : get_option( 'cwv3_d_title' ); + $cwv3_content = ( true == $dtype ) ? get_option( 'cwv3_den_msg' ) : get_option( 'cwv3_d_msg' ); + + $exit_url = get_option( 'cwv3_exit_link', '#' ); + $enter_url = get_option( 'cwv3_enter_link', '#' ); ?>
-
-
-
+
+
+
+ +
+ +
+
@@ -316,50 +325,15 @@ class CWV3 { wp_nonce_field( plugin_basename( __FILE__ ), 'cwv3_meta' ); $curval = get_post_meta( $post->ID, 'cwv3_auth', true ); $sw = get_option( 'cwv3_sitewide' ); - $disabled = $sw[0] == 'enabled' ? 'disabled="disabled"' : ''; + $disabled = $sw[0] == 'enabled' ? true : false; ?> - value="yes" />
- + value="yes" />
+

Cannot be changed while site wide option is enabled.

-
-
- -
-
- Date: Mon, 27 Oct 2014 19:12:07 -0400 Subject: [PATCH 3/4] Wordpress Coding Standards --- inc/options.inc.php | 56 ++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/inc/options.inc.php b/inc/options.inc.php index 73efef9..cb9d561 100644 --- a/inc/options.inc.php +++ b/inc/options.inc.php @@ -2,11 +2,11 @@ // Get categories $cat_list = get_categories(); $final_cat_list = array(); -foreach($cat_list as $cw_cat){ +foreach ( $cat_list as $cw_cat ){ $termID = $cw_cat->term_id; $termName = $cw_cat->name; - - $final_cat_list[$termID] = $termName; + + $final_cat_list[ $termID ] = $termName; } $cwv3_op_data = array( 'plugin_title' => 'Content Warning v3', @@ -20,42 +20,42 @@ $cwv3_op_data = array( 'type' => 'check', 'desc' => 'Takes priority over category, page, and post, home, and misc. pages/posts.', 'fields' => array( - 'enabled' => 'Enable' + 'enabled' => 'Enable', ), - 'def' => 'enabled' + 'def' => 'enabled', ), 'homepage' => array( 'name' => 'Home Page', 'type' => 'check', 'desc' => 'Toggle the home page dialog, useful if you have not set a static page for your front-page in Settings -> Reading.', 'fields' => array( - 'enabled' => 'Enable' + 'enabled' => 'Enable', ), - 'def' => 'enabled' - + 'def' => 'enabled', + ), 'misc' => array( 'name' => 'Misc. Pages', 'type' => 'check', 'desc' => 'Enable this to protect search, archive, and other such pages.', 'fields' => array( - 'enabled' => 'Enable' + 'enabled' => 'Enable', ), - 'def' => 'enabled' - + 'def' => 'enabled', + ), 'death' => array( 'name' => 'Cookie Life', 'desc' => 'How long before the cookie expires.', 'type' => 'timeframe', - 'def' => array('multiplier'=>1, 'time'=>60*60*24) + 'def' => array( 'multiplier' => 1, 'time' => 60 * 60 * 24 ), ), // Dialog Options 'd_title' => array( 'name' => 'Dialog Title', 'desc' => '', 'type' => 'text', - 'def' => 'WARNING: Explicit Content' + 'def' => 'WARNING: Explicit Content', ), 'd_msg' => array( 'name' => 'Dialog Message', @@ -64,39 +64,39 @@ $cwv3_op_data = array( 'def' => 'The content you are about to view may be considered offensive and/or inappropriate. Furthermore, this content may be considered adult content, if you are not of legal age or are easily offended, you are required to click the exit button.', 'settings' => array( 'teeny' => true, - 'media_buttons' => false + 'media_buttons' => false, ) ), 'exit_txt' => array( 'name' => 'Exit Text', 'type' => 'text', 'desc' => 'The text for the exit button.', - 'def' => 'Exit' + 'def' => 'Exit', ), 'exit_link' => array( 'name' => 'Exit Link', 'type' => 'text', 'desc' => 'The full URL a user should be directed to upon clicking the exit button.', - 'def' => 'http://google.com' + 'def' => 'http://google.com', ), 'enter_txt' => array( 'name' => 'Enter Text', 'type' => 'text', 'desc' => 'The text for the enter button.', - 'def' => 'Enter' + 'def' => 'Enter', ), 'enter_link' => array( 'name' => 'Enter Link', 'type' => 'text', 'desc' => 'The full URL a user should be directed to upon clicking the enter button. Leave blank to just close the dialog.', - 'def' => '#' + 'def' => '#', ), // Denial Options 'denial' => array( 'name' => 'Toggle Denial Option', 'desc' => '', 'type' => 'check', - 'fields' => array('enabled' => 'Enable denial handling.') + 'fields' => array( 'enabled' => 'Enable denial handling.' ), ), 'method' => array( 'name' => 'Denial Handling Method', @@ -104,15 +104,15 @@ $cwv3_op_data = array( 'type' => 'radio', 'fields' => array( 'redirect' => 'Redirect the user.', - 'show' => 'Show the denial dialog.' + 'show' => 'Show the denial dialog.', ), - 'def' => 'redirect' + 'def' => 'redirect', ), 'den_title' => array( 'name' => 'Dialog Title', 'desc' => '', 'type' => 'text', - 'def' => 'Access Denied' + 'def' => 'Access Denied', ), 'den_msg' => array( 'name' => 'Denial Message', @@ -121,7 +121,7 @@ $cwv3_op_data = array( 'def' => 'You have been denied access to this content. If you feel this is in error, please contact a site administrator.', 'settings' => array( 'media_buttons' => false, - 'teeny' => true + 'teeny' => true, ) ), // Advanced Options @@ -129,32 +129,32 @@ $cwv3_op_data = array( 'bg_image' => array( 'name' => 'Background Image', 'desc' => 'If not empty, the dialog will use this instead of the background opacity and color.', - 'type' => 'media' + 'type' => 'media', ), 'bg_opacity' => array( 'name' => 'Background Opacity', 'desc' => 'Input a float value from 0-1, the latter being completely opaque.', 'type' => 'number', 'def' => 0.85, - 'step' => 0.01 + 'step' => 0.01, ), 'bg_color' => array( 'name' => 'Background Color', 'desc' => 'The Overlay color.', 'type' => 'color', - 'fields' => array('color'=>'#000000') + 'fields' => array( 'color' => '#000000' ), ), 'css' => array( 'name' => 'Custom CSS', 'desc' => 'For a completely custom look, just drop your css here.', 'type' => 'textbox', - 'def' => '' + 'def' => '', ), 'cat_list' => array( 'name' => 'Category restrictions', 'desc' => 'Select categories that you would like to restrict with the dialog.', 'type' => 'check', - 'fields' => $final_cat_list + 'fields' => $final_cat_list, ) ) ); From 4f30e0466a5198f5c114dd50344e821142fd0677 Mon Sep 17 00:00:00 2001 From: Jay Wood Date: Mon, 27 Oct 2014 19:22:56 -0400 Subject: [PATCH 4/4] Update jw_simple_options with new PR --- lib/jw_simple_options | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jw_simple_options b/lib/jw_simple_options index d159386..80bb3ad 160000 --- a/lib/jw_simple_options +++ b/lib/jw_simple_options @@ -1 +1 @@ -Subproject commit d159386c2e4de92cb61cde4021ba15734c57cf1b +Subproject commit 80bb3ad2399a814882a977309ca18dd35484c6d4