Gutenberg RangeControl

When using a control that modifies a block attribute, you need to set the value of the control to the value of the attribute and the onChange function needs to change the attribute using the setAttributes function: el( RangeControl, { label: ‘Columns’, value: props.attributes.my_attribute, initialPosition: 1, min: 0, max: 3, onChange: function( val ) { … Read more

Unable To Call Javascript With Enqueue

In WP jQuery works in compatibility mode by default. It means that the typical $ shortcut for jQuery doesn’t work, so it doesn’t conflict with any other JavaScript libraries that use the dollar sign also, like MooTools or Prototype. So you should use jQuery instead of $ in your JS file. Of course you can … Read more

Update media library attachments

edit: ok after working on this for the last hour ive finally found a solution that works without affecting uploading and without messing with ignore or reset wp.media.frame.on(‘open’, function() { if (wp.media.frame.content.get() !== null) { // this forces a refresh of the content wp.media.frame.content.get().collection._requery(true); // optional: reset selection wp.media.frame.content.get().options.selection.reset(); } }, this);

How to read inline-CSS from Gutenberg block?

Turns out Gutenberg has another way of storing attribute values: the block’s comment delimiter: If no attribute source is specified, the attribute will be saved to (and read from) the block’s comment delimiter. source When I inspected the database entry, I indeed found the size attribute there: <!– wp:XXX {“size”:48} –> <div>…</div> <!– /wp:XXX –> … Read more

Hide Load more Ajax button if there is no more users to load or less than the number?

I think something like this may work, if response is just HTML and returns an empty string ” when there are no more results: <script type=”text/javascript”> var ajaxurl = “<?php echo admin_url( ‘admin-ajax.php’ ); ?>”; var page = 2; jQuery(function($) { $(‘body’).on(‘click’, ‘.loadmorefollowing’, function() { var data = { ‘action’: ‘user_following_by_ajax’, ‘page’: page, ‘security’: ‘<?php … Read more

wp_mail doesn’t work when logged in?

You’ve got a typo in the hook that runs for logged in users: add_action(‘wp_ajax_search_notify_emaill’, ‘search_notify_email’); There’s an extra l in the hook name. The hook names need to be the same, apart from nopriv_, so you should have: add_action(‘wp_ajax_nopriv_search_notify_email’, ‘search_notify_email’); add_action(‘wp_ajax_search_notify_email’, ‘search_notify_email’); When you send an AJAX request with an action WordPress runs the hook … Read more

Enable right click on WordPress site

This isn’t something WordPress is doing but probably your theme. Perhaps it’s an attempt to get people to not download your images or code, this is basically useless and doesn’t prevent anything like that. Your theme might be using something similar to this… document.addEventListener(‘contextmenu’, event => event.preventDefault()); Try searching your theme files for contextmenu and … Read more

WordPress 5.1 upgrade has lost the parent theme JavaScript

I traced this back to the name of the scripts.js JavaScript file. My parent theme (BeTheme) enqueues the main scripts.js like this: wp_enqueue_script(‘mfn-scripts’, get_theme_file_uri(‘/js/scripts.js’), array(‘jquery’), MFN_THEME_VERSION, true); In my child theme crmpiccodotcom/footer.php I enqueue the scripts.js like this: // include the crmpiccodotcom child theme JavaScript add_action(‘wp_enqueue_scripts’, ‘crmpiccodotcom_enqueue_scripts’); function crmpiccodotcom_enqueue_scripts() { wp_enqueue_script( ‘custom-script’, CHILD_THEME_URI. ‘/js/scripts.js’, array(‘jquery’) … Read more