Better sanity check for column
This commit is contained in:
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
class CWV3Admin {
|
class CWV3Admin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hooks for the administrator panel
|
||||||
|
* @since 3.6.3
|
||||||
|
*/
|
||||||
function hooks() {
|
function hooks() {
|
||||||
// Post Meta Box for this.
|
// Post Meta Box for this.
|
||||||
add_action( 'add_meta_boxes', array( $this, 'setup_metabox' ) );
|
add_action( 'add_meta_boxes', array( $this, 'setup_metabox' ) );
|
||||||
@ -9,34 +13,56 @@ class CWV3Admin {
|
|||||||
|
|
||||||
add_action( 'admin_head', array( $this, 'render_lazy_mans_css' ) );
|
add_action( 'admin_head', array( $this, 'render_lazy_mans_css' ) );
|
||||||
|
|
||||||
// Post column filters
|
$post_types = $this->get_cwv3_post_types();
|
||||||
add_filter( 'manage_page_posts_columns', array( $this, 'post_cols' ) );
|
if ( ! empty( $post_types ) && is_array( $post_types ) ) {
|
||||||
add_filter( 'manage_post_posts_columns', array( $this, 'post_cols' ) );
|
foreach ( $post_types as $post_type ) {
|
||||||
|
add_filter( "manage_{$post_type}_posts_columns", array( $this, 'post_cols' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Centers custom column content
|
||||||
|
* @since 3.6.3
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
public function render_lazy_mans_css() {
|
public function render_lazy_mans_css() {
|
||||||
echo '<style type="text/css">th#cwv2{width: 32px; text-align:center;} td.column-cwv2{text-align:center;}</style>';
|
echo '<style type="text/css">th#cwv2{width: 32px; text-align:center;} td.column-cwv2{text-align:center;}</style>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets column data for the CWv3 column
|
||||||
|
*
|
||||||
|
* @since 3.6.3
|
||||||
|
* @param $col
|
||||||
|
*/
|
||||||
public function set_col_data( $col ) {
|
public function set_col_data( $col ) {
|
||||||
global $post;
|
global $post;
|
||||||
|
|
||||||
$sw = get_option( 'cwv3_sitewide' );
|
$sw = get_option( 'cwv3_sitewide' );
|
||||||
|
$is_enabled = ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) ) ? true : false;;
|
||||||
switch ( $col ) {
|
switch ( $col ) {
|
||||||
case 'cwv2':
|
case 'cwv2':
|
||||||
if ( 'yes' == get_post_meta( $post->ID, 'cwv3_auth', true ) || 'enabled' == $sw[0] ) {
|
if ( $is_enabled || ( isset( $sw[0] ) && 'enabled' == $sw[0] ) ) {
|
||||||
echo '<span class="dashicons dashicons-lock"></span>';
|
echo '<span class="dashicons dashicons-lock"></span>';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds columns to the post list table
|
||||||
|
*
|
||||||
|
* @since 3.6.3
|
||||||
|
* @param $cols
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
public function post_cols( $cols ) {
|
public function post_cols( $cols ) {
|
||||||
|
|
||||||
return array_slice( $cols, 0, 1, true ) +
|
return array_slice( $cols, 0, 1, true ) +
|
||||||
array( 'cwv2' => 'CW' ) +
|
array( 'cwv2' => 'CW' ) +
|
||||||
array_slice( $cols, 1, count( $cols ) - 1, true );
|
array_slice( $cols, 1, count( $cols ) - 1, true );
|
||||||
@ -45,6 +71,8 @@ class CWV3Admin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add metabox to post types
|
* Add metabox to post types
|
||||||
|
*
|
||||||
|
* @since 3.6.3
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setup_metabox() {
|
public function setup_metabox() {
|
||||||
@ -64,6 +92,7 @@ class CWV3Admin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the post types that can be used with CWv2
|
* Gets the post types that can be used with CWv2
|
||||||
|
* @since 3.6.4
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_cwv3_post_types() {
|
public function get_cwv3_post_types() {
|
||||||
@ -72,6 +101,13 @@ class CWV3Admin {
|
|||||||
return ! is_array( $types ) ? array( $types ) : $types;
|
return ! is_array( $types ) ? array( $types ) : $types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves meta data
|
||||||
|
*
|
||||||
|
* @since 3.6.3
|
||||||
|
* @param int $post_id
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
public function cwv3_meta_save( $post_id ) {
|
public function cwv3_meta_save( $post_id ) {
|
||||||
$post_types = $this->get_cwv3_post_types();
|
$post_types = $this->get_cwv3_post_types();
|
||||||
// check isset before access (edit by @jgraup)
|
// check isset before access (edit by @jgraup)
|
||||||
@ -90,6 +126,11 @@ class CWV3Admin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the meta box for CWv3
|
||||||
|
* @since 3.6.3
|
||||||
|
* @param $post
|
||||||
|
*/
|
||||||
public function render_metabox( $post ) {
|
public function render_metabox( $post ) {
|
||||||
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 );
|
||||||
|
Reference in New Issue
Block a user