Wordpress Coding Standards
This commit is contained in:
@ -7,7 +7,7 @@ class CWV3 {
|
|||||||
add_action( 'init', array( &$this, 'register_frontend_data' ) );
|
add_action( 'init', array( &$this, 'register_frontend_data' ) );
|
||||||
add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) );
|
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.
|
// Post Meta Box for this.
|
||||||
add_action( 'add_meta_boxes', array( $this, 'cw_meta' ) );
|
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_page_posts_columns', array( $this, 'post_cols' ) );
|
||||||
add_filter( 'manage_post_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
|
// Post column info
|
||||||
add_action( 'manage_posts_custom_column', array( $this, 'set_col_data' ) );
|
add_action( 'manage_posts_custom_column', array( $this, 'set_col_data' ) );
|
||||||
add_action( 'manage_pages_custom_column', array( $this, 'set_col_data' ) );
|
add_action( 'manage_pages_custom_column', array( $this, 'set_col_data' ) );
|
||||||
@ -37,19 +35,16 @@ class CWV3 {
|
|||||||
$img = get_option( 'cwv3_bg_image', '' );
|
$img = get_option( 'cwv3_bg_image', '' );
|
||||||
$color = get_option( 'cwv3_bg_color' );
|
$color = get_option( 'cwv3_bg_color' );
|
||||||
?><style type="text/css"><?php
|
?><style type="text/css"><?php
|
||||||
$custom_css = get_option( 'cwv3_css' );
|
$custom_css = get_option( 'cwv3_css', '' );
|
||||||
|
|
||||||
if ( ! empty( $custom_css ) ){
|
if ( ! empty( $custom_css ) ){
|
||||||
echo $custom_css;
|
echo $custom_css;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $img ) ) {
|
if ( ! empty( $img ) ) {
|
||||||
?>
|
?>#cboxOverlay{background:url(<?php echo $img; ?>) no-repeat top center; background-color:<?php echo $color['color']; ?>;}<?php
|
||||||
#cboxOverlay{background:url(<?php echo $img; ?>) no-repeat top center; background-color:<?php echo $color['color']; ?>;}
|
|
||||||
<?php
|
|
||||||
}else {
|
}else {
|
||||||
?>
|
?> #cboxOverlay{background-image:url(<?php echo $img; ?>) no-repeat top center; background-color:<?php echo $color['color']; ?>;} <?php
|
||||||
#cboxOverlay{background-image:url(<?php echo $img; ?>) no-repeat top center; background-color:<?php echo $color['color']; ?>;}
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
?></style><?php
|
?></style><?php
|
||||||
}
|
}
|
||||||
@ -64,7 +59,7 @@ class CWV3 {
|
|||||||
$sw = get_option( 'cwv3_sitewide' );
|
$sw = get_option( 'cwv3_sitewide' );
|
||||||
switch ( $col ) {
|
switch ( $col ) {
|
||||||
case 'cwv2':
|
case 'cwv2':
|
||||||
if ( get_post_meta( $post->ID, 'cwv3_auth', true ) == 'yes' || $sw[0] == 'enabled' ) {
|
if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) || 'enabled' == $sw[0] ) {
|
||||||
echo '<span style="color:#0F0; font-weight:bold;" class="cw_protected">Yes</span>';
|
echo '<span style="color:#0F0; font-weight:bold;" class="cw_protected">Yes</span>';
|
||||||
}else {
|
}else {
|
||||||
echo '<span style="color:#F00; font-weight:bold;" class="cw_vulnerable">No</span>';
|
echo '<span style="color:#F00; font-weight:bold;" class="cw_vulnerable">No</span>';
|
||||||
@ -93,20 +88,20 @@ class CWV3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function cwv3_meta_save( $post_id ) {
|
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 ) )
|
|
||||||
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;
|
|
||||||
|
|
||||||
// check isset before access (edit by @jgraup)
|
// check isset before access (edit by @jgraup)
|
||||||
if(isset($_POST['cwv3_auth']))
|
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; }
|
||||||
|
|
||||||
|
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'] ) ){
|
||||||
$mydata = sanitize_text_field( $_POST['cwv3_auth'] );
|
$mydata = sanitize_text_field( $_POST['cwv3_auth'] );
|
||||||
update_post_meta( $post_id, 'cwv3_auth', $mydata );
|
update_post_meta( $post_id, 'cwv3_auth', $mydata );
|
||||||
}
|
}
|
||||||
@ -117,12 +112,12 @@ class CWV3 {
|
|||||||
|
|
||||||
check_ajax_referer( 'cwv3_ajax_'.$post_id, 'nonce' );
|
check_ajax_referer( 'cwv3_ajax_'.$post_id, 'nonce' );
|
||||||
|
|
||||||
if ( $_POST['method'] == 'exit' ) {
|
if ( 'exit' == $_POST['method'] ) {
|
||||||
$d = get_option( 'cwv3_denial' );
|
$d = get_option( 'cwv3_denial' );
|
||||||
if ( $d[0] == 'enabled' ) {
|
if ( 'enabled' == $d[0] ) {
|
||||||
$resp = $this->set_cookie( $post_id, 3 );
|
$resp = $this->set_cookie( $post_id, 3 );
|
||||||
}
|
}
|
||||||
$resp = "denied";
|
$resp = 'denied';
|
||||||
}else {
|
}else {
|
||||||
$resp = $this->set_cookie( $post_id, 1 );
|
$resp = $this->set_cookie( $post_id, 1 );
|
||||||
}
|
}
|
||||||
@ -133,7 +128,7 @@ class CWV3 {
|
|||||||
public function load_dependancies() {
|
public function load_dependancies() {
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
if ( current_user_can( 'manage_options' ) ) return;
|
if ( current_user_can( 'manage_options' ) ) { return; }
|
||||||
|
|
||||||
wp_enqueue_style( 'cwv3_css' );
|
wp_enqueue_style( 'cwv3_css' );
|
||||||
wp_enqueue_script( 'cwv3_js' );
|
wp_enqueue_script( 'cwv3_js' );
|
||||||
@ -158,7 +153,7 @@ class CWV3 {
|
|||||||
// Colorbox w/ MIT License
|
// Colorbox w/ MIT License
|
||||||
wp_register_style( 'colorbox', plugins_url( 'js/colorbox.1.5.10/colorbox.css', dirname( __FILE__ ) ), '', '1.4.14', 'ALL' );
|
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 );
|
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
|
// Main data
|
||||||
@ -187,18 +182,17 @@ class CWV3 {
|
|||||||
$cData[ $key ] = new stdClass;
|
$cData[ $key ] = new stdClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( 'enabled' == ! empty( $sw ) ) {
|
||||||
if ( !empty( $sw ) == 'enabled' ) {
|
|
||||||
$cData['pages']->sitewide = $action;
|
$cData['pages']->sitewide = $action;
|
||||||
return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false );
|
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;
|
$cData['pages']->home = $action;
|
||||||
return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false );
|
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;
|
$cData['pages']->other = $action;
|
||||||
return setcookie( 'cwv3_pages', json_encode( $cData['pages'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false );
|
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' ) {
|
if ( $type == 'post' ) {
|
||||||
$catData = get_option( "cwv3_cat_list" );
|
$catData = get_option( "cwv3_cat_list" );
|
||||||
$curCat = get_the_category( $id );
|
$curCat = get_the_category( $id );
|
||||||
if ( $this->inCat( $catData, $curCat ) ) {
|
if ( $this->in_cat( $catData, $curCat ) ) {
|
||||||
$cData['categories']->$id = $action;
|
$cData['categories']->$id = $action;
|
||||||
return setcookie( 'cwv3_cats', json_encode( $cData['categories'] ), ( $time['multiplier'] * $time['time'] )+time(), COOKIEPATH, COOKIE_DOMAIN, false );
|
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' ) {
|
}else if ( get_post_meta( $id, 'cwv3_auth', true ) == 'yes' ) {
|
||||||
@ -256,56 +250,71 @@ class CWV3 {
|
|||||||
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' ) {
|
if ( is_page() && 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) ) {
|
||||||
$c = $cData['pages'][ $post->ID ];
|
$c = $cData['pages'][ $post->ID ];
|
||||||
return ! empty( $c ) ? $c : false;
|
return ! empty( $c ) ? $c : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = ( is_attachment() ? $post->post_parent : $post->ID );
|
$id = ( is_attachment() ? $post->post_parent : $post->ID );
|
||||||
// First see if categories are setup in the admin side.
|
// 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 );
|
$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.
|
// 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.
|
// 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.
|
// 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() ) {
|
if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) && ! is_front_page() ) {
|
||||||
return ! empty( $cData['posts'][ $post->ID ] ) ? $cData['posts'][ $id ] : false;
|
return ! empty( $cData['posts'][ $post->ID ] ) ? $cData['posts'][ $id ] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function inCat( $catIDs, $catArray ) {
|
public function in_cat( $catIDs, $catArray ) {
|
||||||
if ( ! is_array( $catIDs ) ) {
|
if ( ! is_array( $catIDs ) ) {
|
||||||
$catIDs = array(); // Empty
|
$catIDs = array(); // Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( $catArray as $cat ) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderDialog() {
|
public function render_dialog() {
|
||||||
|
|
||||||
$d = get_option( 'cwv3_denial' );
|
$d = get_option( 'cwv3_denial' );
|
||||||
if ( $this->check_data() == 3 && $d[0] == 'enabled' ) {
|
if ( 3 == $this->check_data() && 'enabled' == $d[0] ) {
|
||||||
$dtype = true;
|
$dtype = true;
|
||||||
}else {
|
}else {
|
||||||
$dtype = false;
|
$dtype = false;
|
||||||
}
|
}
|
||||||
$etxt = get_option( 'cwv3_enter_txt' );
|
$etxt = get_option( 'cwv3_enter_txt', 'Enter' );
|
||||||
$extxt = get_option( 'cwv3_exit_txt' );
|
$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', '#' );
|
||||||
?>
|
?>
|
||||||
<!-- CWV3 Dialog -->
|
<!-- CWV3 Dialog -->
|
||||||
<div style="display: none">
|
<div style="display: none">
|
||||||
<div id="cwv3_auth">
|
<div id="cwv3_auth">
|
||||||
<div id="cwv3_title"><?php if ( $dtype == true ): ?><?php echo get_option( 'cwv3_den_title' ); ?><?php else: ?><?php echo get_option( 'cwv3_d_title' ); ?><?php endif; ?></div>
|
<div id="cwv3_title"><?php echo esc_attr( $title ); ?></div>
|
||||||
<div id="cwv3_content"><?php if ( $dtype === true ): ?><?php echo do_shortcode( get_option( 'cwv3_den_msg' ) ); ?><?php else: ?><?php echo do_shortcode( get_option( 'cwv3_d_msg' ) ); ?><?php endif; ?></div>
|
<div id="cwv3_content"><?php echo wp_kses_post( $cwv3_content ); ?></div>
|
||||||
<div id="cwv3_btns"><?php if ( $dtype !== true ): ?><div id="cwv3_enter"><a href="#" id="cw_enter_link"><?php echo !empty( $etxt ) ? $etxt : 'Enter'; ?></a></div><?php endif; ?><div id="cwv3_exit"><a href="#" id="cw_exit_link"><?php echo !empty( $extxt ) ? $extxt : 'Exit'; ?></a></div></div>
|
<div id="cwv3_btns">
|
||||||
|
<?php if ( true !== $dtype ): ?>
|
||||||
|
<div id="cwv3_enter"><a href="<?php echo esc_url( $enter_url ); ?>" id="cw_enter_link"><?php echo esc_attr( $etxt ); ?></a></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<div id="cwv3_exit"><a href="<?php echo esc_url( $exit_url ); ?>" id="cw_exit_link"><?php echo esc_attr( $extxt ); ?></a></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- END CWV3 Dialog -->
|
<!-- END CWV3 Dialog -->
|
||||||
@ -316,50 +325,15 @@ class CWV3 {
|
|||||||
wp_nonce_field( plugin_basename( __FILE__ ), 'cwv3_meta' );
|
wp_nonce_field( plugin_basename( __FILE__ ), 'cwv3_meta' );
|
||||||
$curval = get_post_meta( $post->ID, 'cwv3_auth', true );
|
$curval = get_post_meta( $post->ID, 'cwv3_auth', true );
|
||||||
$sw = get_option( 'cwv3_sitewide' );
|
$sw = get_option( 'cwv3_sitewide' );
|
||||||
$disabled = $sw[0] == 'enabled' ? 'disabled="disabled"' : '';
|
$disabled = $sw[0] == 'enabled' ? true : false;
|
||||||
?>
|
?>
|
||||||
<label for="cwv3_auth">Use authorization for this content:</label>
|
<label for="cwv3_auth">Use authorization for this content:</label>
|
||||||
<input type="checkbox" id="cwv3_auth" name="cwv3_auth" <?php checked( 'yes', $curval, true ); ?> value="yes" <?php echo $disabled;?>/><br />
|
<input type="checkbox" id="cwv3_auth" name="cwv3_auth" <?php checked( 'yes', $curval, true ); ?> value="yes" <?php disabled( $disabled ); ?>/><br />
|
||||||
<?php if ( $sw[0] == 'enabled' ) : ?>
|
<?php if ( 'enabled' == $sw[0] ) : ?>
|
||||||
<p class="description">Cannot be changed while site wide option is enabled.</p>
|
<p class="description">Cannot be changed while site wide option is enabled.</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
public function display_qe( $column_name, $post_type ) {
|
|
||||||
global $post;
|
|
||||||
?>
|
|
||||||
<fieldset class="inline-edit-col-right inline-edit-book">
|
|
||||||
<div class="inline-edit-col column-<?php echo $column_name ?>">
|
|
||||||
<label class="inline-edit-group">
|
|
||||||
<?php
|
|
||||||
switch ( $column_name ) {
|
|
||||||
case 'cwv2':
|
|
||||||
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"' : ''; ?>
|
|
||||||
|
|
||||||
<label for="cwv3_auth">
|
|
||||||
<input type="checkbox" id="cwv3_auth" name="cwv3_auth" <?php checked( 'yes', $curval, true ); ?> value="yes" <?php echo $disabled; ?>/>
|
|
||||||
<span class="checkbox-title">Use CWv2 for this content <?php echo $post->ID; ?></span>
|
|
||||||
<?php if ( $sw[0] == 'enabled' ) : ?>
|
|
||||||
<span class="description">(Cannot be changed while site wide option is enabled.)</span>
|
|
||||||
<?php endif; ?>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
<?php
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
new CWV3;
|
new CWV3;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user