reduxframework/redux-framework

wp-util.min.js Inclusion

richpeck opened this issue · 7 comments

Good afternoon everybody.

This is a question, not a bug (I've fixed it myself).

I tried using the icon-selector extension in my theme and kept receiving JS errors that window.wp.ajax was not present. Upon further inspection, it was apparent that the problem was wp-util.min.js was not included on the page. Version 6.2.2 of Wordpress etc.

I have fixed the problem by manually queuing the file in my theme.

Would you like me to create a PR to apply the fix I created or do you think it's better to leave as is?

--

Site Health Report

I could not find this.

Steps to reproduce

Use the icon-select extension in a dashboard panel.

Expected Behavior

When clicking on the Add Icon button, the popup should populate with the icons from FontAwesome etc.

Actual Behavior

It does not populate and an error in the JS console says that there is a problem using window.wp.ajax.

Any Error Details (PHP/JavaScript)

Uncaught TypeError: Cannot read properties of undefined (reading 'post') at HTMLAnchorElement.<anonymous> (redux-icon-select.min.js?ver=4.4.4:1:1549) at HTMLAnchorElement.dispatch (load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils&ver=6.2.2:2:43184) at y.handle (load-scripts.php?c=0&load%5Bchunk_0%5D=jquery-core,jquery-migrate,utils&ver=6.2.2:2:41168)

icons

The problem is caused by this line: -

It's trying to access window.wp.ajax.post when window.wp.ajax does not exist. It does not exist because wp-util.min.js is not included by Redux (at least in my implementation of it). I tried installing the Redux plugin and the same problem occurred.

Rich

wp-util is part of WordPress. I need to see your system health report: Instructions: In the WordPress Admin screen, click Settings, select Redux, click Info, and click "Copy site info to clipboard." Paste the results here.

Chances are these is some k ind of caching, minification, or preloading work here.

Thank you for the swift reply!

Unfortunately, I don't have that option.

redux

I installed the plugin and disabled my theme.

I installed the plugin on a naked version of Wordpress and the same screen shows on both.

Regarding it being caching problem, I don't think so. The wp-utils file was present when I was editing a post, which suggests to me that it's not being loaded on pages created by Redux. I managed to get it to work by enqueuing it manually.

--

When I enabled my theme again (which has Redux embedded), the following showed in the Settings > Redux page: -

redux1

The closest I could find to what you're requesting is inside the "Site Health" area, which I've sceenshotted here: -

screencapture-johnc449-sg-host-wp-admin-site-health-php-2023-07-28-17_35_32

I needed to see the plugin list. WP is supposed to be loading wp-util. There is a reason why it's not, and it's most often another plugin. Try disabling that Optimizing plugin and see if the issue continues.

Many thanks for the reply.

I already tried that when I first encountered the issue. Just tried again and the same error.

I also tried the plugin on a naked WP site (no other plugins) and the error occurred there too.

Rich

I'm running a barebones setup, too, and I can't recreate this.

Try this:

In the redux-framework plugin folder, edit this file: redux-core/inc/extensions/icon_select/icon_select/class-redux-icon-select.php

On line 388 to 394, replace the wp_enquque_script call with this:

wp_enqueue_script(
	'redux-field-icon-select',
	$this->url . 'redux-icon-select' . $min . '.js',
	array( 'jquery', 'redux-js', 'wp-util' ),
	Redux_Core::$version,
	true
);

Save the file and reload the option panel.

This should force the enqueueing of the wp-util file.

Thank you again.

Yes, that worked. As mentioned, I managed to find a solution myself which manually queued wp-util inside my theme.

Do you want me to submit a PR for your solution?

Rich

I got it. I have to push another fix with it. I appreciate it, though. 👍