'Ad Type', 'id' => 'select_adtype', 'type' => 'select', 'options' => array( '' => 'Select Ad Type', 'adsense' =>'AdSense', 'media_net' =>'Media.net', 'custom' =>'Custom Code', 'ad_image' =>'Ad Image', ), 'attributes' => array( 'required' => 'required', ), ), array( 'label' => 'AdSense Type', 'id' => 'adsense_type', 'type' => 'select', 'options' => array( 'normal' =>'Normal', 'adsense_auto_ads' =>'AdSense Auto Ads' ) ), array( 'label' => 'Custom Code', 'id' => 'custom_code', 'type' => 'textarea', ), array( 'label' => 'Data Client ID', 'id' => 'data_client_id', 'type' => 'text', 'attributes' => array( 'placeholder' => 'ca-pub-2005XXXXXXXXX342', 'maxlength' => '30', ), ), array( 'label' => 'Data Ad Slot', 'id' => 'data_ad_slot', 'type' => 'text', 'attributes' => array( 'placeholder' => '70XXXXXX12', 'maxlength' => '20', ), ), //Media.net fields starts here array( 'label' => 'Data CID', 'id' => 'data_cid', 'type' => 'text', 'attributes' => array( 'placeholder' => '8XXXXX74', 'maxlength' => '20', ), ), array( 'label' => 'Data CRID', 'id' => 'data_crid', 'type' => 'text', 'attributes' => array( 'placeholder' => '1XXXXXX82', 'maxlength' => '20', ), ), //Media.net fields ends here array( 'label' => 'Size', 'id' => 'banner_size', 'type' => 'select', 'options' => array( '' => 'Select Size', '728x90' => 'leaderboard (728x90)', '468x60' =>'banner (468x60)', '234x60'=>'half banner (234x60)' , '125x125'=>'button (125x125)', '120x600'=>'skyscraper (120x600)', '160x600'=>'wide skyscraper (160x600)', '180x150'=>'small rectangle (180x150)', '120x240'=>'vertical banner (120x240)', '200x200'=>'small square (200x200)', '250x250'=>'square (250x250)', '300x250'=>'medium rectangle (300x250)', '336x280'=>'large rectangle (336x280)', '300x600'=>'half page (300x600)', '300x1050'=>'portrait (300x1050)', '320x50'=>'mobile banner (320x50)', '970x90'=>'large leaderboard (970x90)', '970x250'=>'billboard (970x250)', '728x20'=>'wide horizontal (728x20)', '600x120'=>'horizontal (600x120)', ), ), array( 'label' => 'Upload Ad Image', 'id' => 'adsforwp_ad_image', 'type' => 'media', ), array( 'label' => 'Ad Redirect URL', 'id' => 'adsforwp_ad_redirect_url', 'type' => 'text', ), ); 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( 'adtype', esc_html__( 'Ad Type', 'ads-for-wp' ), array( $this, 'adsforwp_meta_box_callback' ), $single_screen, 'normal', 'default' ); } } public function adsforwp_meta_box_callback( $post ) { wp_nonce_field( 'adsforwp_adtype_data', 'adsforwp_adtype_nonce' ); $this->adsforwp_field_generator( $post ); } public function adsforwp_field_generator( $post ) { $output = ''; foreach ( $this->meta_fields as $meta_field ) { $attributes =''; $label = ''; $meta_value = get_post_meta( $post->ID, $meta_field['id'], true ); if ( empty( $meta_value ) ) { $meta_value = isset($meta_field['default']); } switch ( $meta_field['type'] ) { case 'select': if(isset($meta_field['attributes'])){ foreach ( $meta_field['attributes'] as $key => $value ) { $attributes .= $key."=".'"'.$value.'"'.' '; } } $input = sprintf( ''; break; case 'adsense_type': $input .= '

'.esc_html__('You have already added Adsense Auto Ad.', 'ads-for-wp').' '.esc_html('Edit' ,'ads-for-wp').'

'; break; default: $input .= ''; break; } break; case 'textarea': $input = sprintf( '', $meta_field['id'], $meta_field['id'], $meta_value ); break; case 'media': $input = sprintf( '' . '', $meta_field['id'], $meta_field['id'], $meta_value ); break; default: if(isset($meta_field['attributes'])){ foreach ( $meta_field['attributes'] as $key => $value ) { $attributes .= $key."=".'"'.$value.'"'.' '; } } $input = sprintf( '', $meta_field['type'] !== 'color' ? '' : '', $meta_field['id'], $meta_field['id'], $meta_field['type'], $meta_value, $attributes ); } $output .= $this->adsforwp_format_rows( $label, $input ); } $common_function_obj = new adsforwp_admin_common_functions(); $allowed_html = $common_function_obj->adsforwp_expanded_allowed_tags(); echo '' . wp_kses($output, $allowed_html) . '
'; } public function adsforwp_format_rows( $label, $input ) { return ''.$label.''.$input.''; } public function adsforwp_save_fields( $post_id ) { if ( ! isset( $_POST['adsforwp_adtype_nonce'] ) ) return $post_id; if ( !wp_verify_nonce( $_POST['adsforwp_adtype_nonce'], 'adsforwp_adtype_data' ) ) return $post_id; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; foreach ( $this->meta_fields as $meta_field ) { if ( isset( $_POST[ $meta_field['id'] ] ) ) { switch ( $meta_field['type'] ) { case 'email': $_POST[ $meta_field['id'] ] = sanitize_email( $_POST[ $meta_field['id'] ] ); break; case 'text': $_POST[ $meta_field['id'] ] = sanitize_text_field( $_POST[ $meta_field['id'] ] ); break; } update_post_meta( $post_id, $meta_field['id'], $_POST[ $meta_field['id'] ] ); } else if ( $meta_field['type'] === 'checkbox' ) { update_post_meta( $post_id, $meta_field['id'], '0' ); } } } } if (class_exists('adsforwp_metaboxes_ads_type')) { new adsforwp_metaboxes_ads_type; };