diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/class-wp-xmlrpc-server.php --- a/wp/wp-includes/class-wp-xmlrpc-server.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/class-wp-xmlrpc-server.php Fri Sep 05 18:40:08 2025 +0200 @@ -1,6 +1,6 @@ 'this:mw_getCategories', 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject', - // MetaWeblog API aliases for Blogger API. - // See http://www.xmlrpc.com/stories/storyReader$2460 + /* + * MetaWeblog API aliases for Blogger API. + * See http://www.xmlrpc.com/stories/storyReader$2460 + */ 'metaWeblog.deletePost' => 'this:blogger_deletePost', 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs', @@ -176,9 +179,9 @@ } /** - * Set wp_xmlrpc_server::$is_enabled property. - * - * Determine whether the xmlrpc server is enabled on this WordPress install + * Sets wp_xmlrpc_server::$is_enabled property. + * + * Determines whether the xmlrpc server is enabled on this WordPress install * and set the is_enabled property accordingly. * * @since 5.7.3 @@ -197,8 +200,8 @@ * Filters whether XML-RPC methods requiring authentication are enabled. * * Contrary to the way it's named, this filter does not control whether XML-RPC is *fully* - * enabled, rather, it only controls whether XML-RPC methods requiring authentication - such - * as for publishing purposes - are enabled. + * enabled, rather, it only controls whether XML-RPC methods requiring authentication - + * such as for publishing purposes - are enabled. * * Further, the filter does not control whether pingbacks or other custom endpoints that don't * require authentication are enabled. This behavior is expected, and due to how parity was matched @@ -219,7 +222,7 @@ } /** - * Make private/protected methods readable for backward compatibility. + * Makes private/protected methods readable for backward compatibility. * * @since 4.0.0 * @@ -244,7 +247,7 @@ } /** - * Test XMLRPC API by saying, "Hello!" to client. + * Tests XMLRPC API by saying, "Hello!" to client. * * @since 1.5.0 * @@ -255,15 +258,15 @@ } /** - * Test XMLRPC API by adding two numbers for client. + * Tests XMLRPC API by adding two numbers for client. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $number1 A number to add. - * @type int $number2 A second number to add. + * @type int $0 A number to add. + * @type int $1 A second number to add. * } * @return int Sum of the two given numbers. */ @@ -274,13 +277,13 @@ } /** - * Log user in. + * Logs user in. * * @since 2.8.0 * * @param string $username User's username. * @param string $password User's password. - * @return WP_User|false WP_User object if authentication passed, false otherwise + * @return WP_User|false WP_User object if authentication passed, false otherwise. */ public function login( $username, $password ) { if ( ! $this->is_enabled ) { @@ -317,7 +320,7 @@ } /** - * Check user's credentials. Deprecated. + * Checks user's credentials. Deprecated. * * @since 1.5.0 * @deprecated 2.8.0 Use wp_xmlrpc_server::login() @@ -332,7 +335,7 @@ } /** - * Escape string or array of strings for database. + * Escapes string or array of strings for database. * * @since 1.5.2 * @@ -355,9 +358,9 @@ } /** - * Send error response to client. - * - * Send an XML error response to the client. If the endpoint is enabled + * Sends error response to client. + * + * Sends an XML error response to the client. If the endpoint is enabled * an HTTP 200 response is always sent per the XML-RPC specification. * * @since 5.7.3 @@ -379,7 +382,7 @@ } /** - * Retrieve custom fields for post. + * Retrieves custom fields for post. * * @since 2.5.0 * @@ -408,7 +411,7 @@ } /** - * Set custom fields for post. + * Sets custom fields for post. * * @since 2.5.0 * @@ -446,7 +449,7 @@ } /** - * Retrieve custom fields for a term. + * Retrieves custom fields for a term. * * @since 4.9.0 * @@ -475,7 +478,7 @@ } /** - * Set custom fields for a term. + * Sets custom fields for a term. * * @since 4.9.0 * @@ -508,7 +511,7 @@ } /** - * Set up blog options property. + * Sets up blog options property. * * Passes property through {@see 'xmlrpc_blog_options'} filter. * @@ -677,15 +680,15 @@ } /** - * Retrieve the blogs of the user. + * Retrieves the blogs of the user. * * @since 2.6.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type string $username Username. - * @type string $password Password. + * @type string $0 Username. + * @type string $1 Password. * } * @return array|IXR_Error Array contains: * - 'isAdmin' @@ -867,7 +870,7 @@ } /** - * Convert a WordPress date string to an IXR_Date object. + * Converts a WordPress date string to an IXR_Date object. * * @param string $date Date string to convert. * @return IXR_Date IXR_Date object. @@ -880,7 +883,7 @@ } /** - * Convert a WordPress GMT date string to an IXR_Date object. + * Converts a WordPress GMT date string to an IXR_Date object. * * @param string $date_gmt WordPress GMT date string. * @param string $date Date string. @@ -1064,6 +1067,7 @@ 'description' => $media_item->post_content, 'metadata' => wp_get_attachment_metadata( $media_item->ID ), 'type' => $media_item->post_mime_type, + 'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ), ); $thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); @@ -1260,7 +1264,7 @@ } /** - * Create a new post for any registered post type. + * Creates a new post for any registered post type. * * @since 3.4.0 * @@ -1269,10 +1273,10 @@ * @param array $args { * Method arguments. Note: top-level arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type array $content_struct { + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 { * Content struct for adding a new post. See wp_insert_post() for information on * additional post fields * @@ -1360,8 +1364,8 @@ } /** - * Encapsulate the logic for sticking a post - * and determining if the user has permission to do so + * Encapsulates the logic for sticking a post and determining if + * the user has permission to do so. * * @since 4.3.0 * @@ -1411,19 +1415,19 @@ $defaults = array( 'post_status' => 'draft', 'post_type' => 'post', - 'post_author' => null, - 'post_password' => null, - 'post_excerpt' => null, - 'post_content' => null, - 'post_title' => null, - 'post_date' => null, - 'post_date_gmt' => null, + 'post_author' => 0, + 'post_password' => '', + 'post_excerpt' => '', + 'post_content' => '', + 'post_title' => '', + 'post_date' => '', + 'post_date_gmt' => '', 'post_format' => null, 'post_name' => null, 'post_thumbnail' => null, - 'post_parent' => null, - 'ping_status' => null, - 'comment_status' => null, + 'post_parent' => 0, + 'ping_status' => '', + 'comment_status' => '', 'custom_fields' => null, 'terms_names' => null, 'terms' => null, @@ -1498,11 +1502,11 @@ $post_data['post_author'] = $user->ID; } - if ( isset( $post_data['comment_status'] ) && 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { + if ( 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) { unset( $post_data['comment_status'] ); } - if ( isset( $post_data['ping_status'] ) && 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { + if ( 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) { unset( $post_data['ping_status'] ); } @@ -1528,7 +1532,7 @@ if ( ! isset( $post_data['ID'] ) ) { $post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; } - $post_ID = $post_data['ID']; + $post_id = $post_data['ID']; if ( 'post' === $post_data['post_type'] ) { $error = $this->_toggle_sticky( $post_data, $update ); @@ -1540,16 +1544,16 @@ if ( isset( $post_data['post_thumbnail'] ) ) { // Empty value deletes, non-empty value adds/updates. if ( ! $post_data['post_thumbnail'] ) { - delete_post_thumbnail( $post_ID ); + delete_post_thumbnail( $post_id ); } elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) { return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); } - set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); + set_post_thumbnail( $post_id, $post_data['post_thumbnail'] ); unset( $content_struct['post_thumbnail'] ); } if ( isset( $post_data['custom_fields'] ) ) { - $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); + $this->set_custom_fields( $post_id, $post_data['custom_fields'] ); } if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { @@ -1655,7 +1659,7 @@ } if ( isset( $post_data['post_format'] ) ) { - $format = set_post_format( $post_ID, $post_data['post_format'] ); + $format = set_post_format( $post_id, $post_data['post_format'] ); if ( is_wp_error( $format ) ) { return new IXR_Error( 500, $format->get_error_message() ); @@ -1666,9 +1670,9 @@ // Handle enclosures. $enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null; - $this->add_enclosure_if_new( $post_ID, $enclosure ); - - $this->attach_uploads( $post_ID, $post_data['post_content'] ); + $this->add_enclosure_if_new( $post_id, $enclosure ); + + $this->attach_uploads( $post_id, $post_data['post_content'] ); /** * Filters post data array to be inserted via XML-RPC. @@ -1680,12 +1684,20 @@ */ $post_data = apply_filters( 'xmlrpc_wp_insert_post_data', $post_data, $content_struct ); - $post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); - if ( is_wp_error( $post_ID ) ) { - return new IXR_Error( 500, $post_ID->get_error_message() ); - } - - if ( ! $post_ID ) { + // Remove all null values to allow for using the insert/update post default values for those keys instead. + $post_data = array_filter( + $post_data, + static function ( $value ) { + return null !== $value; + } + ); + + $post_id = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true ); + if ( is_wp_error( $post_id ) ) { + return new IXR_Error( 500, $post_id->get_error_message() ); + } + + if ( ! $post_id ) { if ( $update ) { return new IXR_Error( 401, __( 'Sorry, the post could not be updated.' ) ); } else { @@ -1693,11 +1705,11 @@ } } - return (string) $post_ID; + return (string) $post_id; } /** - * Edit a post for any registered post type. + * Edits a post for any registered post type. * * The $content_struct parameter only needs to contain fields that * should be changed. All other fields will retain their existing values. @@ -1707,11 +1719,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type int $post_id Post ID. - * @type array $content_struct Extra content arguments. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Post ID. + * @type array $4 Extra content arguments. * } * @return true|IXR_Error True on success, IXR_Error on failure. */ @@ -1783,7 +1795,7 @@ } /** - * Delete a post for any registered post type. + * Deletes a post for any registered post type. * * @since 3.4.0 * @@ -1792,10 +1804,10 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type int $post_id Post ID. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Post ID. * } * @return true|IXR_Error True on success, IXR_Error instance on failure. */ @@ -1837,7 +1849,7 @@ } /** - * Retrieve a post. + * Retrieves a post. * * @since 3.4.0 * @@ -1855,11 +1867,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type int $post_id Post ID. - * @type array $fields The subset of post type fields to return. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Post ID. + * @type array $4 Optional. The subset of post type fields to return. * } * @return array|IXR_Error Array contains (based on $fields parameter): * - 'post_id' @@ -1900,11 +1912,12 @@ $fields = $args[4]; } else { /** - * Filters the list of post query fields used by the given XML-RPC method. + * Filters the default post query fields used by the given XML-RPC method. * * @since 3.4.0 * - * @param array $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'. + * @param array $fields An array of post fields to retrieve. By default, + * contains 'post', 'terms', and 'custom_fields'. * @param string $method Method name. */ $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); @@ -1932,7 +1945,7 @@ } /** - * Retrieve posts. + * Retrieves posts. * * @since 3.4.0 * @@ -1943,15 +1956,15 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'post_type', - * 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. - * Default empty array. - * @type array $fields Optional. The subset of post type fields to return in the response array. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Modifies the query used to retrieve posts. Accepts 'post_type', + * 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. + * Default empty array. + * @type array $4 Optional. The subset of post type fields to return in the response array. * } - * @return array|IXR_Error Array contains a collection of posts. + * @return array|IXR_Error Array containing a collection of posts. */ public function wp_getPosts( $args ) { if ( ! $this->minimum_args( $args, 3 ) ) { @@ -2041,7 +2054,7 @@ } /** - * Create a new term. + * Creates a new term. * * @since 3.4.0 * @@ -2050,12 +2063,12 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type array $content_struct Content struct for adding a new term. The struct must contain - * the term 'name' and 'taxonomy'. Optional accepted values include - * 'parent', 'description', and 'slug'. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Content struct for adding a new term. The struct must contain + * the term 'name' and 'taxonomy'. Optional accepted values include + * 'parent', 'description', and 'slug'. * } * @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. */ @@ -2144,7 +2157,7 @@ } /** - * Edit a term. + * Edits a term. * * @since 3.4.0 * @@ -2153,13 +2166,13 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type int $term_id Term ID. - * @type array $content_struct Content struct for editing a term. The struct must contain the - * term ''taxonomy'. Optional accepted values include 'name', 'parent', - * 'description', and 'slug'. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Term ID. + * @type array $4 Content struct for editing a term. The struct must contain the + * term 'taxonomy'. Optional accepted values include 'name', 'parent', + * 'description', and 'slug'. * } * @return true|IXR_Error True on success, IXR_Error instance on failure. */ @@ -2262,7 +2275,7 @@ } /** - * Delete a term. + * Deletes a term. * * @since 3.4.0 * @@ -2271,11 +2284,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type string $taxonomy_name Taxonomy name. - * @type int $term_id Term ID. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string $3 Taxonomy name. + * @type int $4 Term ID. * } * @return true|IXR_Error True on success, IXR_Error instance on failure. */ @@ -2332,7 +2345,7 @@ } /** - * Retrieve a term. + * Retrieves a term. * * @since 3.4.0 * @@ -2341,11 +2354,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type string $taxonomy Taxonomy name. - * @type string $term_id Term ID. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string $3 Taxonomy name. + * @type int $4 Term ID. * } * @return array|IXR_Error IXR_Error on failure, array on success, containing: * - 'term_id' @@ -2402,7 +2415,7 @@ } /** - * Retrieve all terms for a taxonomy. + * Retrieves all terms for a taxonomy. * * @since 3.4.0 * @@ -2414,12 +2427,12 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type string $taxonomy Taxonomy name. - * @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'number', - * 'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string $3 Taxonomy name. + * @type array $4 Optional. Modifies the query used to retrieve posts. Accepts 'number', + * 'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array. * } * @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. */ @@ -2497,7 +2510,7 @@ } /** - * Retrieve a taxonomy. + * Retrieves a taxonomy. * * @since 3.4.0 * @@ -2506,13 +2519,13 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type string $taxonomy Taxonomy name. - * @type array $fields Optional. Array of taxonomy fields to limit to in the return. - * Accepts 'labels', 'cap', 'menu', and 'object_type'. - * Default empty array. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string $3 Taxonomy name. + * @type array $4 Optional. Array of taxonomy fields to limit to in the return. + * Accepts 'labels', 'cap', 'menu', and 'object_type'. + * Default empty array. * } * @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. */ @@ -2531,11 +2544,12 @@ $fields = $args[4]; } else { /** - * Filters the taxonomy query fields used by the given XML-RPC method. + * Filters the default taxonomy query fields used by the given XML-RPC method. * * @since 3.4.0 * - * @param array $fields An array of taxonomy fields to retrieve. + * @param array $fields An array of taxonomy fields to retrieve. By default, + * contains 'labels', 'cap', and 'object_type'. * @param string $method The method name. */ $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); @@ -2563,7 +2577,7 @@ } /** - * Retrieve all taxonomies. + * Retrieves all taxonomies. * * @since 3.4.0 * @@ -2572,11 +2586,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id Blog ID (unused). - * @type string $username Username. - * @type string $password Password. - * @type array $filter Optional. An array of arguments for retrieving taxonomies. - * @type array $fields Optional. The subset of taxonomy fields to return. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. An array of arguments for retrieving taxonomies. + * @type array $4 Optional. The subset of taxonomy fields to return. * } * @return array|IXR_Error An associative array of taxonomy data with returned fields determined * by `$fields`, or an IXR_Error instance on failure. @@ -2625,7 +2639,7 @@ } /** - * Retrieve a user. + * Retrieves a user. * * The optional $fields parameter specifies what fields will be included * in the response array. This should be a list of field names. 'user_id' will @@ -2640,11 +2654,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $user_id - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 User ID. + * @type array $4 Optional. Array of fields to return. * } * @return array|IXR_Error Array contains (based on $fields parameter): * - 'user_id' @@ -2679,7 +2693,7 @@ * * @since 3.5.0 * - * @param array $fields User query fields for given method. Default 'all'. + * @param array $fields An array of user fields to retrieve. By default, contains 'all'. * @param string $method The method name. */ $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); @@ -2707,7 +2721,7 @@ } /** - * Retrieve users. + * Retrieves users. * * The optional $filter parameter modifies the query used to retrieve users. * Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', @@ -2722,11 +2736,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $filter (optional) - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Arguments for the user query. + * @type array $4 Optional. Fields to return. * } * @return array|IXR_Error users data */ @@ -2797,17 +2811,17 @@ } /** - * Retrieve information about the requesting user. + * Retrieves information about the requesting user. * * @uses get_userdata() * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username + * @type string $2 Password + * @type array $3 Optional. Fields to return. * } * @return array|IXR_Error (@see wp_getUser) */ @@ -2846,17 +2860,17 @@ } /** - * Edit user's profile. + * Edits user's profile. * * @uses wp_update_user() * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $content_struct It can optionally contain: + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Content struct. It can optionally contain: * - 'first_name' * - 'last_name' * - 'website' @@ -2937,17 +2951,17 @@ } /** - * Retrieve page. + * Retrieves a page. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $page_id - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type int $1 Page ID. + * @type string $2 Username. + * @type string $3 Password. * } * @return array|IXR_Error */ @@ -2985,17 +2999,17 @@ } /** - * Retrieve Pages. + * Retrieves Pages. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $num_pages + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Optional. Number of pages. Default 10. * } * @return array|IXR_Error */ @@ -3044,7 +3058,7 @@ } /** - * Create new page. + * Creates a new page. * * @since 2.2.0 * @@ -3053,10 +3067,10 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $content_struct + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Content struct. * } * @return int|IXR_Error */ @@ -3081,17 +3095,17 @@ } /** - * Delete page. + * Deletes a page. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $page_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Page ID. * } * @return true|IXR_Error True, if success. */ @@ -3110,8 +3124,10 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.deletePage', $args, $this ); - // Get the current page based on the 'page_id' and - // make sure it is a page and not a post. + /* + * Get the current page based on the 'page_id' and + * make sure it is a page and not a post. + */ $actual_page = get_post( $page_id, ARRAY_A ); if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); @@ -3142,19 +3158,19 @@ } /** - * Edit page. + * Edits a page. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $page_id - * @type string $username - * @type string $password - * @type string $content - * @type string $publish + * @type int $0 Blog ID (unused). + * @type int $1 Page ID. + * @type string $2 Username. + * @type string $3 Password. + * @type string $4 Content. + * @type int $5 Publish flag. 0 for draft, 1 for publish. * } * @return array|IXR_Error */ @@ -3205,7 +3221,7 @@ } /** - * Retrieve page list. + * Retrieves page list. * * @since 2.2.0 * @@ -3214,9 +3230,9 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -3270,16 +3286,16 @@ } /** - * Retrieve authors list. + * Retrieves authors list. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -3314,16 +3330,16 @@ } /** - * Get list of all tags + * Gets the list of all tags. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -3366,17 +3382,17 @@ } /** - * Create new category. + * Creates a new category. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $category + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Category. * } * @return int|IXR_Error Category ID. */ @@ -3400,14 +3416,18 @@ return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); } - // If no slug was provided, make it empty - // so that WordPress will generate one. + /* + * If no slug was provided, make it empty + * so that WordPress will generate one. + */ if ( empty( $category['slug'] ) ) { $category['slug'] = ''; } - // If no parent_id was provided, make it empty - // so that it will be a top-level page (no parent). + /* + * If no parent_id was provided, make it empty + * so that it will be a top-level page (no parent). + */ if ( ! isset( $category['parent_id'] ) ) { $category['parent_id'] = ''; } @@ -3449,17 +3469,17 @@ } /** - * Remove category. + * Deletes a category. * * @since 2.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $category_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Category ID. * } * @return bool|IXR_Error See wp_delete_term() for return info. */ @@ -3500,18 +3520,18 @@ } /** - * Retrieve category list. + * Retrieves category list. * * @since 2.2.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $category - * @type int $max_results + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Category + * @type int $4 Max number of results. * } * @return array|IXR_Error */ @@ -3552,17 +3572,17 @@ } /** - * Retrieve comment. + * Retrieves a comment. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $comment_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Comment ID. * } * @return array|IXR_Error */ @@ -3594,30 +3614,33 @@ } /** - * Retrieve comments. - * - * Besides the common blog_id (unused), username, and password arguments, it takes a filter - * array as last argument. + * Retrieves comments. + * + * Besides the common blog_id (unused), username, and password arguments, + * it takes a filter array as the last argument. * * Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. * * The defaults are as follows: - * - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') - * - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. - * - 'number' - Default is 10. Total number of media items to retrieve. - * - 'offset' - Default is 0. See WP_Query::query() for more. + * - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') + * - 'post_id' - Default is ''. The post where the comment is posted. + * Empty string shows all comments. + * - 'number' - Default is 10. Total number of media items to retrieve. + * - 'offset' - Default is 0. See WP_Query::query() for more. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $struct + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Query arguments. * } - * @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents + * @return array|IXR_Error Array containing a collection of comments. + * See wp_xmlrpc_server::wp_getComment() for a description + * of each item contents. */ public function wp_getComments( $args ) { $this->escape( $args ); @@ -3689,7 +3712,7 @@ } /** - * Delete a comment. + * Deletes a comment. * * By default, the comment will be moved to the Trash instead of deleted. * See wp_delete_comment() for more information on this behavior. @@ -3699,10 +3722,10 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $comment_ID + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Comment ID. * } * @return bool|IXR_Error See wp_delete_comment(). */ @@ -3711,25 +3734,25 @@ $username = $args[1]; $password = $args[2]; - $comment_ID = (int) $args[3]; + $comment_id = (int) $args[3]; $user = $this->login( $username, $password ); if ( ! $user ) { return $this->error; } - if ( ! get_comment( $comment_ID ) ) { + if ( ! get_comment( $comment_id ) ) { return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); } - if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { + if ( ! current_user_can( 'edit_comment', $comment_id ) ) { return new IXR_Error( 403, __( 'Sorry, you are not allowed to delete this comment.' ) ); } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.deleteComment', $args, $this ); - $status = wp_delete_comment( $comment_ID ); + $status = wp_delete_comment( $comment_id ); if ( $status ) { /** @@ -3737,20 +3760,20 @@ * * @since 3.4.0 * - * @param int $comment_ID ID of the deleted comment. + * @param int $comment_id ID of the deleted comment. * @param array $args An array of arguments to delete the comment. */ - do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase } return $status; } /** - * Edit comment. - * - * Besides the common blog_id (unused), username, and password arguments, it takes a - * comment_id integer and a content_struct array as last argument. + * Edits a comment. + * + * Besides the common blog_id (unused), username, and password arguments, + * it takes a comment_id integer and a content_struct array as the last argument. * * The allowed keys in the content_struct array are: * - 'author' @@ -3758,18 +3781,18 @@ * - 'author_email' * - 'content' * - 'date_created_gmt' - * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details + * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $comment_ID - * @type array $content_struct + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Comment ID. + * @type array $4 Content structure. * } * @return true|IXR_Error True, on success. */ @@ -3778,7 +3801,7 @@ $username = $args[1]; $password = $args[2]; - $comment_ID = (int) $args[3]; + $comment_id = (int) $args[3]; $content_struct = $args[4]; $user = $this->login( $username, $password ); @@ -3786,18 +3809,18 @@ return $this->error; } - if ( ! get_comment( $comment_ID ) ) { + if ( ! get_comment( $comment_id ) ) { return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); } - if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { + if ( ! current_user_can( 'edit_comment', $comment_id ) ) { return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.editComment', $args, $this ); $comment = array( - 'comment_ID' => $comment_ID, + 'comment_ID' => $comment_id, ); if ( isset( $content_struct['status'] ) ) { @@ -3849,27 +3872,27 @@ * * @since 3.4.0 * - * @param int $comment_ID ID of the updated comment. + * @param int $comment_id ID of the updated comment. * @param array $args An array of arguments to update the comment. */ - do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + do_action( 'xmlrpc_call_success_wp_editComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return true; } /** - * Create new comment. + * Creates a new comment. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type string|int $post - * @type array $content_struct + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string|int $3 Post ID or URL. + * @type array $4 Content structure. * } * @return int|IXR_Error See wp_new_comment(). */ @@ -3950,7 +3973,7 @@ $comment['comment_author'] = $this->escape( $display_name ); $comment['comment_author_email'] = $this->escape( $user_email ); $comment['comment_author_url'] = $this->escape( $user_url ); - $comment['user_ID'] = $user->ID; + $comment['user_id'] = $user->ID; } else { $comment['comment_author'] = ''; if ( isset( $content_struct['author'] ) ) { @@ -3967,7 +3990,7 @@ $comment['comment_author_url'] = $content_struct['author_url']; } - $comment['user_ID'] = 0; + $comment['user_id'] = 0; if ( get_option( 'require_name_email' ) ) { if ( strlen( $comment['comment_author_email'] ) < 6 || '' === $comment['comment_author'] ) { @@ -3990,12 +4013,12 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'wp.newComment', $args, $this ); - $comment_ID = wp_new_comment( $comment, true ); - if ( is_wp_error( $comment_ID ) ) { - return new IXR_Error( 403, $comment_ID->get_error_message() ); - } - - if ( ! $comment_ID ) { + $comment_id = wp_new_comment( $comment, true ); + if ( is_wp_error( $comment_id ) ) { + return new IXR_Error( 403, $comment_id->get_error_message() ); + } + + if ( ! $comment_id ) { return new IXR_Error( 403, __( 'Something went wrong.' ) ); } @@ -4004,25 +4027,25 @@ * * @since 3.4.0 * - * @param int $comment_ID ID of the new comment. + * @param int $comment_id ID of the new comment. * @param array $args An array of new comment arguments. */ - do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase - - return $comment_ID; + do_action( 'xmlrpc_call_success_wp_newComment', $comment_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + + return $comment_id; } /** - * Retrieve all of the comment status. + * Retrieves all of the comment status. * * @since 2.7.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4048,17 +4071,17 @@ } /** - * Retrieve comment count. + * Retrieves comment counts. * * @since 2.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $post_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Post ID. * } * @return array|IXR_Error */ @@ -4097,16 +4120,16 @@ } /** - * Retrieve post statuses. + * Retrieves post statuses. * * @since 2.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4132,16 +4155,16 @@ } /** - * Retrieve page statuses. + * Retrieves page statuses. * * @since 2.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4167,16 +4190,16 @@ } /** - * Retrieve page templates. + * Retrieves page templates. * * @since 2.6.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4202,17 +4225,17 @@ } /** - * Retrieve blog options. + * Retrieves blog options. * * @since 2.6.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $options + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Options. * } * @return array|IXR_Error */ @@ -4229,7 +4252,7 @@ } // If no specific options where asked for, return all of them. - if ( count( $options ) == 0 ) { + if ( count( $options ) === 0 ) { $options = array_keys( $this->blog_options ); } @@ -4237,7 +4260,7 @@ } /** - * Retrieve blog options value from list. + * Retrieves blog options value from list. * * @since 2.6.0 * @@ -4266,17 +4289,17 @@ } /** - * Update blog options. + * Updates blog options. * * @since 2.6.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $options + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Options. * } * @return array|IXR_Error */ @@ -4315,17 +4338,17 @@ } /** - * Retrieve a media item by ID + * Retrieves a media item by ID. * * @since 3.1.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $attachment_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Attachment ID. * } * @return array|IXR_Error Associative array contains: * - 'date_created_gmt' @@ -4365,17 +4388,18 @@ } /** - * Retrieves a collection of media library items (or attachments) - * - * Besides the common blog_id (unused), username, and password arguments, it takes a filter - * array as last argument. + * Retrieves a collection of media library items (or attachments). + * + * Besides the common blog_id (unused), username, and password arguments, + * it takes a filter array as the last argument. * * Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. * * The defaults are as follows: - * - 'number' - Default is 5. Total number of media items to retrieve. - * - 'offset' - Default is 0. See WP_Query::query() for more. - * - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. + * - 'number' - Default is 5. Total number of media items to retrieve. + * - 'offset' - Default is 0. See WP_Query::query() for more. + * - 'parent_id' - Default is ''. The post where the media item is attached. + * Empty string shows all media items. 0 shows unattached media items. * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') * * @since 3.1.0 @@ -4383,12 +4407,14 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $struct + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Query arguments. * } - * @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents + * @return array|IXR_Error Array containing a collection of media items. + * See wp_xmlrpc_server::wp_getMediaItem() for a description + * of each item contents. */ public function wp_getMediaLibrary( $args ) { $this->escape( $args ); @@ -4441,9 +4467,9 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error List of post formats, otherwise IXR_Error object. */ @@ -4486,7 +4512,7 @@ } /** - * Retrieves a post type + * Retrieves a post type. * * @since 3.4.0 * @@ -4495,11 +4521,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type string $post_type_name - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type string $3 Post type name. + * @type array $4 Optional. Fields to fetch. * } * @return array|IXR_Error Array contains: * - 'labels' @@ -4527,11 +4553,12 @@ $fields = $args[4]; } else { /** - * Filters the default query fields used by the given XML-RPC method. + * Filters the default post type query fields used by the given XML-RPC method. * * @since 3.4.0 * - * @param array $fields An array of post type query fields for the given method. + * @param array $fields An array of post type fields to retrieve. By default, + * contains 'labels', 'cap', and 'taxonomies'. * @param string $method The method name. */ $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); @@ -4559,7 +4586,7 @@ } /** - * Retrieves a post types + * Retrieves post types. * * @since 3.4.0 * @@ -4568,11 +4595,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $filter (optional) - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Optional. Query arguments. + * @type array $4 Optional. Fields to fetch. * } * @return array|IXR_Error */ @@ -4618,7 +4645,7 @@ } /** - * Retrieve revisions for a specific post. + * Retrieves revisions for a specific post. * * @since 3.5.0 * @@ -4631,13 +4658,13 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $post_id - * @type array $fields (optional) + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Post ID. + * @type array $4 Optional. Fields to fetch. * } - * @return array|IXR_Error contains a collection of posts. + * @return array|IXR_Error Array containing a collection of posts. */ public function wp_getRevisions( $args ) { if ( ! $this->minimum_args( $args, 4 ) ) { @@ -4658,7 +4685,8 @@ * * @since 3.5.0 * - * @param array $field An array of revision query fields. + * @param array $field An array of revision fields to retrieve. By default, + * contains 'post_date' and 'post_date_gmt'. * @param string $method The method name. */ $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); @@ -4711,7 +4739,7 @@ } /** - * Restore a post revision + * Restores a post revision. * * @since 3.5.0 * @@ -4720,10 +4748,10 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $revision_id + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Revision ID. * } * @return bool|IXR_Error false if there was an error restoring, true if success. */ @@ -4780,7 +4808,7 @@ */ /** - * Retrieve blogs that user owns. + * Retrieves blogs that user owns. * * Will make more sense once we support multiple blogs. * @@ -4789,9 +4817,9 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4831,15 +4859,16 @@ } /** - * Private function for retrieving a users blogs for multisite setups + * Private function for retrieving a users blogs for multisite setups. * * @since 3.0.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type string $username Username. - * @type string $password Password. + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4849,19 +4878,16 @@ $domain = $current_blog->domain; $path = $current_blog->path . 'xmlrpc.php'; - $rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) ); - $rpc->query( 'wp.getUsersBlogs', $args[1], $args[2] ); - $blogs = $rpc->getResponse(); - - if ( isset( $blogs['faultCode'] ) ) { - return new IXR_Error( $blogs['faultCode'], $blogs['faultString'] ); + $blogs = $this->wp_getUsersBlogs( $args ); + if ( $blogs instanceof IXR_Error ) { + return $blogs; } if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) { return $blogs; } else { foreach ( (array) $blogs as $blog ) { - if ( strpos( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { + if ( str_contains( $blog['url'], $_SERVER['HTTP_HOST'] ) ) { return array( $blog ); } } @@ -4870,7 +4896,7 @@ } /** - * Retrieve user's data. + * Retrieves user's data. * * Gives your client some info about you, so you don't have to. * @@ -4879,9 +4905,9 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -4915,24 +4941,24 @@ } /** - * Retrieve post. + * Retrieves a post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $post_ID - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type int $1 Post ID. + * @type string $2 Username. + * @type string $3 Password. * } * @return array|IXR_Error */ public function blogger_getPost( $args ) { $this->escape( $args ); - $post_ID = (int) $args[1]; + $post_id = (int) $args[1]; $username = $args[2]; $password = $args[3]; @@ -4941,19 +4967,19 @@ return $this->error; } - $post_data = get_post( $post_ID, ARRAY_A ); + $post_data = get_post( $post_id, ARRAY_A ); if ( ! $post_data ) { return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'blogger.getPost', $args, $this ); - $categories = implode( ',', wp_get_post_categories( $post_ID ) ); + $categories = implode( ',', wp_get_post_categories( $post_id ) ); $content = '' . wp_unslash( $post_data['post_title'] ) . ''; $content .= '' . $categories . ''; @@ -4970,18 +4996,18 @@ } /** - * Retrieve list of recent posts. + * Retrieves the list of recent posts. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type string $appkey (unused) - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $numberposts (optional) + * @type string $0 App key (unused). + * @type int $1 Blog ID (unused). + * @type string $2 Username. + * @type string $3 Password. + * @type int $4 Optional. Number of posts. * } * @return array|IXR_Error */ @@ -5068,19 +5094,19 @@ } /** - * Creates new post. + * Creates a new post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type string $appkey (unused) - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type string $content - * @type string $publish + * @type string $0 App key (unused). + * @type int $1 Blog ID (unused). + * @type string $2 Username. + * @type string $3 Password. + * @type string $4 Content. + * @type int $5 Publish flag. 0 for draft, 1 for publish. * } * @return int|IXR_Error */ @@ -5118,44 +5144,44 @@ $post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' ); - $post_ID = wp_insert_post( $post_data ); - if ( is_wp_error( $post_ID ) ) { - return new IXR_Error( 500, $post_ID->get_error_message() ); - } - - if ( ! $post_ID ) { + $post_id = wp_insert_post( $post_data ); + if ( is_wp_error( $post_id ) ) { + return new IXR_Error( 500, $post_id->get_error_message() ); + } + + if ( ! $post_id ) { return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); } - $this->attach_uploads( $post_ID, $post_content ); + $this->attach_uploads( $post_id, $post_content ); /** * Fires after a new post has been successfully created via the XML-RPC Blogger API. * * @since 3.4.0 * - * @param int $post_ID ID of the new post. + * @param int $post_id ID of the new post. * @param array $args An array of new post arguments. */ - do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase - - return $post_ID; + do_action( 'xmlrpc_call_success_blogger_newPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + + return $post_id; } /** - * Edit a post. + * Edits a post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $post_ID - * @type string $username - * @type string $password - * @type string $content - * @type bool $publish + * @type int $0 Blog ID (unused). + * @type int $1 Post ID. + * @type string $2 Username. + * @type string $3 Password. + * @type string $4 Content + * @type int $5 Publish flag. 0 for draft, 1 for publish. * } * @return true|IXR_Error true when done. */ @@ -5163,7 +5189,7 @@ $this->escape( $args ); - $post_ID = (int) $args[1]; + $post_id = (int) $args[1]; $username = $args[2]; $password = $args[3]; $content = $args[4]; @@ -5177,7 +5203,7 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'blogger.editPost', $args, $this ); - $actual_post = get_post( $post_ID, ARRAY_A ); + $actual_post = get_post( $post_id, ARRAY_A ); if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); @@ -5185,7 +5211,7 @@ $this->escape( $actual_post ); - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } if ( 'publish' === $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) { @@ -5213,33 +5239,33 @@ * * @since 3.4.0 * - * @param int $post_ID ID of the updated post. + * @param int $post_id ID of the updated post. * @param array $args An array of arguments for the post to edit. */ - do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + do_action( 'xmlrpc_call_success_blogger_editPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return true; } /** - * Remove a post. + * Deletes a post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $post_ID - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type int $1 Post ID. + * @type string $2 Username. + * @type string $3 Password. * } * @return true|IXR_Error True when post is deleted. */ public function blogger_deletePost( $args ) { $this->escape( $args ); - $post_ID = (int) $args[1]; + $post_id = (int) $args[1]; $username = $args[2]; $password = $args[3]; @@ -5251,17 +5277,17 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'blogger.deletePost', $args, $this ); - $actual_post = get_post( $post_ID, ARRAY_A ); + $actual_post = get_post( $post_id, ARRAY_A ); if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); } - if ( ! current_user_can( 'delete_post', $post_ID ) ) { + if ( ! current_user_can( 'delete_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this post.' ) ); } - $result = wp_delete_post( $post_ID ); + $result = wp_delete_post( $post_id ); if ( ! $result ) { return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) ); @@ -5272,10 +5298,10 @@ * * @since 3.4.0 * - * @param int $post_ID ID of the deleted post. + * @param int $post_id ID of the deleted post. * @param array $args An array of arguments to delete the post. */ - do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + do_action( 'xmlrpc_call_success_blogger_deletePost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return true; } @@ -5286,7 +5312,7 @@ */ /** - * Create a new post. + * Creates a new post. * * The 'content_struct' argument must contain: * - title @@ -5315,11 +5341,11 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $content_struct - * @type int $publish + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Content structure. + * @type int $4 Optional. Publish flag. 0 for draft, 1 for publish. Default 0. * } * @return int|IXR_Error */ @@ -5397,30 +5423,27 @@ // Let WordPress generate the 'post_name' (slug) unless // one has been provided. - $post_name = ''; + $post_name = null; if ( isset( $content_struct['wp_slug'] ) ) { $post_name = $content_struct['wp_slug']; } // Only use a password if one was given. + $post_password = ''; if ( isset( $content_struct['wp_password'] ) ) { $post_password = $content_struct['wp_password']; - } else { - $post_password = ''; } // Only set a post parent if one was given. + $post_parent = 0; if ( isset( $content_struct['wp_page_parent_id'] ) ) { $post_parent = $content_struct['wp_page_parent_id']; - } else { - $post_parent = 0; } // Only set the 'menu_order' if it was given. + $menu_order = 0; if ( isset( $content_struct['wp_page_order'] ) ) { $menu_order = $content_struct['wp_page_order']; - } else { - $menu_order = 0; } $post_author = $user->ID; @@ -5448,8 +5471,8 @@ $post_author = $content_struct['wp_author_id']; } - $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null; - $post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null; + $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : ''; + $post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : ''; $post_status = $publish ? 'publish' : 'draft'; @@ -5462,15 +5485,15 @@ $post_status = $content_struct[ "{$post_type}_status" ]; break; default: - $post_status = $publish ? 'publish' : 'draft'; + // Deliberably left empty. break; } } - $post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : null; - $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; - - $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; + $post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : ''; + $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; + + $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); if ( isset( $content_struct['mt_allow_comments'] ) ) { if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) { @@ -5534,10 +5557,10 @@ } if ( $post_more ) { - $post_content = $post_content . '' . $post_more; - } - - $to_ping = null; + $post_content .= '' . $post_more; + } + + $to_ping = ''; if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { $to_ping = $content_struct['mt_tb_ping_urls']; if ( is_array( $to_ping ) ) { @@ -5553,12 +5576,11 @@ $dateCreated = $content_struct['dateCreated']->getIso(); } + $post_date = ''; + $post_date_gmt = ''; if ( ! empty( $dateCreated ) ) { $post_date = iso8601_to_datetime( $dateCreated ); $post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' ); - } else { - $post_date = ''; - $post_date_gmt = ''; } $post_category = array(); @@ -5574,8 +5596,8 @@ $postdata = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template' ); - $post_ID = get_default_post_to_edit( $post_type, true )->ID; - $postdata['ID'] = $post_ID; + $post_id = get_default_post_to_edit( $post_type, true )->ID; + $postdata['ID'] = $post_id; // Only posts can be sticky. if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) { @@ -5588,11 +5610,11 @@ } if ( isset( $content_struct['custom_fields'] ) ) { - $this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); + $this->set_custom_fields( $post_id, $content_struct['custom_fields'] ); } if ( isset( $content_struct['wp_post_thumbnail'] ) ) { - if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { + if ( set_post_thumbnail( $post_id, $content_struct['wp_post_thumbnail'] ) === false ) { return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); } @@ -5601,22 +5623,24 @@ // Handle enclosures. $thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; - $this->add_enclosure_if_new( $post_ID, $thisEnclosure ); - - $this->attach_uploads( $post_ID, $post_content ); - - // Handle post formats if assigned, value is validated earlier - // in this function. + $this->add_enclosure_if_new( $post_id, $thisEnclosure ); + + $this->attach_uploads( $post_id, $post_content ); + + /* + * Handle post formats if assigned, value is validated earlier + * in this function. + */ if ( isset( $content_struct['wp_post_format'] ) ) { - set_post_format( $post_ID, $content_struct['wp_post_format'] ); - } - - $post_ID = wp_insert_post( $postdata, true ); - if ( is_wp_error( $post_ID ) ) { - return new IXR_Error( 500, $post_ID->get_error_message() ); - } - - if ( ! $post_ID ) { + set_post_format( $post_id, $content_struct['wp_post_format'] ); + } + + $post_id = wp_insert_post( $postdata, true ); + if ( is_wp_error( $post_id ) ) { + return new IXR_Error( 500, $post_id->get_error_message() ); + } + + if ( ! $post_id ) { return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) ); } @@ -5625,12 +5649,12 @@ * * @since 3.4.0 * - * @param int $post_ID ID of the new post. + * @param int $post_id ID of the new post. * @param array $args An array of arguments to create the new post. */ - do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase - - return (string) $post_ID; + do_action( 'xmlrpc_call_success_mw_newPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + + return (string) $post_id; } /** @@ -5638,73 +5662,73 @@ * * @since 2.8.0 * - * @param int $post_ID Post ID. + * @param int $post_id Post ID. * @param array $enclosure Enclosure data. */ - public function add_enclosure_if_new( $post_ID, $enclosure ) { + public function add_enclosure_if_new( $post_id, $enclosure ) { if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; $found = false; - $enclosures = get_post_meta( $post_ID, 'enclosure' ); + $enclosures = get_post_meta( $post_id, 'enclosure' ); if ( $enclosures ) { foreach ( $enclosures as $enc ) { // This method used to omit the trailing new line. #23219 - if ( rtrim( $enc, "\n" ) == rtrim( $encstring, "\n" ) ) { + if ( rtrim( $enc, "\n" ) === rtrim( $encstring, "\n" ) ) { $found = true; break; } } } if ( ! $found ) { - add_post_meta( $post_ID, 'enclosure', $encstring ); + add_post_meta( $post_id, 'enclosure', $encstring ); } } } /** - * Attach upload to a post. + * Attaches an upload to a post. * * @since 2.1.0 * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int $post_ID Post ID. + * @param int $post_id Post ID. * @param string $post_content Post Content for attachment. */ - public function attach_uploads( $post_ID, $post_content ) { + public function attach_uploads( $post_id, $post_content ) { global $wpdb; // Find any unattached files. $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '0' AND post_type = 'attachment'" ); if ( is_array( $attachments ) ) { foreach ( $attachments as $file ) { - if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) { - $wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) ); + if ( ! empty( $file->guid ) && str_contains( $post_content, $file->guid ) ) { + $wpdb->update( $wpdb->posts, array( 'post_parent' => $post_id ), array( 'ID' => $file->ID ) ); } } } } /** - * Edit a post. + * Edits a post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $content_struct - * @type int $publish + * @type int $0 Post ID. + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Content structure. + * @type int $4 Optional. Publish flag. 0 for draft, 1 for publish. Default 0. * } * @return true|IXR_Error True on success. */ public function mw_editPost( $args ) { $this->escape( $args ); - $post_ID = (int) $args[0]; + $post_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; @@ -5718,7 +5742,7 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'metaWeblog.editPost', $args, $this ); - $postdata = get_post( $post_ID, ARRAY_A ); + $postdata = get_post( $post_id, ARRAY_A ); /* * If there is no post data for the give post ID, stop now and return an error. @@ -5728,7 +5752,7 @@ return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } @@ -5784,7 +5808,7 @@ $menu_order = $content_struct['wp_page_order']; } - $page_template = null; + $page_template = ''; if ( ! empty( $content_struct['wp_page_template'] ) && 'page' === $post_type ) { $page_template = $content_struct['wp_page_template']; } @@ -5892,7 +5916,7 @@ $post_excerpt = $content_struct['mt_excerpt']; } - $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null; + $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : ''; $post_status = $publish ? 'publish' : 'draft'; if ( isset( $content_struct[ "{$post_type}_status" ] ) ) { @@ -5909,7 +5933,7 @@ } } - $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null; + $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : array(); if ( 'publish' === $post_status || 'private' === $post_status ) { if ( 'page' === $post_type && ! current_user_can( 'publish_pages' ) ) { @@ -5923,7 +5947,7 @@ $post_content = $post_content . '' . $post_more; } - $to_ping = null; + $to_ping = ''; if ( isset( $content_struct['mt_tb_ping_urls'] ) ) { $to_ping = $content_struct['mt_tb_ping_urls']; if ( is_array( $to_ping ) ) { @@ -5977,16 +6001,16 @@ } if ( isset( $content_struct['custom_fields'] ) ) { - $this->set_custom_fields( $post_ID, $content_struct['custom_fields'] ); + $this->set_custom_fields( $post_id, $content_struct['custom_fields'] ); } if ( isset( $content_struct['wp_post_thumbnail'] ) ) { // Empty value deletes, non-empty value adds/updates. if ( empty( $content_struct['wp_post_thumbnail'] ) ) { - delete_post_thumbnail( $post_ID ); + delete_post_thumbnail( $post_id ); } else { - if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) { + if ( set_post_thumbnail( $post_id, $content_struct['wp_post_thumbnail'] ) === false ) { return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); } } @@ -5995,13 +6019,13 @@ // Handle enclosures. $thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null; - $this->add_enclosure_if_new( $post_ID, $thisEnclosure ); + $this->add_enclosure_if_new( $post_id, $thisEnclosure ); $this->attach_uploads( $ID, $post_content ); // Handle post formats if assigned, validation is handled earlier in this function. if ( isset( $content_struct['wp_post_format'] ) ) { - set_post_format( $post_ID, $content_struct['wp_post_format'] ); + set_post_format( $post_id, $content_struct['wp_post_format'] ); } /** @@ -6009,33 +6033,32 @@ * * @since 3.4.0 * - * @param int $post_ID ID of the updated post. + * @param int $post_id ID of the updated post. * @param array $args An array of arguments to update the post. */ - do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase + do_action( 'xmlrpc_call_success_mw_editPost', $post_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase return true; } /** - * Retrieve post. + * Retrieves a post. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type int $post_ID - * @type string $username - * @type string $password + * @type int $0 Post ID. + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ public function mw_getPost( $args ) { $this->escape( $args ); - $post_ID = (int) $args[0]; + $post_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; @@ -6044,12 +6067,12 @@ return $this->error; } - $postdata = get_post( $post_ID, ARRAY_A ); + $postdata = get_post( $post_id, ARRAY_A ); if ( ! $postdata ) { return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } @@ -6063,13 +6086,13 @@ $post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] ); $categories = array(); - $catids = wp_get_post_categories( $post_ID ); + $catids = wp_get_post_categories( $post_id ); foreach ( $catids as $catid ) { $categories[] = get_cat_name( $catid ); } $tagnames = array(); - $tags = wp_get_post_tags( $post_ID ); + $tags = wp_get_post_tags( $post_id ); if ( ! empty( $tags ) ) { foreach ( $tags as $tag ) { $tagnames[] = $tag->name; @@ -6094,18 +6117,18 @@ } // Get post format. - $post_format = get_post_format( $post_ID ); + $post_format = get_post_format( $post_id ); if ( empty( $post_format ) ) { $post_format = 'standard'; } $sticky = false; - if ( is_sticky( $post_ID ) ) { + if ( is_sticky( $post_id ) ) { $sticky = true; } $enclosure = array(); - foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) { + foreach ( (array) get_post_custom( $post_id ) as $key => $val ) { if ( 'enclosure' === $key ) { foreach ( (array) $val as $enc ) { $encdata = explode( "\n", $enc ); @@ -6140,7 +6163,7 @@ 'wp_author_display_name' => $author->display_name, 'date_created_gmt' => $post_date_gmt, 'post_status' => $postdata['post_status'], - 'custom_fields' => $this->get_custom_fields( $post_ID ), + 'custom_fields' => $this->get_custom_fields( $post_id ), 'wp_post_format' => $post_format, 'sticky' => $sticky, 'date_modified' => $post_modified, @@ -6160,17 +6183,17 @@ } /** - * Retrieve list of recent posts. + * Retrieves list of recent posts. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $numberposts + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Optional. Number of posts. * } * @return array|IXR_Error */ @@ -6287,16 +6310,16 @@ } /** - * Retrieve the list of categories on a given blog. + * Retrieves the list of categories on a given blog. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -6348,21 +6371,17 @@ * * @since 1.5.0 * - * @global wpdb $wpdb WordPress database abstraction object. - * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type array $data + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Data. * } * @return array|IXR_Error */ public function mw_newMediaObject( $args ) { - global $wpdb; - $username = $this->escape( $args[1] ); $password = $this->escape( $args[2] ); $data = $args[3]; @@ -6461,21 +6480,21 @@ /* * MovableType API functions. - * Specs on http://www.movabletype.org/docs/mtmanual_programmatic.html + * Specs archive on http://web.archive.org/web/20050220091302/http://www.movabletype.org:80/docs/mtmanual_programmatic.html */ /** - * Retrieve the post titles of recent posts. + * Retrieves the post titles of recent posts. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password - * @type int $numberposts + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. + * @type int $3 Optional. Number of posts. * } * @return array|IXR_Error */ @@ -6529,16 +6548,16 @@ } /** - * Retrieve list of all categories on blog. + * Retrieves the list of all categories on a blog. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $blog_id (unused) - * @type string $username - * @type string $password + * @type int $0 Blog ID (unused). + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ @@ -6582,23 +6601,23 @@ } /** - * Retrieve post categories. + * Retrieves post categories. * * @since 1.5.0 * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $post_ID - * @type string $username - * @type string $password + * @type int $0 Post ID. + * @type string $1 Username. + * @type string $2 Password. * } * @return array|IXR_Error */ public function mt_getPostCategories( $args ) { $this->escape( $args ); - $post_ID = (int) $args[0]; + $post_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; @@ -6607,11 +6626,11 @@ return $this->error; } - if ( ! get_post( $post_ID ) ) { + if ( ! get_post( $post_id ) ) { return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } @@ -6619,7 +6638,7 @@ do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this ); $categories = array(); - $catids = wp_get_post_categories( (int) $post_ID ); + $catids = wp_get_post_categories( (int) $post_id ); // First listed category will be the primary category. $isPrimary = true; foreach ( $catids as $catid ) { @@ -6642,17 +6661,17 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $post_ID - * @type string $username - * @type string $password - * @type array $categories + * @type int $0 Post ID. + * @type string $1 Username. + * @type string $2 Password. + * @type array $3 Categories. * } * @return true|IXR_Error True on success. */ public function mt_setPostCategories( $args ) { $this->escape( $args ); - $post_ID = (int) $args[0]; + $post_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; $categories = $args[3]; @@ -6665,11 +6684,11 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'mt.setPostCategories', $args, $this ); - if ( ! get_post( $post_ID ) ) { + if ( ! get_post( $post_id ) ) { return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); } @@ -6678,13 +6697,13 @@ $catids[] = $cat['categoryId']; } - wp_set_post_categories( $post_ID, $catids ); + wp_set_post_categories( $post_id, $catids ); return true; } /** - * Retrieve an array of methods supported by this server. + * Retrieves an array of methods supported by this server. * * @since 1.5.0 * @@ -6698,7 +6717,7 @@ } /** - * Retrieve an empty array because we don't support per-post text filters. + * Retrieves an empty array because we don't support per-post text filters. * * @since 1.5.0 */ @@ -6717,28 +6736,28 @@ } /** - * Retrieve trackbacks sent to a given post. + * Retrieves trackbacks sent to a given post. * * @since 1.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * - * @param int $post_ID + * @param int $post_id * @return array|IXR_Error */ - public function mt_getTrackbackPings( $post_ID ) { + public function mt_getTrackbackPings( $post_id ) { global $wpdb; /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ - do_action( 'xmlrpc_call', 'mt.getTrackbackPings', $post_ID, $this ); - - $actual_post = get_post( $post_ID, ARRAY_A ); + do_action( 'xmlrpc_call', 'mt.getTrackbackPings', $post_id, $this ); + + $actual_post = get_post( $post_id, ARRAY_A ); if ( ! $actual_post ) { return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); } - $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) ); + $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); if ( ! $comments ) { return array(); @@ -6768,16 +6787,16 @@ * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type int $post_ID - * @type string $username - * @type string $password + * @type int $0 Post ID. + * @type string $1 Username. + * @type string $2 Password. * } * @return int|IXR_Error */ public function mt_publishPost( $args ) { $this->escape( $args ); - $post_ID = (int) $args[0]; + $post_id = (int) $args[0]; $username = $args[1]; $password = $args[2]; @@ -6789,19 +6808,19 @@ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ do_action( 'xmlrpc_call', 'mt.publishPost', $args, $this ); - $postdata = get_post( $post_ID, ARRAY_A ); + $postdata = get_post( $post_id, ARRAY_A ); if ( ! $postdata ) { return new IXR_Error( 404, __( 'Invalid post ID.' ) ); } - if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_ID ) ) { + if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_id ) ) { return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); } $postdata['post_status'] = 'publish'; // Retain old categories. - $postdata['post_category'] = wp_get_post_categories( $post_ID ); + $postdata['post_category'] = wp_get_post_categories( $post_id ); $this->escape( $postdata ); return wp_update_post( $postdata ); @@ -6817,11 +6836,13 @@ * * @since 1.5.0 * + * @global wpdb $wpdb WordPress database abstraction object. + * * @param array $args { * Method arguments. Note: arguments must be ordered as documented. * - * @type string $pagelinkedfrom - * @type string $pagelinkedto + * @type string $0 URL of page linked from. + * @type string $1 URL of page linked to. * } * @return string|IXR_Error */ @@ -6863,31 +6884,31 @@ * If so, then let's use it and drop the old code. */ $urltest = parse_url( $pagelinkedto ); - $post_ID = url_to_postid( $pagelinkedto ); - if ( $post_ID ) { + $post_id = url_to_postid( $pagelinkedto ); + if ( $post_id ) { // $way } elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) { // The path defines the post_ID (archives/p/XXXX). $blah = explode( '/', $match[0] ); - $post_ID = (int) $blah[1]; + $post_id = (int) $blah[1]; } elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) { // The query string defines the post_ID (?p=XXXX). $blah = explode( '=', $match[0] ); - $post_ID = (int) $blah[1]; + $post_id = (int) $blah[1]; } elseif ( isset( $urltest['fragment'] ) ) { // An #anchor is there, it's either... if ( (int) $urltest['fragment'] ) { // ...an integer #XXXX (simplest case), - $post_ID = (int) $urltest['fragment']; + $post_id = (int) $urltest['fragment']; } elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { // ...a post ID in the form 'post-###', - $post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); + $post_id = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); } elseif ( is_string( $urltest['fragment'] ) ) { // ...or a string #title, a little more complicated. $title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] ); $sql = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); - $post_ID = $wpdb->get_var( $sql ); - if ( ! $post_ID ) { + $post_id = $wpdb->get_var( $sql ); + if ( ! $post_id ) { // Returning unknown error '0' is better than die()'ing. return $this->pingback_error( 0, '' ); } @@ -6896,15 +6917,15 @@ // TODO: Attempt to extract a post ID from the given URL. return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); } - $post_ID = (int) $post_ID; - - $post = get_post( $post_ID ); + $post_id = (int) $post_id; + + $post = get_post( $post_id ); if ( ! $post ) { // Post not found. return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); } - if ( url_to_postid( $pagelinkedfrom ) == $post_ID ) { + if ( url_to_postid( $pagelinkedfrom ) == $post_id ) { return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) ); } @@ -6914,11 +6935,23 @@ } // Let's check that the remote site didn't already pingback this entry. - if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom ) ) ) { + if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_id, $pagelinkedfrom ) ) ) { return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); } - // Very stupid, but gives time to the 'from' server to publish! + /* + * The remote site may have sent the pingback before it finished publishing its own content + * containing this pingback URL. If that happens then it won't be immediately possible to fetch + * the pinging post; adding a small delay reduces the likelihood of this happening. + * + * While there are more robust methods than calling `sleep()` here (because `sleep()` merely + * mitigates the risk of requesting the remote post before it's available), this is effective + * enough for most cases and avoids introducing more complexity into this code. + * + * One way to improve the reliability of this code might be to add failure-handling to the remote + * fetch and retry up to a set number of times if it receives a 404. This could also handle 401 and + * 403 responses to differentiate the "does not exist" failure from the "may not access" failure. + */ sleep( 1 ); $remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); @@ -6976,7 +7009,7 @@ $preg_target = preg_quote( $pagelinkedto, '|' ); foreach ( $p as $para ) { - if ( strpos( $para, $pagelinkedto ) !== false ) { // It exists, but is it a link? + if ( str_contains( $para, $pagelinkedto ) ) { // It exists, but is it a link? preg_match( '|]+?' . $preg_target . '[^>]*>([^>]+?)|', $para, $context ); // If the URL isn't in a link context, keep looking. @@ -6984,8 +7017,10 @@ continue; } - // We're going to use this fake tag to mark the context in a bit. - // The marker is needed in case the link text appears more than once in the paragraph. + /* + * We're going to use this fake tag to mark the context in a bit. + * The marker is needed in case the link text appears more than once in the paragraph. + */ $excerpt = preg_replace( '|\|', '', $para ); // prevent really long link text @@ -7013,7 +7048,7 @@ $context = '[…] ' . esc_html( $excerpt ) . ' […]'; $pagelinkedfrom = $this->escape( $pagelinkedfrom ); - $comment_post_ID = (int) $post_ID; + $comment_post_id = (int) $post_id; $comment_author = $title; $comment_author_email = ''; $this->escape( $comment_author ); @@ -7022,8 +7057,11 @@ $this->escape( $comment_content ); $comment_type = 'pingback'; - $commentdata = compact( - 'comment_post_ID', + $commentdata = array( + 'comment_post_ID' => $comment_post_id, + ); + + $commentdata += compact( 'comment_author', 'comment_author_url', 'comment_author_email', @@ -7033,10 +7071,10 @@ 'remote_source_original' ); - $comment_ID = wp_new_comment( $commentdata ); - - if ( is_wp_error( $comment_ID ) ) { - return $this->pingback_error( 0, $comment_ID->get_error_message() ); + $comment_id = wp_new_comment( $commentdata ); + + if ( is_wp_error( $comment_id ) ) { + return $this->pingback_error( 0, $comment_id->get_error_message() ); } /** @@ -7044,16 +7082,16 @@ * * @since 0.71 * - * @param int $comment_ID Comment ID. + * @param int $comment_id Comment ID. */ - do_action( 'pingback_post', $comment_ID ); + do_action( 'pingback_post', $comment_id ); /* translators: 1: URL of the page linked from, 2: URL of the page linked to. */ return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); } /** - * Retrieve array of URLs that pingbacked the given URL. + * Retrieves an array of URLs that pingbacked the given URL. * * Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html * @@ -7072,20 +7110,20 @@ $url = $this->escape( $url ); - $post_ID = url_to_postid( $url ); - if ( ! $post_ID ) { + $post_id = url_to_postid( $url ); + if ( ! $post_id ) { // We aren't sure that the resource is available and/or pingback enabled. return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either does not exist, or it is not a pingback-enabled resource.' ) ); } - $actual_post = get_post( $post_ID, ARRAY_A ); + $actual_post = get_post( $post_id, ARRAY_A ); if ( ! $actual_post ) { // No such post = resource not found. return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) ); } - $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) ); + $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); if ( ! $comments ) { return array();