diff --git a/src/wp-admin/admin-ajax.php b/src/wp-admin/admin-ajax.php index a06e7df56c..e0f4464d94 100644 --- a/src/wp-admin/admin-ajax.php +++ b/src/wp-admin/admin-ajax.php @@ -64,7 +64,7 @@ $core_actions_post = array( 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', - 'install-theme', 'test_url', 'get-post-thumbnail-html', + 'install-theme', 'get-post-thumbnail-html', ); // Deprecated diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index dad9deaebe..e91b522227 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3886,46 +3886,3 @@ function wp_ajax_search_install_plugins() { wp_send_json_success( $status ); } - -/** - * Ajax handler for testing if a URL exists. - * - * Used in the editor. - * - * @since 4.6.0 - */ -function wp_ajax_test_url() { - if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( $_POST['nonce'], 'wp-test-url' ) ) { - wp_send_json_error(); - } - - $href = esc_url_raw( $_POST['href'] ); - - // Relative URL - if ( strpos( $href, '//' ) !== 0 && in_array( $href[0], array( '/', '#', '?' ), true ) ) { - $href = get_bloginfo( 'url' ) . $href; - } - - // No redirects - $response = wp_safe_remote_get( $href, array( - 'timeout' => 15, - // Use an explicit user-agent - 'user-agent' => 'WordPress URL Test', - ) ); - - $error = false; - - if ( is_wp_error( $response ) ) { - if ( strpos( $response->get_error_message(), 'resolve host' ) !== false ) { - $error = true; - } - } elseif ( wp_remote_retrieve_response_code( $response ) === 404 ) { - $error = true; - } - - if ( $error ) { - wp_send_json_error( array( 'httpError' => true ) ); - } - - wp_send_json_success(); -} diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 85d943c972..f0290b0f1b 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -1065,7 +1065,7 @@ final class _WP_Editors { 'Ctrl + letter:' => __( 'Ctrl + letter:' ), 'Letter' => __( 'Letter' ), 'Action' => __( 'Action' ), - 'Warning: the link has been inserted but the destination cannot be reached.' => __( 'Warning: the link has been inserted but the destination cannot be reached.' ), + 'Warning: the link has been inserted but may have errors. Please test it.' => __( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' => __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ), 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' => @@ -1286,13 +1286,7 @@ final class _WP_Editors { '; - } - - if ( $has_wplink || in_array( 'link', self::$qt_buttons, true ) ) { + if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) { self::wp_link_dialog(); } diff --git a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js index 8ba459a581..1ce1c926c1 100644 --- a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -93,8 +93,9 @@ var doingUndoRedo; var doingUndoRedoTimer; var $ = window.jQuery; - var urlErrors = {}; var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i; + var urlRegex1 = /^https?:\/\/([^\s/?.#-][^\s\/?.#]*\.?)+(\/[^\s"]*)?$/i; + var urlRegex2 = /^https?:\/\/[^\/]+\.[^\/]+($|\/)/i; var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {}; var hasLinkError = false; @@ -150,16 +151,6 @@ }); } - function setLinkError( $link ) { - hasLinkError = true; - $link.attr( 'data-wplink-url-error', 'true' ); - speak( editor.translate( 'Warning: the link has been inserted but the destination cannot be reached.' ), 'assertive' ); - - if ( toolbar && toolbar.visible() ) { - toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ); - } - } - function checkLink( node ) { var $link = editor.$( node ); var href = $link.attr( 'href' ); @@ -170,34 +161,13 @@ hasLinkError = false; - if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) { - urlErrors[href] = true; - } - - if ( urlErrors.hasOwnProperty( href ) ) { - setLinkError( $link ); - return; + if ( /^http/i.test( href ) && ( ! urlRegex1.test( href ) || ! urlRegex2.test( href ) ) ) { + hasLinkError = true; + $link.attr( 'data-wplink-url-error', 'true' ); + speak( editor.translate( 'Warning: the link has been inserted but may have errors. Please test it.' ), 'assertive' ); } else { $link.removeAttr( 'data-wplink-url-error' ); } - - $.post( - window.ajaxurl, { - action: 'test_url', - nonce: $( '#_wplink_urltest_nonce' ).val(), - href: href - }, - 'json' - ).done( function( response ) { - if ( response.success ) { - return; - } - - if ( response.data && response.data.httpError ) { - urlErrors[href] = true; - setLinkError( $link ); - } - }); } editor.on( 'preinit', function() {