Make WordPress Core

Ticket #36765: 36765.diff

File 36765.diff, 3.3 KB (added by dshanske, 8 years ago)
  • src/wp-includes/class-wp-xmlrpc-server.php

    diff --git a/src/wp-includes/class-wp-xmlrpc-server.php b/src/wp-includes/class-wp-xmlrpc-server.php
    index 531dd50..a17c7da 100644
    a b class wp_xmlrpc_server extends IXR_Server { 
    62316231                if ( !$pos1 )
    62326232                        return $this->pingback_error( 0, __( 'Is there no link to us?' ) );
    62336233
    6234                 // let's find which post is linked to
    6235                 // FIXME: does url_to_postid() cover all these cases already?
    6236                 //        if so, then let's use it and drop the old code.
    6237                 $urltest = parse_url($pagelinkedto);
    6238                 if ( $post_ID = url_to_postid($pagelinkedto) ) {
    6239                         // $way
    6240                 } elseif ( isset( $urltest['path'] ) && preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) {
    6241                         // the path defines the post_ID (archives/p/XXXX)
    6242                         $blah = explode('/', $match[0]);
    6243                         $post_ID = (int) $blah[1];
    6244                 } elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) {
    6245                         // the querystring defines the post_ID (?p=XXXX)
    6246                         $blah = explode('=', $match[0]);
    6247                         $post_ID = (int) $blah[1];
    6248                 } elseif ( isset($urltest['fragment']) ) {
    6249                         // an #anchor is there, it's either...
    6250                         if ( intval($urltest['fragment']) ) {
    6251                                 // ...an integer #XXXX (simplest case)
    6252                                 $post_ID = (int) $urltest['fragment'];
    6253                         } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) {
    6254                                 // ...a post id in the form 'post-###'
    6255                                 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
    6256                         } elseif ( is_string($urltest['fragment']) ) {
    6257                                 // ...or a string #title, a little more complicated
    6258                                 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
    6259                                 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title );
    6260                                 if (! ($post_ID = $wpdb->get_var($sql)) ) {
    6261                                         // returning unknown error '0' is better than die()ing
    6262                                         return $this->pingback_error( 0, '' );
    6263                                 }
    6264                         }
    6265                 } else {
    6266                         // TODO: Attempt to extract a post ID from the given URL
    6267                         return $this->pingback_error( 33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
    6268                 }
     6234                $post_ID = url_to_postid( $pagelinkedto );
    62696235                $post_ID = (int) $post_ID;
    62706236
    6271                 $post = get_post($post_ID);
     6237                if ( 0 == $post_ID ) // Post_ID not found
     6238                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
    62726239
    6273                 if ( !$post ) // Post_ID not found
    6274                         return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
    6275 
    6276                 if ( $post_ID == url_to_postid($pagelinkedfrom) )
     6240                if ( $post_ID == url_to_postid( $pagelinkedfrom ) )
    62776241                        return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) );
    62786242
     6243                $post = get_post($post_ID);
     6244
    62796245                // Check if pings are on
    6280                 if ( !pings_open($post) )
     6246                if ( ! pings_open( $post ) )
    62816247                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
    62826248
    62836249                // Let's check that the remote site didn't already pingback this entry