Plugin Directory

Changeset 2005148


Ignore:
Timestamp:
01/02/2019 12:57:19 PM (7 years ago)
Author:
corgdesign
Message:

Version 2.0

Location:
minimum-featured-image-size/trunk
Files:
6 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • minimum-featured-image-size/trunk/admin/mfis-admin-scripts.js

    r1871030 r2005148  
    1 jQuery( function($) {
    2     
    3     // Initialise some variables, used later for the image ID input value
    4     mfis_value = '';
     1/**
     2 * Initialise some variables
     3 */
     4var mfis_value = -1,
    55    previous_value = '';
    66
    7     // Function to reset all things mfis
    8     function mfis_reset(){
    9        
    10         $( '#publishing-action input[type="submit"]' ).removeAttr('disabled').show();
    11        
    12         $( '.mfis_publishing_disabled' ).fadeOut(500, function(){
    13             $( '.mfis_publishing_disabled' ).remove();
    14             $( '#postimagediv .inside' ).removeClass( 'mfis_is_disabled' );
     7
     8/**
     9 * Check the image via ajax
     10 * @param {number} image_id
     11 */
     12function mfis_do_ajax(image_id) {
     13
     14    if (image_id != -1) {
     15
     16        var data = {
     17            action: 'mfis_get_size_from_id',
     18            image_id: image_id,
     19            post_type: mfis.post_type,
     20            editor: 'classic',
     21        };
     22
     23        $.post(ajaxurl, data, function (response) {
     24
     25            var json = JSON.parse(response);
     26
     27            if (json.image_check == 'fail') {
     28
     29                // Add error message
     30                var mfis_publishing_disabled_message = '<div class="mfis_publishing_disabled"><span class="mfis_icon">!</span><span class="mfis_error_message">' + json.error_message + '</span></div>';
     31
     32                if (!$('#postimagediv .inside img').hasClass('mfis_is_disabled')) {
     33                    $('#postimagediv .inside img, #major-publishing-actions').after(mfis_publishing_disabled_message).addClass('mfis_is_disabled');
     34                    $('.mfis_publishing_disabled').hide().fadeIn();
     35                }
     36
     37            } else {
     38
     39                // Image passed, so let's reset things
     40                mfis_reset();
     41
     42            }
     43
    1544        });
    16 
    17         mfis_value = '';
    1845
    1946    }
    2047
    21     // Do the mfis check
    22     function mfis_check_image(){
     48}
    2349
    24         // Check if there is an input with the image ID
    25         if ( $('#_thumbnail_id').length > 0 && $('#_thumbnail_id').val() >= 0 ) {
    2650
    27             // Compare it to the previous value
    28             mfis_value = $('#_thumbnail_id').val();
     51/**
     52 * Reset all things mfis
     53 */
     54function mfis_reset() {
    2955
    30             if ( mfis_value != previous_value ) {
    31                
    32                 // Value has changed, so let's disable the Publish button and do the ajax
    33                 $( '#publishing-action input[type="submit"]' ).attr('disabled', 'disabled').show();
     56    if (mfis.disable_publishing == 'publishing_disabled') $('#publishing-action input[type="submit"]').removeAttr('disabled').show();
    3457
    35                 data = {
    36                     action      : 'mfis_get_size_from_id',
    37                     image_id    : mfis_value,
    38                     post_type   : mfis.post_type,
    39                 };
     58    $('.mfis_publishing_disabled').fadeOut(500, function () {
     59        $('.mfis_publishing_disabled').remove();
     60        $('#postimagediv .inside img').removeClass('mfis_is_disabled');
     61    });
    4062
    41                 $.post( ajaxurl , data , function( response ) {
    42                    
    43                     // Split the response into an array
    44                     response = response.split('[mfis_delimter]');
     63    mfis_value = '';
    4564
    46                     if( response[0] == 'image_failed') {
     65}
    4766
    48                         // Add error message
    49                         var mfis_publishing_disabled_message = '<div class="mfis_publishing_disabled"><span class="mfis_icon">!</span><span class="mfis_error_message">' + response[1] + '</span></div>';
    50                         if( ! $( '#postimagediv .inside' ).hasClass('mfis_is_disabled') ) {
    51                             $( '#postimagediv .inside' ).after( mfis_publishing_disabled_message ).addClass('mfis_is_disabled');
    52                             $( '.mfis_publishing_disabled' ).hide().fadeIn();
    53                         }
    54                    
    55                     } else {
    5667
    57                         // Image passed, so let's reset things
    58                         mfis_reset();
     68/**
     69 * Do the mfis check
     70 */
     71function mfis_check_image() {
    5972
    60                     }
     73    // Check if there is an input with the image ID
     74    if ($('#_thumbnail_id').length > 0 && $('#_thumbnail_id').val() >= 0) {
    6175
    62                 });
    63             }
     76        // Compare it to the previous value
     77        mfis_value = $('#_thumbnail_id').val();
    6478
    65             previous_value = mfis_value;
     79        if (mfis_value != previous_value) {
     80
     81            // Value has changed, so let's disable the Publish button and do the ajax
     82            if (mfis.disable_publishing == 'publishing_disabled') $('#publishing-action input[type="submit"]').attr('disabled', 'disabled').show();
     83
     84            mfis_do_ajax(mfis_value);
     85
     86        }
     87
     88        previous_value = mfis_value;
     89
     90    } else {
    6691
    6792        // There's no image ID input present, so reset things
    68         } else {
     93        mfis_reset();
     94
     95    }
     96
     97}
     98
     99
     100jQuery(function ($) {
     101
     102    if (mfis.disable_ajax != 'ajax_disabled') {
     103
     104        // Reset mfis if 'Remove featured image' link is clicked
     105        $('#remove-post-thumbnail').on('click', function () {
     106
     107            $('#_thumbnail_id').val(-1);
    69108
    70109            mfis_reset();
    71110
    72         }
     111        });
     112
     113        // Do initial check on page load, and then keep checking
     114        mfis_check_image();
     115        setInterval(mfis_check_image, 200);
    73116
    74117    }
    75118
    76     // Reset mfis if 'Remove featured image' link is clicked
    77     $( '#remove-post-thumbnail' ).on( 'click', function(){
    78 
    79         $('#_thumbnail_id').val( -1 );
    80 
    81         mfis_reset();
    82 
    83     });
    84 
    85     // Do initial check on page load, and then keep checking
    86     mfis_check_image();
    87     setInterval(mfis_check_image, 200);
    88 
    89119});
    90 
  • minimum-featured-image-size/trunk/mfis.php

    r1926403 r2005148  
    33Plugin Name: Minimum Featured Image Size
    44Description: Set the minimum size required for featured images used in standard and custom posts.
    5 Version:     1.1.2
     5Version:     2.0
    66Author:      Martin Stewart
    77Author URI:  https://www.corgdesign.com
     
    1414
    1515/**
    16  * Enqueue css for setting page
     16 * Enqueue css for settings page
    1717 * @since 1.0
    1818 */
     
    2020
    2121    # admin css
    22     wp_enqueue_style( 'mfis-admin-css', plugins_url('admin/mfis-admin-styles.css', __FILE__ ));
     22    wp_enqueue_style( 'mfis-admin-css', plugins_url('admin/mfis-admin-styles.min.css', __FILE__ ));
    2323
    2424}
     
    2727
    2828/**
    29  * Enqueue css and js for ajax functionality
     29 * Enqueue js for ajax functionality
    3030 * @since 1.0
    3131 */
     
    3333
    3434    # admin javascript
    35     wp_register_script( 'mfis-admin-js', plugins_url('admin/mfis-admin-scripts.js', __FILE__ ), array( 'jquery' ), false, true );
     35    wp_register_script( 'mfis-admin-js', plugins_url('admin/mfis-admin-scripts.min.js', __FILE__ ), array( 'jquery' ), false, true );
    3636   
    3737    # Localize the script and pass in the post type
     
    3939    $post_type = $current_screen->post_type;
    4040    $translation_array = array(
    41         'post_type' => $post_type
     41        'post_type' => $post_type,
     42        'disable_publishing' => get_option('mfis_disable_publishing'),
     43        'disable_ajax' => get_option( 'mfis_ajax_disable' )
    4244    );
    4345   
     
    4547    wp_enqueue_script( 'mfis-admin-js' );
    4648
    47     # admin css
    48     wp_enqueue_style( 'mfis-admin-ajax-css', plugins_url('admin/mfis-admin-ajax-styles.css', __FILE__ ));
    49 
    5049}
    5150
     
    5857
    5958/**
     59 * Enqueue the js for the block editor, and remove the classic editor scripts
     60 * @since 2.0
     61 */
     62function mfis_enqueue_admin_block_editor_ajax(){
     63   
     64    # admin javascript
     65    wp_register_script( 'mfis-adminblock-editor-js', plugins_url('admin/mfis-admin-block-editor-scripts.min.js', __FILE__ ), array( 'jquery' ), false, true );
     66   
     67    # Localize the script and pass in the post type
     68    $current_screen = get_current_screen();
     69    $post_type = $current_screen->post_type;
     70    $translation_array = array(
     71        'post_type' => $post_type,
     72        'disable_publishing' => get_option('mfis_disable_publishing'),
     73        'disable_ajax' => get_option( 'mfis_ajax_disable' )
     74    );
     75   
     76    wp_localize_script( 'mfis-adminblock-editor-js', 'mfis', $translation_array );
     77    wp_enqueue_script( 'mfis-adminblock-editor-js' );
     78
     79    # Remove the previously enqueued classic editor scripts
     80    remove_action( 'admin_enqueue_scripts' , 'mfis_enqueue_admin_ajax' );
     81
     82}
     83
     84add_action('enqueue_block_editor_assets', 'mfis_enqueue_admin_block_editor_ajax');
     85
     86
     87/**
    6088 * Add an admin options page for MFIS settings
    6189 * @since 1.0
     
    81109
    82110    # Default error message
    83     $mfis_default_error_message = 'Publishing disabled! The Featured Image you\'ve chosen is not large enough, it must be at least [width] x [height]';
    84 
    85     ?>
     111    $mfis_default_error_message = 'Publishing disabled! The Featured Image you\'ve chosen is not large enough, it must be at least [width] x [height]';
     112   
     113    # Custom post types
     114    $post_types = get_post_types( array( 'public' => true, '_builtin' => false ), 'objects' ); ?>
    86115
    87116    <div class="wrap mfis_wrap">
     
    114143                </tr>
    115144
     145                <tr valign="top">
     146                    <th scope="row">Exact dimensions</th>
     147                    <td>
     148                        <label for="mfis_exact_dimensions">
     149                            <input type="checkbox" id="mfis_exact_dimensions" name="mfis_exact_dimensions" class="mfis_exact_dimensions" value="use_exact_dimensions" <?php checked( 'use_exact_dimensions', get_option( 'mfis_exact_dimensions' ) ); ?> />
     150                            Use exact dimensions?
     151                        </label>
     152                    </td>
     153                </tr>
     154
     155                <tr valign="top">
     156                    <th scope="row">Post publishing</th>
     157                    <td>
     158                        <label for="mfis_disable_publishing">
     159                            <input type="checkbox" id="mfis_disable_publishing" name="mfis_disable_publishing" class="mfis_disable_publishing" value="publishing_disabled" <?php checked( 'publishing_disabled', get_option( 'mfis_disable_publishing' ) ); ?> />
     160                            Disable publishing? <em><small>When the featured image isn't the required size</small></em>
     161                        </label><br>
     162                       
     163                    </td>
     164                </tr>
     165
    116166                <tr valign="top">
    117167                    <th scope="row">Error message</th>
     
    126176                        <label for="mfis_ajax_disable">
    127177                            <input type="checkbox" id="mfis_ajax_disable" name="mfis_ajax_disable" class="mfis_ajax_disable" value="ajax_disabled" <?php checked( 'ajax_disabled', get_option( 'mfis_ajax_disable' ) ); ?> />
    128                             Disable Ajax?
     178                            Disable Ajax? <small><em>Classic editor only</em></small>
    129179                        </label>
    130180                    </td>
    131181                </tr>
    132182               
     183                <?php if ( ! empty($post_types) ) : ?>
     184
    133185                <tr valign="top">
    134186                    <th valign="top" scope="row">Custom Post Types</th>
     
    140192                    </td>
    141193                </tr>
     194
     195                <?php endif; ?>
    142196               
    143197            </table>
     198
     199            <?php if ( ! empty($post_types) ) : ?>
    144200
    145201            <table class="form-table" id="mfis_custom_posts_options_table">
     
    152208                                <th valign="top" scope="row">Minimum width (px)</th>
    153209                                <th valign="top" scope="row">Minimum height (px)</th>
     210                                <th valign="top" scope="row">
     211                                    Use exact dimensions?<br>
     212                                    <small><a href="#" class="dimensions_select_all">Select all</a></small>
     213                                </th>
     214                                <th valign="top" scope="row">
     215                                    Error message<small> (Optional)<br>
     216                                    <em>
     217                                        <small>
     218                                            Use [width] and [height] to display your settings
     219                                        </small>
     220                                    </em>
     221                                </th>
    154222                            </tr>
    155223                        </table>
     
    163231                   
    164232                    $mfis_min_width  = get_option( 'mfis_min_width_' . $post_type->name );
    165                     $mfis_min_height = get_option( 'mfis_min_height_' . $post_type->name ); ?>
     233                    $mfis_min_height = get_option( 'mfis_min_height_' . $post_type->name );
     234                    $mfis_exact_dimensions = get_option( 'mfis_exact_dimensions_' . $post_type->name );
     235                    $mfis_error_message = get_option( 'mfis_error_message_' . $post_type->name ); ?>
    166236                   
    167                     <tr valign="middle">
    168                         <th valign="middle" scope="row"><?php echo $post_type->labels->singular_name; ?></th>
    169                         <td valign="middle">
     237                    <tr valign="top">
     238                        <th valign="top" scope="row"><?php echo $post_type->labels->singular_name; ?></th>
     239                        <td valign="top">
    170240                            <table>
    171241                                <tr>                           
    172                                     <td valign="middle">
     242                                    <td valign="top">
    173243                                        <input type="number" name="mfis_min_width_<?php echo $post_type->name; ?>" class="mfis_min_width" value="<?php echo empty( $mfis_min_width ) ? '' : esc_attr( $mfis_min_width ); ?>" /> px
    174244                                    </td>
    175                                     <td valign="middle">
     245                                    <td valign="top">
    176246                                        <input type="number" name="mfis_min_height_<?php echo $post_type->name; ?>" class="mfis_min_width" value="<?php echo empty( $mfis_min_height ) ? '' : esc_attr( $mfis_min_height ); ?>" /> px
    177247                                    </td>
     248                                    </td>
     249                                    <td valign="top">
     250                                        <input type="checkbox" name="mfis_exact_dimensions_<?php echo $post_type->name; ?>" class="mfis_exact_dimensions_cpt" value="mfis_exact_dimensions_<?php echo $post_type->name; ?>" <?php checked( 'mfis_exact_dimensions_' . $post_type->name, get_option( 'mfis_exact_dimensions_' . $post_type->name ) ); ?> />
     251                                    </td>
     252                                    <td valign="top">
     253                                        <textarea name="mfis_error_message_<?php echo $post_type->name; ?>" class="mfis_error_message"><?php echo empty( $mfis_error_message ) ? '' : esc_attr( $mfis_error_message ); ?></textarea>
     254                                    </td>
    178255                                </tr>
    179256                            </table>
     
    185262            </table> <?php
    186263
     264            endif;
     265
    187266            submit_button(); ?>
    188267
     
    212291            $( '#mfis_custom_posts_options_table' ).show();
    213292       
    214         }
     293        }
     294       
     295        $('.dimensions_select_all').on('click', function(e){
     296
     297            e.preventDefault();
     298
     299            if ($(this).hasClass('all-checkboxes-selected')) {
     300
     301                $('.mfis_exact_dimensions_cpt').prop('checked', false);
     302                $(this).text('Select all').removeClass('all-checkboxes-selected');
     303
     304            } else {
     305
     306                $('.mfis_exact_dimensions_cpt').prop('checked', true);
     307                $(this).text('Deselect all').addClass('all-checkboxes-selected');
     308
     309            }
     310
     311        });
    215312
    216313    });
     
    230327    register_setting( 'mfis_option_group' , 'mfis_min_width' );
    231328    register_setting( 'mfis_option_group' , 'mfis_min_height' );
     329    register_setting( 'mfis_option_group' , 'mfis_exact_dimensions' );
     330    register_setting( 'mfis_option_group' , 'mfis_disable_publishing' );
    232331    register_setting( 'mfis_option_group' , 'mfis_error_message' );
    233332    register_setting( 'mfis_option_group' , 'mfis_ajax_disable' );
     
    239338        register_setting( 'mfis_option_group' , 'mfis_min_width_' . $post_type );
    240339        register_setting( 'mfis_option_group' , 'mfis_min_height_' . $post_type );
     340        register_setting( 'mfis_option_group' , 'mfis_exact_dimensions_' . $post_type );
     341        register_setting( 'mfis_option_group' , 'mfis_error_message_' . $post_type );
    241342
    242343    }
     
    251352}
    252353
    253 
    254 /**
    255  * Check featured image size meets minimum requirements
    256  * @since 1.0
    257  */
    258 function mfis_image_size_ok( $image_id, $post_type = 'post' ){
     354# Set a default value for the mfis_allow_publishing setting
     355add_option('mfis_disable_publishing', 'publishing_disabled');
     356
     357
     358/**
     359 * Check featured image size meets minimum or exact requirements
     360 * @since 1.0
     361 * @param {number} $image_id
     362 * @param {string} $post_type
     363 */
     364function mfis_image_size_ok( $image_id, $post_type = 'post' ) {
    259365
    260366    $image_data = wp_get_attachment_image_src( $image_id, "Full" );
     
    269375
    270376        $min_width = get_option( 'mfis_min_width' );
    271         $min_height = get_option( 'mfis_min_height' );
     377        $min_height = get_option( 'mfis_min_height' );
     378        $exact_dimensions = get_option( 'mfis_exact_dimensions' );
    272379   
    273380    else :
    274381
    275382        $min_width = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_width_' . $post_type ) : get_option( 'mfis_min_width' );
    276         $min_height = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_height_' . $post_type ) : $min_height = get_option( 'mfis_min_height' );;
    277 
    278     endif;
    279    
    280     if( $image_width < $min_width || $image_height < $min_height ) :
     383        $min_height = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_height_' . $post_type ) : $min_height = get_option( 'mfis_min_height' );
     384        $exact_dimensions = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_exact_dimensions_' . $post_type ) : get_option( 'mfis_exact_dimensions' );
     385
     386    endif;
     387   
     388    # Use exact dimensions?
     389    if ( $exact_dimensions != '' ) {
     390
     391        if( $image_width == $min_width && $image_height == $min_height ) :
    281392       
    282         return false; # image is too small
    283 
    284     else :
    285    
    286         return true; # image is big enough
    287    
    288     endif;
     393            return true; # image is exact size
     394           
     395        else :
     396               
     397            return false; # image is not exact size
     398       
     399        endif;
     400
     401    } else {
     402
     403        if( $image_width < $min_width || $image_height < $min_height ) :
     404       
     405            return false; # image is too small
     406   
     407        else :
     408       
     409            return true; # image is big enough
     410       
     411        endif;
     412
     413    }
     414
     415}
     416
     417
     418/**
     419 * Get the error message based on post type
     420 * @since 2.0
     421 * @param {string} $post_type
     422 */
     423function mfis_get_error_message($post_type) {
     424
     425    # Default error message
     426    $mfis_default_error_message = 'Publishing disabled! The Featured Image you\'ve chosen is not large enough, it must be at least [width] x [height]';
     427
     428    if ( $post_type === 'post' ) :
     429
     430        $min_width = get_option( 'mfis_min_width' );
     431        $min_height = get_option( 'mfis_min_height' );
     432        $mfis_error_message = get_option( 'mfis_error_message' );
     433       
     434    else :
     435
     436        $min_width = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_width_' . $post_type ) : get_option( 'mfis_min_width' );
     437        $min_height = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_height_' . $post_type ) : $min_height = get_option( 'mfis_min_height' );
     438        $mfis_error_message = get_option( 'mfis_error_message_' . $post_type );
     439
     440    endif;
     441       
     442    $mfis_error_message = empty( $mfis_error_message ) ? str_replace( array( '[width]' ,  '[height]' ), array( $min_width , $min_height ), $mfis_default_error_message ) : str_replace( array( '[width]' ,  '[height]' ), array( $min_width , $min_height ), $mfis_error_message );
     443
     444    return $mfis_error_message;
    289445
    290446}
     
    305461    if( ! mfis_image_size_ok( $image_id, $post_type ) ) :
    306462       
    307         if ( $post_type === 'post' ) :
    308 
    309             $min_width = get_option( 'mfis_min_width' );
    310             $min_height = get_option( 'mfis_min_height' );
    311        
    312         else :
    313    
    314             $min_width = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_width_' . $post_type ) : get_option( 'mfis_min_width' );
    315             $min_height = get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? get_option( 'mfis_min_height_' . $post_type ) : $min_height = get_option( 'mfis_min_height' );;
    316    
    317         endif;
    318            
    319         $mfis_ajax_error_message = get_option( 'mfis_error_message' );
    320 
    321         $mfis_ajax_error_message = empty( $mfis_ajax_error_message ) ? str_replace( array( '[width]' ,  '[height]' ), array( $min_width , $min_height ), $mfis_default_error_message ) : str_replace( array( '[width]' ,  '[height]' ), array( $min_width , $min_height ), $mfis_ajax_error_message );
    322 
    323         $returned_data = 'image_failed[mfis_delimter]' . esc_attr( $mfis_ajax_error_message );
     463        $mfis_ajax_error_message = mfis_get_error_message($post_type);
     464
     465        $returned_data = '{"image_check":"fail", "error_message":"' . $mfis_ajax_error_message . '"}';
    324466
    325467        die( $returned_data );
     
    327469    else :
    328470
    329         die();
     471        die('{"image_check":"pass"}');
    330472
    331473    endif;
     
    335477
    336478/**
    337  * If Ajax is disabled or the user gets past the javascript, check the image on post saving
     479 * If publishing and the ajax is disabled or the user gets
     480 * past the javascript, check the image on post saving
    338481 * @since 1.0
    339482 */
     
    359502    if( ! mfis_image_size_ok( $image_id, $post_type ) ){
    360503       
    361         $reverted_status = in_array( $old_status, $run_on_statuses ) ? 'draft' : $old_status;
    362 
    363         if ( $post_type === 'post' ) :
    364 
    365             $min_width = get_option( 'mfis_min_width' );
    366             $min_height = get_option( 'mfis_min_height' );
    367        
    368         else :
    369            
    370             $min_width = get_option( 'mfis_min_width_' . $post_type );
    371             $min_height = get_option( 'mfis_min_height_' . $post_type );
    372 
    373             $min_width = ! empty($min_width) && get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? $min_width : get_option( 'mfis_min_width' );
    374             $min_height = ! empty($min_height) && get_option('mfis_custom_post_types') === 'mfis_custom_post_types' ? $min_height : get_option( 'mfis_min_height' );
    375    
    376         endif;
    377 
    378         $mfis_error_message = str_replace( array( '[width]' ,  '[height]' ), array( $min_width , $min_height ), get_option( 'mfis_error_message' ) );
     504        $reverted_status = in_array( $old_status, $run_on_statuses ) ? 'draft' : $new_status;
     505
     506        $mfis_error_message = mfis_get_error_message($post_type);
    379507       
    380508        wp_update_post(array(
     
    382510            'post_status' => $reverted_status,
    383511        ));
     512
     513    }
     514}
     515if (is_admin() && get_option('mfis_disable_publishing') === 'publishing_disabled') add_action('transition_post_status', 'mfis_after_save', 10, 3);
     516
     517
     518/**
     519 * Update error message on post save if publishing and the
     520 * ajax is disabled or the user gets past the javascript
     521 * @since 2.0
     522 */
     523function mfis_output_error_message($new_status, $old_status, $post){
     524
     525    $post_id = $post->ID;
     526   
     527    if ( wp_is_post_revision( $post_id ) )
     528        return;
     529   
     530    if( !function_exists('get_current_screen') )
     531        return;
     532
     533    $image_id = get_post_thumbnail_id( $post_id );
     534    $current_screen = get_current_screen();
     535    $post_type = $current_screen->post_type;
     536
     537    if( ! mfis_image_size_ok( $image_id, $post_type ) ){
     538
     539        $mfis_error_message = mfis_get_error_message($post_type);
    384540       
    385         update_option('mfis_size', '<span class="mfis_error"><span class="mfis_icon">!</span> <span class="mfis_error_message">' . esc_html($mfis_error_message) . '</span></span>');
     541        update_option('mfis_editor_error_message', '<span class="mfis_error"><span class="mfis_icon">!</span> <span class="mfis_error_message">' . esc_html($mfis_error_message) . '</span></span>');
    386542
    387543    }
    388 }
    389 if (is_admin()) add_action('transition_post_status', 'mfis_after_save', 10, 3);
     544
     545}
     546if (is_admin()) add_action('transition_post_status', 'mfis_output_error_message', 10, 3);
    390547
    391548
     
    396553function mfis_notice(){
    397554
    398     if( get_option( 'mfis_size' ) ) : ?>
     555    if( get_option( 'mfis_editor_error_message' ) ) : ?>
    399556
    400557        <div class="notice notice-error mfis-notice-error">
    401             <p><?php echo get_option( 'mfis_size' ); ?></p>
     558            <p><?php echo get_option( 'mfis_editor_error_message' ); ?></p>
    402559        </div>
    403560
    404561    <?php endif;
    405562
    406     delete_option( 'mfis_size' );
     563    delete_option( 'mfis_editor_error_message' );
    407564}
    408565add_action( 'admin_notices','mfis_notice' );
     
    415572function mfis_remove_notice( $messages ){
    416573
    417     if(get_option('mfis_size')) :
     574    if(get_option('mfis_editor_error_message')) :
    418575
    419576        return array();
     
    429586/**
    430587 * Function to check if we are in the MFIS settings page
    431  *
    432588 * @since    1.0.0
    433589 */
  • minimum-featured-image-size/trunk/readme.txt

    r1926403 r2005148  
    44Donate link: https://www.paypal.me/corgdesign/5
    55Requires at least: 4.7.5
    6 Tested up to: 4.9.6
     6Tested up to: 5.0.2
    77Stable tag: trunk
    88License: GPL2
     
    1212
    1313== Description ==
    14 With this plugin you can set the minimum width and height required for featured images used in standard and custom posts. You can also customise the error message shown to the user when an image isn't large enough.
     14With this plugin you can set the minimum width and height required for featured images used in standard and custom posts. You can also customise the error message shown to the user when an image isn't large enough. Supports the Gutenberg Block Editor.
    1515
    1616== Installation ==
    1717* Upload minimum-featured-image-size folder to your /wp-content/plugins/ directory.
    1818* Activate the plugin through the ‘Plugins’ menu in WordPress.
    19 * Set the minimum width and height for your featured images, customise the error message, and disable/enable Ajax by going to Settings > Minimum Featured Image Size.
     19* Go to Settings > Minimum Featured Image Size.
    2020
    2121== Frequently Asked Questions ==
     
    2424== Screenshots ==
    25251. Plugin settings
    26 2. Ajax error message displayed to user if image isn't large enough
    27 3. Non-ajax error message displayed to user if image isn't large enough
     262. Error message displayed to user if image isn't large enough
    2827
    2928== Changelog ==
     
    4544= 1.1.2 =
    4645* Bug fix
     46
     47= 2.0 =
     48* Feature requests added - exact dimensions, choice of post disabling
     49* Add Gutenberg Block Editor support
Note: See TracChangeset for help on using the changeset viewer.