'Display Type', 'id' => 'wheretodisplay', 'type' => 'select', 'optgroup' => array( 'both-options' => array( 'ad_shortcode' => 'Shortcode (Manual)', 'between_the_content' => 'Between the Content (Automatic)', 'after_the_content' => 'After the Content (Automatic)', 'before_the_content' => 'Before the Content (Automatic)', 'custom_target' => 'Custom Target', 'sticky' => 'Sticky', ), 'amp-options' => array( 'adsforwp_after_featured_image' => 'Ad after Featured Image', 'adsforwp_below_the_header' => 'Below the Header (SiteWide)', 'adsforwp_below_the_footer' => 'Below the Footer (SiteWide)', 'adsforwp_above_the_footer' => 'Above the Footer (SiteWide)', 'adsforwp_above_the_post_content' => 'Above the Post Content (Single Post)', 'adsforwp_below_the_post_content' => 'Below the Post Content (Single Post)', 'adsforwp_below_the_title' => 'Below the Title (Single Post)', 'adsforwp_above_related_post' => 'Above Related Posts (Single Post)', 'adsforwp_below_author_box' => 'Below the Author Box (Single Post)', 'adsforwp_ads_in_loops' => 'Ads Inbetween Loop', ), ), ), array( 'label' => 'Position', 'id' => 'adposition', 'type' => 'select', 'options' => array( '50_of_the_content' => 'Percent of the content', 'number_of_paragraph' => 'Number of paragraph', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content' ), ), ), array( 'label' => 'Count As Per The', 'id' => 'display_tag_name', 'type' => 'select', 'options' => array( 'p_tag' => 'p (default)', 'div_tag' => 'div', 'img_tag' => 'img', 'h1' => 'H1', 'h2' => 'H2', 'h3' => 'H3', 'h4' => 'H4', 'h5' => 'H5', 'h6' => 'H6', 'custom_tag' => 'custom', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content', 'adposition' => 'number_of_paragraph', ), ), ), array( 'label' => 'Enter Your Tag', 'id' => 'entered_tag_name', 'type' => 'text', 'attributes' => array( 'placeholder' => 'div', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content', 'adposition' => 'number_of_paragraph', 'display_tag_name' => 'custom_tag', ), ), ), array( 'label' => 'Percent', 'id' => 'percent_content', 'type' => 'number', 'default' => 50, 'type' => 'number', 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content', 'adposition' => '50_of_the_content', ), ), ), array( 'label' => 'Paragraph', 'id' => 'paragraph_number', 'type' => 'number', 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content', 'adposition' => 'number_of_paragraph', ), ), ), array( 'label' => 'Manual Ad', 'id' => 'manual_ads_type', 'type' => 'text', 'attributes' => array( 'readonly' => 'readonly', 'disabled' => 'disabled', 'class' => 'afw_manual_ads_type', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'ad_shortcode' ), ), ), array( 'label' => 'After How Many Posts?', 'id' => 'adsforwp_after_how_many_post', 'type' => 'number', 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'adsforwp_ads_in_loops' ), ), ), array( 'label' => 'Alignment', 'id' => 'adsforwp_ad_align', 'type' => 'radio', 'options' => array( 'left' => 'Left', 'center' => 'Center', 'right' => 'Right', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => array( 'ad_shortcode', 'between_the_content', 'after_the_content', 'before_the_content', 'adsforwp_after_featured_image', 'adsforwp_below_the_header', 'adsforwp_below_the_footer', 'adsforwp_above_the_footer', 'adsforwp_above_the_post_content', 'adsforwp_below_the_post_content', 'adsforwp_below_the_title', 'adsforwp_above_related_post', 'adsforwp_below_author_box', 'adsforwp_ads_in_loops' ) ), ), ), array( 'label' => 'Text Wrap Around', 'id' => 'ads_text_wrap', 'type' => 'checkbox', 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'between_the_content' ), ), ), array( 'label' => 'Position', 'id' => 'adsforwp_custom_target_position', 'type' => 'radio', 'options' => array( 'existing_element' => 'Existing html element', 'new_element' => 'New html element', ), 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => 'custom_target' ), ), ), array( 'label' => 'jQuery Selector', 'id' => 'adsforwp_jquery_selector', 'type' => 'text', 'attributes' => array( 'placeholder' => '#container_id or .container_id', ), ), array( 'label' => 'New Element', 'id' => 'adsforwp_new_element', 'type' => 'text', ), array( 'label' => 'Action', 'id' => 'adsforwp_existing_element_action', 'type' => 'select', 'options' => array( 'prepend_content' => 'Before Element', 'append_content' => 'Inside Element', ), ), array( 'label' => 'Margin', 'id' => 'adsforwp_ad_margin', 'type' => 'multiple-text', 'fields' => array( array( 'label' => 'Top', 'id' => 'ad_margin_top', 'type' => 'number', ), array( 'label' => 'Bottom', 'id' => 'ad_margin_bottom', 'type' => 'number', ), array( 'label' => 'Left', 'id' => 'ad_margin_left', 'type' => 'number', ), array( 'label' => 'Right', 'id' => 'ad_margin_right', 'type' => 'number', ), ), ), array( 'label' => 'Floating Ad', 'id' => 'adsforwp_ad_floating', 'type' => 'checkbox', 'required' => array( 'type' => 'and', 'fields' => array( 'wheretodisplay' => array( 'ad_shortcode', 'between_the_content', 'after_the_content', 'before_the_content', 'custom_target', 'adsforwp_above_the_post_content', 'adsforwp_below_the_post_content' ) ), ), ), array( 'label' => 'Hide Ad Label', 'id' => 'adsforwp_hide_ad_label', 'type' => 'checkbox', ), ); public function __construct() { add_action( 'add_meta_boxes', array( $this, 'adsforwp_add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'adsforwp_save_fields' ) ); } public function adsforwp_add_meta_boxes() { foreach ( $this->screen as $single_screen ) { add_meta_box( 'display-metabox', esc_html__( 'Display', 'ads-for-wp' ), array( $this, 'adsforwp_meta_box_callback' ), $single_screen, 'normal', 'high' ); } } public function adsforwp_meta_box_callback( $post ) { wp_nonce_field( 'adsforwp_display_data', 'adsforwp_display_nonce' ); $this->adsforwp_field_generator( $post ); } public function adsforwp_display_metabox_fields() { $allmetafields = $this->meta_fields; return $allmetafields; } public function adsforwp_field_generator( $post ) { $output_escaped = ''; foreach ( $this->meta_fields as $meta_field ) { $attributes = ''; $label = ''; $meta_value = get_post_meta( $post->ID, $meta_field['id'], true ); if ( empty( $meta_value ) ) { if ( $meta_field['id'] == 'adsforwp_new_element' ) { $meta_value = esc_html( '
' ); } elseif ( isset( $meta_field['default'] ) ) { $meta_value = $meta_field['default']; } } switch ( $meta_field['type'] ) { case 'select': switch ( $meta_field['id'] ) { case 'adposition': $input = sprintf( '' . esc_html__( 'Advance Option', 'ads-for-wp' ) . ''; break; case 'wheretodisplay': if ( is_plugin_active( 'accelerated-mobile-pages/accelerated-moblie-pages.php' ) || is_plugin_active( 'amp/amp.php' ) ) { $opt_label = 'Full Support ( AMP & NON AMP )'; } else { $opt_label = 'Display Type'; unset( $meta_field['optgroup']['amp-options'] ); } $input = sprintf( ''; break; default: $input = sprintf( ''; break; } break; case 'multiple-text': $input = '