Changeset 1346331
- Timestamp:
- 02/08/2016 11:17:19 PM (10 years ago)
- Location:
- require-featured-image/trunk
- Files:
-
- 4 edited
-
admin-options.php (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
-
require-featured-image-on-edit.js (modified) (2 diffs)
-
require-featured-image.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
require-featured-image/trunk/admin-options.php
r1341002 r1346331 61 61 } 62 62 63 function rfi_return_min_dimensions() {63 function rfi_return_min_dimensions() { 64 64 $minimum_size = get_option('rfi_minimum_size'); 65 if (isset($minimum_size[ "width"]) && $minimum_size["width"] == 0) {66 $minimum_size[ "width"] = 0;65 if (isset($minimum_size['width']) && $minimum_size['width'] == 0) { 66 $minimum_size['width'] = 0; 67 67 } 68 if (isset($minimum_size[ "height"]) && $minimum_size["height"] == 0) {69 $minimum_size[ "height"] = 0;68 if (isset($minimum_size['height']) && $minimum_size['height'] == 0) { 69 $minimum_size['height'] = 0; 70 70 } 71 71 return $minimum_size; … … 87 87 function rfi_size_option_renderer(){ 88 88 $dimensions = rfi_return_min_dimensions(); 89 echo '<input type="number" name = "rfi_minimum_size[width]", value ="'.$dimensions["width"].'"> width (px) <br>';90 echo '<input type="number" name = "rfi_minimum_size[height]", value ="'.$dimensions["height"].'"> height (px)<br>';89 echo '<input type="number" name="rfi_minimum_size[width]", value="'.$dimensions["width"].'"> width (px) <br>'; 90 echo '<input type="number" name="rfi_minimum_size[height]", value="'.$dimensions["height"].'"> height (px)<br>'; 91 91 } -
require-featured-image/trunk/readme.txt
r1341002 r1346331 5 5 Requires at least: 3.5 6 6 Tested up to: 4.4.1 7 Stable tag: 1.2. 07 Stable tag: 1.2.1 8 8 License: MIT 9 9 License URI: http://opensource.org/licenses/MIT … … 59 59 = Support for other languages? = 60 60 61 Yes. We're currently (e nd 2015/early 2016) hoping that these can start being done on [traslate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/require-featured-image), so if you'd like to contribute one and are familiar with the process, go ahead and do it there.61 Yes. We're currently (early 2016) hoping that these can start being done on [traslate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/require-featured-image), so if you'd like to contribute one and are familiar with the process, go ahead and do it there. 62 62 63 63 As the dust is still settling on that process, we will continue supporting other languages via contributions of translations which will be rolled into the next point release of the plugin, as we've done historically. … … 70 70 71 71 == CHANGELOG == 72 73 = 1.2.1 (2016.02.08) = 74 * Smattering of small changes to make code more readable and standardized in formatting. 75 * Addressed and issue where a translation function was being used in the wrong place at the wrong time. 72 76 73 77 = 1.2.0 (2016.02.01) = -
require-featured-image/trunk/require-featured-image-on-edit.js
r1341002 r1346331 9 9 } 10 10 11 function imageIsTooSmall() { 12 var $img = $('#postimagediv').find('img'); 13 var regex = /-\d+[Xx]\d+\./g; 14 var input = $img[0].src; 15 var pathToImage = input.replace(regex, "."); 16 17 var featuredImage = new Image(); 18 featuredImage.src = pathToImage; 19 20 return featuredImage.width < passedFromServer.width || featuredImage.height < passedFromServer.height; 21 } 22 11 23 function publishButtonIsPublishText() { 12 24 return $('#publish').attr('name') === 'publish'; 13 25 } 14 26 15 function disablePublishAndWarn() { 27 function disablePublishAndWarn(reason) { 28 if (reason == 'none') { 29 var message = passedFromServer.jsWarningHtml; 30 } else { 31 var message = passedFromServer.jsSmallHtml; 32 } 16 33 createMessageAreaIfNeeded(); 17 34 $('#nofeature-message').addClass("error") 18 .html('<p>'+ passedFromServer.jsWarningHtml+'</p>');35 .html('<p>'+message+'</p>'); 19 36 $('#publish').attr('disabled','disabled'); 20 37 } … … 31 48 } 32 49 33 function disableTooSmallAndWarn() {34 createMessageAreaIfNeeded();35 $('#nofeature-message').addClass("error")36 .html('<p>'+passedFromServer.jsSmallHtml+'</p>');37 $('#publish').attr('disabled','disabled');38 }39 40 function checkImageSizeThenWarnOrEnable(){41 $img = $('#postimagediv').find('img');42 var regex = /-\d+[Xx]\d+\./g;43 var input = $img[0].src;44 var pathToImage = input.replace(regex, ".");45 46 var featuredImage = new Image();47 featuredImage.src = pathToImage;48 49 featuredImage.onload = function() {50 if ((featuredImage.width < passedFromServer.width) || (featuredImage.height < passedFromServer.height) && publishButtonIsPublishText() ){51 return disableTooSmallAndWarn();52 }53 else{54 return clearWarningAndEnablePublish();55 }56 };57 }58 59 50 function detectWarnFeaturedImage() { 60 51 if (postTypeSupportsFeaturedImage()) { 61 52 if (lacksFeaturedImage() && publishButtonIsPublishText()) { 62 disablePublishAndWarn(); 53 disablePublishAndWarn( 'none' ); 54 } else if (imageIsTooSmall() && publishButtonIsPublishText()) { 55 disablePublishAndWarn( 'too-small' ); 63 56 } else { 64 c heckImageSizeThenWarnOrEnable();57 clearWarningAndEnablePublish(); 65 58 } 66 59 } 67 60 } 68 61 69 70 62 detectWarnFeaturedImage(); 71 63 setInterval(detectWarnFeaturedImage, 3000); -
require-featured-image/trunk/require-featured-image.php
r1341002 r1346331 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. 07 Version: 1.2.1 8 8 Author URI: http://pressupinc.com 9 9 Text Domain: require-featured-image … … 14 14 add_action( 'transition_post_status', 'rfi_guard', 10, 3 ); 15 15 function rfi_guard( $new_status, $old_status, $post ) { 16 if ( $new_status === 'publish' 17 && !rfi_should_let_post_publish( $post ) ) { 18 $warning_message = rfi_check_size_is_set(); 19 wp_die( __( $warning_message, 'require-featured-image' ) ); 16 if ( $new_status === 'publish' && !rfi_should_let_post_publish( $post ) ) { 17 wp_die( rfi_get_warning_message() ); 20 18 } 21 19 } … … 39 37 function rfi_enqueue_edit_screen_js( $hook ) { 40 38 global $post; 41 if ( $hook !== 'post.php' && $hook !== 'post-new.php' ) 39 if ( $hook !== 'post.php' && $hook !== 'post-new.php' ) { 42 40 return; 41 } 43 42 44 43 if ( in_array( $post->post_type, rfi_return_post_types() ) ) { 45 $minimum_size = get_option('rfi_minimum_size');46 47 44 wp_register_script( 'rfi-admin-js', plugins_url( '/require-featured-image-on-edit.js', __FILE__ ), array( 'jquery' ) ); 48 45 wp_enqueue_script( 'rfi-admin-js' ); 49 46 47 $minimum_size = get_option( 'rfi_minimum_size' ); 50 48 wp_localize_script( 51 49 'rfi-admin-js', … … 74 72 $option = array( 'post' ); 75 73 add_option( 'rfi_post_types', $option ); 76 } 77 elseif ( $option === '' ) { 74 } elseif ( $option === '' ) { 78 75 // For people who want the plugin on, but doing nothing 79 76 $option = array(); … … 94 91 } 95 92 96 function rfi_check_featured_image_size($post){ 97 if(has_post_thumbnail($post->ID)){ 98 $image_id = get_post_thumbnail_id($post->ID); 99 if($image_id != null){ 100 $image_meta = wp_get_attachment_image_src($image_id, 'full'); 101 $width = $image_meta[1]; 102 $height = $image_meta[2]; 103 $minimum_size = get_option('rfi_minimum_size'); 93 function rfi_posts_featured_image_is_large_enough($post) { 94 if ( has_post_thumbnail( $post->ID ) ) { 95 $image_id = get_post_thumbnail_id( $post->ID ); 96 if ( $image_id === null ) { 97 return false; 98 } 99 $image_meta = wp_get_attachment_image_src( $image_id, 'full' ); 100 $width = $image_meta[1]; 101 $height = $image_meta[2]; 102 $minimum_size = get_option( 'rfi_minimum_size' ); 104 103 105 if ($width < $minimum_size['width'] ){ 106 return false; 107 } 108 elseif ($height < $minimum_size['height']){ 109 return false; 110 } 111 else{ 112 return true; 113 } 104 if ( $width >= $minimum_size['width'] && $height >= $minimum_size['height'] ){ 105 return true; 114 106 } 107 return false; 115 108 } 116 109 } 117 110 118 function rfi_ check_size_is_set(){111 function rfi_get_warning_message() { 119 112 $minimum_size = get_option('rfi_minimum_size'); 120 if($minimum_size['width'] == 0 && $minimum_size['height'] == 0){ 121 return "You cannot publish without a featured image."; 113 // Legacy case 114 if ( $minimum_size['width'] == 0 && $minimum_size['height'] == 0 ) { 115 return __( 'You cannot publish without a featured image.', 'require-featured-image' ); 122 116 } 123 else{ 124 return "You cannot publish without a featured image which is at least ". $minimum_size['width'] ."x".$minimum_size['height']." pixels."; 125 } 117 return sprintf( 118 __( 'You cannot publish without a featured image that is at least %s x %s pixels.', 'require-featured-image' ), 119 $minimum_size['width'], 120 $minimum_size['height'] 121 ); 126 122 } 127 123 … … 130 126 $is_watched_post_type = in_array( $post->post_type, rfi_return_post_types() ); 131 127 $is_after_enforcement_time = strtotime( $post->post_date ) > rfi_enforcement_start_time(); 132 $image_ size_check = rfi_check_featured_image_size($post);128 $image_is_large_enough = rfi_posts_featured_image_is_large_enough( $post ); 133 129 134 130 if ( $is_after_enforcement_time && $is_watched_post_type ) { 135 return $has_featured_image && $image_ size_check;131 return $has_featured_image && $image_is_large_enough; 136 132 } 137 133 return true;
Note: See TracChangeset
for help on using the changeset viewer.