Changeset 1714373
- Timestamp:
- 08/16/2017 09:51:54 PM (9 years ago)
- Location:
- require-featured-image/trunk
- Files:
-
- 3 edited
-
readme.txt (modified) (2 diffs)
-
require-featured-image-on-edit.js (modified) (1 diff)
-
require-featured-image.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
require-featured-image/trunk/readme.txt
r1539458 r1714373 4 4 Tags: featured image, images, edit, post, admin, require featured image, image, media, thumbnail, thumbnails, post thumbnail, photo, pictures 5 5 Requires at least: 3.5 6 Tested up to: 4. 6.17 Stable tag: 1. 2.36 Tested up to: 4.8.1 7 Stable tag: 1.3.0 8 8 License: MIT 9 9 License URI: http://opensource.org/licenses/MIT … … 70 70 71 71 == CHANGELOG == 72 73 = 1.3.0 (2017.08.16) = 74 * Fixing an issue where the PHP didn't stop the post from publishing, if it were invoked 75 * Fixing an issue where the size warning banner would flash on in Chrome erroneously 72 76 73 77 = 1.2.3 (2016.11.23) = -
require-featured-image/trunk/require-featured-image-on-edit.js
r1355892 r1714373 1 1 jQuery(document).ready(function($) { 2 2 3 function checkImageReturnWarningMessageOrEmpty() {4 var $img = $('#postimagediv').find('img');5 if ($img.length === 0) {6 return passedFromServer.jsWarningHtml;7 }8 if (passedImageIsTooSmall($img)) {9 return passedFromServer.jsSmallHtml;10 }11 return '';12 }3 function checkImageReturnWarningMessageOrEmpty() { 4 var $img = $('#postimagediv').find('img'); 5 if ($img.length === 0) { 6 return passedFromServer.jsWarningHtml; 7 } 8 if (featuredImageIsTooSmall()) { 9 return passedFromServer.jsSmallHtml; 10 } 11 return ''; 12 } 13 13 14 function passedImageIsTooSmall($img) { 15 var input = $img[0].src; 16 var pathToImage = input.replace(/-\d+[Xx]\d+\./g, "."); 17 var featuredImage = new Image(); 18 featuredImage.src = pathToImage; 19 return featuredImage.width < passedFromServer.width || featuredImage.height < passedFromServer.height; 20 } 14 // Contains three test "failures" at page load 15 var isTooSmallTrials = [ true, true, true ]; 21 16 22 function disablePublishAndWarn(message) { 23 createMessageAreaIfNeeded(); 24 $('#nofeature-message').addClass("error") 25 .html('<p>'+message+'</p>'); 26 $('#publish').attr('disabled','disabled'); 27 } 17 function featuredImageIsTooSmall() { 18 // A weird polling issue in Chrome made this necessary 19 var $img = $('#postimagediv').find('img'); 28 20 29 function clearWarningAndEnablePublish() { 30 $('#nofeature-message').remove(); 31 $('#publish').removeAttr('disabled'); 32 } 21 // pop one off, if needed 22 if( isTooSmallTrials.length > 2 ) { 23 isTooSmallTrials.shift(); 24 } 25 isTooSmallTrials.push( passedImageIsTooSmall($img) ); 33 26 34 function createMessageAreaIfNeeded() { 35 if ($('body').find("#nofeature-message").length === 0) { 36 $('#post').before('<div id="nofeature-message"></div>'); 37 } 38 } 27 var imageIsTooSmallCount = isTooSmallTrials.reduce(function (a, b) { 28 return a + b; 29 }, 0); 30 31 return (imageIsTooSmallCount > 2); 32 } 33 34 function passedImageIsTooSmall($img) { 35 var input = $img[0].src; 36 var pathToImage = input.replace(/-\d+[Xx]\d+\./g, "."); 37 var featuredImage = new Image(); 38 featuredImage.src = pathToImage; 39 40 return featuredImage.width < passedFromServer.width || featuredImage.height < passedFromServer.height; 41 } 42 43 function disablePublishAndWarn(message) { 44 createMessageAreaIfNeeded(); 45 $('#nofeature-message').addClass("error") 46 .html('<p>'+message+'</p>'); 47 $('#publish').attr('disabled','disabled'); 48 } 49 50 function clearWarningAndEnablePublish() { 51 $('#nofeature-message').remove(); 52 $('#publish').removeAttr('disabled'); 53 } 54 55 function createMessageAreaIfNeeded() { 56 if ($('body').find("#nofeature-message").length === 0) { 57 $('#post').before('<div id="nofeature-message"></div>'); 58 } 59 } 39 60 40 61 function detectWarnFeaturedImage() { 41 if (checkImageReturnWarningMessageOrEmpty()) {42 disablePublishAndWarn(checkImageReturnWarningMessageOrEmpty());43 } else {44 clearWarningAndEnablePublish();45 }46 }62 if (checkImageReturnWarningMessageOrEmpty()) { 63 disablePublishAndWarn(checkImageReturnWarningMessageOrEmpty()); 64 } else { 65 clearWarningAndEnablePublish(); 66 } 67 } 47 68 48 detectWarnFeaturedImage();49 setInterval(detectWarnFeaturedImage, 800);69 detectWarnFeaturedImage(); 70 setInterval(detectWarnFeaturedImage, 800); 50 71 51 72 }); -
require-featured-image/trunk/require-featured-image.php
r1539458 r1714373 5 5 Description: Like it says on the tin: requires posts to have a featured image set before they'll be published. 6 6 Author: Press Up 7 Version: 1. 2.37 Version: 1.3.0 8 8 Author URI: http://pressupinc.com 9 9 Text Domain: require-featured-image … … 15 15 function rfi_guard( $new_status, $old_status, $post ) { 16 16 if ( $new_status === 'publish' && rfi_should_stop_post_publishing( $post ) ) { 17 // transition_post_status comes after the post has changed statuses, so we must roll back here 18 // because publish->publish->... is an infinite loop, move a published post without an image to draft 19 if ( $old_status == 'publish' ) { 20 $old_status = 'draft'; 21 } 22 $post->post_status = $old_status; 23 wp_update_post( $post ); 17 24 wp_die( rfi_get_warning_message() ); 18 25 }
Note: See TracChangeset
for help on using the changeset viewer.