Changeset 2022083
- Timestamp:
- 01/30/2019 04:41:05 PM (7 years ago)
- Location:
- minimum-featured-image-size/trunk
- Files:
-
- 2 deleted
- 3 edited
-
admin/mfis-admin-block-editor-scripts.js (modified) (1 diff)
-
admin/mfis-admin-block-editor-scripts.min.js (deleted)
-
admin/mfis-admin-scripts.js (modified) (1 diff)
-
admin/mfis-admin-scripts.min.js (deleted)
-
mfis.php (modified) (3 diffs)
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 = ''; 1 jQuery(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 = ''; 10 12 11 13 12 /**13 * Reset all things mfis in the block editor14 */15 function mfis_reset_block_editor() {14 /** 15 * Reset all things mfis in the block editor 16 */ 17 function mfis_reset_block_editor() { 16 18 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 21 37 } 22 38 23 // Remove error message from below image24 $('.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 });28 39 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) { 31 45 32 mfis_value = ''; 33 mfis_do_check = false; 46 if (image_id != -1) { 34 47 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 }; 36 54 55 $.post(ajaxurl, data, function (response) { 37 56 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); 43 58 44 if (image_id != -1) {59 if (json.image_check == 'fail') { 45 60 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>'; 52 63 53 $.post(ajaxurl, data, function (response) {64 if (!$('.editor-post-featured-image img').hasClass('mfis_is_disabled')) { 54 65 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(); 56 68 57 if (json.image_check == 'fail') {69 } 58 70 59 // Add error message60 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) { 61 73 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 }); 63 77 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(); 66 101 67 102 } 68 103 69 // Display an error message at top of editor 70 if (!mfis_dismiss_error_messages) { 104 }); 71 105 72 wp.data.dispatch('core/notices').createInfoNotice(json.error_message, { 73 id: 'mfis_dismissible_error_message' 74 }); 106 } 75 107 76 mfis_dismiss_error_messages = true;108 } 77 109 78 }79 110 80 // Disable publishing 81 if (mfis.disable_publishing == 'publishing_disabled') { 111 /** 112 * Perform the image check 113 */ 114 function mfis_check_image_block_editor() { 82 115 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 } 85 119 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 } 90 121 91 // Set mfis_do_check to false92 mfis_do_check = false;93 mfis_image_passed = false;94 122 95 } else { 123 /** 124 * Subscribe to the featured_image data, to detect changes 125 */ 126 wp.data.subscribe(function () { 96 127 97 // Image passed, so let's reset things 98 mfis_reset_block_editor(); 128 wp.domReady(function () { 99 129 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; 101 133 102 134 }); 103 135 104 }105 106 }107 108 109 /**110 * Perform the image check111 */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 changes123 */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 132 136 }); 133 137 134 });135 136 137 jQuery(function ($) {138 138 139 139 // 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 = ''; 1 jQuery(function ($) { 2 3 /** 4 * Initialise some variables 5 */ 6 var mfis_value = -1, 7 previous_value = ''; 6 8 7 9 8 /**9 * Check the image via ajax10 * @param {number} image_id11 */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) { 13 15 14 if (image_id != -1) {16 if (image_id != -1) { 15 17 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 }; 22 24 23 $.post(ajaxurl, data, function (response) {25 $.post(ajaxurl, data, function (response) { 24 26 25 var json = JSON.parse(response);27 var json = JSON.parse(response); 26 28 27 if (json.image_check == 'fail') {29 if (json.image_check == 'fail') { 28 30 29 // Add error message30 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>'; 31 33 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 35 44 } 36 45 37 } else {46 }); 38 47 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); 41 87 42 88 } 43 89 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 } 45 98 46 99 } 47 100 48 }49 101 50 51 /**52 * Reset all things mfis53 */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 check70 */71 function mfis_check_image() {72 73 // Check if there is an input with the image ID74 if ($('#_thumbnail_id').length > 0 && $('#_thumbnail_id').val() >= 0) {75 76 // Compare it to the previous value77 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 ajax82 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 things93 mfis_reset();94 95 }96 97 }98 99 100 jQuery(function ($) {101 102 102 103 if (mfis.disable_ajax != 'ajax_disabled') { -
minimum-featured-image-size/trunk/mfis.php
r2005148 r2022083 3 3 Plugin Name: Minimum Featured Image Size 4 4 Description: Set the minimum size required for featured images used in standard and custom posts. 5 Version: 2.0 5 Version: 2.0.1 6 6 Author: Martin Stewart 7 7 Author URI: https://www.corgdesign.com … … 33 33 34 34 # 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 ); 36 36 37 37 # Localize the script and pass in the post type … … 63 63 64 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 );65 wp_register_script( 'mfis-adminblock-editor-js', plugins_url('admin/mfis-admin-block-editor-scripts.js', __FILE__ ), array( 'jquery' ), false, true ); 66 66 67 67 # Localize the script and pass in the post type
Note: See TracChangeset
for help on using the changeset viewer.