meta_box_ids = array( 'ad-main-box', 'ad-parameters-box', 'ad-output-box', 'ad-display-box', 'ad-visitor-box', 'advads-pro-pitch', 'advads-tracking-pitch', 'revisionsdiv', // revisions – only when activated 'advanced_ads_groupsdiv' // automatically added by ad groups taxonomy ); // force AA meta boxes to never be completely hidden by screen options add_filter( 'hidden_meta_boxes', array( $this, 'unhide_meta_boxes' ), 10, 2 ); $whitelist = apply_filters( 'advanced-ads-ad-edit-allowed-metaboxes', array_merge( $this->meta_box_ids, array( 'submitdiv', 'slugdiv', 'tracking-ads-box', 'ad-layer-ads-box', // deprecated ) ) ); global $wp_meta_boxes; // remove non-white-listed meta boxes foreach ( array( 'normal', 'advanced', 'side' ) as $context ) { if ( isset( $wp_meta_boxes[ $post_type ][ $context ] ) ) { foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) { if ( isset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ]) ) { foreach ( (array) $wp_meta_boxes[ $post_type ][ $context ][ $priority ] as $id => $box ) { if ( ! in_array( $id, $whitelist ) ) { unset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ][ $id ] ); } } } } } } } /** * load templates for all meta boxes * * @since 1.0.0 * @param obj $post * @param array $box * @todo move ad initialization to main function and just global it */ public function markup_meta_boxes($post, $box) { $ad = new Advanced_Ads_Ad( $post->ID ); switch ( $box['id'] ) { case 'ad-main-box': $view = 'ad-main-metabox.php'; $hndlelinks = '' . __('Manual', 'advanced-ads') . ''; break; case 'ad-parameters-box': $view = 'ad-parameters-metabox.php'; break; case 'ad-output-box': $view = 'ad-output-metabox.php'; break; case 'ad-display-box': $view = 'ad-display-metabox.php'; $hndlelinks = '' . __('Video', 'advanced-ads') . ''; $hndlelinks .= '' . __('Manual', 'advanced-ads') . ''; $videomarkup = ''; break; case 'ad-visitor-box': $view = 'ad-visitor-metabox.php'; $hndlelinks = '' . __('Manual', 'advanced-ads') . ''; break; case 'advads-pro-pitch': $view = 'pitch-bundle.php'; // $hndlelinks = '' . __('Manual', 'advanced-ads') . ''; break; case 'advads-tracking-pitch': $view = 'pitch-tracking.php'; // $hndlelinks = '' . __('Manual', 'advanced-ads') . ''; break; } if ( ! isset( $view ) ) { return; } // markup moved to handle headline of the metabox if( isset( $hndlelinks ) ){ ?> '; } /** * list general notices * * elements in $warnings contain [text] and [class] attributes */ $warnings = array(); // show warning if ad contains https in parameters box if ( 'ad-parameters-box' === $box['id'] && $message = Advanced_Ads_Ad_Debug::is_https_and_http( $ad ) ) { $warnings[] = array( 'text' => $message, 'class' =>'advads-ad-notice-https-missing error' ); } $warnings = apply_filters( 'advanced-ads-ad-notices', $warnings, $box, $post ); echo '
'; include ADVADS_BASE_PATH . 'admin/views/' . $view; } /** * force all AA related meta boxes to stay visible * * @since 1.7.4.2 * @param array $hidden An array of hidden meta boxes * @param WP_Screen $screen WP_Screen object of the current screen */ public function unhide_meta_boxes( $hidden, $screen ){ // only check on Advanced Ads edit screen if ( ! isset( $screen->id ) || $screen->id !== 'advanced_ads' || !is_array( $this->meta_box_ids ) ) { return $hidden; } // return only hidden elements which are not among the Advanced Ads meta box ids return array_diff( $hidden, $this->meta_box_ids ); } /** * add a meta box to post type edit screens with ad settings * * @since 1.3.10 * @param string $post_type current post type */ public function add_post_meta_box($post_type = ''){ // don’t display for non admins if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) { return; } // get public post types $public_post_types = get_post_types( array('public' => true, 'publicly_queryable' => true), 'names', 'or' ); //limit meta box to public post types if ( in_array( $post_type, $public_post_types ) ) { add_meta_box( 'advads-ad-settings', __( 'Ad Settings', 'advanced-ads' ), array( $this, 'render_post_meta_box' ), $post_type, 'advanced', 'low' ); } } /** * render meta box for ad settings on a per post basis * * @since 1.3.10 * @param WP_Post $post The post object. */ public function render_post_meta_box( $post ) { // nonce field to check when we save the values wp_nonce_field( 'advads_post_meta_box', 'advads_post_meta_box_nonce' ); // retrieve an existing value from the database. $values = get_post_meta( $post->ID, '_advads_ad_settings', true ); // load the view include ADVADS_BASE_PATH . 'admin/views/post-ad-settings-metabox.php'; do_action( 'advanced_ads_render_post_meta_box', $post, $values ); } /** * save the ad meta when the post is saved. * * @since 1.3.10 * @param int $post_id The ID of the post being saved. */ public function save_post_meta_box( $post_id ) { if( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) { return; } // check nonce if ( ! isset( $_POST['advads_post_meta_box_nonce'] ) ) { return $post_id; } $nonce = $_POST['advads_post_meta_box_nonce']; // Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce, 'advads_post_meta_box' ) ) { return $post_id; } // don’t save on autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // check the user's permissions. if ( 'page' == $_POST['post_type'] ) { if ( ! current_user_can( 'edit_page', $post_id ) ) { return $post_id; } } else { if ( ! current_user_can( 'edit_post', $post_id ) ) { return $post_id; } } // Sanitize the user input. $_data['disable_ads'] = isset($_POST['advanced_ads']['disable_ads']) ? absint( $_POST['advanced_ads']['disable_ads'] ) : 0; $_data = apply_filters( 'advanced_ads_save_post_meta_box', $_data ); // Update the meta field. update_post_meta( $post_id, '_advads_ad_settings', $_data ); } /** * add "close" class to collapse the ad-type metabox after ad was saved first * * @since 1.7.2 * @param arr $classes * @return arr $classes */ public function close_ad_type_metabox( $classes = array() ) { global $post; if ( isset( $post->ID ) && 'publish' === $post->post_status ) { if ( ! in_array( 'closed', $classes ) ) { $classes[] = 'closed'; } } else { $classes = array(); } return $classes; } /** * add dashboard widget with ad stats and additional information * * @since 1.3.12 */ public function add_dashboard_widget(){ // display dashboard widget only to authors and higher roles if( ! current_user_can('publish_posts') ) { return; } add_meta_box( 'advads_dashboard_widget', __( 'Ads Dashboard', 'advanced-ads' ), array($this, 'dashboard_widget_function'), 'dashboard', 'side', 'high' ); } /** * display widget functions */ public static function dashboard_widget_function($post, $callback_args){ // get number of ads $ads_count = Advanced_Ads::get_number_of_ads(); if( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) { echo ''; printf(__( '%d ads – manage - new', 'advanced-ads' ), $ads_count, 'edit.php?post_type='. Advanced_Ads::POST_TYPE_SLUG, 'post-new.php?post_type='. Advanced_Ads::POST_TYPE_SLUG); echo '
'; } // get and display plugin version $advads_plugin_data = get_plugin_data( ADVADS_BASE_PATH . 'advanced-ads.php' ); if ( isset($advads_plugin_data['Version']) ){ $version = $advads_plugin_data['Version']; echo 'Advanced Ads '. $version .'
'; } $notice_options = Advanced_Ads_Admin_Notices::get_instance()->options(); $_notice = 'nl_first_steps'; if ( ! isset($notice_options['closed'][ $_notice ] ) ) { ?>