nonce = $this->nonce( basename( __FILE__ ), AdCommander::posttype_placement() ); add_action( 'edit_form_after_title', array( $this, 'posttype_meta_boxes' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'save_post_' . AdCommander::posttype_placement(), array( $this, 'save_posted_metadata' ), 10, 2 ); /** * Targeting */ $this->admin_targeting()->hooks(); } /** * Create a new WOMeta instance if necessary. * * @return WOMeta */ public function meta() { if ( ! $this->wo_meta ) { $this->wo_meta = new WOMeta( AdCommander::ns() ); } return $this->wo_meta; } /** * Sets the current meta if it is not yet set. * * @return mixed */ private function current_meta() { global $post; if ( ! $this->current_meta && isset( $post->ID ) ) { $this->current_meta = $this->meta()->get_post_meta( $post->ID, PlacementPostMeta::post_meta_keys() ); } return $this->current_meta; } /** * Enqueue scripts if we're on a screen that needs them. * * @return void */ public function admin_enqueue_scripts() { if ( $this->is_screen( array( AdCommander::posttype_placement() ) ) ) { wp_enqueue_script( 'jquery' ); $settingrestrict_handle = $this->enqueue_setting_restrict(); $repeater_handle = $this->meta()->repeater_enqueue(); $targeting_handle = $this->admin_targeting()->enqueue(); $deps = array( 'jquery', $settingrestrict_handle, $repeater_handle, $targeting_handle, ); $handle = Util::ns( 'placement' ); wp_register_script( $handle, AdCommander::assets_url() . 'js/placement-post.js', $deps, AdCommander::version(), array( 'in_footer' => true ) ); wp_enqueue_script( $handle ); } } /** * Hook function for creating/editing meta boxes for our post type. * * @return void */ public function posttype_meta_boxes() { $current_screen = get_current_screen(); if ( isset( $current_screen->id ) && $current_screen->id === AdCommander::posttype_placement() ) { /** * Insert our nonce field */ $this->nonce_field( $this->nonce ); /** * General */ add_meta_box( 'adcmdrsettingsdiv', __( 'Placement Display Settings', 'ad-commander' ), array( $this, 'adcmdrsettings_meta_box' ), AdCommander::posttype_placement(), 'normal', 'high' ); add_meta_box( 'adcmdritemsdiv', __( 'Placement Groups & Ads', 'ad-commander' ), array( $this, 'adcmdritems_meta_box' ), AdCommander::posttype_placement(), 'normal', 'high' ); add_meta_box( 'adcmdrorderdiv', __( 'Placement Settings', 'ad-commander' ), array( $this, 'adcmdrorderdiv_meta_box' ), AdCommander::posttype_placement(), 'side' ); /** * Targeting */ $targeting_title = __( 'Targeting', 'ad-commander' ); if ( ! ProBridge::instance()->is_pro_loaded() ) { $targeting_title .= ProBridge::pro_label(); } add_meta_box( 'adcmdrtargetingdiv', $targeting_title, array( $this, 'adcmdrtargeting_meta_box' ), AdCommander::posttype_placement(), 'normal', 'high' ); } } /** * Add fields to the Settings meta box. * * @return void */ public function adcmdrsettings_meta_box() { $this->metaitem_placement_position(); // $this->metaitem_placement_post_types(); } /** * Add fields to the Items meta box. * * @return void */ public function adcmdritems_meta_box() { $this->metaitem_placement_items(); } /** * Add fields to the Order meta box. * * @return void */ public function adcmdrorderdiv_meta_box() { $this->metaitem_placement_order(); } /** * Add fields to the Targeting meta box. * * @return void */ public function adcmdrtargeting_meta_box() { $this->metaitem_content_targeting(); } /** * Placement position meta fields. * * TODO: Improvements to placement admin; Only show 'Post Types' when applicable, for example. */ private function metaitem_placement_position() { $positions = PlacementPostMeta::placement_positions(); $current_position = $this->meta()->get_value( $this->current_meta(), 'placement_position' ); if ( ! ProBridge::instance()->is_pro_loaded() ) { $nonpro_positions = array(); foreach ( $positions as $key => $position ) { if ( in_array( $key, ProBridge::instance()->pro_placement_positions() ) ) { $key = 'disabled:' . $key; $position .= ProBridge::pro_label(); if ( $current_position === $key ) { $current_position = null; } } $nonpro_positions[ $key ] = $position; } $positions = $nonpro_positions; } ?>
is_pro_loaded() ? '' : ProBridge::instance()->pro_label(); if ( $pro_message ) { $pro_message = '' . $pro_message . ''; } $this->info( $info_message . $pro_message ); $this->admin_targeting()->metaitem_targeting( $this->meta()->get_value( $this->current_meta(), 'content_conditions' ), true ); $this->admin_targeting()->metaitem_targeting( $this->meta()->get_value( $this->current_meta(), 'visitor_conditions' ), true, 'visitor' ); } /** * Save posted meta data. Interfaces with WOMeta. * * @param int $post_id The Post ID that has saved. * @param object $post The WP_Post that has saved. * * @return void */ public function save_posted_metadata( $post_id, $post ) { $this->meta()->save_posted_metadata( $post, PlacementPostMeta::post_meta_keys(), $this->nonce, AdCommander::capability() ); } }