Changeset 1341002
- Timestamp:
- 02/01/2016 11:01:17 PM (10 years ago)
- Location:
- require-featured-image/trunk
- Files:
-
- 4 edited
-
admin-options.php (modified) (3 diffs)
-
readme.txt (modified) (5 diffs)
-
require-featured-image-on-edit.js (modified) (3 diffs)
-
require-featured-image.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
require-featured-image/trunk/admin-options.php
r1185295 r1341002 25 25 register_setting( $option_group, $option_name ); 26 26 27 $minimum_size_option = 'rfi_minimum_size'; 28 register_setting( $option_group, $minimum_size_option ); 29 27 30 // Create section of Page 28 31 $settings_section = 'rfi_main'; 29 32 $page = 'rfi'; 30 33 add_settings_section( $settings_section, __( 'Post Types', 'require-featured-image' ), 'rfi_main_section_text_output', $page ); 31 34 32 35 // Add fields to that section 33 36 add_settings_field( $option_name, __('Post Types that require featured images ', 'require-featured-image' ), 'rfi_post_types_input_renderer', $page, $settings_section ); 37 38 // Minimum Image requirements 39 $size_section = 'rfi_size'; 40 add_settings_section($size_section, __('Image Size', 'require-featured-image'), 'rfi_size_text_output', $page); 41 42 add_settings_field($minimum_size_option, __('Minimum size of the featured images', 'require-featured-image'), 'rfi_size_option_renderer', $page, $size_section); 34 43 } 35 44 36 45 function rfi_main_section_text_output() { 37 46 _e( '<p>You can specify the post type for Require Featured Image to work on. By default it works on Posts only.</p><p>If you\'re not seeing a post type here that you think should be, it probably does not have support for featured images. Only post types that support featured images will appear on this list.</p>', 'require-featured-image' ); 47 } 48 49 function rfi_size_text_output(){ 50 _e('<p>The minimum acceptable size can be set for featured images. This size means that posts with images smaller than the specified dimensions cannot be published. By default the sizes are zero, so any image size will be accepted.</p>','require-featured-image'); 38 51 } 39 52 … … 46 59 } 47 60 return $return; 61 } 62 63 function rfi_return_min_dimensions(){ 64 $minimum_size = get_option('rfi_minimum_size'); 65 if (isset($minimum_size["width"]) && $minimum_size["width"] == 0) { 66 $minimum_size["width"] = 0; 67 } 68 if (isset($minimum_size["height"]) && $minimum_size["height"] == 0) { 69 $minimum_size["height"] = 0; 70 } 71 return $minimum_size; 48 72 } 49 73 … … 60 84 } 61 85 } 86 87 function rfi_size_option_renderer(){ 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>'; 91 } -
require-featured-image/trunk/readme.txt
r1302625 r1341002 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.4 7 Stable tag: 1. 1.46 Tested up to: 4.4.1 7 Stable tag: 1.2.0 8 8 License: MIT 9 9 License URI: http://opensource.org/licenses/MIT … … 15 15 = Simplify Your Editing Life = 16 16 17 Requires your various post types — as specified in a simple options page — to have a featured image set before they can be published. If a lack of featured images causes your layout to break, or just look less-than-optimal, this is the plugin for you. 17 Requires your various post types — as specified in a simple options page — to have a featured image set before they can be published. If a lack of featured images causes your layout to break, or just look less-than-optimal, this is the plugin for you. 18 18 19 Rather than forcing you to manually enforce your editorial standards of including a featured image in every post, if your contributors fail to add a featured image to a post before publishing it they'll simply find it impossible to publish. 19 Rather than forcing you to manually enforce your editorial standards of including a featured image in every post, if your contributors fail to add a featured image to a post before publishing it they'll simply find it impossible to publish. 20 20 21 21 = Setting up the Plugin = 22 22 23 By default it works on the "Post" content type only, but you can specify other content types, or turn it off for Posts in the new options page in your left sidebar: Settings > Req Featured Image. Simply check and uncheck the appropriate types, hit save and you're all set. Happy publishing!23 By default it works on the "Post" content type only, but you can specify other content types, or turn it off for Posts in the new options page in your left sidebar: Settings > Req Featured Image. Simply check and uncheck the appropriate types, set a minimum image size if you desire, hit save and you're all set. Happy publishing! 24 24 25 25 = Anything else? = … … 29 29 == Installation == 30 30 31 Activate the plugin. No other steps are necessary to require featured images on Posts only. 31 Activate the plugin. No other steps are necessary to require featured images on Posts only. 32 32 33 If you want to require featured images on a different content type, or allow Posts to be published without them simply go to the settings page in your left sidebar: Settings > Req Featured Image. Check and uncheck the appropriate types, hit "Save", and you're all set. Happy publishing!33 If you want to require featured images on a different content type, or allow Posts to be published without them simply go to the settings page in your left sidebar: Settings > Req Featured Image. Check and uncheck the appropriate types, set a minimum image size if you desire, hit "Save", and you're all set. Happy publishing! 34 34 35 35 == Frequently Asked Questions == … … 55 55 = Are there any options? = 56 56 57 Yep, just for different "custom post types." In your left sidebar under Settings, you should see "Req Featured Image". There are options. Or an option, more accurately. Happy publishing!57 Yep, just for different "custom post types." In your left sidebar under Settings, you should see "Req Featured Image". There are options. You can choose which Post Types you want check as well as setting a minimum size for the featured image. Happy publishing! 58 58 59 59 = Support for other languages? = … … 70 70 71 71 == CHANGELOG == 72 73 = 1.2.0 (2016.02.01) = 74 * Adding the ability to declare, check for, and enforce a minimum featured image size. Big props to [@cjk508](https://github.com/cjk508) for making that happen. 72 75 73 76 = 1.1.4 (2015.12.7) = -
require-featured-image/trunk/require-featured-image-on-edit.js
r1268975 r1341002 16 16 createMessageAreaIfNeeded(); 17 17 $('#nofeature-message').addClass("error") 18 .html('<p>'+ objectL10n.jsWarningHtml+'</p>');18 .html('<p>'+passedFromServer.jsWarningHtml+'</p>'); 19 19 $('#publish').attr('disabled','disabled'); 20 20 } … … 31 31 } 32 32 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 33 59 function detectWarnFeaturedImage() { 34 60 if (postTypeSupportsFeaturedImage()) { … … 36 62 disablePublishAndWarn(); 37 63 } else { 38 c learWarningAndEnablePublish();64 checkImageSizeThenWarnOrEnable(); 39 65 } 40 66 } 41 67 } 42 68 69 43 70 detectWarnFeaturedImage(); 44 71 setInterval(detectWarnFeaturedImage, 3000); -
require-featured-image/trunk/require-featured-image.php
r1302614 r1341002 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. 1.47 Version: 1.2.0 8 8 Author URI: http://pressupinc.com 9 9 Text Domain: require-featured-image 10 */ 10 */ 11 11 12 12 require_once('admin-options.php'); … … 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' 16 if ( $new_status === 'publish' 17 17 && !rfi_should_let_post_publish( $post ) ) { 18 wp_die( __( 'You cannot publish without a featured image.', 'require-featured-image' ) ); 18 $warning_message = rfi_check_size_is_set(); 19 wp_die( __( $warning_message, 'require-featured-image' ) ); 19 20 } 20 21 } … … 28 29 add_action( 'plugins_loaded', 'rfi_textdomain_init' ); 29 30 function rfi_textdomain_init() { 30 load_plugin_textdomain( 31 'require-featured-image', 32 false, 33 dirname( plugin_basename( __FILE__ ) ).'/lang' 34 ); 31 load_plugin_textdomain( 32 'require-featured-image', 33 false, 34 dirname( plugin_basename( __FILE__ ) ).'/lang' 35 ); 35 36 } 36 37 … … 42 43 43 44 if ( in_array( $post->post_type, rfi_return_post_types() ) ) { 45 $minimum_size = get_option('rfi_minimum_size'); 46 44 47 wp_register_script( 'rfi-admin-js', plugins_url( '/require-featured-image-on-edit.js', __FILE__ ), array( 'jquery' ) ); 45 48 wp_enqueue_script( 'rfi-admin-js' ); 49 46 50 wp_localize_script( 47 51 'rfi-admin-js', 48 ' objectL10n',52 'passedFromServer', 49 53 array( 50 54 'jsWarningHtml' => __( '<strong>This entry has no featured image.</strong> Please set one. You need to set a featured image before publishing.', 'require-featured-image' ), 55 'jsSmallHtml' => sprintf( 56 __( '<strong>This entry has a featured image that is too small.</strong> Please use an image that is at least %s x %s pixels.', 'require-featured-image' ), 57 $minimum_size['width'], 58 $minimum_size['height'] 59 ), 60 'width' => $minimum_size['width'], 61 'height' => $minimum_size['height'], 51 62 ) 52 63 ); … … 63 74 $option = array( 'post' ); 64 75 add_option( 'rfi_post_types', $option ); 65 } 76 } 66 77 elseif ( $option === '' ) { 67 78 // For people who want the plugin on, but doing nothing … … 75 86 if ( $option === 'default' ) { 76 87 // added in 1.1.0, activation times for installations before 77 // that release are set to two weeks prior to the first call 88 // that release are set to two weeks prior to the first call 78 89 $existing_install_guessed_time = time() - ( 86400*14 ); 79 90 add_option( 'rfi_enforcement_start', $existing_install_guessed_time ); … … 83 94 } 84 95 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'); 104 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 } 114 } 115 } 116 } 117 118 function rfi_check_size_is_set(){ 119 $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."; 122 } 123 else{ 124 return "You cannot publish without a featured image which is at least ". $minimum_size['width'] ."x".$minimum_size['height']." pixels."; 125 } 126 } 127 85 128 function rfi_should_let_post_publish( $post ) { 86 129 $has_featured_image = has_post_thumbnail( $post->ID ); 87 130 $is_watched_post_type = in_array( $post->post_type, rfi_return_post_types() ); 88 131 $is_after_enforcement_time = strtotime( $post->post_date ) > rfi_enforcement_start_time(); 89 132 $image_size_check = rfi_check_featured_image_size($post); 133 90 134 if ( $is_after_enforcement_time && $is_watched_post_type ) { 91 return $has_featured_image ;135 return $has_featured_image && $image_size_check; 92 136 } 93 137 return true;
Note: See TracChangeset
for help on using the changeset viewer.