Add filters for post types
This commit is contained in:
@ -4,7 +4,7 @@ class CWV3Admin {
|
|||||||
|
|
||||||
function hooks() {
|
function hooks() {
|
||||||
// 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, 'setup_metabox' ) );
|
||||||
add_action( 'save_post', array( $this, 'cwv3_meta_save' ) );
|
add_action( 'save_post', array( $this, 'cwv3_meta_save' ) );
|
||||||
|
|
||||||
add_action( 'admin_head', array( $this, 'render_lazy_mans_css' ) );
|
add_action( 'admin_head', array( $this, 'render_lazy_mans_css' ) );
|
||||||
@ -45,9 +45,14 @@ class CWV3Admin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cw_meta() {
|
/**
|
||||||
$scr = array( 'post', 'page' );
|
* Add metabox to post types
|
||||||
foreach ( $scr as $screen ) {
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setup_metabox() {
|
||||||
|
$post_type = $this->get_cwv3_post_types();
|
||||||
|
if ( is_array( $post_type ) ) {
|
||||||
|
foreach ( $post_type as $screen ) {
|
||||||
add_meta_box( 'cwv3_meta_section',
|
add_meta_box( 'cwv3_meta_section',
|
||||||
__( 'CWV3 Security', 'cwv3' ),
|
__( 'CWV3 Security', 'cwv3' ),
|
||||||
array( $this, 'render_metabox' ),
|
array( $this, 'render_metabox' ),
|
||||||
@ -57,16 +62,25 @@ class CWV3Admin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the post types that can be used with CWv2
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_cwv3_post_types() {
|
||||||
|
$types = apply_filters( 'cwv3_post_types', array( 'post', 'page' ) );
|
||||||
|
$types = empty( $types ) ? array() : $types;
|
||||||
|
return ! is_array( $types ) ? array( $types ) : $types;
|
||||||
|
}
|
||||||
|
|
||||||
public function cwv3_meta_save( $post_id ) {
|
public function cwv3_meta_save( $post_id ) {
|
||||||
|
$post_types = $this->get_cwv3_post_types();
|
||||||
// check isset before access (edit by @jgraup)
|
// check isset before access (edit by @jgraup)
|
||||||
if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
|
if ( isset( $_POST['post_type'] ) && in_array( $_POST['post_type'], $post_types ) ) {
|
||||||
if ( ! current_user_can( 'edit_page', $post_id ) ) {
|
if ( ! current_user_can( 'edit_page', $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user