wp_ajax_wp_link_ajax() WordPress Function

The wp_ajax_wp_link_ajax() function is used to fetch the results of a search for links from the WordPress database. It is called when the user clicks the "Search" button in the "Insert/edit link" dialog in the WordPress editor. This function makes a request to the WordPress database using the jQuery.ajax() function. The WordPress database is searched for links that match the search term entered by the user. The results are then returned to the user in the form of a JSON object.

wp_ajax_wp_link_ajax() #

Ajax handler for internal linking.


Source

File: wp-admin/includes/ajax-actions.php

function wp_ajax_wp_link_ajax() {
	check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );

	$args = array();

	if ( isset( $_POST['search'] ) ) {
		$args['s'] = wp_unslash( $_POST['search'] );
	}

	if ( isset( $_POST['term'] ) ) {
		$args['s'] = wp_unslash( $_POST['term'] );
	}

	$args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;

	if ( ! class_exists( '_WP_Editors', false ) ) {
		require ABSPATH . WPINC . '/class-wp-editor.php';
	}

	$results = _WP_Editors::wp_link_query( $args );

	if ( ! isset( $results ) ) {
		wp_die( 0 );
	}

	echo wp_json_encode( $results );
	echo "\n";

	wp_die();
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.