plugin_name = $plugin_name; add_action( 'add_meta_boxes', array( $this, 'arp_add_meta_box')); add_action( 'save_post', array( $this, 'arp_save_metabox' )); } public function arp_add_meta_box( $post_type ) { $this->options = Advanced_Related_Posts_Data::get_arp_validated_data_from_array(); $show_meta_box = $this->options[ $this->name_prefix . 'under_posts_enable_meta_box' ]; $show_meta_box_admins_only = $this->options[ $this->name_prefix . 'under_posts_enable_meta_box_to_admin_only' ]; if(!$show_meta_box){ return; }else{ if($show_meta_box_admins_only){ if(! current_user_can( 'manage_options' ) ){ return; }else{ add_meta_box( $this->name_prefix . 'metabox', __( 'Advanced Related Posts', $this->plugin_name ), array( $this, 'arp_call_meta_box' ), $post_type, 'advanced', 'default' ); } }else{ add_meta_box( $this->name_prefix . 'metabox', __( 'Advanced Related Posts', $this->plugin_name ), array( $this, 'arp_call_meta_box' ), $post_type, 'advanced', 'default' ); } } } public function arp_call_meta_box() { global $post; wp_nonce_field( $this->name_prefix . 'metabox_nonce_action', $this->name_prefix . 'meta_box_nonce' ); $arp_get_post_metas = get_post_meta( $post->ID, $this->name_prefix . 'post_meta' ); $arp_post_metas_values = array(); foreach ($arp_get_post_metas as $key => $arp_get_post_meta) { $arp_metabox_post_ids = ( isset( $arp_get_post_meta [ $this->name_prefix . 'metabox_exclude_post_ids'] ) && sanitize_text_field( $arp_get_post_meta [ $this->name_prefix . 'metabox_exclude_post_ids'] ) != '') ? sanitize_text_field( $arp_get_post_meta [ $this->name_prefix . 'metabox_exclude_post_ids'] ) : ''; $arp_post_metas_values = array( $this->name_prefix . 'metabox_post_ids' => $arp_metabox_post_ids, ); } $arp_exclude_post_ids = ( isset( $arp_post_metas_values [ $this->name_prefix . 'metabox_post_ids'] ) && sanitize_text_field( $arp_post_metas_values [ $this->name_prefix . 'metabox_post_ids'] ) != '' ) ? sanitize_text_field( $arp_post_metas_values [ $this->name_prefix . 'metabox_post_ids'] ) : ''; $content = array(); $content[] = '