Plugin Directory

Changeset 1346331


Ignore:
Timestamp:
02/08/2016 11:17:19 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

    r1341002 r1346331  
    6161}
    6262
    63 function rfi_return_min_dimensions(){
     63function rfi_return_min_dimensions() {
    6464    $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;
    6767    }
    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;
    7070    }
    7171    return $minimum_size;
     
    8787function rfi_size_option_renderer(){
    8888    $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>';
    9191}
  • require-featured-image/trunk/readme.txt

    r1341002 r1346331  
    55Requires at least: 3.5
    66Tested up to: 4.4.1
    7 Stable tag: 1.2.0
     7Stable tag: 1.2.1
    88License: MIT
    99License URI: http://opensource.org/licenses/MIT
     
    5959= Support for other languages? =
    6060
    61 Yes. We're currently (end 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.
     61Yes. 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.
    6262
    6363As 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.
     
    7070
    7171== 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.
    7276
    7377= 1.2.0 (2016.02.01) =
  • require-featured-image/trunk/require-featured-image-on-edit.js

    r1341002 r1346331  
    99    }
    1010
     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
    1123    function publishButtonIsPublishText() {
    1224        return $('#publish').attr('name') === 'publish';
    1325    }
    1426
    15     function disablePublishAndWarn() {
     27    function disablePublishAndWarn(reason) {
     28        if (reason == 'none') {
     29            var message = passedFromServer.jsWarningHtml;
     30        } else {
     31            var message = passedFromServer.jsSmallHtml;
     32        }
    1633        createMessageAreaIfNeeded();
    1734        $('#nofeature-message').addClass("error")
    18             .html('<p>'+passedFromServer.jsWarningHtml+'</p>');
     35            .html('<p>'+message+'</p>');
    1936        $('#publish').attr('disabled','disabled');
    2037    }
     
    3148    }
    3249
    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 
    5950    function detectWarnFeaturedImage() {
    6051        if (postTypeSupportsFeaturedImage()) {
    6152            if (lacksFeaturedImage() && publishButtonIsPublishText()) {
    62                 disablePublishAndWarn();
     53                disablePublishAndWarn( 'none' );
     54            } else if (imageIsTooSmall() && publishButtonIsPublishText()) {
     55                disablePublishAndWarn( 'too-small' );
    6356            } else {
    64                 checkImageSizeThenWarnOrEnable();
     57                clearWarningAndEnablePublish();
    6558            }
    6659        }
    6760    }
    6861
    69 
    7062    detectWarnFeaturedImage();
    7163    setInterval(detectWarnFeaturedImage, 3000);
  • require-featured-image/trunk/require-featured-image.php

    r1341002 r1346331  
    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.2.0
     7Version: 1.2.1
    88Author URI: http://pressupinc.com
    99Text Domain: require-featured-image
     
    1414add_action( 'transition_post_status', 'rfi_guard', 10, 3 );
    1515function 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() );
    2018    }
    2119}
     
    3937function rfi_enqueue_edit_screen_js( $hook ) {
    4038    global $post;
    41     if ( $hook !== 'post.php' && $hook !== 'post-new.php' )
     39    if ( $hook !== 'post.php' && $hook !== 'post-new.php' ) {
    4240        return;
     41    }
    4342
    4443    if ( in_array( $post->post_type, rfi_return_post_types() ) ) {
    45         $minimum_size = get_option('rfi_minimum_size');
    46 
    4744        wp_register_script( 'rfi-admin-js', plugins_url( '/require-featured-image-on-edit.js', __FILE__ ), array( 'jquery' ) );
    4845        wp_enqueue_script( 'rfi-admin-js' );
    4946
     47        $minimum_size = get_option( 'rfi_minimum_size' );
    5048        wp_localize_script(
    5149            'rfi-admin-js',
     
    7472        $option = array( 'post' );
    7573        add_option( 'rfi_post_types', $option );
    76     }
    77     elseif ( $option === '' ) {
     74    } elseif ( $option === '' ) {
    7875        // For people who want the plugin on, but doing nothing
    7976        $option = array();
     
    9491}
    9592
    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');
     93function 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' );
    104103
    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;
    114106        }
     107        return false;
    115108    }
    116109}
    117110
    118 function rfi_check_size_is_set(){
     111function rfi_get_warning_message() {
    119112    $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' );
    122116    }
    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    );
    126122}
    127123
     
    130126    $is_watched_post_type = in_array( $post->post_type, rfi_return_post_types() );
    131127    $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 );
    133129
    134130    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;
    136132    }
    137133    return true;
Note: See TracChangeset for help on using the changeset viewer.