'Set Expire Date', 'id' => 'adsforwp_ad_expire_enable', 'type' => 'checkbox', ), array( 'label' => 'From', 'id' => 'adsforwp_ad_expire_from', 'type' => 'text', ), array( 'label' => 'To', 'id' => 'adsforwp_ad_expire_to', 'type' => 'text', ), array( 'label' => 'Set Specific Days', 'id' => 'adsforwp_ad_expire_day_enable', 'type' => 'checkbox', ), array( 'label' => 'Days', 'id' => 'adsforwp_ad_expire_days', 'type' => 'select', 'options' => array( '0' => 'Monday', '1' => 'Tuesday', '2' => 'Wednesday', '3' => 'Thursday', '4' => 'Friday', '5' => 'Saturday', '6' => 'Sunday' ) ), // array( // 'label' => 'Time', // 'id' => 'adsforwp_ad_expire_time', // 'type' => 'select', // 'options' => array( // '', // ), // ), ); public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_fields' ) ); } public function add_meta_boxes() { foreach ( $this->screen as $single_screen ) { add_meta_box( 'setexpiredate', esc_html__( 'Set Expire Date', 'ads-for-wp' ), array( $this, 'meta_box_callback' ), $single_screen, 'side', 'high' ); } } public function meta_box_callback( $post ) { wp_nonce_field( 'setexpiredate_data', 'setexpiredate_nonce' ); $this->field_generator( $post ); } public function field_generator( $post ) { $output = ''; foreach ( $this->meta_fields as $meta_field ) { $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 'checkbox': $input = sprintf( '', $meta_value === '1' ? 'checked' : '', $meta_field['id'], $meta_field['id'] ); break; case 'select': switch ($meta_field['id']) { case 'adsforwp_ad_expire_time': $input = sprintf( ''; break; case 'adsforwp_ad_expire_days': $input = sprintf( ''; break; default: $input = sprintf( ''; break; } break; default: $input = sprintf( '', $meta_field['type'] !== 'color' ? 'style="width: 100%; background:#fff"' : '', $meta_field['id'], $meta_field['id'], $meta_field['type'], $meta_value, $meta_field['id'] ); } $output .= $this->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 format_rows( $label, $input ) { return ''.$label.''.$input.''; } public function save_fields( $post_id ) { if ( ! isset( $_POST['setexpiredate_nonce'] ) ) return $post_id; if ( !wp_verify_nonce( $_POST['setexpiredate_nonce'], 'setexpiredate_data' ) ) return $post_id; if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; $adsforwp_days_array = array(); $adsforwp_days_array = array_map('sanitize_text_field', $_POST['adsforwp_ad_expire_days']); update_post_meta($post_id, 'adsforwp_ad_expire_days', $adsforwp_days_array); foreach ( $this->meta_fields as $meta_field ) { if($meta_field['id'] != 'adsforwp_ad_expire_days'){ 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_expiredate')) { new adsforwp_view_expiredate; };