Mentions AJAX Dropdown for WordPress is a lightweight plugin that enables you to easily find and mention users while writing in bbPress, BuddyPress, and even in the admin dashboard post editor.

 

This plugin can work as an autosuggestion and autocomplete after typing the at sign/symbol (@), listing the matching users if any query is after @ or all if no query entered (just an @) paginated in form of a dropdown.

Requirements:

Although the plugin states bbPress and BuddyPress in the title, none of these plugins are required in order for Mentions AJAX Dropdown to work, as you can implement it to work with other fields whether in the admin or front-end, as it is quite easier to integrate it.

When it comes to technical requirements, this plugin requires at least PHP 5.3, and can work with any latest WordPress install.

Features:

Mentions AJAX dropdown is lightweight and users query is cached, so you wouldn’t worry about performance and it loads faster!

It is also easy to integrate to work with other fields, easy to extend and fully customizable.

Custom Integration:

Integrating Mentions AJAX Dropdown is simple and easy, to implement it to work with extra fields or other plugins.

Using plugin settings:

You can navigate to the plugin settings interface, going to Dashboard > Options > Mentions Dropdown, and check “Show advanced settings” then, in “Targeted Fields” setting, add the DOM selector for the fields you want to add mentions dropdown feature to.

An example, I have a text box with id attribute set to “my-text” added to the bottom of each post, and I want to enable mentions dropdown on it, I will simply go to settings and add #my-text  after a comma onto the previously mention setting.

Using jQuery plugin:

Mentions AJAX Dropdown plugin comes with a custom jQuery plugin you can use;

jQuery(target).mentionsDropdown();

Just insert your elements selector (for fields to target) in the jQuery argument and make sure to enqueue this line of JavaScript.

Making sure all scripts and assets are enqueued:

By default, the scripts required for Mentions AJAX Dropdown to function are queued only if:

  • On bbPress pages (if bbPress is active)
  • on BuddyPress pages (if BuddyPress is active)
  • In the admin if “Enable dropdown in admin editor” setting is checked.

If not enqueued, then you must enqueue them for your case (to use the jQuery plugin or enable mentions when no assets/scripts are loaded) with a custom code:

function loadMentionsScripts() {
	// making sure the plugin as active
	if ( !class_exists('\Bma\Includes\Plugin') ) return;
	// enqeueue scripts (JS,CSS)
	add_action("admin_enqueue_scripts", array( \Bma\Includes\Plugin::instance(), "enqueueScripts" ) );
	// allow scripts to be queued
	add_filter("bma_enqueue","__return_true");
}

// load scripts and assets
loadMentionsScripts();

The above code can be added to a custom plugin, or via your child theme’s functions file.