ID); $banner_owner = get_post_meta($post->ID, 'banner_owner', true); //check if image, video or text are allowable fields $banner_location = get_post_meta($post->ID, 'banner_location', true); $location_imagead = intval(get_post_meta($banner_location, 'location_imagead', true)); $location_videoad = intval(get_post_meta($banner_location, 'location_videoad', true)); $location_textad = intval(get_post_meta($banner_location, 'location_textad', true)); if ($banner_status === 'publish' && !current_user_can('publish_adverts') || empty($banner_owner)) return; if( $location_imagead === 1){ add_meta_box('postimagediv', __( 'Banner Image', 'ADVERT_TEXTDOMAIN' ), 'post_image_meta_box', 'advert-banner', 'normal', 'low'); } if( $location_videoad === 1){ add_meta_box('postvideodiv', __( 'Banner Video', 'ADVERT_TEXTDOMAIN' ), 'post_video_meta_box', 'advert-banner', 'normal', 'low'); } if( $location_textad === 1){ add_meta_box('posttextdiv', __( 'Banner Text', 'ADVERT_TEXTDOMAIN' ), 'post_text_meta_box', 'advert-banner', 'normal', 'low'); } if ( !current_user_can('publish_adverts') ){ remove_meta_box( 'advert_categorydiv', 'advert-banner', 'normal' ); } } function post_image_meta_box($post){ $thumbnail_id = get_post_meta($post->ID, '_thumbnail_id', true); $banner_location = get_post_meta($post->ID , 'banner_location' ,true); $location_enforce = get_post_meta($banner_location, 'location_enforce', true); $location_width = get_post_meta($banner_location, 'location_width', true); $location_height = get_post_meta($banner_location, 'location_height', true); echo _wp_post_thumbnail_html( $thumbnail_id ); echo ''; if($location_enforce){ echo '
'; } echo ''. __( 'AdVert Tip: This is an image preview.', 'ADVERT_TEXTDOMAIN' ) .'
'; } function post_video_meta_box($post){ $banner_video_title = get_post_meta($post->ID, 'banner_video_title', true); $banner_video_url = get_post_meta($post->ID, 'banner_video_url', true); $banner_location = get_post_meta($post->ID, 'banner_location', true); $location_duration = get_post_meta($banner_location, 'location_duration', true); if($banner_video_url){ echo ''; } ?>'. __( 'Enable JavaScript to add/remove video', 'ADVERT_TEXTDOMAIN' ) .''; echo ''; echo ''; if($location_duration){echo '
';} echo ''. __( 'AdVert Tip: Select an Banner Image (if available) in case the video does not display or if you want a video thumbnail', 'ADVERT_TEXTDOMAIN' ) .'
'; } else{ echo ''; echo ''. __( 'Remove featured video', 'ADVERT_TEXTDOMAIN' ) .''; echo ''. __( 'Set featured video', 'ADVERT_TEXTDOMAIN' ) .''; if($location_duration){echo '';} echo ''. __( 'AdVert Tip: Select an Banner Image in case the video does not display or if you want a video thumbnail', 'ADVERT_TEXTDOMAIN' ) .'
'; } ?> ID , 'banner_text_ad1' ,true); $banner_text_ad2 = get_post_meta($post->ID , 'banner_text_ad2' ,true); $banner_location = get_post_meta($post->ID , 'banner_location' ,true); $location_characters1 = get_post_meta($banner_location, 'location_characters1', true); $location_characters2 = get_post_meta($banner_location, 'location_characters2', true); echo ''; ?>'advert-advertiser' , 'posts_per_page' => -1, 'post_status' => 'publish')); $banner_owner = get_post_meta($post->ID , 'banner_owner' ,true); if( !current_user_can('publish_adverts') ){ $user_id = get_current_user_id(); $args = array('post_type' => 'advert-advertiser', 'author' => $user_id); $the_post = new WP_Query($args); $company = $the_post->posts[0]->ID; wp_reset_postdata(); ?>
'. __('No Locations have been created', 'ADVERT_TEXTDOMAIN') .' – '. __('add new location', 'ADVERT_TEXTDOMAIN') .'
value="" name="banner_link"/>
Current Control: post_author, 'publish_adverts' )){echo _e('Advertiser', 'ADVERT_TEXTDOMAIN');}else{ _e('AdVert Manager', 'ADVERT_TEXTDOMAIN'); } ?>
' . $error['message'] . '
'; } echo $message; delete_transient( 'banner_settings_errors' ); remove_action( 'admin_notices', 'banner_admin_notice' ); } //control the messages function banner_updated_messages( $messages ) { global $post, $post_ID; $messages['advert-banner'] = array( 0 => '', // Unused. Messages start at index 1. 1 => __('Banner updated.', 'ADVERT_TEXTDOMAIN') , 6 => __('Banner published.', 'ADVERT_TEXTDOMAIN'), 8 => __('Banner submitted.', 'ADVERT_TEXTDOMAIN'), 9 => sprintf( __('banner scheduled for: %1$s.', 'ADVERT_TEXTDOMAIN'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ) ), 10 => __('Banner draft updated.', 'ADVERT_TEXTDOMAIN') ); return $messages; } function banner_save_meta($post_id) { if ('advert-banner' != get_post_type() || !current_user_can('edit_adverts')) return; if(!isset($_POST['banner_meta_box_nonce']) || !wp_verify_nonce($_POST['banner_meta_box_nonce'], 'banner_meta_box')) return; $banner_status = get_post_status($post_id); //justincase if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; //check if image, video or text are allowable fields $banner_location = get_post_meta($post_id, 'banner_location', true); $location_videoad = intval(get_post_meta($banner_location, 'location_videoad', true)); $location_textad = intval(get_post_meta($banner_location, 'location_textad', true)); //double check the user $company_id = (isset($_POST['banner_owner']) ? intval($_POST['banner_owner']) : intval(get_post_meta($post_id, 'banner_owner', true))); if(!current_user_can('publish_adverts')){ $user_id = get_current_user_id(); $company_id = intval(apply_filters('get_advertiser_id', $user_id)); } if( $banner_status != 'publish' || current_user_can('publish_adverts') ){ if(!empty($company_id)){ global $wpdb; $wpdb->update($wpdb->posts , array('post_parent' => $company_id) , array('ID' => $post_id) , array('%d'),array('%d')); update_post_meta( $post_id, 'banner_owner' , sanitize_text_field(strip_tags($company_id)) ); } if(isset($_POST['banner_location'])){ update_post_meta( $post_id, 'banner_location' , sanitize_text_field(strip_tags($_POST['banner_location'])) ); } if(isset($_POST['banner_link'])){ update_post_meta( $post_id, 'banner_link' , esc_url($_POST['banner_link']) ); } } if(isset($_POST['banner_priority'])){ update_post_meta( $post_id, 'banner_priority' , number_format(strip_tags($_POST['banner_priority'])) ); } if(isset($_POST['banner_target'])){ update_post_meta( $post_id, 'banner_target' , sanitize_text_field(strip_tags($_POST['banner_target'])) ); } if(isset($_POST['banner_custom_html']) && current_user_can('publish_adverts')){ update_post_meta( $post_id, 'banner_custom_html' , htmlspecialchars($_POST['banner_custom_html']) ); } if( $location_videoad === 1){ if( isset($_POST['advert_video_url']) && $_POST['advert_video_url'] === 'advertremovevideo'){ delete_post_meta( $post_id, 'banner_video_url'); delete_post_meta( $post_id, 'banner_video_id'); delete_post_meta( $post_id, 'banner_video_title'); } else{ if(isset($_POST['advert_video_url']) && !empty($_POST['advert_video_url']) ){ update_post_meta( $post_id, 'banner_video_url' , esc_url($_POST['advert_video_url']) ); } if(isset($_POST['advert_video_id']) && !empty($_POST['advert_video_id']) ){ update_post_meta( $post_id, 'banner_video_id' , intval($_POST['advert_video_id']) ); } if(isset($_POST['advert_video_title']) && !empty($_POST['advert_video_title'])){ update_post_meta( $post_id, 'banner_video_title' , sanitize_text_field(strip_tags($_POST['advert_video_title'])) ); } } } if( $location_textad === 1 ){ if(isset($_POST['banner_text_ad1'])){ update_post_meta( $post_id, 'banner_text_ad1' , sanitize_text_field(strip_tags($_POST['banner_text_ad1'])) ); } if(isset($_POST['banner_text_ad2'])){ update_post_meta( $post_id, 'banner_text_ad2' , sanitize_text_field(strip_tags($_POST['banner_text_ad2'])) ); } } if (isset($_POST['banner_change_owner']) && current_user_can('publish_adverts') ){ $post_author_id = get_post_field('post_author', $post_id); $newOwner = intval(strip_tags($_POST['banner_change_owner'])); if ( $newOwner != $post_author_id && !wp_is_post_revision($post_id)){ // unhook this function so it doesn't loop infinitely remove_action('save_post', 'banner_save_meta'); $update_banner = array( 'ID' => $post_id, 'post_author' => $newOwner, ); wp_update_post( $update_banner ); // re-hook this function add_action('save_post', 'banner_save_meta'); } } //check post status if($banner_status != 'publish') return; //update post to draft if checks fail $banner_location = get_post_meta($post_id, 'banner_location', true); $location_enforce = intval(get_post_meta($banner_location, 'location_enforce', true)); $banner_image = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'full'); $banner_video_url = get_post_meta($post_id, 'banner_video_url', true); $location_textad = get_post_meta($banner_location, 'location_textad', true); $location_characters1 = get_post_meta($banner_location, 'location_characters1', true); $location_characters2 = get_post_meta($banner_location, 'location_characters2', true); $banner_text_ad1 = get_post_meta($post_id, 'banner_text_ad1', true); $banner_text_ad2 = get_post_meta($post_id, 'banner_text_ad2', true); $banner_error = FALSE; if($banner_image[0] !=''){ if($location_enforce === 1){ $filename = explode('/',$banner_image[0]); $filename = end($filename); $filetype = wp_check_filetype($filename); $filetype = $filetype['ext']; if($filetype === 'jpg' || $filetype === 'jpeg' || $filetype === 'png' || $filetype === 'gif' || $filetype === 'ico' || $filetype === 'svg'){ if($filetype === 'ico' || $filetype === 'svg'){ add_settings_error('', '', __('Error: The image selected is not the correct format. Accepted formats are jpg, jpeg, png and gif. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), 'error'); } else{ $location_width = get_post_meta($banner_location, 'location_width', true); $location_height = get_post_meta($banner_location, 'location_height', true); $img = getimagesize($banner_image); $imgW = $img[0]; $imgH = $img[1]; if($imgW != $location_width && $imgH != $location_height){ $banner_error = TRUE; add_settings_error('', '', sprintf( __('Error: The image selected is not the correct size. The width should be %1$spx and the height should be %2$spx. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), $location_width, $location_height), 'error'); } } } } }//image check if($banner_video_url !=''){ $filename = explode('/',$banner_video_url); $filename = end($filename); $filetype = wp_check_filetype($filename); $filetype = $filetype['ext']; if($filetype === 'mp4' || $filetype === 'mov' || $filetype === 'wmv' || $filetype === 'avi' || $filetype === 'mpg' || $filetype === 'ogv' || $filetype === '3gp' || $filetype === '3g2'){ $banner_video_id = get_post_meta($post_id, 'banner_video_id', true); $video_meta = wp_get_attachment_metadata($banner_video_id); if($filetype != 'mp4'){ $banner_error = TRUE; add_settings_error('', '', __('Error: The video selected is not mp4 format. AdVert currently uses mp4 format. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), 'error'); } else{ $location_duration = get_post_meta($banner_location, 'location_duration', true); if($location_duration != ''){ $videoLength = $video_meta['length']; if($videoLength > $location_duration){ $banner_error = TRUE; add_settings_error('', '', sprintf( __('Error: The video selected exceeds the recommended length of %1$s seconds. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), $location_duration), 'error'); } } } } }//video check if($location_textad === '1'){ if($banner_text_ad1 !='' && strlen($banner_text_ad1) > $location_characters1 && $location_characters1 > 0 || strlen($banner_text_ad1) > 800){ $banner_error = TRUE; add_settings_error('', '', __('Error: The text length for the first text block is too long. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), 'error'); } if($banner_text_ad2 !='' && strlen($banner_text_ad2) > $location_characters2 && $location_characters2 > 0 || strlen($banner_text_ad2) > 800){ $banner_error = TRUE; add_settings_error('', '', __('Error: The text length for the second text block is too long. The Banner has been saved as draft.', 'ADVERT_TEXTDOMAIN'), 'error'); } }//text check if($banner_error === TRUE){ wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); add_filter('redirect_post_location', 'banner_redirect_post_location_filter', 99); set_transient( 'banner_settings_errors', get_settings_errors(), 30 ); } } /*** * ********** LOOK AT ME *********** * */ function banner_redirect_post_location_filter($location) { remove_filter('redirect_post_location', __FUNCTION__, 99); //add crazy number to $message query so it doesnt display, oldschool texting 238378 = advert $location = add_query_arg('message', 238378, $location); return $location; } //add and change columns for banners function custom_banner_columns($columns) { $date = $columns['date']; $title = $columns['title']; unset( $columns['date'], $columns['taxonomy-advert_category'] ); if(current_user_can('publish_adverts')){ $new_columns = array( 'owner' => __( 'Owner', 'ADVERT_TEXTDOMAIN' ), 'location' => __( 'Location', 'ADVERT_TEXTDOMAIN' ), 'priority' => __( 'Priority', 'ADVERT_TEXTDOMAIN' ), 'link' => __( 'Linked', 'ADVERT_TEXTDOMAIN' ), 'custom' => __( 'Custom HTML', 'ADVERT_TEXTDOMAIN' ), 'banner' => __( 'Banner Type', 'ADVERT_TEXTDOMAIN' ), ); } else{ $new_columns = array( 'location' => __( 'Location', 'ADVERT_TEXTDOMAIN' ), 'priority' => __( 'Priority', 'ADVERT_TEXTDOMAIN' ), 'link' => __( 'Linked', 'ADVERT_TEXTDOMAIN' ), 'banner' => __( 'Banner Type', 'ADVERT_TEXTDOMAIN' ), ); } return array_merge($columns, $new_columns); } function custom_banner_column( $column, $post_id ) { switch ( $column ) { case 'owner' : if(current_user_can('publish_adverts')){ if (get_post_meta($post_id, 'banner_owner', true)){echo get_the_title(get_post_meta($post_id, 'banner_owner', true));} } break; case 'location' : if (get_post_meta($post_id, 'banner_location', true)){echo get_the_title( get_post_meta($post_id, 'banner_location', true ));} break; case 'priority' : $priority = ( is_numeric(get_post_meta($post_id, 'banner_priority', true)) ? number_format_i18n(get_post_meta($post_id, 'banner_priority', true)) : '' ); echo $priority; break; case 'link' : if (get_post_meta($post_id, 'banner_link', true) !=''){ _e( 'Yes', 'ADVERT_TEXTDOMAIN' ); }else{ _e( 'No', 'ADVERT_TEXTDOMAIN' ); } break; case 'custom': if (get_post_meta($post_id, 'banner_custom_html', true) !=''){ _e( 'Yes', 'ADVERT_TEXTDOMAIN' ); }else{ _e( 'No', 'ADVERT_TEXTDOMAIN' ); } break; case 'banner': $thumb_id = get_post_thumbnail_id($post_id); $banner_video_title = get_post_meta($post_id, 'banner_video_title', true); $banner_text_ad1 = get_post_meta($post_id, 'banner_text_ad1', true); $banner_text_ad2 = get_post_meta($post_id, 'banner_text_ad2', true); if ($thumb_id && $banner_video_title === ''){ _e( 'Image', 'ADVERT_TEXTDOMAIN' ); } elseif($banner_video_title !=''){ _e( 'Video', 'ADVERT_TEXTDOMAIN' ); } elseif($banner_text_ad1 !='' || $banner_text_ad2 !=''){ _e( 'Text', 'ADVERT_TEXTDOMAIN' ); } else{ _e( 'None', 'ADVERT_TEXTDOMAIN' ); } break; } } function banner_sortable_columns( $sortable_columns ) { $sortable_columns['location'] = 'location'; $sortable_columns['priority'] = 'priority'; $sortable_columns['link'] = 'link'; $sortable_columns['custom'] = 'custom'; $sortable_columns['banner'] = 'banner'; return $sortable_columns; }