Plugin Directory

Changeset 2022083


Ignore:
Timestamp:
01/30/2019 04:41:05 PM (7 years ago)
Author:
corgdesign
Message:

Bug fix.

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

Legend:

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

    r2005148 r2022083  
    1 /**
    2  * Initialise some variables
    3  */
    4 var mfis_value = -1,
    5     previous_value = '',
    6     mfis_image_passed = true,
    7     mfis_do_check = true,
    8     mfis_dismiss_error_messages = false,
    9     mfis_publishing_disabled_message = '';
     1jQuery(function ($) {
     2
     3    /**
     4     * Initialise some variables
     5     */
     6    var mfis_value = -1,
     7        previous_value = '',
     8        mfis_image_passed = true,
     9        mfis_do_check = true,
     10        mfis_dismiss_error_messages = false,
     11        mfis_publishing_disabled_message = '';
    1012
    1113
    12 /**
    13  * Reset all things mfis in the block editor
    14  */
    15 function mfis_reset_block_editor() {
     14    /**
     15     * Reset all things mfis in the block editor
     16     */
     17    function mfis_reset_block_editor() {
    1618
    17     // Renable publishing
    18     if (mfis.disable_publishing == 'publishing_disabled') {
    19         $('.editor-post-publish-button').removeAttr('disabled').show();
    20         wp.data.dispatch('core/editor').unlockPostSaving('mfis_lock');
     19        // Renable publishing
     20        if (mfis.disable_publishing == 'publishing_disabled') {
     21            $('.editor-post-publish-button').removeAttr('disabled').show();
     22            wp.data.dispatch('core/editor').unlockPostSaving('mfis_lock');
     23        }
     24
     25        // Remove error message from below image
     26        $('.mfis_publishing_disabled_block_editor').fadeOut(500, function () {
     27            $('.mfis_publishing_disabled_block_editor').remove();
     28            $('.editor-post-featured-image img').removeClass('mfis_is_disabled');
     29        });
     30
     31        // Remove the error message from top of editor
     32        wp.data.dispatch('core/notices').removeNotice('mfis_dismissible_error_message');
     33
     34        mfis_value = '';
     35        mfis_do_check = false;
     36
    2137    }
    2238
    23     // Remove error message from below image
    24     $('.mfis_publishing_disabled_block_editor').fadeOut(500, function () {
    25         $('.mfis_publishing_disabled_block_editor').remove();
    26         $('.editor-post-featured-image img').removeClass('mfis_is_disabled');
    27     });
    2839
    29     // Remove the error message from top of editor
    30     wp.data.dispatch('core/notices').removeNotice('mfis_dismissible_error_message');
     40    /**
     41     * Check the image via ajax
     42     * @param {number} image_id
     43     */
     44    function mfis_do_ajax_block_editor(image_id) {
    3145
    32     mfis_value = '';
    33     mfis_do_check = false;
     46        if (image_id != -1) {
    3447
    35 }
     48            var data = {
     49                action: 'mfis_get_size_from_id',
     50                image_id: image_id,
     51                post_type: mfis.post_type,
     52                editor: 'block',
     53            };
    3654
     55            $.post(ajaxurl, data, function (response) {
    3756
    38 /**
    39  * Check the image via ajax
    40  * @param {number} image_id
    41  */
    42 function mfis_do_ajax_block_editor(image_id) {
     57                var json = JSON.parse(response);
    4358
    44     if (image_id != -1) {
     59                if (json.image_check == 'fail') {
    4560
    46         var data = {
    47             action: 'mfis_get_size_from_id',
    48             image_id: image_id,
    49             post_type: mfis.post_type,
    50             editor: 'block',
    51         };
     61                    // Add error message
     62                    mfis_publishing_disabled_message = '<div class="mfis_publishing_disabled_block_editor"><span class="mfis_icon">!</span><span class="mfis_error_message">' + json.error_message + '</span></div>';
    5263
    53         $.post(ajaxurl, data, function (response) {
     64                    if (!$('.editor-post-featured-image img').hasClass('mfis_is_disabled')) {
    5465
    55             var json = JSON.parse(response);
     66                        $('.editor-post-featured-image img').after(mfis_publishing_disabled_message).addClass('mfis_is_disabled');
     67                        $('.mfis_publishing_disabled_block_editor').hide().fadeIn();
    5668
    57             if (json.image_check == 'fail') {
     69                    }
    5870
    59                 // Add error message
    60                 mfis_publishing_disabled_message = '<div class="mfis_publishing_disabled_block_editor"><span class="mfis_icon">!</span><span class="mfis_error_message">' + json.error_message + '</span></div>';
     71                    // Display an error message at top of editor
     72                    if (!mfis_dismiss_error_messages) {
    6173
    62                 if (!$('.editor-post-featured-image img').hasClass('mfis_is_disabled')) {
     74                        wp.data.dispatch('core/notices').createInfoNotice(json.error_message, {
     75                            id: 'mfis_dismissible_error_message'
     76                        });
    6377
    64                     $('.editor-post-featured-image img').after(mfis_publishing_disabled_message).addClass('mfis_is_disabled');
    65                     $('.mfis_publishing_disabled_block_editor').hide().fadeIn();
     78                        mfis_dismiss_error_messages = true;
     79
     80                    }
     81
     82                    // Disable publishing
     83                    if (mfis.disable_publishing == 'publishing_disabled') {
     84
     85                        // Disable the Publish button
     86                        $('.editor-post-publish-button').attr('disabled', 'disabled').show();
     87
     88                        // Adding in the gutenberg lockPostSaving, though it doesn't actually lock
     89                        // saving, just adds an aria disabled attr, so the onclick event still works
     90                        wp.data.dispatch('core/editor').lockPostSaving('mfis_lock');
     91                    }
     92
     93                    // Set mfis_do_check to false
     94                    mfis_do_check = false;
     95                    mfis_image_passed = false;
     96
     97                } else {
     98
     99                    // Image passed, so let's reset things
     100                    mfis_reset_block_editor();
    66101
    67102                }
    68103
    69                 // Display an error message at top of editor
    70                 if (!mfis_dismiss_error_messages) {
     104            });
    71105
    72                     wp.data.dispatch('core/notices').createInfoNotice(json.error_message, {
    73                         id: 'mfis_dismissible_error_message'
    74                     });
     106        }
    75107
    76                     mfis_dismiss_error_messages = true;
     108    }
    77109
    78                 }
    79110
    80                 // Disable publishing
    81                 if (mfis.disable_publishing == 'publishing_disabled') {
     111    /**
     112     * Perform the image check
     113     */
     114    function mfis_check_image_block_editor() {
    82115
    83                     // Disable the Publish button
    84                     $('.editor-post-publish-button').attr('disabled', 'disabled').show();
     116        if (mfis_do_check) {
     117            mfis_do_ajax_block_editor(mfis_value);
     118        }
    85119
    86                     // Adding in the gutenberg lockPostSaving, though it doesn't actually lock
    87                     // saving, just adds an aria disabled attr, so the onclick event still works
    88                     wp.data.dispatch('core/editor').lockPostSaving('mfis_lock');
    89                 }
     120    }
    90121
    91                 // Set mfis_do_check to false
    92                 mfis_do_check = false;
    93                 mfis_image_passed = false;
    94122
    95             } else {
     123    /**
     124     * Subscribe to the featured_image data, to detect changes
     125     */
     126    wp.data.subscribe(function () {
    96127
    97                 // Image passed, so let's reset things
    98                 mfis_reset_block_editor();
     128        wp.domReady(function () {
    99129
    100             }
     130            mfis_value = (wp.data.select('core/editor').getEditedPostAttribute('featured_media')) ? wp.data.select('core/editor').getEditedPostAttribute('featured_media') : mfis_value;
     131
     132            mfis_do_check = true;
    101133
    102134        });
    103135
    104     }
    105 
    106 }
    107 
    108 
    109 /**
    110  * Perform the image check
    111  */
    112 function mfis_check_image_block_editor() {
    113 
    114     if (mfis_do_check) {
    115         mfis_do_ajax_block_editor(mfis_value);
    116     }
    117 
    118 }
    119 
    120 
    121 /**
    122  * Subscribe to the featured_image data, to detect changes
    123  */
    124 wp.data.subscribe(function () {
    125 
    126     wp.domReady(function () {
    127 
    128         mfis_value = (wp.data.select('core/editor').getEditedPostAttribute('featured_media')) ? wp.data.select('core/editor').getEditedPostAttribute('featured_media') : mfis_value;
    129 
    130         mfis_do_check = true;
    131 
    132136    });
    133137
    134 });
    135 
    136 
    137 jQuery(function ($) {
    138138
    139139    // Do initial check on page load, and then keep checking
  • minimum-featured-image-size/trunk/admin/mfis-admin-scripts.js

    r2005148 r2022083  
    1 /**
    2  * Initialise some variables
    3  */
    4 var mfis_value = -1,
    5     previous_value = '';
     1jQuery(function ($) {
     2
     3    /**
     4     * Initialise some variables
     5     */
     6    var mfis_value = -1,
     7        previous_value = '';
    68
    79
    8 /**
    9  * Check the image via ajax
    10  * @param {number} image_id
    11  */
    12 function mfis_do_ajax(image_id) {
     10    /**
     11     * Check the image via ajax
     12     * @param {number} image_id
     13     */
     14    function mfis_do_ajax(image_id) {
    1315
    14     if (image_id != -1) {
     16        if (image_id != -1) {
    1517
    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         };
     18            var data = {
     19                action: 'mfis_get_size_from_id',
     20                image_id: image_id,
     21                post_type: mfis.post_type,
     22                editor: 'classic',
     23            };
    2224
    23         $.post(ajaxurl, data, function (response) {
     25            $.post(ajaxurl, data, function (response) {
    2426
    25             var json = JSON.parse(response);
     27                var json = JSON.parse(response);
    2628
    27             if (json.image_check == 'fail') {
     29                if (json.image_check == 'fail') {
    2830
    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                    // Add error message
     32                    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>';
    3133
    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();
     34                    if (!$('#postimagediv .inside img').hasClass('mfis_is_disabled')) {
     35                        $('#postimagediv .inside img, #major-publishing-actions').after(mfis_publishing_disabled_message).addClass('mfis_is_disabled');
     36                        $('.mfis_publishing_disabled').hide().fadeIn();
     37                    }
     38
     39                } else {
     40
     41                    // Image passed, so let's reset things
     42                    mfis_reset();
     43
    3544                }
    3645
    37             } else {
     46            });
    3847
    39                 // Image passed, so let's reset things
    40                 mfis_reset();
     48        }
     49
     50    }
     51
     52
     53    /**
     54     * Reset all things mfis
     55     */
     56    function mfis_reset() {
     57
     58        if (mfis.disable_publishing == 'publishing_disabled') $('#publishing-action input[type="submit"]').removeAttr('disabled').show();
     59
     60        $('.mfis_publishing_disabled').fadeOut(500, function () {
     61            $('.mfis_publishing_disabled').remove();
     62            $('#postimagediv .inside img').removeClass('mfis_is_disabled');
     63        });
     64
     65        mfis_value = '';
     66
     67    }
     68
     69
     70    /**
     71     * Do the mfis check
     72     */
     73    function mfis_check_image() {
     74
     75        // Check if there is an input with the image ID
     76        if ($('#_thumbnail_id').length > 0 && $('#_thumbnail_id').val() >= 0) {
     77
     78            // Compare it to the previous value
     79            mfis_value = $('#_thumbnail_id').val();
     80
     81            if (mfis_value != previous_value) {
     82
     83                // Value has changed, so let's disable the Publish button and do the ajax
     84                if (mfis.disable_publishing == 'publishing_disabled') $('#publishing-action input[type="submit"]').attr('disabled', 'disabled').show();
     85
     86                mfis_do_ajax(mfis_value);
    4187
    4288            }
    4389
    44         });
     90            previous_value = mfis_value;
     91
     92        } else {
     93
     94            // There's no image ID input present, so reset things
     95            mfis_reset();
     96
     97        }
    4598
    4699    }
    47100
    48 }
    49101
    50 
    51 /**
    52  * Reset all things mfis
    53  */
    54 function mfis_reset() {
    55 
    56     if (mfis.disable_publishing == 'publishing_disabled') $('#publishing-action input[type="submit"]').removeAttr('disabled').show();
    57 
    58     $('.mfis_publishing_disabled').fadeOut(500, function () {
    59         $('.mfis_publishing_disabled').remove();
    60         $('#postimagediv .inside img').removeClass('mfis_is_disabled');
    61     });
    62 
    63     mfis_value = '';
    64 
    65 }
    66 
    67 
    68 /**
    69  * Do the mfis check
    70  */
    71 function mfis_check_image() {
    72 
    73     // Check if there is an input with the image ID
    74     if ($('#_thumbnail_id').length > 0 && $('#_thumbnail_id').val() >= 0) {
    75 
    76         // Compare it to the previous value
    77         mfis_value = $('#_thumbnail_id').val();
    78 
    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 {
    91 
    92         // There's no image ID input present, so reset things
    93         mfis_reset();
    94 
    95     }
    96 
    97 }
    98 
    99 
    100 jQuery(function ($) {
    101102
    102103    if (mfis.disable_ajax != 'ajax_disabled') {
  • minimum-featured-image-size/trunk/mfis.php

    r2005148 r2022083  
    33Plugin Name: Minimum Featured Image Size
    44Description: Set the minimum size required for featured images used in standard and custom posts.
    5 Version:     2.0
     5Version:     2.0.1
    66Author:      Martin Stewart
    77Author URI:  https://www.corgdesign.com
     
    3333
    3434    # admin javascript
    35     wp_register_script( 'mfis-admin-js', plugins_url('admin/mfis-admin-scripts.min.js', __FILE__ ), array( 'jquery' ), false, true );
     35    wp_register_script( 'mfis-admin-js', plugins_url('admin/mfis-admin-scripts.js', __FILE__ ), array( 'jquery' ), false, true );
    3636   
    3737    # Localize the script and pass in the post type
     
    6363   
    6464    # 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 );
     65    wp_register_script( 'mfis-adminblock-editor-js', plugins_url('admin/mfis-admin-block-editor-scripts.js', __FILE__ ), array( 'jquery' ), false, true );
    6666   
    6767    # Localize the script and pass in the post type
Note: See TracChangeset for help on using the changeset viewer.