Make WordPress Core


Ignore:
Timestamp:
07/26/2016 11:23:21 PM (8 years ago)
Author:
azaozz
Message:

TinyMCE, inline link:

  • Remove proxying through WordPress to test if an URL exists.
  • Fix and enhance the regex that tests if the URL is well formed.

Fixes #36638.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r38126 r38159  
    38873887    wp_send_json_success( $status );
    38883888}
    3889 
    3890 /**
    3891  * Ajax handler for testing if a URL exists.
    3892  *
    3893  * Used in the editor.
    3894  *
    3895  * @since 4.6.0
    3896  */
    3897 function wp_ajax_test_url() {
    3898     if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( $_POST['nonce'], 'wp-test-url' ) ) {
    3899         wp_send_json_error();
    3900     }
    3901 
    3902     $href = esc_url_raw( $_POST['href'] );
    3903 
    3904     // Relative URL
    3905     if ( strpos( $href, '//' ) !== 0 && in_array( $href[0], array( '/', '#', '?' ), true ) ) {
    3906         $href = get_bloginfo( 'url' ) . $href;
    3907     }
    3908 
    3909     // No redirects
    3910     $response = wp_safe_remote_get( $href, array(
    3911         'timeout' => 15,
    3912         // Use an explicit user-agent
    3913         'user-agent' => 'WordPress URL Test',
    3914     ) );
    3915 
    3916     $error = false;
    3917 
    3918     if ( is_wp_error( $response ) ) {
    3919         if ( strpos( $response->get_error_message(), 'resolve host' ) !== false ) {
    3920             $error = true;
    3921         }
    3922     } elseif ( wp_remote_retrieve_response_code( $response ) === 404 ) {
    3923         $error = true;
    3924     }
    3925 
    3926     if ( $error ) {
    3927         wp_send_json_error( array( 'httpError' => true ) );
    3928     }
    3929 
    3930     wp_send_json_success();
    3931 }
Note: See TracChangeset for help on using the changeset viewer.