post_types ) ) ) || ! isset( $_GET['post_type'] ) ) { ?>
current_action();
$sendback = '';
switch ( $action ) {
case ( 'unblock' ):
case ( 'block' ):
case ( 'hide' ):
// Validate nonce.
check_admin_referer( 'bulk-posts' );
// Get the posts.
$posts = wpmem_get( 'post', '', 'request' );
// Convert action.
$status = ( 'hide' == $action ) ? 2 : ( ( 'block' == $action ) ? 1 : 0 );
// Update posts.
$x = '';
if ( $posts ) {
foreach ( $posts as $post_id ) {
// Keep a count of posts updated.
$x++;
// Make sure $post_id is just an integer.
$post_id = (int)$post_id;
// Get the post type.
$post = get_post( $post_id );
$type = $post->post_type;
// Update accordingly.
wpmem_set_block_status( $status, $post_id, $post->post_type );
}
// Set the return message.
$arr = array(
'a' => 'updated',
'n' => $x,
'post_type' => $type,
);
if ( isset( $_GET['post_status'] ) && 'all' != $_GET['post_status'] ) {
$arr['post_status'] = sanitize_text_field( $_GET['post_status'] );
}
$sendback = add_query_arg( array( $arr ), '', $sendback );
} else {
// Set the return message.
$sendback = add_query_arg( array( 'a' => 'none' ), '', $sendback );
}
break;
default:
return;
}
// If we did not return already, we need to wp_safe_redirect.
wp_safe_redirect( $sendback );
exit();
}
/**
* Function to echo admin update message.
*
* @since 2.8.2
*
* @global $pagenow
* @global $post_type
*/
function wpmem_posts_admin_notices() {
global $pagenow, $post_type;
if ( $pagenow == 'edit.php' && isset( $_REQUEST['a'] ) ) {
$msg = ( $_REQUEST['a'] == 'block' ) ? sprintf( __( '%s blocked', 'wp-members' ), $post_type ) : sprintf( __( '%s unblocked', 'wp-members' ), $post_type );
echo '
' . esc_html( $_REQUEST['n'] ) . ' ' . esc_html( $msg ) . '
';
}
}
/**
* Adds the blocking meta boxes for post and page editor screens.
*
* @since 2.8
*
* @global object $wp_post_types The Post Type object.
* @global object $wpmem The WP-Members object.
*/
function wpmem_block_meta_add() {
global $wp_post_types, $wpmem;
// Build an array of post types
$post_arr = array(
'post' => 'Posts',
'page' => 'Pages',
);
if ( isset( $wpmem->post_types ) ) {
foreach ( $wpmem->post_types as $key => $val ) {
$post_arr[ $key ] = $val;
}
}
foreach ( $post_arr as $key => $val ) {
if ( isset( $wp_post_types[ $key ] ) ) {
$post_type = $wp_post_types[ $key ];
/**
* Filter the post meta box title.
*
* @since 2.9.0
*
* @param Post restriction title.
*/
$post_title = apply_filters( 'wpmem_admin_' . $key . '_meta_title', sprintf( __( '%s Restriction', 'wp-members' ), $post_type->labels->singular_name ) );
add_meta_box( 'wpmem-block-meta-id', $post_title, 'wpmem_block_meta', $key, 'side', 'high'
// ,array( '__back_compat_meta_box' => true, ) // @todo Convert to Block and declare this for backwards compat ONLY!
);
}
}
}
/**
* Builds the meta boxes for post and page editor screens.
*
* @since 2.8
*
* @global object $post The WordPress post object.
* @global object $wp_post_types The Post Type object.
* @global object $wpmem The WP-Members object.
*/
function wpmem_block_meta() {
global $post, $wp_post_types, $wpmem;
wp_nonce_field( 'wpmem_block_meta_nonce', 'wpmem_block_meta_nonce' );
$post_type = $wp_post_types[ $post->post_type ];
$post_meta_value = get_post_meta( $post->ID, '_wpmem_block', true );
$post_meta_value = ( null == $post_meta_value ) ? $wpmem->block[ $post->post_type ] : $post_meta_value;
$post_meta_settings = array(
'0' => array( 'text' => __( 'Unblocked', 'wp-members' ), 'icon' => '' ),
'1' => array( 'text' => __( 'Blocked', 'wp-members' ), 'icon' => '' ),
'2' => array( 'text' => __( 'Hidden', 'wp-members' ), 'icon' => '' ),
); ?>
$value ) {
echo $value['icon'];
} ?>
$value ) {
$original_value = ( $post_meta_value == $key ) ? $key : $original_value;
$original_label = ( $post_meta_value == $key ) ? $value['text'] : $original_label;
echo '
';
}
echo '
';
echo '
';
?>
post_type );
/**
* Fires after the post block meta box is saved.
*
* Allows actions to be hooked to the meta save process.
*
* @since 2.8.8
*
* @param $post object The WP Post Object.
* @param $block boolean The WP-Members block value.
*/
do_action( 'wpmem_admin_block_meta_save', $post, $block, '' );
}
/**
* Adds WP-Members blocking status to Posts Table columns.
*
* @since 2.8.3
*
* @global object $wpmem The WP-Members Object
* @param array $columns The array of table columns.
* @return array $columns
*/
function wpmem_post_columns( $columns ) {
global $wpmem;
$post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_text_field( $_REQUEST['post_type'] ) : 'post';
if ( $post_type == 'page' || $post_type == 'post' || array_key_exists( $post_type, $wpmem->post_types ) ) {
$columns['wpmem_block'] = __( 'Status', 'wp-members' );
}
return $columns;
}
/**
* Adds blocking status to the Post Table column.
*
* @since 2.8.3
*
* @global object $wpmem The WP_Members Object.
* @param string $column_name
* @param int $post_ID
*/
function wpmem_post_columns_content( $column_name, $post_ID ) {
global $wpmem;
$post_type = sanitize_text_field( wpmem_get( 'post_type', 'post', 'request' ) );
if ( $column_name == 'wpmem_block' ) {
$block_meta = get_post_meta( $post_ID, '_wpmem_block', true );
// Backward compatibility for old block/unblock meta.
if ( ! $block_meta ) {
// Check for old meta.
$old_block = get_post_meta( $post_ID, 'block', true );
$old_unblock = get_post_meta( $post_ID, 'unblock', true );
$block_meta = ( $old_block ) ? 1 : ( ( $old_unblock ) ? 0 : $block_meta );
}
if ( $wpmem->block[ $post_type ] == 1 ) {
$block_span = array( 'lock', 'green', 'Blocked' );
}
if ( $wpmem->block[ $post_type ] == 0 ) {
$block_span = array( 'unlock', 'red', 'Unblocked' );
}
if ( $wpmem->block[ $post_type ] == 1 && $block_meta == '0' ) {
$block_span = array( 'unlock', 'red', 'Unblocked' );
} elseif ( $wpmem->block[ $post_type ] == 0 && $block_meta == '1' ) {
$block_span = array( 'lock', 'green', 'Blocked' );
} elseif ( 2 == $block_meta ) {
$block_span = array( 'hidden', '', 'Hidden' );
}
echo '';
}
}
/**
* Adds shortcode dropdown to post editor tinymce.
*
* @since 3.0
*
* @global object $wpmem_shortcode The WP_Members_TinyMCE_Buttons object.
*/
function wpmem_load_tinymce() {
if ( version_compare( get_bloginfo( 'version' ), '3.9', '>=' ) ) {
global $wpmem_shortcode;
include( WPMEM_PATH . 'admin/includes/class-wp-members-tinymce-buttons.php' );
$wpmem_shortcode = new WP_Members_TinyMCE_Buttons;
}
}
/**
* Sets custom block status for a post.
*
* @since 3.2.0
*
* @global object $wpmem The WP_Members object class.
* @param int $status 0|1|2 for unblock|block|hide
* @param int $post_id The post ID to set a meta value.
* @param string $post_type The post type.
*/
function wpmem_set_block_status( $status, $post_id, $post_type ) {
global $wpmem;
// Previous value.
$prev_value = get_post_meta( $post_id, '_wpmem_block', true );
// Update accordingly.
if ( false !== $prev_value && $status != $prev_value ) {
if ( $status == $wpmem->block[ $post_type ] ) {
delete_post_meta( $post_id, '_wpmem_block' );
} else {
update_post_meta( $post_id, '_wpmem_block', $status );
}
} elseif ( ! $prev_value && $status != $wpmem->block[ $post_type ] ) {
update_post_meta( $post_id, '_wpmem_block', $status );
} elseif ( $status != $prev_value ) {
delete_post_meta( $post_id, '_wpmem_block' );
}
// If the value is to hide, delete the transient so that it updates.
if ( 2 == $status || ( 2 == $prev_value && $status != $prev_value ) ) {
$wpmem->update_hidden_posts();
}
}
// End of File.