Plugin Directory

Changeset 1341002


Ignore:
Timestamp:
02/01/2016 11:01:17 PM (10 years ago)
Author:
pressupinc
Message:

deploy from git

Location:
require-featured-image/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • require-featured-image/trunk/admin-options.php

    r1185295 r1341002  
    2525    register_setting( $option_group, $option_name );
    2626
     27    $minimum_size_option = 'rfi_minimum_size';
     28    register_setting( $option_group, $minimum_size_option );
     29
    2730    // Create section of Page
    2831    $settings_section = 'rfi_main';
    2932    $page = 'rfi';
    3033    add_settings_section( $settings_section, __( 'Post Types', 'require-featured-image' ), 'rfi_main_section_text_output', $page );
    31    
     34
    3235    // Add fields to that section
    3336    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);
    3443}
    3544
    3645function rfi_main_section_text_output() {
    3746    _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
     49function 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');
    3851}
    3952
     
    4659    }
    4760    return $return;
     61}
     62
     63function 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;
    4872}
    4973
     
    6084    }
    6185}
     86
     87function 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  
    44Tags: featured image, images, edit, post, admin, require featured image, image, media, thumbnail, thumbnails, post thumbnail, photo, pictures
    55Requires at least: 3.5
    6 Tested up to: 4.4
    7 Stable tag: 1.1.4
     6Tested up to: 4.4.1
     7Stable tag: 1.2.0
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    1515= Simplify Your Editing Life =
    1616
    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. 
     17Requires 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.
    1818
    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. 
     19Rather 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.
    2020
    2121= Setting up the Plugin =
    2222
    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!
     23By 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!
    2424
    2525= Anything else? =
     
    2929== Installation ==
    3030
    31 Activate the plugin. No other steps are necessary to require featured images on Posts only. 
     31Activate the plugin. No other steps are necessary to require featured images on Posts only.
    3232
    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!
     33If 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!
    3434
    3535== Frequently Asked Questions ==
     
    5555= Are there any options? =
    5656
    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!
     57Yep, 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!
    5858
    5959= Support for other languages? =
     
    7070
    7171== 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.
    7275
    7376= 1.1.4 (2015.12.7) =
  • require-featured-image/trunk/require-featured-image-on-edit.js

    r1268975 r1341002  
    1616        createMessageAreaIfNeeded();
    1717        $('#nofeature-message').addClass("error")
    18             .html('<p>'+objectL10n.jsWarningHtml+'</p>');
     18            .html('<p>'+passedFromServer.jsWarningHtml+'</p>');
    1919        $('#publish').attr('disabled','disabled');
    2020    }
     
    3131    }
    3232
     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
    3359    function detectWarnFeaturedImage() {
    3460        if (postTypeSupportsFeaturedImage()) {
     
    3662                disablePublishAndWarn();
    3763            } else {
    38                 clearWarningAndEnablePublish();
     64                checkImageSizeThenWarnOrEnable();
    3965            }
    4066        }
    4167    }
    4268
     69
    4370    detectWarnFeaturedImage();
    4471    setInterval(detectWarnFeaturedImage, 3000);
  • require-featured-image/trunk/require-featured-image.php

    r1302614 r1341002  
    55Description: Like it says on the tin: requires posts to have a featured image set before they'll be published.
    66Author: Press Up
    7 Version: 1.1.4
     7Version: 1.2.0
    88Author URI: http://pressupinc.com
    99Text Domain: require-featured-image
    10 */ 
     10*/
    1111
    1212require_once('admin-options.php');
     
    1414add_action( 'transition_post_status', 'rfi_guard', 10, 3 );
    1515function rfi_guard( $new_status, $old_status, $post ) {
    16     if ( $new_status === 'publish' 
     16    if ( $new_status === 'publish'
    1717        && !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' ) );
    1920    }
    2021}
     
    2829add_action( 'plugins_loaded', 'rfi_textdomain_init' );
    2930function 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    );
    3536}
    3637
     
    4243
    4344    if ( in_array( $post->post_type, rfi_return_post_types() ) ) {
     45        $minimum_size = get_option('rfi_minimum_size');
     46
    4447        wp_register_script( 'rfi-admin-js', plugins_url( '/require-featured-image-on-edit.js', __FILE__ ), array( 'jquery' ) );
    4548        wp_enqueue_script( 'rfi-admin-js' );
     49
    4650        wp_localize_script(
    4751            'rfi-admin-js',
    48             'objectL10n',
     52            'passedFromServer',
    4953            array(
    5054                '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'],
    5162            )
    5263        );
     
    6374        $option = array( 'post' );
    6475        add_option( 'rfi_post_types', $option );
    65     } 
     76    }
    6677    elseif ( $option === '' ) {
    6778        // For people who want the plugin on, but doing nothing
     
    7586    if ( $option === 'default' ) {
    7687        // 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
    7889        $existing_install_guessed_time = time() - ( 86400*14 );
    7990        add_option( 'rfi_enforcement_start', $existing_install_guessed_time );
     
    8394}
    8495
     96function 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
     118function 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
    85128function rfi_should_let_post_publish( $post ) {
    86129    $has_featured_image = has_post_thumbnail( $post->ID );
    87130    $is_watched_post_type = in_array( $post->post_type, rfi_return_post_types() );
    88131    $is_after_enforcement_time = strtotime( $post->post_date ) > rfi_enforcement_start_time();
    89    
     132    $image_size_check = rfi_check_featured_image_size($post);
     133
    90134    if ( $is_after_enforcement_time && $is_watched_post_type ) {
    91         return $has_featured_image;
     135        return $has_featured_image && $image_size_check;
    92136    }
    93137    return true;
Note: See TracChangeset for help on using the changeset viewer.