wo_meta = new WOMeta( AdCommander::ns() ); $this->nonce = $this->nonce( basename( __FILE__ ), AdCommander::posttype_ad() ); add_action( 'admin_enqueue_scripts', array( $this, 'maybe_delete_meta_box_order' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'edit_form_after_title', array( $this, 'posttype_meta_boxes' ), 100 ); add_action( 'save_post_' . AdCommander::posttype_ad(), array( $this, 'save_posted_metadata' ), 10, 2 ); add_action( 'admin_notices', array( $this, 'admin_notices' ) ); /** * Ad post type edit.php */ add_action( 'manage_' . AdCommander::posttype_ad() . '_posts_custom_column', array( $this, 'manage_column_data' ), 10, 3 ); add_action( 'post_row_actions', array( $this, 'add_copy_tag_actions' ), 10, 2 ); add_filter( 'manage_edit-' . AdCommander::posttype_ad() . '_columns', array( $this, 'manage_columns' ) ); add_filter( 'manage_edit-' . AdCommander::posttype_ad() . '_sortable_columns', array( $this, 'manage_sortable_columns' ) ); add_action( 'pre_get_posts', array( $this, 'ads_sort_pre_get_posts' ) ); add_action( 'restrict_manage_posts', array( $this, 'ad_type_filter' ) ); add_action( 'restrict_manage_posts', array( $this, 'ad_group_filter' ) ); add_action( 'restrict_manage_posts', array( $this, 'ad_campaign_filter' ) ); add_action( 'restrict_manage_posts', array( $this, 'ad_advertiser_filter' ) ); add_filter( 'parse_query', array( $this, 'filter_ads_by_type' ) ); /** * Targeting */ $this->admin_targeting()->hooks(); } /** * 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->wo_meta->get_post_meta( $post->ID, AdPostMeta::post_meta_keys() ); } return $this->current_meta; } /** * Create any needed admin notices. * * @return void */ public function admin_notices() { $this->notice_unfiltered_html(); $this->notice_invalid_ad(); $this->new_ad_notice(); } /** * Create notice if unfiltered HTML disabled. * * @return void */ private function notice_unfiltered_html() { if ( $this->is_screen( array( AdCommander::posttype_ad(), AdCommander::posttype_placement(), 'edit-' . AdCommander::tax_group() ) ) && ! self::allow_unfiltered_html() ) { $screen = get_current_screen(); if ( $screen->base === 'edit-tags' ) { return; } ?>

is_screen( array( AdCommander::posttype_ad() ) ) && ( $message = $this->invalid_ad_message() ) !== false ) { ?>

ID ) || ! $this->has_ad_saved() || ! isset( $post->post_type ) || $post->post_type !== AdCommander::posttype_ad() ) { return false; } $ad_type = $this->wo_meta->get_value( $this->current_meta(), 'adtype' ); if ( ! $ad_type ) { $message = esc_html__( 'This ad will not display because it does not have an ad type.', 'ad-commander' ); } elseif ( $ad_type === 'bannerad' && ! has_post_thumbnail( $post->ID ) ) { $message = esc_html__( 'This ad will not display because it does not yet have an image.', 'ad-commander' ); } elseif ( ( $ad_type === 'textcode' && ! $this->wo_meta->get_value( $this->current_meta(), 'adcontent_text' ) ) || ( $ad_type === 'richcontent' && ! $this->wo_meta->get_value( $this->current_meta(), 'adcontent_rich' ) ) ) { $message = esc_html__( 'This ad will not display because it does not yet have any content.', 'ad-commander' ); } elseif ( $ad_type === 'adsense' && ! AdSense::instance()->has_valid_ad( $this->current_meta() ) ) { $message = esc_html__( 'This ad will not display because it is missing some AdSense data. Please check your settings.', 'ad-commander' ); } return $message; } /** * Possibly delete a user's meta box order due to an ACF conflict. * * @return void */ public function maybe_delete_meta_box_order() { /** * User meta box order doesn't work right with our meta box setup if ACF is active. * Not enqueuing anything here, but want to delete this early on in the page load. * Without this, sorted meta boxes end up at the bottom. */ if ( $this->is_screen( array( AdCommander::posttype_ad() ) ) ) { $meta_box_order = get_user_meta( get_current_user_id(), 'meta-box-order_' . AdCommander::posttype_ad(), true ); if ( $meta_box_order && isset( $meta_box_order['acf_after_title'] ) ) { delete_user_meta( get_current_user_id(), 'meta-box-order_' . AdCommander::posttype_ad() ); } } } /** * 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_ad() ) ) ) { $handle = Util::ns( 'adpost' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-core' ); wp_enqueue_script( 'jquery-ui-datepicker' ); $this->enqueue_jquery_ui_styles(); $settingrestrict_handle = $this->enqueue_setting_restrict(); $repeater_handle = $this->wo_meta->repeater_enqueue(); $targeting_handle = $this->admin_targeting()->enqueue(); $deps = array( 'jquery', 'jquery-ui-core', 'jquery-ui-datepicker', $settingrestrict_handle, $repeater_handle, $targeting_handle, ); $code_handle = $this->maybe_register_code_editor( $handle, $deps ); if ( $code_handle ) { $deps[] = 'wp-theme-plugin-editor'; } wp_register_script( $handle, AdCommander::assets_url() . 'js/ad-post.js', $deps, AdCommander::version(), array( 'in_footer' => true ) ); wp_enqueue_script( $handle ); Util::enqueue_script_data( $handle, array( 'media_rest_url' => get_rest_url( null, 'wp/v2/media/' ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'adsense' => array( 'actions' => AdminAdsense::instance()->get_ajax_actions( true ), 'quota' => array( 'remaining' => AdSenseRateLimiter::instance()->api_calls_remaining() ), 'ad_table_columns' => array( 'name' => esc_html__( 'Name', 'ad-commander' ), 'slot_id' => esc_html__( 'Slot ID', 'ad-commander' ), 'type' => esc_html__( 'Format', 'ad-commander' ), 'size' => esc_html__( 'Size', 'ad-commander' ), ), 'translations' => array( 'unsupported' => esc_html__( 'UNSUPPORTED', 'ad-commander' ), 'hide_inactive' => esc_html__( 'Hide inactive', 'ad-commander' ), 'hide_unsupported' => esc_html__( 'Hide unsupported', 'ad-commander' ), 'refresh_ads' => esc_html__( 'Refresh ads', 'ad-commander' ), 'total_ads' => esc_html__( 'Total ads:', 'ad-commander' ), ), ), ) ); if ( $code_handle ) { wp_enqueue_script( $code_handle ); } } } /** * Check if user has meta boxes (other than slug) hidden. * This could maybe happen because of another plugin? This is more precautionary than anything. * * NOTE: This function is not currently in use. If we hide Screen Options in the future, may reactivate. * * @return void */ public function set_user_metaboxes() { $current_screen = get_current_screen(); if ( isset( $current_screen->id ) && $current_screen->id === AdCommander::posttype_ad() ) { $user_id = get_current_user_id(); if ( ! $user_id ) { return; } $meta_key_hidden = 'metaboxhidden_' . AdCommander::posttype_ad(); $hidden = get_user_meta( $user_id, $meta_key_hidden, true ); $should_hide = array( 'slugdiv' ); if ( $hidden !== $should_hide ) { update_user_meta( $user_id, $meta_key_hidden, $should_hide ); } } } /** * 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_ad() ) { /** * Insert our nonce field */ $this->nonce_field( $this->nonce ); /** * Create meta boxes. */ global $wp_meta_boxes; /** * Settings */ add_meta_box( 'adcmdrsettingsdiv', __( 'Ad Settings & Embed', 'ad-commander' ), array( $this, 'adcmdrsettings_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Banner Ad */ add_filter( 'postbox_classes_' . AdCommander::posttype_ad() . '_postimagediv', array( $this, 'add_bannerad_metabox_classes' ) ); add_filter( 'admin_post_thumbnail_html', array( $this, 'adcmdrbanner_meta_box' ), 10, 2 ); if ( isset( $wp_meta_boxes[ AdCommander::posttype_ad() ]['side']['low']['postimagediv'] ) ) { /** * If the meta boxes were manually sorted, this won't fire. * Becomes a bit of a UI issue if using ACF and manually sorting... */ $featured_image_meta = $wp_meta_boxes[ AdCommander::posttype_ad() ]['side']['low']['postimagediv']; if ( isset( $featured_image_meta['title'] ) ) { remove_meta_box( 'postimagediv', AdCommander::posttype_ad(), 'side' ); add_meta_box( 'postimagediv', $featured_image_meta['title'], 'post_thumbnail_meta_box', AdCommander::posttype_ad(), 'normal', 'high' ); } } /** * Ad type meta boxes */ add_filter( 'postbox_classes_' . AdCommander::posttype_ad() . '_adcmdrtextcodediv', array( $this, 'add_textcode_metabox_classes' ) ); add_filter( 'postbox_classes_' . AdCommander::posttype_ad() . '_adcmdrrichcontentdiv', array( $this, 'add_richcontent_metabox_classes' ) ); add_filter( 'postbox_classes_' . AdCommander::posttype_ad() . '_adcmdradsensediv', array( $this, 'add_adsense_metabox_classes' ) ); add_meta_box( 'adcmdrtextcodediv', __( 'Text or Code Ad', 'ad-commander' ), array( $this, 'adcmdrtextcode_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); add_meta_box( 'adcmdrrichcontentdiv', __( 'Rich Content Ad', 'ad-commander' ), array( $this, 'adcmdrrichcontent_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); add_meta_box( 'adcmdradsensediv', __( 'AdSense Ad', 'ad-commander' ), array( $this, 'adcmdradsense_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Layout */ add_meta_box( 'adcmdrlayoutdiv', __( 'Layout', 'ad-commander' ), array( $this, 'adcmdrlayout_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Targeting */ add_meta_box( 'adcmdrtargetingdiv', __( 'Targeting', 'ad-commander' ), array( $this, 'adcmdrtargeting_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Expirations */ $expirations_title = __( 'Expirations', 'ad-commander' ); if ( ! ProBridge::instance()->is_pro_loaded() ) { $expirations_title .= ProBridge::pro_label(); } add_meta_box( 'adcmdrexpirationsdiv', $expirations_title, array( $this, 'adcmdrexpirations_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Advanced */ add_meta_box( 'adcmdradvanceddiv', __( 'Advanced', 'ad-commander' ), array( $this, 'adcmdradvanced_meta_box' ), AdCommander::posttype_ad(), 'normal', 'high' ); /** * Statistics */ add_meta_box( 'adcmdrreportdiv', __( 'Statistics', 'ad-commander' ), array( $this, 'adcmdrreport_meta_box' ), AdCommander::posttype_ad(), 'side', 'low' ); /** * Override */ add_meta_box( 'adcmdroverridediv', __( 'Override Settings', 'ad-commander' ), array( $this, 'adcmdroverride_meta_box' ), AdCommander::posttype_ad(), 'side', 'low' ); } } /** * Add classes to a metbox. * * @param array $classes Current classes. * * @return array */ public function add_bannerad_metabox_classes( $classes ) { array_push( $classes, 'adcmdr-mode-restrict adcmdr-mode-restrict--bannerad' ); return $classes; } /** * Add classes to a metbox. * * @param array $classes Current classes. * * @return array */ public function add_adsense_metabox_classes( $classes ) { array_push( $classes, 'adcmdr-mode-restrict adcmdr-mode-restrict--adsense' ); return $classes; } /** * Add classes to a metbox. * * @param array $classes Current classes. * * @return array */ public function add_textcode_metabox_classes( $classes ) { array_push( $classes, 'adcmdr-mode-restrict adcmdr-mode-restrict--textcode' ); return $classes; } /** * Add classes to a metbox. * * @param array $classes Current classes. * * @return array */ public function add_richcontent_metabox_classes( $classes ) { array_push( $classes, 'adcmdr-mode-restrict adcmdr-mode-restrict--richcontent' ); return $classes; } /** * Add fields to the Settings meta box. * * @return void */ public function adcmdrsettings_meta_box() { $this->metaitem_addtype(); $this->metaitem_usage(); } /** * Add fields to the banner meta box. * This filters the HTML in the Featured Image div, so it works a bit differently. * * @param string $content The current content. * @param int $post_id The current post id. * * @return string */ public function adcmdrbanner_meta_box( $content, $post_id ) { $display_width = intval( $this->wo_meta->get_value( $this->current_meta(), 'display_width' ) ); if ( $display_width > 5 ) { $content .= ''; } $content .= '
'; // $content .= $this->metaitem_bannerurl(); $content .= $this->metaitem_display_size(); $content .= $this->metaitem_bannerurlsettings(); $content .= '
'; return $content; } /** * Add fields to the Text/Code meta box. * * @return void */ public function adcmdrtextcode_meta_box() { $this->metaitem_adcontent_textarea(); } /** * Add fields to the Rich Content meta box. * * @return void */ public function adcmdrrichcontent_meta_box() { $this->metaitem_adcontent_richcontent(); } /** * Add fields to the Rich Content meta box. * * @return void */ public function adcmdradsense_meta_box() { $pub_id = AdSense::instance()->current_adsense_publisher_id(); $is_adsense_connected = AdminAdsense::instance()->has_access_token( $pub_id ); $this->metaitem_adsense_connect( $is_adsense_connected, $pub_id ); $this->metaitem_adsense_meta( $is_adsense_connected, $pub_id ); } /** * Add fields to the Expirations meta box. * * @return void */ public function adcmdrexpirations_meta_box() { $this->metaitem_expire_datetime(); $this->metaitem_expire_stats(); } /** * Add fields to the Reports meta box. * * @return void */ public function adcmdrreport_meta_box() { $this->metaitem_tracking(); } /** * Add fields to the Override meta box. * * @return void */ public function adcmdroverride_meta_box() { $this->metaitem_donottrack(); } /** * Add fields to the Layout meta box. * * @return void */ public function adcmdrlayout_meta_box() { $this->info( __( "Apply layout settings to an individual ad. If this ad is used in a group, some of these settings will be ignored in favor of the group's layout.", 'ad-commander' ) ); $this->metaitem_ad_label(); $this->metaitem_responsive_adimages(); $this->metaitem_float(); $this->metaitem_margin(); $this->metaitem_custom_classes(); } /** * Add fields to the Targeting meta box. * * @return void */ public function adcmdrtargeting_meta_box() { $this->metaitem_targeting(); } /** * Add fields to the Advanced meta box. * * @return void */ public function adcmdradvanced_meta_box() { $this->metaitem_disable_consent(); $this->metaitem_additional_code(); } /** * Meta item for connecting adsense * * @param mixed $is_adsense_connected If AdSense is currently connected. * @param mixed $global_publisher_id If we have a publisher ID. */ private function metaitem_adsense_connect( $is_adsense_connected, $global_publisher_id ) { if ( ! $is_adsense_connected && ! $global_publisher_id ) : ?>
info( esc_html__( 'AdSense is not yet configured. Connect your site to AdSense or specify a publisher ID to build ads manually. Alternatively, you can paste your ad code below. Settings must be configured by an administrator.', 'ad-commander' ), array( 'classes' => 'adcmdr-metaitem__warning' ) ); ?>
>
wo_meta->get_value( $this->current_meta(), 'adsense_ad_pub_id' ); if ( ! $ad_pub_id ) { $ad_pub_id = $global_publisher_id; } ?>
wo_meta->get_value( $this->current_meta(), 'adsense_ad_mode' ); $current = $this->determine_current_adsense_ad_mode( $current_ad_mode, $modes ); $this->wo_meta->label( 'adsense_ad_mode', __( 'AdSense Ad Mode', 'ad-commander' ) ); $this->wo_meta->radiogroup( 'adsense_ad_mode', $modes, $current ); ?>


', '', '', '', '', '' ); ?>


', '' ); ?>


is_pro_loaded() ) : ?>

wo_meta->get_value( $this->current_meta(), 'adsense_ad_format' ); $this->wo_meta->label( 'adsense_ad_format', __( 'Ad type', 'ad-commander' ) ); $this->wo_meta->select( 'adsense_ad_format', AdSense::instance()::ad_formats(), $ad_format ? $ad_format : 'responsive' ); ?>
wo_meta->label( 'adsense_adslot_id', __( 'Ad Slot ID', 'ad-commander' ) ); $this->wo_meta->input( 'adsense_adslot_id', $this->wo_meta->get_value( $this->current_meta(), 'adsense_adslot_id' ), 'text' ); ?>
wo_meta->label( 'adsense_full_width_responsive', __( 'Full width responsive', 'ad-commander' ) ); $current = $this->wo_meta->get_value( $this->current_meta(), 'adsense_full_width_responsive', 'true' ); $full_width_modes = array( 'true' => 'Yes', 'false' => 'No', 'default' => 'Default', ); $this->wo_meta->radiogroup( 'adsense_full_width_responsive', $full_width_modes, $current ? $current : 'true' ); ?>
wo_meta->label( 'adsense_size_width', __( 'Width', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_size_width', $this->wo_meta->get_value( $this->current_meta(), 'adsense_size_width' ), 'number' ); ?> px
wo_meta->label( 'adsense_size_height', __( 'Height', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_size_height', $this->wo_meta->get_value( $this->current_meta(), 'adsense_size_height' ), 'number' ); ?> px
message( __( 'Leave dimensions blank to create a responsive multiplex ad.', 'ad-commander' ) ); ?>
wo_meta->label( 'adsense_multiplex_uitype', __( 'UI Type', 'ad-commander' ) ); ?> wo_meta->select( 'adsense_multiplex_uitype', $ui_types, $this->wo_meta->get_value( $this->current_meta(), 'adsense_multiplex_uitype', 'default' ) ); ?>
wo_meta->label( 'adsense_multiplex_cols', __( 'Columns', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_multiplex_cols', $this->wo_meta->get_value( $this->current_meta(), 'adsense_multiplex_cols', 4 ), 'number', array( 'min' => 1 ) ); ?>
wo_meta->label( 'adsense_multiplex_rows', __( 'Rows', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_multiplex_rows', $this->wo_meta->get_value( $this->current_meta(), 'adsense_multiplex_rows', 1 ), 'number', array( 'min' => 1 ) ); ?>
wo_meta->label( 'adsense_layout_key', __( 'Layout key', 'ad-commander' ) ); $this->wo_meta->input( 'adsense_layout_key', $this->wo_meta->get_value( $this->current_meta(), 'adsense_layout_key' ), 'text' ); ?>
wo_meta->label( 'adsense_ad_code', __( 'Ad code', 'ad-commander' ) ); $this->wo_meta->textarea( 'adsense_ad_code', $this->wo_meta->get_value( $this->current_meta(), 'adsense_ad_code' ), $this->textarea_code_args() ); ?>
is_pro_loaded(); if ( $disabled ) { $options = Util::disable_options( $options ); $label .= ProBridge::instance()->pro_label( true ); } $this->wo_meta->label( 'adsense_amp_ad_mode', $label ); $this->wo_meta->radiogroup( 'adsense_amp_ad_mode', $options, $this->wo_meta->get_value( $this->current_meta(), 'adsense_amp_ad_mode', 'automatic' ), array( 'disabled' => $disabled ) ); ?>
has_amp_plugin() ) { $this->message( esc_html__( 'No AMP plugin found. View documentation for more information.', 'ad-commander' ) ); } ?> adcmdr-ampmode-restrict adcmdr-ampmode-restrict--dynamic">
wo_meta->label( 'adsense_amp_dynamic_width', __( 'Width', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_amp_dynamic_width', $this->wo_meta->get_value( $this->current_meta(), 'adsense_amp_dynamic_width' ), 'number' ); ?> px
wo_meta->label( 'adsense_amp_dynamic_height', __( 'Height', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_amp_dynamic_height', $this->wo_meta->get_value( $this->current_meta(), 'adsense_amp_dynamic_height' ), 'number' ); ?> px
wo_meta->label( 'adsense_amp_fixed_height', __( 'Height', 'ad-commander' ) ); ?> wo_meta->input( 'adsense_amp_fixed_height', $this->wo_meta->get_value( $this->current_meta(), 'adsense_amp_fixed_height' ), 'number' ); ?> px
*/ ?>
' . esc_html( $ad_pub_id_message ) . ''; if ( $ad_pub_id !== $global_publisher_id ) { $message .= '
' . __( 'The publisher ID for this ad does not match the publisher ID from settings. If this is unintentional, delete this ad and create a new one or update your publisher ID in settings.', 'ad-commander' ) . ''; } $this->message( $message ); } $this->wo_meta->input( 'adsense_ad_pub_id', $ad_pub_id, 'hidden' ); ?>
required_pro_version_message( '1.2.0', true ); $this->wo_meta->label( 'max_displays_per_view', __( 'Max Displays Per Page Load', 'ad-commander' ) . ( ! ProBridge::instance()->is_pro_loaded() ? ProBridge::instance()->pro_label( true ) : '' ) ); $this->wo_meta->input( 'max_displays_per_view', $this->wo_meta->get_value( $this->current_meta(), 'max_displays_per_view' ), 'number', array( 'disabled' => ! ProBridge::instance()->is_pro_loaded() ) ); Doc::doc_link( 'max_displays_per_view' ); $this->message( __( 'Example: Set to 1 to only display this ad once per page load. 0 or blank for unlimited displays.', 'ad-commander' ) ); ?>
info( __( 'Only display this ad if certain conditions are met.', 'ad-commander' ) ); $this->metaitem_maxdisplays(); $this->admin_targeting()->metaitem_targeting( $this->wo_meta->get_value( $this->current_meta(), 'content_conditions' ), false, 'content', AdCommander::posttype_ad() ); $this->admin_targeting()->metaitem_targeting( $this->wo_meta->get_value( $this->current_meta(), 'visitor_conditions' ), false, 'visitor', AdCommander::posttype_ad() ); } /** * HTML/fields for Display Size meta. * * @return string */ private function metaitem_display_size() { return '
' . $this->wo_meta->label( 'display_width', __( 'Width', 'ad-commander' ), array( 'display' => false ) ) . $this->wo_meta->input( 'display_width', $this->wo_meta->get_value( $this->current_meta(), 'display_width' ), 'number', array( 'display' => false ) ) . ' px
' . $this->wo_meta->label( 'display_height', __( 'Height', 'ad-commander' ), array( 'display' => false ) ) . $this->wo_meta->input( 'display_height', $this->wo_meta->get_value( $this->current_meta(), 'display_height' ), 'number', array( 'display' => false ) ) . ' px
' . $this->message( __( 'Theme styles may override these settings.', 'ad-commander' ), array(), array( 'display' => false ) ); } /** * HTML/fields for Additional Code meta. */ private function metaitem_additional_code() { ?>
info( __( 'Javascript and CSS allowed (must include style or script tags). Use with caution and test your ad display and tracking.', 'ad-commander' ) ); Doc::doc_link( 'custom_code' ); ?>
wo_meta->label( 'custom_code_before', __( 'Custom Code - Before Ad', 'ad-commander' ) ); ?> wo_meta->textarea( 'custom_code_before', $this->wo_meta->get_value( $this->current_meta(), 'custom_code_before' ), $this->textarea_code_args( array( 'rows' => 5 ) ) ); ?>
wo_meta->label( 'custom_code_after', __( 'Custom Code - After Ad', 'ad-commander' ) ); ?> wo_meta->textarea( 'custom_code_after', $this->wo_meta->get_value( $this->current_meta(), 'custom_code_after' ), $this->textarea_code_args( array( 'rows' => 5 ) ) ); ?>
wo_meta->label( 'disable_consent', __( 'Disable Consent Requirement', 'ad-commander' ) ); $this->wo_meta->checkbox( 'disable_consent', $this->wo_meta->get_value( $this->current_meta(), 'disable_consent' ) ); $this->wo_meta->label( 'disable_consent', __( 'Ignore site-wide setting and disable consent requirement for this ad.', 'ad-commander' ) ); $this->message( __( 'Note that this setting will be ignored if ad is used in a group or insert. You must disable consent for the entire group or insert instead.', 'ad-commander' ) ); ?>
wo_meta->label( 'float', __( 'Float', 'ad-commander' ) ); ?> wo_meta->radiogroup( 'float', $radios, $this->wo_meta->get_value( $this->current_meta(), 'float', 'no' ) ); ?>
wo_meta->label( 'clear_float', __( 'Clear float', 'ad-commander' ) ); $this->wo_meta->checkbox( 'clear_float', $this->wo_meta->get_value( $this->current_meta(), 'clear_float' ) ); $this->wo_meta->label( 'clear_float', __( 'Attempt to prevent text from wrapping around floated ad', 'ad-commander' ) ); ?>
wo_meta->label( 'custom_classes', __( 'Custom Classes', 'ad-commander' ) ); $this->wo_meta->input( 'custom_classes', $this->wo_meta->get_value( $this->current_meta(), 'custom_classes' ), 'text' ); ?>
wo_meta->label( 'margin_top', __( 'Margin Top', 'ad-commander' ) ); $this->wo_meta->input( 'margin_top', $this->wo_meta->get_value( $this->current_meta(), 'margin_top' ), 'number' ); ?> px
wo_meta->label( 'margin_right', __( 'Margin Right', 'ad-commander' ) ); $this->wo_meta->input( 'margin_right', $this->wo_meta->get_value( $this->current_meta(), 'margin_right' ), 'number' ); ?> px
wo_meta->label( 'margin_bottom', __( 'Margin Bottom', 'ad-commander' ) ); $this->wo_meta->input( 'margin_bottom', $this->wo_meta->get_value( $this->current_meta(), 'margin_bottom' ), 'number' ); ?> px
wo_meta->label( 'margin_left', __( 'Margin Left', 'ad-commander' ) ); $this->wo_meta->input( 'margin_left', $this->wo_meta->get_value( $this->current_meta(), 'margin_left' ), 'number' ); ?> px
is_pro_loaded(); $classes = array( 'expire_datetime', 'group' ); if ( $disabled ) { $classes[] = 'disabled'; } else { $info = __( "Expired ads will move to Draft status. Leave values blank to disable a feature. To schedule a start date, edit this Ad post's Publish date and time in the Publish settings.", 'ad-commander' ); $this->info( $info ); } Doc::doc_link( 'expiring_ads' ); $this->message( __( 'Expire ad at the below date and time. Both must be specified.', 'ad-commander' ) ); ?>
wo_meta->label( 'expire_date', __( 'Expiration Date', 'ad-commander' ) ); $this->wo_meta->input( 'expire_date', $this->wo_meta->get_value( $this->current_meta(), 'expire_date' ), 'text', array( 'classes' => 'adcmdr-datepicker', 'disabled' => $disabled, ) ); ?>
wo_meta->label( 'expire_hour', __( 'Expiration Time', 'ad-commander' ) ); $this->wo_meta->select( 'expire_hour', Util::hours_formatted(), $this->wo_meta->get_value( $this->current_meta(), 'expire_hour' ), array( 'disabled' => $disabled ) ); echo ':'; $this->wo_meta->select( 'expire_min', Util::mins_formatted(), $this->wo_meta->get_value( $this->current_meta(), 'expire_min' ), array( 'disabled' => $disabled ) ); $this->wo_meta->select( 'expire_ampm', Util::ampm_formatted(), $this->wo_meta->get_value( $this->current_meta(), 'expire_ampm' ), array( 'disabled' => $disabled ) ); ?>
Clear
is_pro_loaded(); $disabled_c = false; $disabled_i = false; $click_disabled = ''; $imp_disabled = ''; if ( ! $disabled ) { if ( ! Tracking::instance()->should_track_local( 'clicks', false ) ) { $disabled_c = true; $click_disabled = __( 'Local click tracking is disabled.', 'ad-commander' ); } if ( ! Tracking::instance()->should_track_local( 'impressions', false ) ) { $disabled_i = true; $imp_disabled = __( 'Local impression tracking is disabled.', 'ad-commander' ); } if ( $this->wo_meta->get_value( $this->current_meta(), 'donottrack_c' ) ) { $disabled_c = true; if ( ! $click_disabled ) { $click_disabled = __( 'Local click tracking is disabled for this ad.', 'ad-commander' ); } } if ( $this->wo_meta->get_value( $this->current_meta(), 'donottrack_i' ) ) { $disabled_i = true; if ( ! $imp_disabled ) { $imp_disabled = __( 'Local impression tracking is disabled for this ad', 'ad-commander' ); } } } $classes = array( 'expire_stats', 'divide' ); if ( $disabled ) { $classes[] = 'disabled'; } ?>
info( implode( ' ', $disabled_message ), 'adcmdr-metaitem__warning' ); } $this->message( __( 'Expire ad if it meets or exceeds either of these statistics.', 'ad-commander' ) ); ?>
wo_meta->label( 'expire_clicks', __( 'Maximum Clicks', 'ad-commander' ) ); $this->wo_meta->input( 'expire_clicks', $this->wo_meta->get_value( $this->current_meta(), 'expire_clicks' ), 'number', array( 'disabled' => $disabled || $disabled_c ) ); ?>
wo_meta->label( 'expire_impressions', __( 'Maximum Impressions', 'ad-commander' ) ); $this->wo_meta->input( 'expire_impressions', $this->wo_meta->get_value( $this->current_meta(), 'expire_impressions' ), 'number', array( 'disabled' => $disabled || $disabled_i ) ); ?>
wo_meta->get_value( $this->current_meta(), 'adtype' ); if ( ! $current_ad_type ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is executed on the single ad post page; do not want nonce verification here. Input is restricted to pre-defined keys. $default_ad_type = isset( $_GET['adcmdr_default_ad_type'] ) ? sanitize_text_field( wp_unslash( $_GET['adcmdr_default_ad_type'] ) ) : false; if ( $default_ad_type && in_array( $default_ad_type, array_keys( AdPostMeta::ad_types() ), true ) ) { $current_ad_type = $default_ad_type; } } ?>
wo_meta->label( 'adtype', __( 'Ad Type', 'ad-commander' ) ); $this->wo_meta->select( 'adtype', AdPostMeta::ad_types(), $current_ad_type, array( 'empty_text' => __( 'Select an ad type', 'ad-commander' ), ) ); Doc::doc_link( 'ad_type' ); ?>
ID ) && $this->has_ad_saved() ) : ?>
wo_meta->label( 'shortcode', __( 'Shortcode', 'ad-commander' ) ); ?> wo_meta->input( 'shortcode', '[adcmdr_ad id="' . $post->ID . '"]', 'text', array( 'readonly' => true, 'classes' => 'code', ) ); self::copy_button_ad_shortcode( $post->ID, false ); ?>
wo_meta->label( 'template', __( 'Template function', 'ad-commander' ) ); ?> wo_meta->input( 'template', 'ID . '); ?>', 'text', array( 'readonly' => true, 'classes' => 'code', ) ); self::copy_button_ad_template_tag( $post->ID, false ); ?>
wo_meta->label( '', __( 'Disable ad tracking', 'ad-commander' ) ); $tracking = new Tracking(); if ( ! $tracking->has_tracking_methods() ) { /* translators: %1$s: anchor tag with URL, %2$s: close anchor tag */ $message = sprintf( __( 'There are currently no %1$s tracking methods enabled.%2$s', 'ad-commander' ), '', '' ); $this->message( $message ); } else { $disabled_tracking = array(); if ( Options::instance()->get( 'disable_track_impressions', 'tracking', true ) ) { $disabled_tracking[] = __( 'Impression tracking', 'ad-commander' ); } if ( Options::instance()->get( 'disable_track_clicks', 'tracking', true ) ) { $disabled_tracking[] = __( 'Click tracking', 'ad-commander' ); } if ( ! empty( $disabled_tracking ) ) { if ( count( $disabled_tracking ) > 1 ) { /* translators: %1$s: %2$s anchor tag with URL, %2$s: close anchor tag */ $disabled_text = __( 'Tracking currently disabled %1$sfor all ads%2$s.', 'ad-commander' ); } else { /* translators: %1$s: %2$s anchor tag with URL, %2$s: close anchor tag, starts with a space because tracking method previously translated and prepended. */ $disabled_text = $disabled_tracking[0] . __( ' tracking currently disabled %1$sfor all ads%2$s.', 'ad-commander' ); } $message = sprintf( esc_html( $disabled_text ), '', '' ); $this->message( $message ); } ?>
wo_meta->checkbox( 'donottrack_c', $this->wo_meta->get_value( $this->current_meta(), 'donottrack_c' ) ); $this->wo_meta->label( 'donottrack_c', __( 'Do not track clicks for this ad.', 'ad-commander' ) ); ?>
wo_meta->checkbox( 'donottrack_i', $this->wo_meta->get_value( $this->current_meta(), 'donottrack_i' ) ); $this->wo_meta->label( 'donottrack_i', __( 'Do not track impressions for this ad.', 'ad-commander' ) ); ?>
wo_meta->label( '', __( 'Click Fraud Prevention', 'ad-commander' ) ); ?>
wo_meta->checkbox( 'clickfraud_disable', $this->wo_meta->get_value( $this->current_meta(), 'clickfraud_disable' ) ); $this->wo_meta->label( 'clickfraud_disable', __( 'Continue to display this ad after Click Fraud is detected.', 'ad-commander' ) ); ?>
wo_meta->label( 'responsive_banners', __( 'Responsive Ad Images', 'ad-commander' ) ); ?> wo_meta->radiogroup( 'responsive_banners', $radios, $this->wo_meta->get_value( $this->current_meta(), 'responsive_banners', 'site_default' ) ); ?>
wo_meta->label( 'ad_label', __( 'Ad Label', 'ad-commander' ) ); ?> wo_meta->radiogroup( 'ad_label', $radios, $this->wo_meta->get_value( $this->current_meta(), 'ad_label', 'site_default' ) ); ?>
'; $html .= '
'; $html .= $this->wo_meta->label( 'bannerurl', __( 'Banner Link', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->input( 'bannerurl', $this->wo_meta->get_value( $this->current_meta(), 'bannerurl' ), 'url', array( 'placeholder' => 'https:// ', 'display' => false, ) ); $html .= '
'; $html .= '
'; $html .= $this->wo_meta->label( 'newwindow', __( 'Open in a new window', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->radiogroup( 'newwindow', $radios, $this->wo_meta->get_value( $this->current_meta(), 'newwindow', 'site_default' ), array( 'display' => false ) ); $html .= '
'; $html .= ''; $html .= '
'; $html .= '
' . __( 'rel', 'ad-commander' ) . ' ' . __( 'attributes', 'ad-commander' ) . '
'; $html .= '
'; $html .= '
'; $html .= $this->wo_meta->label( 'sponsored', __( 'Sponsored', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->radiogroup( 'sponsored', $radios, $this->wo_meta->get_value( $this->current_meta(), 'sponsored', 'site_default' ), array( 'display' => false ) ); $html .= '
'; $html .= '
'; $html .= $this->wo_meta->label( 'nofollow', __( 'Nofollow', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->radiogroup( 'nofollow', $radios, $this->wo_meta->get_value( $this->current_meta(), 'nofollow', 'site_default' ), array( 'display' => false ) ); $html .= '
'; $html .= '
'; $html .= $this->wo_meta->label( 'noopener', __( 'Noopener', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->radiogroup( 'noopener', $radios, $this->wo_meta->get_value( $this->current_meta(), 'noopener', 'site_default' ), array( 'display' => false ) ); $html .= '
'; $html .= '
'; $html .= $this->wo_meta->label( 'noreferrer', __( 'Noreferrer', 'ad-commander' ), array( 'display' => false ) ); $html .= $this->wo_meta->radiogroup( 'noreferrer', $radios, $this->wo_meta->get_value( $this->current_meta(), 'noreferrer', 'site_default' ), array( 'display' => false ) ); $html .= '
'; $html .= '
'; $html .= '
'; return $html; } /** * HTML/fields for Content ad meta. */ private function metaitem_adcontent_textarea() { ?>
wo_meta->textarea( 'adcontent_text', $this->wo_meta->get_value( $this->current_meta(), 'adcontent_text' ), $this->textarea_code_args() ); /* translators: %1$s anchor tag, %2$s close anchor tag */ $this->message( sprintf( __( 'Paste your entire ad code here. Linebreaks will be removed from output. For text ads with linebreaks, use the %1$sRich Content Editor%2$s.', 'ad-commander' ), '', '' ) ); ?>
wo_meta->get_value( $this->current_meta(), 'adcontent_rich' ); $editor_id = $this->wo_meta->make_key( 'adcontent_rich' ); $settings = array( 'wpautop' => true, // use wpautop? 'media_buttons' => true, // show insert/upload button(s) 'textarea_name' => $editor_id, // set the textarea name to something different, square brackets [] can be used here 'textarea_rows' => get_option( 'default_post_edit_rows', 10 ), // rows="..." 'tabindex' => '', 'editor_css' => '', // extra styles for both visual and HTML editors buttons, 'editor_class' => '', // add extra class(es) to the editor textarea 'teeny' => false, // output the minimal editor config used in Press This 'dfw' => false, // replace the default fullscreen with DFW (supported on the front-end in WordPress 3.4) 'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array() 'quicktags' => true, // load Quicktags, can be used to pass settings directly to Quicktags using an array() ); wp_editor( $content === null ? '' : $content, $editor_id, $settings ); ?>
ID ) && $this->has_ad_saved() ) : $reports = $this->admin_reports(); ?>
message( __( 'Stats may take a minute to update.', 'ad-commander' ) ); ?> wo_meta->label( 'impressions', __( 'Impressions:', 'ad-commander' ) ); ?>
ad_stats( $post->ID ) ); ?> ad_stats( $post->ID, 30 ) ); ?> ad_stats( $post->ID, 7 ) ); ?>
wo_meta->label( 'clicks', __( 'Clicks:', 'ad-commander' ) ); ?>
ad_stats( $post->ID, 'all', 'clicks' ) ); ?> ad_stats( $post->ID, 30, 'clicks' ) ); ?> ad_stats( $post->ID, 7, 'clicks' ) ); ?>
$post->ID, ), self::reports_admin_url() ); $report_url = wp_nonce_url( $report_url, $reports->nonce['action'], $reports->nonce['name'] ); ?> View full report >
wo_meta->message( $message, $args ); } /** * Check if this ad has saved previously. * * @return bool */ private function has_ad_saved() { global $post; return isset( $post->post_status ) && $post->post_status !== 'auto-draft'; } /** * The onboarding message (maybe) displayed after a post is published. * * @return void */ public function new_ad_notice() { global $post; if ( ! $post || ! isset( $post->ID ) || ! $this->has_ad_saved() || ! isset( $post->post_type ) || $post->post_type !== AdCommander::posttype_ad() || ! $this->is_screen( AdCommander::posttype_ad() ) || $post->post_status !== 'publish' || ! AdminOnboarding::instance()->should_onboard( 'ads' ) ) { return; } $ad_type = $this->wo_meta->get_value( $this->current_meta(), 'adtype' ); if ( ! $ad_type || $this->invalid_ad_message() !== false ) { return; } /** * TODO: Consider some restrictions on when this should show. * We could do by X minutes, but that seems unreliable. * Could check if the post is in an insert or not? * Or a combination of the two. * Right now it shows until the onboarding messages are disabled. */ ?>

wo_meta->save_posted_metadata( $post, AdPostMeta::post_meta_keys(), $this->nonce, AdCommander::capability() ) ) { $this->save_expire_gmt( $post_id ); $this->save_adtype_meta( $post_id ); } delete_transient( AdminReports::filter_ads_transient() ); } /** * Button to copy an ad shortcode. * * @param int $post_id The post ID to copy. * * @return void|string */ public static function copy_button_ad_shortcode( $post_id, $include_text = true, $display = true ) { $html = ''; if ( ! $display ) { return $html; } // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The string is escaped above. echo $html; } /** * Button to copy an ad template tag. * * @param int $post_id The post ID to copy. * @param bool $include_text Whether to include the "Template Tag" text in the button. * @param bool $display Whether to echo the button or return it as a string. * * @return void|string */ public static function copy_button_ad_template_tag( $post_id, $include_text = true, $display = true ) { $html = ''; if ( ! $display ) { return $html; } echo $html; } /** * Convert the saved expire meta into a GMT timestamp and save it. * * @param int $post_id The post ID that was saved. * * @return void */ private function save_expire_gmt( $post_id ) { $post_meta = $this->wo_meta->get_post_meta( $post_id, AdPostMeta::post_meta_keys() ); $expire_date = $this->wo_meta->get_value( $post_meta, 'expire_date' ); $expire_hour = $this->wo_meta->get_value( $post_meta, 'expire_hour' ); $expire_min = $this->wo_meta->get_value( $post_meta, 'expire_min' ); $expire_ampm = $this->wo_meta->get_value( $post_meta, 'expire_ampm' ); $expire_gmt = null; if ( $expire_date && $expire_hour && $expire_min && $expire_ampm ) { $expire_date = Util::datetime_wp_timezone( $expire_date . ' ' . $expire_hour . ':' . $expire_min . ' ' . $expire_ampm ); $expire_gmt = $expire_date->getTimestamp(); } $this->wo_meta->update_post_meta( $post_id, 'expire_gmt', $expire_gmt ); } /** * Save publisher ID for adsense ads. * * @param int $post_id The post ID that was saved. * * @return void */ private function save_adtype_meta( $post_id ) { $post_meta = $this->wo_meta->get_post_meta( $post_id, AdPostMeta::post_meta_keys() ); $ad_type = $this->wo_meta->get_value( $post_meta, 'adtype' ); if ( $ad_type !== 'bannerad' ) { delete_post_thumbnail( $post_id ); } if ( $ad_type === 'adsense' ) { /** * Publisher ID */ $adsense_ad_mode = $this->wo_meta->get_value( $this->current_meta(), 'adsense_ad_mode' ); $ad_pub_id = $this->wo_meta->get_value( $this->current_meta(), 'adsense_ad_pub_id' ); $adsense = AdSense::instance(); if ( $adsense_ad_mode ) { setcookie( 'adcmdr_last_adsense_ad_mode', $adsense_ad_mode, 0, '/' ); } else { setcookie( 'adcmdr_last_adsense_ad_mode', '', 1, '/' ); } if ( $adsense_ad_mode !== 'ad_code' && ( ! $ad_pub_id || ! $adsense->is_publisher_id_valid( $ad_pub_id ) ) ) { $pub_id = $adsense->current_adsense_publisher_id(); if ( $pub_id ) { $this->wo_meta->update_post_meta( $post_id, 'adsense_ad_pub_id', sanitize_text_field( $pub_id ) ); } } /** * Erase unecessary meta if we have an ad_code ad */ $ad_code = $this->wo_meta->get_value( $this->current_meta(), 'adsense_ad_code' ); if ( $adsense_ad_mode !== 'ad_code' && $ad_code ) { $this->wo_meta->update_post_meta( $post_id, 'adsense_ad_code', null ); } elseif ( $adsense_ad_mode === 'ad_code' ) { $this->wo_meta->update_post_meta( $post_id, 'adsense_ad_pub_id', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_adslot_id', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_size_width', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_size_height', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_layout_key', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_ad_format', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_full_width_responsive', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_multiplex_uitype', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_multiplex_cols', null ); $this->wo_meta->update_post_meta( $post_id, 'adsense_multiplex_rows', null ); } } } /** * Add copy buttons to the row actions on the ad list table. * * @param array $actions The current row actions. * @param WP_Post $post The current post object for the row. * * @return array The modified row actions. */ public function add_copy_tag_actions( $actions, $post ) { if ( ! $this->is_screen( 'edit-' . AdCommander::posttype_ad() ) || ! isset( $post->ID ) ) { return $actions; } $actions[ Util::ns( 'copy_shortcode', '_' ) ] = self::copy_button_ad_shortcode( $post->ID, true, false ); $actions[ Util::ns( 'copy_template_tag', '_' ) ] = self::copy_button_ad_template_tag( $post->ID, true, false ); return $actions; } public function manage_column_data( $column, $post_id ) { switch ( $column ) { case 'type': $meta = $this->wo_meta->get_post_meta( $post_id, AdPostMeta::post_meta_keys() ); $adtype = $this->wo_meta->get_value( $meta, 'adtype', null ); if ( $adtype ) { if ( $adtype === 'bannerad' && has_post_thumbnail( $post_id ) ) { the_post_thumbnail( 'adcmdr-thumb' ); } else { echo esc_html( AdPostMeta::ad_types()[ $adtype ] ); } } $valid_ad = Util::has_valid_ad( $adtype, $meta, $this->wo_meta, $post_id ); if ( $valid_ad && $adtype === 'adsense' && $this->wo_meta->get_value( $meta, 'adsense_ad_mode', null ) !== 'ad_code' ) { $global_publisher_id = AdSense::instance()->current_adsense_publisher_id(); $ad_pub_id = $this->wo_meta->get_value( $meta, 'adsense_ad_pub_id', null ); if ( $global_publisher_id !== $ad_pub_id ) { $valid_ad = false; } } if ( ! $valid_ad ) { Util::wp_kses_icon( '' ); } break; case 'stats': $stat_parts = array(); if ( ! Tracking::instance()->is_tracking_disabled_for( 'impressions' ) && ! Util::truthy( get_post_meta( $post_id, $this->wo_meta->make_key( 'donottrack_i' ), true ) ) ) { $impressions = $this->admin_reports()->ad_stats( $post_id, 'all', 'impressions' ); /* translators: %d - number of impressoins */ $stat_parts[] = '' . sprintf( esc_html__( 'Impressions: %d', 'ad-commander' ), intval( $impressions ) ) . ''; } if ( ! Tracking::instance()->is_tracking_disabled_for( 'clicks' ) && ! Util::truthy( get_post_meta( $post_id, $this->wo_meta->make_key( 'donottrack_c' ), true ) ) ) { $clicks = $this->admin_reports()->ad_stats( $post_id, 'all', 'clicks' ); /* translators: %d - number of clicks */ $stat_parts[] = '' . sprintf( esc_html__( 'Clicks: %d', 'ad-commander' ), intval( $clicks ) ) . ''; } if ( ! empty( $stat_parts ) ) : ?> array() ) ); ?> $label ) { $new_columns[ $key ] = $label; if ( $key === 'title' ) { $new_columns['type'] = __( 'Type', 'ad-commander' ); } elseif ( $key === 'taxonomy-' . AdCommander::tax_advertiser() ) { if ( Tracking::instance()->is_local_tracking_enabled() ) { $new_columns['stats'] = __( 'Stats', 'ad-commander' ); } } } return $new_columns; } /** * Update sortable columns on the ad page. * * @param array $columns The current columns. * * @return array */ public function manage_sortable_columns( $columns ) { $columns['type'] = 'type'; return $columns; } /** * Create a group filter on ad table. * * @param string $post_type The current post type. * * @return void */ public function ad_group_filter( $post_type ) { if ( AdCommander::posttype_ad() !== $post_type ) { return; } if ( ! current_user_can( AdCommander::capability() ) ) { return; } $taxonomy_name = AdCommander::tax_group(); $groups = get_terms( array( 'taxonomy' => $taxonomy_name, 'hide_empty' => false, ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce not needed in this case $selected = isset( $_GET[ $taxonomy_name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $taxonomy_name ] ) ) : ''; if ( $groups ) { ?> $taxonomy_name, 'hide_empty' => false, ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce not needed in this case $selected = isset( $_GET[ $taxonomy_name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $taxonomy_name ] ) ) : ''; if ( $campaigns ) { ?> $taxonomy_name, 'hide_empty' => false, ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce not needed in this case $selected = isset( $_GET[ $taxonomy_name ] ) ? sanitize_text_field( wp_unslash( $_GET[ $taxonomy_name ] ) ) : ''; if ( $advertisers ) { ?> get( 'orderby' ); if ( $filtered_ad_type !== '' && $orderby === 'type' ) { return; } /** * Order our query. */ if ( 'type' == $orderby ) { $adtype_key = $this->wo_meta->make_key( 'adtype' ); $meta_query = array( 'relation' => 'OR', array( 'key' => $adtype_key, 'compare' => 'NOT EXISTS', ), array( 'key' => $adtype_key, ), ); $query->set( 'meta_query', $meta_query ); $query->set( 'orderby', 'meta_value' ); } } /** * Filter the admin query to add ad type meta_query. * * @param mixed $query The current query. * * @return void */ public function filter_ads_by_type( $query ) { global $pagenow; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce not needed in this case if ( ! is_admin() || $pagenow !== 'edit.php' || ! isset( $_GET['post_type'] ) || AdCommander::posttype_ad() !== sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) ) { return; } if ( ! current_user_can( AdCommander::capability() ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nonce not needed in this case $ad_type = isset( $_GET['adcmdr_ad_type'] ) ? sanitize_text_field( wp_unslash( $_GET['adcmdr_ad_type'] ) ) : ''; if ( $ad_type !== '' ) { $query->query_vars['meta_query'][] = array( 'key' => $this->wo_meta->make_key( 'adtype' ), 'value' => $ad_type, 'compare' => '=', ); } } }