post_types ) ) ) || ! isset( $_GET['post_type'] ) ) { ?> current_action(); $sendback = ''; switch ( $action ) { case ( 'block' ): case ( 'unblock' ): // Validate nonce. check_admin_referer( 'bulk-posts' ); // Get the posts. $posts = ( isset( $_REQUEST['post'] ) ) ? $_REQUEST['post'] : ''; // Update posts. $x = ''; if ( $posts ) { foreach ( $posts as $post_id ) { $x++; $post = get_post( $post_id ); $type = $post->post_type; // Update accordingly. if ( $wpmem->block[ $type ] == 0 ) { if ( $action == 'block' ) { update_post_meta( $post_id, '_wpmem_block', 1 ); } else { delete_post_meta( $post_id, '_wpmem_block' ); } } if ( $wpmem->block[ $type ] == 1 ) { if ( $action == 'unblock' ) { update_post_meta( $post_id, '_wpmem_block', 0 ); } else { delete_post_meta( $post_id, '_wpmem_block' ); } } } // Set the return message. $arr = array( 'a' => $action, 'n' => $x, 'post_type' => $type, ); if ( isset( $_GET['post_status'] ) && 'all' != $_GET['post_status'] ) { $arr['post_status'] = $_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_redirect. wp_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 '

' . $_REQUEST['n'] . ' ' . $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' ); } } } /** * 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 ]; if ( isset( $wpmem->block[ $post->post_type ] ) && $wpmem->block[ $post->post_type ] == 1 ) { $block = 0; $notice_text = sprintf( __( '%s are blocked by default.', 'wp-members' ), $post_type->labels->name ); $text = sprintf( __( 'Unblock this %s', 'wp-members' ), strtolower( $post_type->labels->singular_name ) ); } else { $block = 1; $notice_text = sprintf( __( '%s are not blocked by default.', 'wp-members' ), $post_type->labels->name ); $text = sprintf( __( 'Block this %s', 'wp-members' ), strtolower( $post_type->labels->singular_name ) ); } $meta = '_wpmem_block'; $admin_url = get_admin_url(); ?>

' . __( 'Edit', 'wp-members' ) . ''; ?>

ID, $meta, true ), $block ); ?> />

post_types ) ) { $columns['wpmem_block'] = ( $wpmem->block[ $post_type ] == 1 ) ? __( 'Unblocked?', 'wp-members' ) : __( 'Blocked?', '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 = ( isset( $_REQUEST['post_type'] ) ) ? $_REQUEST['post_type'] : 'post'; 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 ); } echo ( $wpmem->block[ $post_type ] == 1 && $block_meta == '0' ) ? __( 'Yes' ) : ''; echo ( $wpmem->block[ $post_type ] == 0 && $block_meta == '1' ) ? __( 'Yes' ) : ''; } } /** * Adds shortcode dropdown to post editor tinymce. * * @since 3.0 * * @global object $wpmem_shortcode The WP_Members_TinyMCE_Buttons object. */ function wpmem_load_tinymce() { // @todo For now, only load if WP version is high enough. 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; } } // End of File.