--- a/wp/wp-includes/class-wp-xmlrpc-server.php Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class-wp-xmlrpc-server.php Tue Dec 15 13:49:49 2020 +0100
@@ -60,7 +60,7 @@
*/
public function __construct() {
$this->methods = array(
- // WordPress API
+ // WordPress API.
'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
'wp.newPost' => 'this:wp_newPost',
'wp.editPost' => 'this:wp_editPost',
@@ -85,13 +85,13 @@
'wp.editPage' => 'this:wp_editPage',
'wp.getPageList' => 'this:wp_getPageList',
'wp.getAuthors' => 'this:wp_getAuthors',
- 'wp.getCategories' => 'this:mw_getCategories', // Alias
+ 'wp.getCategories' => 'this:mw_getCategories', // Alias.
'wp.getTags' => 'this:wp_getTags',
'wp.newCategory' => 'this:wp_newCategory',
'wp.deleteCategory' => 'this:wp_deleteCategory',
'wp.suggestCategories' => 'this:wp_suggestCategories',
- 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
- 'wp.deleteFile' => 'this:wp_deletePost', // Alias
+ 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias.
+ 'wp.deleteFile' => 'this:wp_deletePost', // Alias.
'wp.getCommentCount' => 'this:wp_getCommentCount',
'wp.getPostStatusList' => 'this:wp_getPostStatusList',
'wp.getPageStatusList' => 'this:wp_getPageStatusList',
@@ -112,7 +112,7 @@
'wp.getRevisions' => 'this:wp_getRevisions',
'wp.restoreRevision' => 'this:wp_restoreRevision',
- // Blogger API
+ // Blogger API.
'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
'blogger.getUserInfo' => 'this:blogger_getUserInfo',
'blogger.getPost' => 'this:blogger_getPost',
@@ -121,7 +121,7 @@
'blogger.editPost' => 'this:blogger_editPost',
'blogger.deletePost' => 'this:blogger_deletePost',
- // MetaWeblog API (with MT extensions to structs)
+ // MetaWeblog API (with MT extensions to structs).
'metaWeblog.newPost' => 'this:mw_newPost',
'metaWeblog.editPost' => 'this:mw_editPost',
'metaWeblog.getPost' => 'this:mw_getPost',
@@ -129,12 +129,12 @@
'metaWeblog.getCategories' => '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',
- // MovableType API
+ // MovableType API.
'mt.getCategoryList' => 'this:mt_getCategoryList',
'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
'mt.getPostCategories' => 'this:mt_getPostCategories',
@@ -144,7 +144,7 @@
'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
'mt.publishPost' => 'this:mt_publishPost',
- // PingBack
+ // Pingback.
'pingback.ping' => 'this:pingback_ping',
'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
@@ -161,7 +161,7 @@
*
* @since 1.5.0
*
- * @param array $methods An array of XML-RPC methods.
+ * @param string[] $methods An array of XML-RPC methods, keyed by their methodName.
*/
$this->methods = apply_filters( 'xmlrpc_methods', $this->methods );
}
@@ -171,13 +171,13 @@
*
* @since 4.0.0
*
- * @param string $name Method to call.
- * @param array $arguments Arguments to pass when calling.
+ * @param string $name Method to call.
+ * @param array $arguments Arguments to pass when calling.
* @return array|IXR_Error|false Return value of the callback, false otherwise.
*/
public function __call( $name, $arguments ) {
if ( '_multisite_getUsersBlogs' === $name ) {
- return call_user_func_array( array( $this, $name ), $arguments );
+ return $this->_multisite_getUsersBlogs( ...$arguments );
}
return false;
}
@@ -207,7 +207,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $number1 A number to add.
@@ -278,7 +278,7 @@
if ( is_wp_error( $user ) ) {
$this->error = new IXR_Error( 403, __( 'Incorrect username or password.' ) );
- // Flag that authentication has failed once on this wp_xmlrpc_server instance
+ // Flag that authentication has failed once on this wp_xmlrpc_server instance.
$this->auth_failed = true;
/**
@@ -286,8 +286,8 @@
*
* @since 3.5.0
*
- * @param string $error The XML-RPC error message.
- * @param WP_User $user WP_User object.
+ * @param string $error The XML-RPC error message.
+ * @param WP_Error $user WP_Error object.
*/
$this->error = apply_filters( 'xmlrpc_login_error', $this->error, $user );
return false;
@@ -369,8 +369,8 @@
*
* @since 2.5.0
*
- * @param int $post_id Post ID.
- * @param array $fields Custom fields.
+ * @param int $post_id Post ID.
+ * @param array $fields Custom fields.
*/
public function set_custom_fields( $post_id, $fields ) {
$post_id = (int) $post_id;
@@ -436,8 +436,8 @@
*
* @since 4.9.0
*
- * @param int $term_id Term ID.
- * @param array $fields Custom fields.
+ * @param int $term_id Term ID.
+ * @param array $fields Custom fields.
*/
public function set_term_custom_fields( $term_id, $fields ) {
$term_id = (int) $term_id;
@@ -473,7 +473,7 @@
*/
public function initialise_blog_option_info() {
$this->blog_options = array(
- // Read only options
+ // Read-only options.
'software_name' => array(
'desc' => __( 'Software Name' ),
'readonly' => true,
@@ -535,7 +535,7 @@
'value' => current_theme_supports( 'post-thumbnails' ),
),
- // Updatable options
+ // Updatable options.
'time_zone' => array(
'desc' => __( 'Time Zone' ),
'readonly' => false,
@@ -612,12 +612,12 @@
'option' => 'large_size_h',
),
'default_comment_status' => array(
- 'desc' => __( 'Allow people to post comments on new articles' ),
+ 'desc' => __( 'Allow people to submit comments on new posts.' ),
'readonly' => false,
'option' => 'default_comment_status',
),
'default_ping_status' => array(
- 'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ),
+ 'desc' => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new posts.' ),
'readonly' => false,
'option' => 'default_ping_status',
),
@@ -657,7 +657,7 @@
return $this->error;
}
- // If this isn't on WPMU then just use blogger_getUsersBlogs
+ // If this isn't on WPMU then just use blogger_getUsersBlogs().
if ( ! is_multisite() ) {
array_unshift( $args, 1 );
return $this->blogger_getUsersBlogs( $args );
@@ -668,7 +668,8 @@
$username = $args[0];
$password = $args[1];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -695,7 +696,7 @@
foreach ( $blogs as $blog ) {
// Don't include blogs that aren't hosted at this site.
- if ( $blog->site_id != get_current_network_id() ) {
+ if ( get_current_network_id() != $blog->site_id ) {
continue;
}
@@ -726,12 +727,12 @@
*
* @since 3.4.0
*
- * @param string|array $args Sanitize single string or array of strings.
- * @param int $count Minimum number of arguments.
- * @return bool if `$args` contains at least $count arguments.
+ * @param array $args An array of arguments to check.
+ * @param int $count Minimum number of arguments.
+ * @return bool True if `$args` contains at least `$count` arguments, false otherwise.
*/
protected function minimum_args( $args, $count ) {
- if ( count( $args ) < $count ) {
+ if ( ! is_array( $args ) || count( $args ) < $count ) {
$this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) );
return false;
}
@@ -743,7 +744,7 @@
* Prepares taxonomy data for return in an XML-RPC object.
*
* @param object $taxonomy The unprepared taxonomy data.
- * @param array $fields The subset of taxonomy fields to return.
+ * @param array $fields The subset of taxonomy fields to return.
* @return array The prepared taxonomy data.
*/
protected function _prepare_taxonomy( $taxonomy, $fields ) {
@@ -756,19 +757,19 @@
'_builtin' => (bool) $taxonomy->_builtin,
);
- if ( in_array( 'labels', $fields ) ) {
+ if ( in_array( 'labels', $fields, true ) ) {
$_taxonomy['labels'] = (array) $taxonomy->labels;
}
- if ( in_array( 'cap', $fields ) ) {
+ if ( in_array( 'cap', $fields, true ) ) {
$_taxonomy['cap'] = (array) $taxonomy->cap;
}
- if ( in_array( 'menu', $fields ) ) {
+ if ( in_array( 'menu', $fields, true ) ) {
$_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu;
}
- if ( in_array( 'object_type', $fields ) ) {
+ if ( in_array( 'object_type', $fields, true ) ) {
$_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type );
}
@@ -826,7 +827,7 @@
* @return IXR_Date IXR_Date object.
*/
protected function _convert_date( $date ) {
- if ( $date === '0000-00-00 00:00:00' ) {
+ if ( '0000-00-00 00:00:00' === $date ) {
return new IXR_Date( '00000000T00:00:00Z' );
}
return new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date, false ) );
@@ -840,7 +841,7 @@
* @return IXR_Date IXR_Date object.
*/
protected function _convert_date_gmt( $date_gmt, $date ) {
- if ( $date !== '0000-00-00 00:00:00' && $date_gmt === '0000-00-00 00:00:00' ) {
+ if ( '0000-00-00 00:00:00' !== $date && '0000-00-00 00:00:00' === $date_gmt ) {
return new IXR_Date( get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $date, false ), 'Ymd\TH:i:s' ) );
}
return $this->_convert_date( $date_gmt );
@@ -878,7 +879,7 @@
'menu_order' => intval( $post['menu_order'] ),
'comment_status' => $post['comment_status'],
'ping_status' => $post['ping_status'],
- 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ),
+ 'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ),
);
// Thumbnail.
@@ -890,7 +891,7 @@
}
// Consider future posts as published.
- if ( $post_fields['post_status'] === 'future' ) {
+ if ( 'future' === $post_fields['post_status'] ) {
$post_fields['post_status'] = 'publish';
}
@@ -901,16 +902,16 @@
}
// Merge requested $post_fields fields into $_post.
- if ( in_array( 'post', $fields ) ) {
+ if ( in_array( 'post', $fields, true ) ) {
$_post = array_merge( $_post, $post_fields );
} else {
$requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) );
$_post = array_merge( $_post, $requested_fields );
}
- $all_taxonomy_fields = in_array( 'taxonomies', $fields );
-
- if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) {
+ $all_taxonomy_fields = in_array( 'taxonomies', $fields, true );
+
+ if ( $all_taxonomy_fields || in_array( 'terms', $fields, true ) ) {
$post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' );
$terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies );
$_post['terms'] = array();
@@ -919,11 +920,11 @@
}
}
- if ( in_array( 'custom_fields', $fields ) ) {
+ if ( in_array( 'custom_fields', $fields, true ) ) {
$_post['custom_fields'] = $this->get_custom_fields( $post['ID'] );
}
- if ( in_array( 'enclosure', $fields ) ) {
+ if ( in_array( 'enclosure', $fields, true ) ) {
$_post['enclosure'] = array();
$enclosures = (array) get_post_meta( $post['ID'], 'enclosure' );
if ( ! empty( $enclosures ) ) {
@@ -968,22 +969,22 @@
'supports' => get_all_post_type_supports( $post_type->name ),
);
- if ( in_array( 'labels', $fields ) ) {
+ if ( in_array( 'labels', $fields, true ) ) {
$_post_type['labels'] = (array) $post_type->labels;
}
- if ( in_array( 'cap', $fields ) ) {
+ if ( in_array( 'cap', $fields, true ) ) {
$_post_type['cap'] = (array) $post_type->cap;
$_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap;
}
- if ( in_array( 'menu', $fields ) ) {
+ if ( in_array( 'menu', $fields, true ) ) {
$_post_type['menu_position'] = (int) $post_type->menu_position;
$_post_type['menu_icon'] = $post_type->menu_icon;
$_post_type['show_in_menu'] = (bool) $post_type->show_in_menu;
}
- if ( in_array( 'taxonomies', $fields ) ) {
+ if ( in_array( 'taxonomies', $fields, true ) ) {
$_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' );
}
@@ -1130,7 +1131,7 @@
if ( '0' == $comment->comment_approved ) {
$comment_status = 'hold';
- } elseif ( 'spam' == $comment->comment_approved ) {
+ } elseif ( 'spam' === $comment->comment_approved ) {
$comment_status = 'spam';
} elseif ( '1' == $comment->comment_approved ) {
$comment_status = 'approve';
@@ -1189,10 +1190,10 @@
'roles' => $user->roles,
);
- if ( in_array( 'all', $fields ) ) {
+ if ( in_array( 'all', $fields, true ) ) {
$_user = array_merge( $_user, $user_fields );
} else {
- if ( in_array( 'basic', $fields ) ) {
+ if ( in_array( 'basic', $fields, true ) ) {
$basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' );
$fields = array_merge( $fields, $basic_fields );
}
@@ -1219,7 +1220,7 @@
*
* @link https://en.wikipedia.org/wiki/RSS_enclosure for information on RSS enclosures.
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: top-level arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -1270,19 +1271,22 @@
$password = $args[2];
$content_struct = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
- // convert the date field back to IXR form
+ // Convert the date field back to IXR form.
if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) {
$content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] );
}
- // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
- // since _insert_post will ignore the non-GMT date if the GMT date is set
+ /*
+ * Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
+ * since _insert_post() will ignore the non-GMT date if the GMT date is set.
+ */
if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) {
- if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) {
+ if ( '0000-00-00 00:00:00' === $content_struct['post_date_gmt'] || isset( $content_struct['post_date'] ) ) {
unset( $content_struct['post_date_gmt'] );
} else {
$content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] );
@@ -1397,7 +1401,7 @@
if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
}
- if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) ) {
+ if ( get_post_type( $post_data['ID'] ) !== $post_data['post_type'] ) {
return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
}
} else {
@@ -1447,11 +1451,11 @@
$post_data['post_author'] = $user->ID;
}
- if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) {
+ if ( isset( $post_data['comment_status'] ) && 'open' !== $post_data['comment_status'] && 'closed' !== $post_data['comment_status'] ) {
unset( $post_data['comment_status'] );
}
- if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) {
+ if ( isset( $post_data['ping_status'] ) && 'open' !== $post_data['ping_status'] && 'closed' !== $post_data['ping_status'] ) {
unset( $post_data['ping_status'] );
}
@@ -1467,8 +1471,8 @@
$post_data['edit_date'] = false;
if ( ! empty( $dateCreated ) ) {
- $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
- $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
+ $post_data['post_date'] = iso8601_to_datetime( $dateCreated );
+ $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'gmt' );
// Flag the post date to be edited.
$post_data['edit_date'] = true;
@@ -1479,7 +1483,7 @@
}
$post_ID = $post_data['ID'];
- if ( $post_data['post_type'] == 'post' ) {
+ if ( 'post' === $post_data['post_type'] ) {
$error = $this->_toggle_sticky( $post_data, $update );
if ( $error ) {
return $error;
@@ -1487,7 +1491,7 @@
}
if ( isset( $post_data['post_thumbnail'] ) ) {
- // empty value deletes, non-empty value adds/updates.
+ // Empty value deletes, non-empty value adds/updates.
if ( ! $post_data['post_thumbnail'] ) {
delete_post_thumbnail( $post_ID );
} elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) {
@@ -1511,7 +1515,7 @@
if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) {
$taxonomies = array_keys( $post_data['terms'] );
- // Validating term ids.
+ // Validating term IDs.
foreach ( $taxonomies as $taxonomy ) {
if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) {
return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) );
@@ -1555,8 +1559,8 @@
$ambiguous_terms = array();
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$tax_term_names = get_terms(
- $taxonomy,
array(
+ 'taxonomy' => $taxonomy,
'fields' => 'names',
'hide_empty' => false,
)
@@ -1573,7 +1577,7 @@
$term_names = $post_data['terms_names'][ $taxonomy ];
foreach ( $term_names as $term_name ) {
- if ( in_array( $term_name, $ambiguous_terms ) ) {
+ if ( in_array( $term_name, $ambiguous_terms, true ) ) {
return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) );
}
@@ -1635,7 +1639,11 @@
}
if ( ! $post_ID ) {
- return new IXR_Error( 401, __( 'Sorry, your entry could not be posted.' ) );
+ if ( $update ) {
+ return new IXR_Error( 401, __( 'Sorry, the post could not be updated.' ) );
+ } else {
+ return new IXR_Error( 401, __( 'Sorry, the post could not be created.' ) );
+ }
}
return strval( $post_ID );
@@ -1649,7 +1657,7 @@
*
* @since 3.4.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -1672,7 +1680,8 @@
$post_id = (int) $args[3];
$content_struct = $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -1699,12 +1708,22 @@
* Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
* since _insert_post() will ignore the non-GMT date if the GMT date is set.
*/
- if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) {
+ if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] || isset( $content_struct['post_date'] ) ) {
unset( $post['post_date_gmt'] );
} else {
$post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
}
+ /*
+ * If the API client did not provide 'post_date', then we must not perpetuate the value that
+ * was stored in the database, or it will appear to be an intentional edit. Conveying it here
+ * as if it was coming from the API client will cause an otherwise zeroed out 'post_date_gmt'
+ * to get set with the value that was originally stored in the database when the draft was created.
+ */
+ if ( ! isset( $content_struct['post_date'] ) ) {
+ unset( $post['post_date'] );
+ }
+
$this->escape( $post );
$merged_content_struct = array_merge( $post, $content_struct );
@@ -1723,7 +1742,7 @@
*
* @see wp_delete_post()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -1744,7 +1763,8 @@
$password = $args[2];
$post_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -1763,7 +1783,7 @@
$result = wp_delete_post( $post_id );
if ( ! $result ) {
- return new IXR_Error( 500, __( 'The post cannot be deleted.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) );
}
return true;
@@ -1843,7 +1863,8 @@
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -1903,7 +1924,8 @@
$fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2001,7 +2023,8 @@
$password = $args[2];
$content_struct = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2020,7 +2043,7 @@
$taxonomy = (array) $taxonomy;
- // hold the data of the term
+ // Hold the data of the term.
$term_data = array();
$term_data['name'] = trim( $content_struct['name'] );
@@ -2062,7 +2085,7 @@
}
if ( ! $term ) {
- return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the term could not be created.' ) );
}
// Add term meta.
@@ -2105,7 +2128,8 @@
$term_id = (int) $args[3];
$content_struct = $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2120,7 +2144,7 @@
$taxonomy = (array) $taxonomy;
- // hold the data of the term
+ // Hold the data of the term.
$term_data = array();
$term = get_term( $term_id, $content_struct['taxonomy'] );
@@ -2197,7 +2221,7 @@
*
* @see wp_delete_term()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -2220,7 +2244,8 @@
$taxonomy = $args[3];
$term_id = (int) $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2266,7 +2291,7 @@
*
* @see get_term()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -2298,7 +2323,8 @@
$taxonomy = $args[3];
$term_id = (int) $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2338,7 +2364,7 @@
*
* @see get_terms()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -2362,7 +2388,8 @@
$taxonomy = $args[3];
$filter = isset( $args[4] ) ? $args[4] : array();
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2379,7 +2406,7 @@
return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) );
}
- $query = array();
+ $query = array( 'taxonomy' => $taxonomy->name );
if ( isset( $filter['number'] ) ) {
$query['number'] = absint( $filter['number'] );
@@ -2407,7 +2434,7 @@
$query['search'] = $filter['search'];
}
- $terms = get_terms( $taxonomy->name, $query );
+ $terms = get_terms( $query );
if ( is_wp_error( $terms ) ) {
return new IXR_Error( 500, $terms->get_error_message() );
@@ -2429,7 +2456,7 @@
*
* @see get_taxonomy()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -2467,7 +2494,8 @@
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2494,7 +2522,7 @@
*
* @see get_taxonomies()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id Blog ID (unused).
@@ -2524,7 +2552,8 @@
$fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2533,11 +2562,11 @@
$taxonomies = get_taxonomies( $filter, 'objects' );
- // holds all the taxonomy data
+ // Holds all the taxonomy data.
$struct = array();
foreach ( $taxonomies as $taxonomy ) {
- // capability check for post_types
+ // Capability check for post types.
if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
continue;
}
@@ -2561,7 +2590,7 @@
*
* @uses get_userdata()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2609,7 +2638,8 @@
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2642,7 +2672,7 @@
* @uses get_users()
* @see wp_getUser() for more on $fields and return values
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2671,7 +2701,8 @@
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2723,7 +2754,7 @@
*
* @uses get_userdata()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2750,7 +2781,8 @@
$fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2771,7 +2803,7 @@
*
* @uses wp_update_user()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2799,7 +2831,8 @@
$password = $args[2];
$content_struct = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2810,11 +2843,11 @@
return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) );
}
- // holds data of the user
+ // Holds data of the user.
$user_data = array();
$user_data['ID'] = $user->ID;
- // only set the user details if it was given
+ // Only set the user details if they were given.
if ( isset( $content_struct['first_name'] ) ) {
$user_data['first_name'] = $content_struct['first_name'];
}
@@ -2850,7 +2883,7 @@
}
if ( ! $result ) {
- return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the user could not be updated.' ) );
}
return true;
@@ -2861,7 +2894,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2878,7 +2911,8 @@
$username = $args[2];
$password = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2895,10 +2929,10 @@
do_action( 'xmlrpc_call', 'wp.getPage' );
// If we found the page then format the data.
- if ( $page->ID && ( $page->post_type == 'page' ) ) {
+ if ( $page->ID && ( 'page' === $page->post_type ) ) {
return $this->_prepare_page( $page );
} else {
- // If the page doesn't exist indicate that.
+ // If the page doesn't exist, indicate that.
return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
}
}
@@ -2908,7 +2942,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2925,7 +2959,8 @@
$password = $args[2];
$num_pages = isset( $args[3] ) ? (int) $args[3] : 10;
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2968,7 +3003,7 @@
*
* @see wp_xmlrpc_server::mw_newPost()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -2979,11 +3014,12 @@
* @return int|IXR_Error
*/
public function wp_newPage( $args ) {
- // Items not escaped here will be escaped in newPost.
+ // Items not escaped here will be escaped in wp_newPost().
$username = $this->escape( $args[1] );
$password = $this->escape( $args[2] );
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -2993,7 +3029,7 @@
// Mark this as content for a page.
$args[3]['post_type'] = 'page';
- // Let mw_newPost do all of the heavy lifting.
+ // Let mw_newPost() do all of the heavy lifting.
return $this->mw_newPost( $args );
}
@@ -3002,7 +3038,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3019,17 +3055,18 @@
$password = $args[2];
$page_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.deletePage' );
- // Get the current page based on the page_id and
+ // 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 || ( $actual_page['post_type'] != 'page' ) ) {
+ if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) {
return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
}
@@ -3052,7 +3089,7 @@
* @param int $page_id ID of the deleted page.
* @param array $args An array of arguments to delete the page.
*/
- do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args );
+ do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return true;
}
@@ -3062,7 +3099,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3075,7 +3112,7 @@
* @return array|IXR_Error
*/
public function wp_editPage( $args ) {
- // Items will be escaped in mw_editPost.
+ // Items will be escaped in mw_editPost().
$page_id = (int) $args[1];
$username = $args[2];
$password = $args[3];
@@ -3085,7 +3122,8 @@
$escaped_username = $this->escape( $username );
$escaped_password = $this->escape( $password );
- if ( ! $user = $this->login( $escaped_username, $escaped_password ) ) {
+ $user = $this->login( $escaped_username, $escaped_password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3094,7 +3132,7 @@
// Get the page data and make sure it is a page.
$actual_page = get_post( $page_id, ARRAY_A );
- if ( ! $actual_page || ( $actual_page['post_type'] != 'page' ) ) {
+ if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) {
return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
}
@@ -3106,7 +3144,7 @@
// Mark this as content for a page.
$content['post_type'] = 'page';
- // Arrange args in the way mw_editPost understands.
+ // Arrange args in the way mw_editPost() understands.
$args = array(
$page_id,
$username,
@@ -3115,7 +3153,7 @@
$publish,
);
- // Let mw_editPost do all of the heavy lifting.
+ // Let mw_editPost() do all of the heavy lifting.
return $this->mw_editPost( $args );
}
@@ -3126,7 +3164,7 @@
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3143,7 +3181,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3154,7 +3193,7 @@
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.getPageList' );
- // Get list of pages ids and titles
+ // Get list of page IDs and titles.
$page_list = $wpdb->get_results(
"
SELECT ID page_id,
@@ -3188,7 +3227,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3203,7 +3242,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3231,7 +3271,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3246,7 +3286,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3259,7 +3300,8 @@
$tags = array();
- if ( $all_tags = get_tags() ) {
+ $all_tags = get_tags();
+ if ( $all_tags ) {
foreach ( (array) $all_tags as $tag ) {
$struct = array();
$struct['tag_id'] = $tag->term_id;
@@ -3281,7 +3323,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3298,7 +3340,8 @@
$password = $args[2];
$category = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3310,19 +3353,19 @@
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'] = '';
}
- // If no description was provided make it empty.
+ // If no description was provided, make it empty.
if ( empty( $category['description'] ) ) {
$category['description'] = '';
}
@@ -3336,13 +3379,13 @@
$cat_id = wp_insert_category( $new_category, true );
if ( is_wp_error( $cat_id ) ) {
- if ( 'term_exists' == $cat_id->get_error_code() ) {
+ if ( 'term_exists' === $cat_id->get_error_code() ) {
return (int) $cat_id->get_error_data();
} else {
- return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) );
}
} elseif ( ! $cat_id ) {
- return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the category could not be created.' ) );
}
/**
@@ -3353,7 +3396,7 @@
* @param int $cat_id ID of the new category.
* @param array $args An array of new category arguments.
*/
- do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args );
+ do_action( 'xmlrpc_call_success_wp_newCategory', $cat_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return $cat_id;
}
@@ -3363,7 +3406,7 @@
*
* @since 2.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3380,7 +3423,8 @@
$password = $args[2];
$category_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3402,7 +3446,7 @@
* @param int $category_id ID of the deleted category.
* @param array $args An array of arguments to delete the category.
*/
- do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args );
+ do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
}
return $status;
@@ -3413,7 +3457,7 @@
*
* @since 2.2.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3432,7 +3476,8 @@
$category = $args[3];
$max_results = (int) $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3464,7 +3509,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3481,14 +3526,16 @@
$password = $args[2];
$comment_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.getComment' );
- if ( ! $comment = get_comment( $comment_id ) ) {
+ $comment = get_comment( $comment_id );
+ if ( ! $comment ) {
return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
}
@@ -3515,7 +3562,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3532,7 +3579,8 @@
$password = $args[2];
$struct = isset( $args[3] ) ? $args[3] : array();
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3596,12 +3644,12 @@
/**
* Delete a comment.
*
- * By default, the comment will be moved to the trash instead of deleted.
+ * By default, the comment will be moved to the Trash instead of deleted.
* See wp_delete_comment() for more information on this behavior.
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3618,7 +3666,8 @@
$password = $args[2];
$comment_ID = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3644,7 +3693,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
}
return $status;
@@ -3666,7 +3715,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3685,7 +3734,8 @@
$comment_ID = (int) $args[3];
$content_struct = $args[4];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3707,19 +3757,19 @@
$statuses = get_comment_statuses();
$statuses = array_keys( $statuses );
- if ( ! in_array( $content_struct['status'], $statuses ) ) {
+ if ( ! in_array( $content_struct['status'], $statuses, true ) ) {
return new IXR_Error( 401, __( 'Invalid comment status.' ) );
}
$comment['comment_approved'] = $content_struct['status'];
}
- // Do some timestamp voodoo
+ // Do some timestamp voodoo.
if ( ! empty( $content_struct['date_created_gmt'] ) ) {
- // We know this is supposed to be GMT, so we're going to slap that Z on there by force
+ // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
- $comment['comment_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
- $comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
+ $comment['comment_date'] = get_date_from_gmt( $dateCreated );
+ $comment['comment_date_gmt'] = iso8601_to_datetime( $dateCreated, 'gmt' );
}
if ( isset( $content_struct['content'] ) ) {
@@ -3738,13 +3788,13 @@
$comment['comment_author_email'] = $content_struct['author_email'];
}
- $result = wp_update_comment( $comment );
+ $result = wp_update_comment( $comment, true );
if ( is_wp_error( $result ) ) {
return new IXR_Error( 500, $result->get_error_message() );
}
if ( ! $result ) {
- return new IXR_Error( 500, __( 'Sorry, the comment could not be edited.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the comment could not be updated.' ) );
}
/**
@@ -3755,7 +3805,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_wp_editComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return true;
}
@@ -3765,7 +3815,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3799,7 +3849,7 @@
if ( ! $user ) {
$logged_in = false;
if ( $allow_anon && get_option( 'comment_registration' ) ) {
- return new IXR_Error( 403, __( 'You must be registered to comment.' ) );
+ return new IXR_Error( 403, __( 'Sorry, you must be logged in to comment.' ) );
} elseif ( ! $allow_anon ) {
return $this->error;
}
@@ -3862,7 +3912,7 @@
$comment['user_ID'] = 0;
if ( get_option( 'require_name_email' ) ) {
- if ( 6 > strlen( $comment['comment_author_email'] ) || '' == $comment['comment_author'] ) {
+ if ( strlen( $comment['comment_author_email'] < 6 ) || '' === $comment['comment_author'] ) {
return new IXR_Error( 403, __( 'Comment author name and email are required.' ) );
} elseif ( ! is_email( $comment['comment_author_email'] ) ) {
return new IXR_Error( 403, __( 'A valid email address is required.' ) );
@@ -3892,7 +3942,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_wp_newComment', $comment_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return $comment_ID;
}
@@ -3902,7 +3952,7 @@
*
* @since 2.7.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3917,7 +3967,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3936,7 +3987,7 @@
*
* @since 2.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3953,7 +4004,8 @@
$password = $args[2];
$post_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -3984,7 +4036,7 @@
*
* @since 2.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -3999,7 +4051,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4018,7 +4071,7 @@
*
* @since 2.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4033,7 +4086,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4052,7 +4106,7 @@
*
* @since 2.6.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4067,7 +4121,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4086,7 +4141,7 @@
*
* @since 2.6.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4103,11 +4158,12 @@
$password = $args[2];
$options = isset( $args[3] ) ? (array) $args[3] : array();
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
- // If no specific options where asked for, return all of them
+ // If no specific options where asked for, return all of them.
if ( count( $options ) == 0 ) {
$options = array_keys( $this->blog_options );
}
@@ -4129,7 +4185,7 @@
foreach ( $options as $option ) {
if ( array_key_exists( $option, $this->blog_options ) ) {
$data[ $option ] = $this->blog_options[ $option ];
- //Is the value static or dynamic?
+ // Is the value static or dynamic?
if ( isset( $data[ $option ]['option'] ) ) {
$data[ $option ]['value'] = get_option( $data[ $option ]['option'] );
unset( $data[ $option ]['option'] );
@@ -4149,7 +4205,7 @@
*
* @since 2.6.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4166,7 +4222,8 @@
$password = $args[2];
$options = (array) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4181,14 +4238,14 @@
continue;
}
- if ( $this->blog_options[ $o_name ]['readonly'] == true ) {
+ if ( true == $this->blog_options[ $o_name ]['readonly'] ) {
continue;
}
update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) );
}
- //Now return the updated values
+ // Now return the updated values.
return $this->_getOptions( $option_names );
}
@@ -4197,7 +4254,7 @@
*
* @since 3.1.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4222,7 +4279,8 @@
$password = $args[2];
$attachment_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4233,7 +4291,8 @@
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.getMediaItem' );
- if ( ! $attachment = get_post( $attachment_id ) ) {
+ $attachment = get_post( $attachment_id );
+ if ( ! $attachment ) {
return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
}
@@ -4256,7 +4315,7 @@
*
* @since 3.1.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4273,7 +4332,8 @@
$password = $args[2];
$struct = isset( $args[3] ) ? $args[3] : array();
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4313,7 +4373,7 @@
*
* @since 3.1.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4328,7 +4388,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4341,7 +4402,7 @@
$formats = get_post_format_strings();
- // find out if they want a list of currently supports formats
+ // Find out if they want a list of currently supports formats.
if ( isset( $args[3] ) && is_array( $args[3] ) ) {
if ( $args[3]['show-supported'] ) {
if ( current_theme_supports( 'post-formats' ) ) {
@@ -4366,7 +4427,7 @@
*
* @see get_post_type_object()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4411,7 +4472,8 @@
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4438,7 +4500,7 @@
*
* @see get_post_types()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4467,7 +4529,8 @@
$fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4500,7 +4563,7 @@
* @uses wp_get_post_revisions()
* @see wp_getPost() for more on $fields
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4536,14 +4599,16 @@
$fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' );
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.getRevisions' );
- if ( ! $post = get_post( $post_id ) ) {
+ $post = get_post( $post_id );
+ if ( ! $post ) {
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
}
@@ -4569,7 +4634,7 @@
continue;
}
- // Skip autosaves
+ // Skip autosaves.
if ( wp_is_post_autosave( $revision ) ) {
continue;
}
@@ -4587,7 +4652,7 @@
*
* @uses wp_restore_post_revision()
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4608,14 +4673,16 @@
$password = $args[2];
$revision_id = (int) $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'wp.restoreRevision' );
- if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
+ $revision = wp_get_post_revision( $revision_id );
+ if ( ! $revision ) {
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
}
@@ -4623,7 +4690,8 @@
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
}
- if ( ! $post = get_post( $revision->post_parent ) ) {
+ $post = get_post( $revision->post_parent );
+ if ( ! $post ) {
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
}
@@ -4641,8 +4709,9 @@
return (bool) $post;
}
- /* Blogger API functions.
- * specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/
+ /*
+ * Blogger API functions.
+ * Specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/
*/
/**
@@ -4652,7 +4721,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4675,7 +4744,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4741,7 +4811,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4756,7 +4826,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4783,7 +4854,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -4800,7 +4871,8 @@
$username = $args[2];
$password = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4837,7 +4909,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type string $appkey (unused)
@@ -4852,7 +4924,7 @@
$this->escape( $args );
- // $args[0] = appkey - ignored
+ // $args[0] = appkey - ignored.
$username = $args[2];
$password = $args[3];
if ( isset( $args[4] ) ) {
@@ -4861,7 +4933,8 @@
$query = array();
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4913,7 +4986,7 @@
* @return IXR_Error Error object.
*/
public function blogger_getTemplate( $args ) {
- return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) );
+ return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) );
}
/**
@@ -4926,7 +4999,7 @@
* @return IXR_Error Error object.
*/
public function blogger_setTemplate( $args ) {
- return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) );
+ return new IXR_Error( 403, __( 'Sorry, this method is not supported.' ) );
}
/**
@@ -4954,7 +5027,8 @@
$content = $args[4];
$publish = $args[5];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -4985,7 +5059,7 @@
}
if ( ! $post_ID ) {
- return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) );
}
$this->attach_uploads( $post_ID, $post_content );
@@ -4998,7 +5072,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return $post_ID;
}
@@ -5008,7 +5082,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -5030,7 +5104,8 @@
$content = $args[4];
$publish = $args[5];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -5039,7 +5114,7 @@
$actual_post = get_post( $post_ID, ARRAY_A );
- if ( ! $actual_post || $actual_post['post_type'] != 'post' ) {
+ if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) {
return new IXR_Error( 404, __( 'Sorry, no such post.' ) );
}
@@ -5048,7 +5123,7 @@
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' ) ) {
+ if ( 'publish' === $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) {
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) );
}
@@ -5064,7 +5139,7 @@
$result = wp_update_post( $postdata );
if ( ! $result ) {
- return new IXR_Error( 500, __( 'For some strange yet very annoying reason, this post could not be edited.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) );
}
$this->attach_uploads( $actual_post['ID'], $postdata['post_content'] );
@@ -5076,7 +5151,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return true;
}
@@ -5086,7 +5161,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -5103,7 +5178,8 @@
$username = $args[2];
$password = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -5112,7 +5188,7 @@
$actual_post = get_post( $post_ID, ARRAY_A );
- if ( ! $actual_post || $actual_post['post_type'] != 'post' ) {
+ if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) {
return new IXR_Error( 404, __( 'Sorry, no such post.' ) );
}
@@ -5123,7 +5199,7 @@
$result = wp_delete_post( $post_ID );
if ( ! $result ) {
- return new IXR_Error( 500, __( 'The post cannot be deleted.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the post could not be deleted.' ) );
}
/**
@@ -5134,13 +5210,14 @@
* @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 );
+ do_action( 'xmlrpc_call_success_blogger_deletePost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return true;
}
- /* MetaWeblog API functions
- * specs on wherever Dave Winer wants them to be
+ /*
+ * MetaWeblog API functions.
+ * Specs on wherever Dave Winer wants them to be.
*/
/**
@@ -5170,7 +5247,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -5189,7 +5266,8 @@
$content_struct = $args[3];
$publish = isset( $args[4] ) ? $args[4] : 0;
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -5198,10 +5276,10 @@
$page_template = '';
if ( ! empty( $content_struct['post_type'] ) ) {
- if ( $content_struct['post_type'] == 'page' ) {
+ if ( 'page' === $content_struct['post_type'] ) {
if ( $publish ) {
$cap = 'publish_pages';
- } elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] ) {
+ } elseif ( isset( $content_struct['page_status'] ) && 'publish' === $content_struct['page_status'] ) {
$cap = 'publish_pages';
} else {
$cap = 'edit_pages';
@@ -5211,10 +5289,10 @@
if ( ! empty( $content_struct['wp_page_template'] ) ) {
$page_template = $content_struct['wp_page_template'];
}
- } elseif ( $content_struct['post_type'] == 'post' ) {
+ } elseif ( 'post' === $content_struct['post_type'] ) {
if ( $publish ) {
$cap = 'publish_posts';
- } elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) {
+ } elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) {
$cap = 'publish_posts';
} else {
$cap = 'edit_posts';
@@ -5222,13 +5300,13 @@
$error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
$post_type = 'post';
} else {
- // No other post_type values are allowed here
+ // No other 'post_type' values are allowed here.
return new IXR_Error( 401, __( 'Invalid post type.' ) );
}
} else {
if ( $publish ) {
$cap = 'publish_posts';
- } elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) {
+ } elseif ( isset( $content_struct['post_status'] ) && 'publish' === $content_struct['post_status'] ) {
$cap = 'publish_posts';
} else {
$cap = 'edit_posts';
@@ -5244,7 +5322,7 @@
return new IXR_Error( 401, $error_message );
}
- // Check for a valid post format if one was given
+ // Check for a valid post format if one was given.
if ( isset( $content_struct['wp_post_format'] ) ) {
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
@@ -5252,7 +5330,7 @@
}
}
- // Let WordPress generate the post_name (slug) unless
+ // Let WordPress generate the 'post_name' (slug) unless
// one has been provided.
$post_name = '';
if ( isset( $content_struct['wp_slug'] ) ) {
@@ -5266,14 +5344,14 @@
$post_password = '';
}
- // Only set a post parent if one was provided.
+ // Only set a post parent if one was given.
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 provided.
+ // Only set the 'menu_order' if it was given.
if ( isset( $content_struct['wp_page_order'] ) ) {
$menu_order = $content_struct['wp_page_order'];
} else {
@@ -5402,17 +5480,17 @@
}
}
- // Do some timestamp voodoo
+ // Do some timestamp voodoo.
if ( ! empty( $content_struct['date_created_gmt'] ) ) {
- // We know this is supposed to be GMT, so we're going to slap that Z on there by force
+ // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
$dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
} elseif ( ! empty( $content_struct['dateCreated'] ) ) {
$dateCreated = $content_struct['dateCreated']->getIso();
}
if ( ! empty( $dateCreated ) ) {
- $post_date = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
- $post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' );
+ $post_date = iso8601_to_datetime( $dateCreated );
+ $post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' );
} else {
$post_date = '';
$post_date_gmt = '';
@@ -5431,10 +5509,11 @@
$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 = $postdata['ID'] = get_default_post_to_edit( $post_type, true )->ID;
-
- // Only posts can be sticky
- if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
+ $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'] ) ) {
$data = $postdata;
$data['sticky'] = $content_struct['sticky'];
$error = $this->_toggle_sticky( $data );
@@ -5455,14 +5534,14 @@
unset( $content_struct['wp_post_thumbnail'] );
}
- // Handle enclosures
+ // 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
+ // in this function.
if ( isset( $content_struct['wp_post_format'] ) ) {
set_post_format( $post_ID, $content_struct['wp_post_format'] );
}
@@ -5473,7 +5552,7 @@
}
if ( ! $post_ID ) {
- return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) );
+ return new IXR_Error( 500, __( 'Sorry, the post could not be created.' ) );
}
/**
@@ -5484,7 +5563,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return strval( $post_ID );
}
@@ -5499,9 +5578,10 @@
*/
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;
- if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) {
+ $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n";
+ $found = false;
+ $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" ) ) {
@@ -5523,13 +5603,13 @@
*
* @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 ) {
global $wpdb;
- // find any unattached files
+ // 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 ) {
@@ -5545,7 +5625,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -5565,7 +5645,8 @@
$content_struct = $args[3];
$publish = isset( $args[4] ) ? $args[4] : 0;
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -5575,7 +5656,7 @@
$postdata = get_post( $post_ID, ARRAY_A );
/*
- * If there is no post data for the give post id, stop now and return an error.
+ * If there is no post data for the give post ID, stop now and return an error.
* Otherwise a new post will be created (which was the old behavior).
*/
if ( ! $postdata || empty( $postdata['ID'] ) ) {
@@ -5587,7 +5668,7 @@
}
// Use wp.editPost to edit post types other than post and page.
- if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ) ) ) {
+ if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ), true ) ) {
return new IXR_Error( 401, __( 'Invalid post type.' ) );
}
@@ -5596,7 +5677,7 @@
return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
}
- // Check for a valid post format if one was given
+ // Check for a valid post format if one was given.
if ( isset( $content_struct['wp_post_format'] ) ) {
$content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
@@ -5633,19 +5714,19 @@
$post_parent = $content_struct['wp_page_parent_id'];
}
- // Only set the menu_order if it was given.
+ // Only set the 'menu_order' if it was given.
if ( isset( $content_struct['wp_page_order'] ) ) {
$menu_order = $content_struct['wp_page_order'];
}
$page_template = null;
- if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) {
+ if ( ! empty( $content_struct['wp_page_template'] ) && 'page' === $post_type ) {
$page_template = $content_struct['wp_page_template'];
}
$post_author = $postdata['post_author'];
- // Only set the post_author if one is set.
+ // If an author id was provided then use it instead.
if ( isset( $content_struct['wp_author_id'] ) ) {
// Check permissions if attempting to switch author to or from another user.
if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) {
@@ -5765,8 +5846,8 @@
$tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
- if ( 'publish' == $post_status || 'private' == $post_status ) {
- if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
+ if ( 'publish' === $post_status || 'private' === $post_status ) {
+ if ( 'page' === $post_type && ! current_user_can( 'publish_pages' ) ) {
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this page.' ) );
} elseif ( ! current_user_can( 'publish_posts' ) ) {
return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) );
@@ -5797,8 +5878,8 @@
$edit_date = false;
if ( ! empty( $dateCreated ) ) {
- $post_date = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
- $post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' );
+ $post_date = iso8601_to_datetime( $dateCreated );
+ $post_date_gmt = iso8601_to_datetime( $dateCreated, 'gmt' );
// Flag the post date to be edited.
$edit_date = true;
@@ -5816,11 +5897,11 @@
}
if ( ! $result ) {
- return new IXR_Error( 500, __( 'Sorry, your entry could not be edited.' ) );
- }
-
- // Only posts can be sticky
- if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
+ return new IXR_Error( 500, __( 'Sorry, the post could not be updated.' ) );
+ }
+
+ // Only posts can be sticky.
+ if ( 'post' === $post_type && isset( $content_struct['sticky'] ) ) {
$data = $newpost;
$data['sticky'] = $content_struct['sticky'];
$data['post_type'] = 'post';
@@ -5866,7 +5947,7 @@
* @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 );
+ do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
return true;
}
@@ -5876,7 +5957,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -5893,7 +5974,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -5909,7 +5991,7 @@
/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
do_action( 'xmlrpc_call', 'metaWeblog.getPost' );
- if ( $postdata['post_date'] != '' ) {
+ if ( '' !== $postdata['post_date'] ) {
$post_date = $this->_convert_date( $postdata['post_date'] );
$post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] );
$post_modified = $this->_convert_date( $postdata['post_modified'] );
@@ -5938,15 +6020,15 @@
// Get the author info.
$author = get_userdata( $postdata['post_author'] );
- $allow_comments = ( 'open' == $postdata['comment_status'] ) ? 1 : 0;
- $allow_pings = ( 'open' == $postdata['ping_status'] ) ? 1 : 0;
-
- // Consider future posts as published
- if ( $postdata['post_status'] === 'future' ) {
+ $allow_comments = ( 'open' === $postdata['comment_status'] ) ? 1 : 0;
+ $allow_pings = ( 'open' === $postdata['ping_status'] ) ? 1 : 0;
+
+ // Consider future posts as published.
+ if ( 'future' === $postdata['post_status'] ) {
$postdata['post_status'] = 'publish';
}
- // Get post format
+ // Get post format.
$post_format = get_post_format( $post_ID );
if ( empty( $post_format ) ) {
$post_format = 'standard';
@@ -5959,7 +6041,7 @@
$enclosure = array();
foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) {
- if ( $key == 'enclosure' ) {
+ if ( 'enclosure' === $key ) {
foreach ( (array) $val as $enc ) {
$encdata = explode( "\n", $enc );
$enclosure['url'] = trim( htmlspecialchars( $encdata[0] ) );
@@ -5978,8 +6060,8 @@
'title' => $postdata['post_title'],
'link' => $link,
'permaLink' => $link,
- // commented out because no other tool seems to use this
- // 'content' => $entry['post_content'],
+ // Commented out because no other tool seems to use this.
+ // 'content' => $entry['post_content'],
'categories' => $categories,
'mt_excerpt' => $postdata['post_excerpt'],
'mt_text_more' => $post['extended'],
@@ -6017,7 +6099,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -6038,7 +6120,8 @@
$query = array();
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6089,15 +6172,15 @@
// Get the post author info.
$author = get_userdata( $entry['post_author'] );
- $allow_comments = ( 'open' == $entry['comment_status'] ) ? 1 : 0;
- $allow_pings = ( 'open' == $entry['ping_status'] ) ? 1 : 0;
-
- // Consider future posts as published
- if ( $entry['post_status'] === 'future' ) {
+ $allow_comments = ( 'open' === $entry['comment_status'] ) ? 1 : 0;
+ $allow_pings = ( 'open' === $entry['ping_status'] ) ? 1 : 0;
+
+ // Consider future posts as published.
+ if ( 'future' === $entry['post_status'] ) {
$entry['post_status'] = 'publish';
}
- // Get post format
+ // Get post format.
$post_format = get_post_format( $entry['ID'] );
if ( empty( $post_format ) ) {
$post_format = 'standard';
@@ -6111,7 +6194,7 @@
'title' => $entry['post_title'],
'link' => $link,
'permaLink' => $link,
- // commented out because no other tool seems to use this
+ // Commented out because no other tool seems to use this.
// 'content' => $entry['post_content'],
'categories' => $categories,
'mt_excerpt' => $entry['post_excerpt'],
@@ -6130,7 +6213,7 @@
'wp_post_format' => $post_format,
'date_modified' => $post_modified,
'date_modified_gmt' => $post_modified_gmt,
- 'sticky' => ( $entry['post_type'] === 'post' && is_sticky( $entry['ID'] ) ),
+ 'sticky' => ( 'post' === $entry['post_type'] && is_sticky( $entry['ID'] ) ),
'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] ),
);
}
@@ -6143,7 +6226,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -6158,7 +6241,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6171,7 +6255,8 @@
$categories_struct = array();
- if ( $cats = get_categories( array( 'get' => 'all' ) ) ) {
+ $cats = get_categories( array( 'get' => 'all' ) );
+ if ( $cats ) {
foreach ( $cats as $cat ) {
$struct = array();
$struct['categoryId'] = $cat->term_id;
@@ -6200,7 +6285,7 @@
*
* @global wpdb $wpdb WordPress database abstraction object.
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -6221,7 +6306,8 @@
$type = $data['type'];
$bits = $data['bits'];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6237,7 +6323,7 @@
$this->error = new IXR_Error(
401,
sprintf(
- /* translators: %s: allowed space allocation */
+ /* translators: %s: Allowed space allocation. */
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
size_format( get_space_allowed() * MB_IN_BYTES )
)
@@ -6255,17 +6341,18 @@
*
* @param bool $error Whether to pre-empt the media upload. Default false.
*/
- if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) {
+ $upload_err = apply_filters( 'pre_upload_error', false );
+ if ( $upload_err ) {
return new IXR_Error( 500, $upload_err );
}
$upload = wp_upload_bits( $name, null, $bits );
if ( ! empty( $upload['error'] ) ) {
- /* translators: 1: file name, 2: error message */
+ /* translators: 1: File name, 2: Error message. */
$errorString = sprintf( __( 'Could not write file %1$s (%2$s).' ), $name, $upload['error'] );
return new IXR_Error( 500, $errorString );
}
- // Construct the attachment array
+ // Construct the attachment array.
$post_id = 0;
if ( ! empty( $data['post_id'] ) ) {
$post_id = (int) $data['post_id'];
@@ -6283,7 +6370,7 @@
'guid' => $upload['url'],
);
- // Save the data
+ // Save the data.
$id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
@@ -6295,11 +6382,11 @@
* @param int $id ID of the new attachment.
* @param array $args An array of arguments to add the attachment.
*/
- do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args );
+ do_action( 'xmlrpc_call_success_mw_newMediaObject', $id, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
$struct = $this->_prepare_media_item( get_post( $id ) );
- // Deprecated values
+ // Deprecated values.
$struct['id'] = $struct['attachment_id'];
$struct['file'] = $struct['title'];
$struct['url'] = $struct['link'];
@@ -6307,8 +6394,9 @@
return $struct;
}
- /* MovableType API functions
- * specs on http://www.movabletype.org/docs/mtmanual_programmatic.html
+ /*
+ * MovableType API functions.
+ * Specs on http://www.movabletype.org/docs/mtmanual_programmatic.html
*/
/**
@@ -6316,7 +6404,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -6337,7 +6425,8 @@
$query = array();
}
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6379,7 +6468,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $blog_id (unused)
@@ -6394,7 +6483,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6407,12 +6497,13 @@
$categories_struct = array();
- if ( $cats = get_categories(
+ $cats = get_categories(
array(
'hide_empty' => 0,
'hierarchical' => 0,
)
- ) ) {
+ );
+ if ( $cats ) {
foreach ( $cats as $cat ) {
$struct = array();
$struct['categoryId'] = $cat->term_id;
@@ -6430,7 +6521,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $post_ID
@@ -6446,7 +6537,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6463,7 +6555,7 @@
$categories = array();
$catids = wp_get_post_categories( intval( $post_ID ) );
- // first listed category will be the primary category
+ // First listed category will be the primary category.
$isPrimary = true;
foreach ( $catids as $catid ) {
$categories[] = array(
@@ -6482,7 +6574,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $post_ID
@@ -6500,7 +6592,8 @@
$password = $args[2];
$categories = $args[3];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6588,7 +6681,7 @@
$trackback_pings = array();
foreach ( $comments as $comment ) {
- if ( 'trackback' == $comment->comment_type ) {
+ if ( 'trackback' === $comment->comment_type ) {
$content = $comment->comment_content;
$title = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) );
$trackback_pings[] = array(
@@ -6607,7 +6700,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type int $post_ID
@@ -6623,7 +6716,8 @@
$username = $args[1];
$password = $args[2];
- if ( ! $user = $this->login( $username, $password ) ) {
+ $user = $this->login( $username, $password );
+ if ( ! $user ) {
return $this->error;
}
@@ -6641,16 +6735,16 @@
$postdata['post_status'] = 'publish';
- // retain old cats
- $cats = wp_get_post_categories( $post_ID );
- $postdata['post_category'] = $cats;
+ // Retain old categories.
+ $postdata['post_category'] = wp_get_post_categories( $post_ID );
$this->escape( $postdata );
return wp_update_post( $postdata );
}
- /* PingBack functions
- * specs on www.hixie.ch/specs/pingback/pingback
+ /*
+ * Pingback functions.
+ * Specs on www.hixie.ch/specs/pingback/pingback
*/
/**
@@ -6658,7 +6752,7 @@
*
* @since 1.5.0
*
- * @param array $args {
+ * @param array $args {
* Method arguments. Note: arguments must be ordered as documented.
*
* @type string $pagelinkedfrom
@@ -6692,78 +6786,82 @@
return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) );
}
- // Check if the page linked to is in our site
+ // Check if the page linked to is on our site.
$pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) );
if ( ! $pos1 ) {
return $this->pingback_error( 0, __( 'Is there no link to us?' ) );
}
- // let's find which post is linked to
- // FIXME: does url_to_postid() cover all these cases already?
- // if so, then let's use it and drop the old code.
+ /*
+ * Let's find which post is linked to.
+ * FIXME: Does url_to_postid() cover all these cases already?
+ * If so, then let's use it and drop the old code.
+ */
$urltest = parse_url( $pagelinkedto );
- if ( $post_ID = url_to_postid( $pagelinkedto ) ) {
+ $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)
+ // The path defines the post_ID (archives/p/XXXX).
$blah = explode( '/', $match[0] );
$post_ID = (int) $blah[1];
} elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) {
- // the querystring defines the post_ID (?p=XXXX)
+ // The query string defines the post_ID (?p=XXXX).
$blah = explode( '=', $match[0] );
$post_ID = (int) $blah[1];
} elseif ( isset( $urltest['fragment'] ) ) {
- // an #anchor is there, it's either...
+ // An #anchor is there, it's either...
if ( intval( $urltest['fragment'] ) ) {
- // ...an integer #XXXX (simplest case)
+ // ...an integer #XXXX (simplest case),
$post_ID = (int) $urltest['fragment'];
} elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) {
- // ...a post id in the form 'post-###'
+ // ...a post ID in the form 'post-###',
$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 );
- if ( ! ( $post_ID = $wpdb->get_var( $sql ) ) ) {
- // returning unknown error '0' is better than die()ing
+ // ...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 ) {
+ // Returning unknown error '0' is better than die()'ing.
return $this->pingback_error( 0, '' );
}
}
} else {
- // TODO: Attempt to extract a post ID from the given URL
+ // 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 doesn’t exist, or it is not a pingback-enabled resource.' ) );
}
$post_ID = (int) $post_ID;
$post = get_post( $post_ID );
- if ( ! $post ) { // Post_ID not found
+ if ( ! $post ) { // Post not found.
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
}
- if ( $post_ID == url_to_postid( $pagelinkedfrom ) ) {
+ 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.' ) );
}
- // Check if pings are on
+ // Check if pings are on.
if ( ! pings_open( $post ) ) {
return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) );
}
- // Let's check that the remote site didn't already pingback this entry
+ // 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 ) ) ) {
return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) );
}
- // very stupid, but gives time to the 'from' server to publish !
+ // Very stupid, but gives time to the 'from' server to publish!
sleep( 1 );
$remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] );
/** This filter is documented in wp-includes/class-http.php */
- $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $url );
-
- // Let's check the remote site
+ $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $pagelinkedfrom );
+
+ // Let's check the remote site.
$http_api_args = array(
'timeout' => 10,
'redirection' => 0,
@@ -6774,8 +6872,9 @@
),
);
- $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args );
- $remote_source = $remote_source_original = wp_remote_retrieve_body( $request );
+ $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args );
+ $remote_source = wp_remote_retrieve_body( $request );
+ $remote_source_original = $remote_source;
if ( ! $remote_source ) {
return $this->pingback_error( 16, __( 'The source URL does not exist.' ) );
@@ -6802,23 +6901,26 @@
return $this->pingback_error( 32, __( 'We cannot find a title on that page.' ) );
}
- $remote_source = strip_tags( $remote_source, '<a>' ); // just keep the tag we need
+ // Remove all script and style tags including their content.
+ $remote_source = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $remote_source );
+ // Just keep the tag we need.
+ $remote_source = strip_tags( $remote_source, '<a>' );
$p = explode( "\n\n", $remote_source );
$preg_target = preg_quote( $pagelinkedto, '|' );
foreach ( $p as $para ) {
- if ( strpos( $para, $pagelinkedto ) !== false ) { // it exists, but is it a link?
+ if ( strpos( $para, $pagelinkedto ) !== false ) { // It exists, but is it a link?
preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context );
- // If the URL isn't in a link context, keep looking
+ // If the URL isn't in a link context, keep looking.
if ( empty( $context ) ) {
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( '|\</?wpcontext\>|', '', $para );
// prevent really long link text
@@ -6826,18 +6928,18 @@
$context[1] = substr( $context[1], 0, 100 ) . '…';
}
- $marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // set up our marker
- $excerpt = str_replace( $context[0], $marker, $excerpt ); // swap out the link for our marker
- $excerpt = strip_tags( $excerpt, '<wpcontext>' ); // strip all tags but our context marker
+ $marker = '<wpcontext>' . $context[1] . '</wpcontext>'; // Set up our marker.
+ $excerpt = str_replace( $context[0], $marker, $excerpt ); // Swap out the link for our marker.
+ $excerpt = strip_tags( $excerpt, '<wpcontext>' ); // Strip all tags but our context marker.
$excerpt = trim( $excerpt );
$preg_marker = preg_quote( $marker, '|' );
$excerpt = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt );
- $excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper
+ $excerpt = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper.
break;
}
}
- if ( empty( $context ) ) { // Link to target not found
+ if ( empty( $context ) ) { // Link to target not found.
return $this->pingback_error( 17, __( 'The source URL does not contain a link to the target URL, and so cannot be used as a source.' ) );
}
@@ -6881,7 +6983,7 @@
*/
do_action( 'pingback_post', $comment_ID );
- /* translators: 1: URL of the page linked from, 2: URL of the page linked to */
+ /* 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 );
}
@@ -6907,14 +7009,14 @@
$post_ID = url_to_postid( $url );
if ( ! $post_ID ) {
- // We aren't sure that the resource is available and/or pingback enabled
+ // 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 doesn’t exist, or it is not a pingback-enabled resource.' ) );
}
$actual_post = get_post( $post_ID, ARRAY_A );
if ( ! $actual_post ) {
- // No such post = resource not found
+ // No such post = resource not found.
return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) );
}
@@ -6926,7 +7028,7 @@
$pingbacks = array();
foreach ( $comments as $comment ) {
- if ( 'pingback' == $comment->comment_type ) {
+ if ( 'pingback' === $comment->comment_type ) {
$pingbacks[] = $comment->comment_author_url;
}
}