'Usage', 'id' => 'adsforwp_group_shortcode', 'type' => 'text', 'attributes' => array( 'readonly' => 'readonly', 'disabled' => 'disabled', 'class' => 'afw_manual_ads_type', ), ), array( 'label' => 'Sorting', 'id' => 'adsforwp_group_type', 'type' => 'radio', 'default' => 'rand', 'options' => array( 'rand' =>'Random ads', 'ordered' =>'Ordered ads ', ), ), array( 'label' => 'Refresh Type', 'id' => 'adsforwp_refresh_type', 'type' => 'select', 'options' => array( 'on_load' => 'On Reload', 'on_interval' => 'Auto Refresh' ) ), array( 'id' => 'adsforwp_group_ref_interval_sec', 'type' => 'number', ), array( 'label' => 'Ads', 'id' => 'adsforwp_ads', 'class' => 'afw-option afw-option-group-ads', 'type' => 'div', ), array( 'label' => 'Ad New', 'id' => 'adsforwp_group_ad_list', 'type' => 'select', ), ); 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( 'adgroup', esc_html__( 'Ad Group', 'ads-for-wp' ), array( $this, 'adsforwp_meta_box_callback' ), $single_screen, 'advanced', 'low' ); } } public function adsforwp_meta_box_callback( $post ) { wp_nonce_field( 'adgroup_data', 'adgroup_nonce' ); $this->adsforwp_field_generator( $post ); } public function adsforwp_field_generator( $post ) { $common_function_obj = new adsforwp_admin_common_functions(); $all_ads = $common_function_obj->adsforwp_fetch_all_ads(); $output = ''; foreach ( $this->meta_fields as $meta_field ) { $id =''; $attributes =''; $metafieldlabel =''; if(array_key_exists('id', $meta_field)){ $id =$meta_field['id']; } if(array_key_exists('label', $meta_field)){ $metafieldlabel =$meta_field['label']; } $label = ''; $meta_value = get_post_meta( $post->ID, $id, true ); if ( empty( $meta_value ) ) { $meta_value = isset($meta_field['default']); } switch ( $meta_field['type'] ) { case 'checkbox': $input = sprintf( '', $meta_value === '1' ? 'checked' : '', $id, $id ); break; case 'div': $this->added_ad_list = $meta_value; $input = '
'; $input .= ''; if($meta_value){ foreach($meta_value as $key => $val){ if(get_post_status($key) == 'publish'){ $input .= '' . '' . '' . ''; }else{ $input .= '' . '' . '' . ''; } } } $input .= ''; $input .= '
'.esc_html($val).'
'.esc_html($val).'

'.esc_html__('This ad does not exist. Remove', 'ads-for-wp').'

'; $input .= '
'; $input .= ''. esc_html__('Add More...', 'ads-for-wp').''; break; case 'radio': if($meta_value === 'ordered' || $meta_value === 'rand'){ $default_val = $meta_value; }else{ $default_val = $meta_field['default']; } $input = '
'; $input .= '' . $meta_field['label'] . ''; $i = 0; foreach ( $meta_field['options'] as $key => $value ) { $meta_field_value = !is_numeric( $key ) ? $key : $value; $input .= sprintf( '%s', $default_val === $meta_field_value ? 'checked' : '', $id, $id, $meta_field_value, $value, $i < count( $meta_field['options'] ) - 1 ? '
' : '' ); $i++; } $input .= '
'; break; case 'select': switch ($id) { case 'adsforwp_group_ad_list': $input = sprintf( ''. esc_html__('You have added all ads', 'ads-for-wp').'
'; break; default: $input = sprintf( ''; break; } break; default: switch ($meta_field['id']) { case 'adsforwp_group_ref_interval_sec': $input = sprintf( ' '.esc_html__('milliseconds', 'ads-for-wp') . '

'. esc_html__('Refresh ads on the same spot', 'ads-for-wp').'

' . '

'.esc_html__('On AMP ads will be shown only on reload.', 'ads-for-wp').' '.esc_html__('why?', 'ads-for-wp').'

', $meta_field['type'] !== 'color' ? '' : '', $id, $id, $meta_field['type'], $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' ? '' : '', $id, $id, $meta_field['type'], $meta_value, $attributes ); break; } } $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['adgroup_nonce'] ) ) return $post_id; if ( !wp_verify_nonce( $_POST['adgroup_nonce'], 'adgroup_data' ) ) return $post_id; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; $adsforwp_ads_array = array(); $adsforwp_ads_array = array_map('sanitize_text_field', $_POST['adsforwp_ads']); update_post_meta($post_id, 'adsforwp_ads', $adsforwp_ads_array); foreach ( $this->meta_fields as $meta_field ) { if($meta_field['id'] != 'adsforwp_ads'){ 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_view_ad_groups')) { new adsforwp_view_ad_groups; };