Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On posts list: "Uncaught ReferenceError: coAuthorsPlus_ajax_suggest_link is not defined" #1037

Closed
kwisatz opened this issue Apr 25, 2024 · 1 comment · Fixed by #1038
Closed

Comments

@kwisatz
Copy link

kwisatz commented Apr 25, 2024

I'll add more information here as I find any. After the 3.6.0 update, we're seeing this error on the posts list, preventing any other scripts from running:

Uncaught ReferenceError: coAuthorsPlus_ajax_suggest_link is not defined
    at HTMLDocument.<anonymous> (co-authors-plus.js?ver=3.6.0:356:30)
    at HTMLDocument.dispatch (jquery.min.js?ver=3.7.1:2:40035)
    at v.handle (jquery.min.js?ver=3.7.1:2:38006)
    at Object.trigger (jquery.min.js?ver=3.7.1:2:70124)
    at Function.ajax (jquery.min.js?ver=3.7.1:2:76037)
    at Function.<anonymous> (jquery-migrate.min.js?ver=3.4.1:2:4771)
    at e.<computed> [as ajax] (jquery-migrate.min.js?ver=3.4.1:2:1582)
    at HTMLTableSectionElement.update (cpt.js?ver=6.5.2:48:68)
    at x.<computed>.<computed>._trigger (core.min.js?ver=1.13.2:116:7687)
    at x.<computed>.<computed>._trigger (sortable.min.js?ver=1.13.2:9:25015)

Code in question is this:

// Show loading cursor for autocomplete ajax requests
	jQuery( document ).ajaxSend(function( e, xhr, settings ) {
		if ( settings.url.indexOf( coAuthorsPlus_ajax_suggest_link ) != -1 ) {
			// Including existing authors on the AJAX suggest link
			// allows us to filter them out of the search request
			var existing_authors = jQuery( 'input[name="coauthors[]"]' ).map(function(){return jQuery( this ).val();}).get();
			settings.url = settings.url.split( '&existing_authors' )[0];
			settings.url += '&existing_authors=' + existing_authors.join( ',' );
			show_loading();
		}
	});

I can see the variable gets defined here

var coAuthorsPlus_ajax_suggest_link =
but this code doesn't seem to run for the posts list, at least not in our case.

@kwisatz
Copy link
Author

kwisatz commented Apr 25, 2024

$this->is_post_type_enabled() is returning false in our case, despite the settings now having been touched and showing that the functionality is enabled for Posts.

I've added debug statements and can see that at some point, while the array of enabled post types has been 'post' and 'page' for a while, 'post' suddenly gets dropped. (Just before the closing </head>, which is where the variable would be output).

So I'm guessing the coauthors_supported_post_types filter runs at some point and removes the post post type from the list of supported types.

I will stop here for lack of time. IMHO, even if there is a reason for the filter to remove 'post' from the supported types, the javascript code should make sure that the variable is defined before using it and/or the file should only be enqueued if the post type is supported. The former is probably easier to achieve than the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant