osompress / genesis-simple-share

Plugin: Genesis Simple Share
36 stars 16 forks source link

Waypoint.js not enqueued if site uses static front page and includes front-page.php #65

Closed nickcernis closed 6 years ago

nickcernis commented 8 years ago

The following setup causes an Uncaught TypeError: $(...).waypoint is not a function error:

Adding is_front_page() to the is_archive check in front-end.php seems to solve this:

function is_archive() {
    if( is_home() || is_archive() || is_search() || is_page_template('page_blog.php') || is_front_page() )
        return true;
    return false;
}

Combined with #49 I think the archive check needs to read:

is_home() || is_archive() || is_search() || is_page_template('page_blog.php') || is_front_page() || is_customize_preview()
nickcernis commented 8 years ago

We've also had reports of this waypoint error with sites that use Genesis Simple Share and plugins that allow posts to be embedded within posts, such as Content Views Pro. The error causes all other JS on the page to break, which prevents Content Views Pro from loading.

Maybe it would be better to enqueue waypoint.js unconditionally to prevent issues with edge cases like these?

if( $this->is_archive() ) { // Remove this check?
    wp_enqueue_script( 'genesis-simple-share-waypoint-js' );
}
carasmo commented 8 years ago

+1 please fix. Thanks!

nickcernis commented 8 years ago

We still see reports of the waypoint is not a function error, which causes other scripts on the page to fail. e.g. https://wordpress.org/support/topic/waypoints?replies=11

@NicktheGeek How do you feel about a pull request to unconditionally enqueue waypoints.min.js? The file is only 8kb. We're seeing the buttons appear on pages they weren't originally envisioned to be used on. Loading the JS everywhere to prevent the waypoint error seems worthwhile to me.

dreamwhisper commented 7 years ago

@NicktheGeek thoughts on https://github.com/copyblogger/genesis-simple-share/issues/65#issuecomment-239617877?

This comes up pretty often.

NicktheGeek commented 7 years ago

I hate to enqueue it all the time. Ideally I'd rather fix the is_archive() method but I think another good solution is to update the code to make sure the function is available before trying to use it and put a filter into the is_archive() method so if a theme author/plugin author wants to make a page that is an archive but doesn't return true in the function in this plugin it can be made to.

This solves the function not found error but allows the additional script to not load unless needed so things stay as clean and efficient as possible.

NicktheGeek commented 7 years ago

I did a quick patch based on the above notes. It is in the develop_65_nc and develop branches if someone wants to give it a spin. I need to see if we can get this into 2.9 before putting it into the rainmaker-develop branch for RM testing.

katyfb13 commented 7 years ago

@nickcernis or @dreamwhisper can you see if Nick's fix works?

nickcernis commented 7 years ago

Tested the updated version – it solves the issue above and https://github.com/copyblogger/genesis-simple-share/issues/49, but share buttons no longer appear on any archive page for me with “Show on Archive Pages” ticked.

uncategorized genesis_simple_share_settings_ _wp_ _wordpress
srikat commented 7 years ago

Want to report that

Uncaught TypeError: $(...).waypoint is not a function(…)

also appears on the front page in this scenario:

a) Settings > Reading: Default i.e., front page set to show latest blog posts.

b) Genesis > Simple Share:

screenshot

c) home.php having this code:

add_action( 'genesis_entry_content', 'sk_featured_post_social' );
function sk_featured_post_social() {
    if ( function_exists( 'genesis_share_icon_output' ) ) {
        global $Genesis_Simple_Share;
        genesis_share_icon_output( 'featured-post', $Genesis_Simple_Share->icons );
    }
}
gspice commented 7 years ago

Still geting this in Utility Pro which uses a static page and front-page.php and has posts on the homepage.

NicktheGeek commented 7 years ago

Genesis Simple Share

dreamwhisper commented 7 years ago

Confirmed x3