Changeset 2381538
- Timestamp:
- 09/15/2020 12:29:06 AM (6 years ago)
- Location:
- exifize-my-dates/trunk
- Files:
-
- 2 edited
-
exifize-my-dates.php (modified) (7 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
exifize-my-dates/trunk/exifize-my-dates.php
r1725193 r2381538 4 4 Plugin URI: http://wordpress.org/extend/plugins/exifize-my-dates/ 5 5 Description: Photoblog plugin to change the published dates of a selected post type to the EXIF:capture_date of the Featured or 1st attached image of the post. 6 Version: 1. 36 Version: 1.5 7 7 Author: LBell 8 Author URI: http://twitter.com/lbell8 Author URI: lorenbell.com 9 9 License: GPL2 10 10 11 Copyright 20 17 -- LorenBell11 Copyright 2020 -- LBell 12 12 This program is free software; you can redistribute it and/or modify 13 13 it under the terms of the GNU General Public License, version 2, as … … 41 41 <?php 42 42 43 // Get Post Types 44 $args=array( 45 'public' => true, 46 //'_builtin' => false 47 ); 48 $output = 'objects'; 49 $operator = 'and'; 50 $post_types = get_post_types($args,$output,$operator); 51 $types_list = array(); 52 foreach ($post_types as $post_type ){ 53 if($post_type->name != 'attachment') $types_list[] = $post_type->name; 54 } 55 43 56 if(isset($_POST['submit']) && $_POST['ptype'] != 'none') { 44 // Check nonce if we are asked to do something... 45 if( check_admin_referer('exifize_my_dates_nuclear_nonce') ){ 46 $ptype = $_POST['ptype']; 57 $ptype = sanitize_text_field( $_POST['ptype'] ); 58 59 // Check nonce if we are asked to do something... 60 if( check_admin_referer('exifize_my_dates_nuclear_nonce') && in_array( $ptype, $types_list ) ){ 47 61 exifizer_nuclear_option($ptype); 48 62 } else { … … 51 65 } 52 66 53 $args=array( 54 'public' => true, 55 //'_builtin' => false 56 ); 57 $output = 'objects'; 58 $operator = 'and'; 59 $post_types = get_post_types($args,$output,$operator); 67 60 68 ?> 61 69 … … 112 120 foreach($allposts as $post) : setup_postdata($post); 113 121 114 $exifdate = 'none'; //safety 115 $postid = $post->ID; 116 $posttitle = $post -> post_title; 117 $postdate = $post -> post_date; 118 $metadate = trim(get_post_meta($postid, 'exifize_date', true)); 119 $pediturl = get_admin_url() . "post.php?post=" . $postid . "&action=edit"; 120 121 echo "<p>Processing " . $ptype . " <a href = \"". $pediturl . "\" title=\"Edit " . $ptype . " \">" . $postid . ": \"" . $posttitle . "\"</a> "; 122 123 if($metadate && $metadate != ''){ //If custome meta `efize_date` is set, use it 124 switch ($metadate){ 125 case date('Y-m-d H:i:s', strtotime($metadate)): //check for correct date format 126 $exifdate = $metadate; 127 $exifdetails = "exifize_date custom meta"; 122 $exif_date = 'none'; //safety 123 $post_id = $post->ID; 124 $post_title = $post -> post_title; 125 $post_date = $post -> post_date; 126 $meta_date = trim(get_post_meta($post_id, 'exifize_date', true)); 127 $post_edit_url = get_admin_url() . "post.php?post=" . $post_id . "&action=edit"; 128 129 echo "<p>Processing " . $ptype . " <a href = \"". $post_edit_url . "\" title=\"Edit " . $ptype . " \">" . $post_id . ": \"" . $post_title . "\"</a> "; 130 131 //If custom meta `exifize_date` is set, use it 132 if($meta_date && $meta_date != ''){ 133 switch ($meta_date){ 134 case date('Y-m-d H:i:s', strtotime($meta_date)): 135 $exif_date = $meta_date; 136 $exif_details = "exifize_date custom meta"; 128 137 break; 129 138 case 'skip': 130 $exif date = 'skip';139 $exif_date = 'skip'; 131 140 break; 132 141 default: 133 $exifdate = 'badmeta'; 134 } 142 $exif_date = 'badmeta'; 143 } 144 // Otherwise, try to get the featured image id 135 145 }else{ 136 $attach id = get_post_thumbnail_id($postid); // First, try to get the featured image id137 138 if($attachid){139 $exifdetails = "Featured Image";140 $attachname = get_post( $attachid )->post_title; 141 }else{ // if no featured image id, then get first attached142 $attach args = array(143 'post_parent' => $post id,146 $attach_id = get_post_thumbnail_id($post_id); 147 if($attach_id){ 148 $exif_details = "Featured Image"; 149 $attach_name = get_post( $attach_id )->post_title; 150 // if no featured image id, then get first attached 151 }else{ 152 $attach_args = array( 153 'post_parent' => $post_id, 144 154 'post_type' => 'attachment', 145 155 'numberposts' => 1, … … 147 157 ); 148 158 149 $attachment = get_posts($attach args);159 $attachment = get_posts($attach_args); 150 160 151 161 if($attachment){ 152 $attach id = $attachment[0]->ID;153 $attach name = $attachment[0]->post_name;154 $exif details = "attached image";162 $attach_id = $attachment[0]->ID; 163 $attach_name = $attachment[0]->post_name; 164 $exif_details = "attached image"; 155 165 } else { 156 $exif details = "What are you doing, Dave?";166 $exif_details = "What are you doing, Dave?"; 157 167 } 158 168 } // end if no featured image … … 160 170 161 171 162 if(!$attach id){163 $exif date = "none"; // No attachment or thumbnail ID found172 if(!$attach_id){ 173 $exif_date = "none"; // No attachment or thumbnail ID found 164 174 } else { 165 echo "using EXIF date from " . $exif details . " id ". $attachid . ": \"" . $attachname . "\"</p>";166 167 $img meta = wp_get_attachment_metadata($attachid, false);168 169 if($img meta && $imgmeta['image_meta']['created_timestamp'] != 0){ //use EXIF date if not 0170 $exif date = date("Y-m-d H:i:s", $imgmeta['image_meta']['created_timestamp']);175 echo "using EXIF date from " . $exif_details . " id ". $attach_id . ": \"" . $attach_name . "\"</p>"; 176 177 $img_meta = wp_get_attachment_metadata($attach_id, false); 178 179 if($img_meta && $img_meta['image_meta']['created_timestamp'] != 0){ //use EXIF date if not 0 180 $exif_date = date("Y-m-d H:i:s", $img_meta['image_meta']['created_timestamp']); 171 181 } else { 172 $exif date = 'badexif';182 $exif_date = 'badexif'; 173 183 } 174 184 }// end get EXIF date 175 }// end no meta date185 }// end no meta_date 176 186 177 187 // if we have image meta and it is not 0 then... 178 188 179 switch ($exif date){189 switch ($exif_date){ 180 190 case 'skip': 181 $exif excuse = __("SKIP: 'exifize_date' meta is set to 'skip'");182 $ex ifexclass = "updated";191 $exif_excuse = __("SKIP: 'exifize_date' meta is set to 'skip'"); 192 $excuse_class = "updated"; 183 193 break; 184 194 case 'none': 185 $exif excuse = __("SKIP: No attachment, featured image, or 'exifize_date' meta found");186 $ex ifexclass = "updated";195 $exif_excuse = __("SKIP: No attachment, featured image, or 'exifize_date' meta found"); 196 $excuse_class = "updated"; 187 197 break; 188 198 case 'badexif': 189 $exif excuse = __("SKIP: WARNING - image EXIF date missing or can't be read");190 $ex ifexclass = "error";199 $exif_excuse = __("SKIP: WARNING - image EXIF date missing or can't be read"); 200 $excuse_class = "error"; 191 201 break; 192 202 case 'badmeta': 193 $exif excuse = __("SKIP: WARNING - 'exifize_date' custom meta is formatted wrong: ") . $metadate;194 $ex ifexclass = "error";195 break; 196 case $post date:197 $exif excuse = __("Already EXIFized!");198 $ex ifexclass = "updated \" style=\" background:none ";203 $exif_excuse = __("SKIP: WARNING - 'exifize_date' custom meta is formatted wrong: ") . $meta_date; 204 $excuse_class = "error"; 205 break; 206 case $post_date: 207 $exif_excuse = __("Already EXIFized!"); 208 $excuse_class = "updated \" style=\" background:none "; 199 209 break; 200 210 default: 201 211 $update_post = array( 202 'ID' => $post id,203 'post_date' => $exif date,204 'post_date_gmt' => $exif date,212 'ID' => $post_id, 213 'post_date' => $exif_date, 214 'post_date_gmt' => $exif_date, 205 215 //'edit_date' => true, 206 216 ); … … 209 219 210 220 if($howditgo != 0){ 211 $exif excuse = "Post " . $howditgo . " EXIFIZED! using " . $exifdetails . " date: " . $exifdate . " " ;212 $ex ifexclass = "updated highlight";221 $exif_excuse = "Post " . $howditgo . " EXIFIZED! using " . $exif_details . " date: " . $exif_date . " " ; 222 $excuse_class = "updated highlight"; 213 223 }else{ 214 $exif excuse = "ERROR... something went wrong... with " . $postid .". You might get that checked out.";215 $ex ifexclass = "error highlight";224 $exif_excuse = "ERROR... something went wrong... with " . $post_id .". You might get that checked out."; 225 $excuse_class = "error highlight"; 216 226 } //end howditgo 217 227 } //end switch 218 228 219 echo "<div class=\"" . $ex ifexclass . "\"><p>" . $exifexcuse . "</p></div>";229 echo "<div class=\"" . $excuse_class . "\"><p>" . $exif_excuse . "</p></div>"; 220 230 221 231 endforeach; -
exifize-my-dates/trunk/readme.txt
r1725193 r2381538 1 1 === Plugin Name === 2 Contributors: Driftless12 Contributors: LBell 3 3 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BTMZ87DJDYBPS 4 Tags: EXIF, date, photoblog, custom, post, bulk ,4 Tags: EXIF, date, photoblog, custom, post, bulk-date-change 5 5 Requires at least: 3.0 6 Tested up to: 4.8.17 Stable tag: 1. 36 Tested up to: 5.5 7 Stable tag: 1.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 48 48 == Changelog == 49 49 50 = 1.4 = 51 * Tested with WP 5.5 52 50 53 = 1.3 = 51 54 * Tested with WP 4.8
Note: See TracChangeset
for help on using the changeset viewer.