Make WordPress Core

Ticket #49905: 49905.diff

File 49905.diff, 3.8 KB (added by SergeyBiryukov, 5 years ago)
  • src/wp-includes/functions.php

     
    722722}
    723723
    724724/**
    725  * Retrieve post title from XMLRPC XML.
     725 * Retrieves post title from XML-RPC XML.
    726726 *
    727  * If the title element is not part of the XML, then the default post title from
    728  * the $post_default_title will be used instead.
     727 * If the title element is not found, the default post title
     728 * from the $post_default_title global will be used instead.
    729729 *
    730730 * @since 0.71
    731731 *
    732732 * @global string $post_default_title Default XML-RPC post title.
    733733 *
    734  * @param string $content XMLRPC XML Request content
    735  * @return string Post title
     734 * @param string $content XML-RPC XML request content.
     735 * @return string Post title.
    736736 */
    737737function xmlrpc_getposttitle( $content ) {
    738738        global $post_default_title;
     739
     740        if ( ! isset( $post_default_title ) ) {
     741                $post_default_title = '';
     742        }
     743
    739744        if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) {
    740745                $post_title = $matchtitle[1];
    741746        } else {
    742747                $post_title = $post_default_title;
    743748        }
     749
    744750        return $post_title;
    745751}
    746752
    747753/**
    748  * Retrieve the post category or categories from XMLRPC XML.
     754 * Retrieves the post category or categories from XML-RPC XML.
    749755 *
    750  * If the category element is not found, then the default post category will be
    751  * used. The return type then would be what $post_default_category. If the
    752  * category is found, then it will always be an array.
     756 * If the category element is not found, the default post category
     757 * from the $post_default_category global will be used instead.
    753758 *
    754759 * @since 0.71
    755760 *
    756  * @global string $post_default_category Default XML-RPC post category.
     761 * @global int $post_default_category Default XML-RPC post category ID.
    757762 *
    758  * @param string $content XMLRPC XML Request content
    759  * @return string|array List of categories or category name.
     763 * @param string $content XML-RPC XML request content.
     764 * @return int[] Array of category IDs.
    760765 */
    761766function xmlrpc_getpostcategory( $content ) {
    762767        global $post_default_category;
     768
     769        if ( ! isset( $post_default_category ) ) {
     770                $post_default_category = (int) get_option( 'default_category' );
     771        }
     772
    763773        if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) {
    764774                $post_category = trim( $matchcat[1], ',' );
    765                 $post_category = explode( ',', $post_category );
     775                $post_category = array_map( 'intval', explode( ',', $post_category ) );
    766776        } else {
    767                 $post_category = $post_default_category;
     777                $post_category = array( $post_default_category );
    768778        }
     779
    769780        return $post_category;
    770781}
    771782
    772783/**
    773  * XMLRPC XML content without title and category elements.
     784 * XML-RPC XML content without title and category elements.
    774785 *
    775786 * @since 0.71
    776787 *
    777  * @param string $content XML-RPC XML Request content.
    778  * @return string XMLRPC XML Request content without title and category elements.
     788 * @param string $content XML-RPC XML request content.
     789 * @return string XML-RPC XML request content without title and category elements.
    779790 */
    780791function xmlrpc_removepostdata( $content ) {
    781792        $content = preg_replace( '/<title>(.+?)<\/title>/si', '', $content );
    782793        $content = preg_replace( '/<category>(.+?)<\/category>/si', '', $content );
    783794        $content = trim( $content );
     795
    784796        return $content;
    785797}
    786798
  • src/xmlrpc.php

     
    6565require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
    6666
    6767/**
    68  * Posts submitted via the XML-RPC interface get that title
    69  *
    70  * @name post_default_title
    71  * @var string
    72  */
    73 $post_default_title = '';
    74 
    75 /**
    7668 * Filters the class used for handling XML-RPC requests.
    7769 *
    7870 * @since 3.1.0