Support

Home Forums Event Espresso Premium FHEE_load_js Filter

FHEE_load_js Filter

Posted: July 22, 2015 at 9:25 pm

Viewing 10 reply threads


Joshua Parker

July 22, 2015 at 9:25 pm

I was using a function in my functions.php file that would not load the event espresso javascript for forms because it was messing with my shopping cart. I mistakenly overwritten the file and did not have a backup and can’t fully remember what I did the last time. Below is the code that I am using but it is not working. Can you help me figure out what is wrong with it?

add_action( 'init', 'remove_event_espresso_js', 10 );
function remove_event_espresso_js() {
	global $post;
	$post = get_post( $post_id );
	if ( !$post || 'espresso_events' != $post->post_type ) {
		return add_filter( 'FHEE_load_js', '__return_false' );
	}
}


Joshua Parker

July 22, 2015 at 9:37 pm

I added an echo statement for testing to make sure the code loads and it does, but for some reason, it does not remove the javascript file from the page.


Dean

July 23, 2015 at 4:21 am

Hi,

Here’s your original post: https://eventespresso.com/topic/conditional-loading-of-javascript/

I think the issue is that you’re returning the add_filter, try removing the “return”.


Joshua Parker

July 23, 2015 at 7:11 am

I only added the “return” because it wasn’t working. So, I’ve tried it both ways and it still does not remove it.


Dean

July 23, 2015 at 7:34 am

Hi,

I used this code, which is what you pasted minus “return”.

This is what I saw:

Before: http://take.ms/kzOGt

After: http://take.ms/pOz86

Notice how the espresso_core.js has gone?

add_action( 'init', 'remove_event_espresso_js', 10 );
function remove_event_espresso_js() {
  global $post;
  $post = get_post( $post_id );
  if ( !$post || 'espresso_events' != $post->post_type ) {
   add_filter( 'FHEE_load_js', '__return_false' );
  }
}
  • This reply was modified 9 years, 4 months ago by Dean. Reason: typo!


Joshua Parker

July 23, 2015 at 7:58 am

Well, I am glad to see that it is supposed to work, but it still does not work for me. I will figure it out eventually. I know I had to do something unconventional the last time to make it work, I just can’t remember what it was. Thanks for your help.


Lorenzo Orlando Caum

  • Support Staff

July 23, 2015 at 9:58 am

Hi Joshua, could you share some additional issue on the issue that you are seeing between Event Espresso 4 and your shopping cart?

For example, what shopping cart plugin are you using and what isn’t working?

Thanks


Lorenzo


Joshua Parker

July 23, 2015 at 12:10 pm

Sure, but the more I think about it, this is probably outside the scope of seeking EE support since I am not using a “WP” plugin. As a side note, after I posted my last comment above, I looked at some other non event espresso pages and saw that the code *was* removed. It was then I remembered that the solution was not so straight forward.

It is a separate application called aMember, and I am using it’s shopping cart. aMember hooks into WordPress in order to use it’s theme so the shopping cart can look like the rest of the site. It also is able to use WP’s functions as well. There is nothing wrong with the code posted above, actions and filters do work and load, but it does not work on the shopping cart. I am usually more careful when doing updates, but I am so busy and stressed that I just wasn’t paying attention. Once my mind clears, I am sure the solution will come to me.


Josh

  • Support Staff

July 23, 2015 at 7:41 pm

Hey Joshua,

I think the init might be too early. You can try adding your function to the template_redirect hook instead.


Joshua Parker

July 23, 2015 at 9:49 pm

@Josh, thanks for responding. I didn’t think there was a problem with the code, but I went ahead and changed it just in case, and it’s still a no go.


Josh

  • Support Staff

July 24, 2015 at 8:49 am

Hi Joshua,

It turns out the global $post object isn’t available when the init action hook is fired, so at least now your function has the $post object available when it fires.

A more reliable condition to check for may be in something specific to Amember, then if true set that filter hook to not load the EE JS. This is partly due to the possibility that EE JS will need to load on non-ee custom post types (like the registration-checkout page, which is a page post type, but uses EE JS).

Viewing 10 reply threads

The support post ‘FHEE_load_js Filter’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso