Make WordPress Core

Ticket #35185: 35185.diff

File 35185.diff, 26.7 KB (added by dd32, 9 years ago)

number of places isset() would have to change to !empty() UNTESTED - Pretty sure I missed a lot of other $args[3] & $args[4] uses.

  • src/wp-includes/class-wp-xmlrpc-server.php

    class wp_xmlrpc_server extends IXR_Serve 
    11831183         */
    11841184        public function wp_newPost( $args ) {
    11851185                if ( ! $this->minimum_args( $args, 4 ) )
    11861186                        return $this->error;
    11871187
    11881188                $this->escape( $args );
    11891189
    11901190                $username       = $args[1];
    11911191                $password       = $args[2];
    11921192                $content_struct = $args[3];
    11931193
    11941194                if ( ! $user = $this->login( $username, $password ) )
    11951195                        return $this->error;
    11961196
    11971197                // convert the date field back to IXR form
    1198                 if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) {
     1198                if ( !empty( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) {
    11991199                        $content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] );
    12001200                }
    12011201
    12021202                // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
    12031203                // since _insert_post will ignore the non-GMT date if the GMT date is set
    1204                 if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) {
    1205                         if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) {
     1204                if ( !empty( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) {
     1205                        if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || !empty( $content_struct['post_date'] ) ) {
    12061206                                unset( $content_struct['post_date_gmt'] );
    12071207                        } else {
    12081208                                $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] );
    12091209                        }
    12101210                }
    12111211
    12121212                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    12131213                do_action( 'xmlrpc_call', 'wp.newPost' );
    12141214
    12151215                unset( $content_struct['ID'] );
    12161216
    12171217                return $this->_insert_post( $user, $content_struct );
    12181218        }
    12191219
    12201220        /**
    class wp_xmlrpc_server extends IXR_Serve 
    15351535                $password       = $args[2];
    15361536                $post_id        = (int) $args[3];
    15371537                $content_struct = $args[4];
    15381538
    15391539                if ( ! $user = $this->login( $username, $password ) )
    15401540                        return $this->error;
    15411541
    15421542                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    15431543                do_action( 'xmlrpc_call', 'wp.editPost' );
    15441544
    15451545                $post = get_post( $post_id, ARRAY_A );
    15461546
    15471547                if ( empty( $post['ID'] ) )
    15481548                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    15491549
    1550                 if ( isset( $content_struct['if_not_modified_since'] ) ) {
     1550                if ( !empty( $content_struct['if_not_modified_since'] ) ) {
    15511551                        // If the post has been modified since the date provided, return an error.
    15521552                        if ( mysql2date( 'U', $post['post_modified_gmt'] ) > $content_struct['if_not_modified_since']->getTimestamp() ) {
    15531553                                return new IXR_Error( 409, __( 'There is a revision of this post that is more recent.' ) );
    15541554                        }
    15551555                }
    15561556
    15571557                // Convert the date field back to IXR form.
    15581558                $post['post_date'] = $this->_convert_date( $post['post_date'] );
    15591559
    15601560                /*
    15611561                 * Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
    15621562                 * since _insert_post() will ignore the non-GMT date if the GMT date is set.
    15631563                 */
    1564                 if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) )
     1564                if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || !empty( $content_struct['post_date'] ) )
    15651565                        unset( $post['post_date_gmt'] );
    15661566                else
    15671567                        $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
    15681568
    15691569                $this->escape( $post );
    15701570                $merged_content_struct = array_merge( $post, $content_struct );
    15711571
    15721572                $retval = $this->_insert_post( $user, $merged_content_struct );
    15731573                if ( $retval instanceof IXR_Error )
    15741574                        return $retval;
    15751575
    15761576                return true;
    15771577        }
    15781578
    15791579        /**
    class wp_xmlrpc_server extends IXR_Serve 
    18551855
    18561856                $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
    18571857
    18581858                if ( ! current_user_can( $taxonomy->cap->manage_terms ) )
    18591859                        return new IXR_Error( 401, __( 'You are not allowed to create terms in this taxonomy.' ) );
    18601860
    18611861                $taxonomy = (array) $taxonomy;
    18621862
    18631863                // hold the data of the term
    18641864                $term_data = array();
    18651865
    18661866                $term_data['name'] = trim( $content_struct['name'] );
    18671867                if ( empty( $term_data['name'] ) )
    18681868                        return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
    18691869
    1870                 if ( isset( $content_struct['parent'] ) ) {
     1870                if ( !empty( $content_struct['parent'] ) ) {
    18711871                        if ( ! $taxonomy['hierarchical'] )
    18721872                                return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
    18731873
    18741874                        $parent_term_id = (int) $content_struct['parent'];
    18751875                        $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
    18761876
    18771877                        if ( is_wp_error( $parent_term ) )
    18781878                                return new IXR_Error( 500, $parent_term->get_error_message() );
    18791879
    18801880                        if ( ! $parent_term )
    18811881                                return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
    18821882
    18831883                        $term_data['parent'] = $content_struct['parent'];
    18841884                }
    18851885
    1886                 if ( isset( $content_struct['description'] ) )
     1886                if ( !empty( $content_struct['description'] ) )
    18871887                        $term_data['description'] = $content_struct['description'];
    18881888
    1889                 if ( isset( $content_struct['slug'] ) )
     1889                if ( !empty( $content_struct['slug'] ) )
    18901890                        $term_data['slug'] = $content_struct['slug'];
    18911891
    18921892                $term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data );
    18931893
    18941894                if ( is_wp_error( $term ) )
    18951895                        return new IXR_Error( 500, $term->get_error_message() );
    18961896
    18971897                if ( ! $term )
    18981898                        return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) );
    18991899
    19001900                return strval( $term['term_id'] );
    19011901        }
    19021902
    19031903        /**
    19041904         * Edit a term.
    class wp_xmlrpc_server extends IXR_Serve 
    19461946                        return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) );
    19471947
    19481948                $taxonomy = (array) $taxonomy;
    19491949
    19501950                // hold the data of the term
    19511951                $term_data = array();
    19521952
    19531953                $term = get_term( $term_id , $content_struct['taxonomy'] );
    19541954
    19551955                if ( is_wp_error( $term ) )
    19561956                        return new IXR_Error( 500, $term->get_error_message() );
    19571957
    19581958                if ( ! $term )
    19591959                        return new IXR_Error( 404, __( 'Invalid term ID' ) );
    19601960
    1961                 if ( isset( $content_struct['name'] ) ) {
     1961                if ( !empty( $content_struct['name'] ) ) {
    19621962                        $term_data['name'] = trim( $content_struct['name'] );
    19631963
    19641964                        if ( empty( $term_data['name'] ) )
    19651965                                return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
    19661966                }
    19671967
    19681968                if ( ! empty( $content_struct['parent'] ) ) {
    19691969                        if ( ! $taxonomy['hierarchical'] )
    19701970                                return new IXR_Error( 403, __( "This taxonomy is not hierarchical so you can't set a parent." ) );
    19711971
    19721972                        $parent_term_id = (int) $content_struct['parent'];
    19731973                        $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
    19741974
    19751975                        if ( is_wp_error( $parent_term ) )
    19761976                                return new IXR_Error( 500, $parent_term->get_error_message() );
    19771977
    19781978                        if ( ! $parent_term )
    19791979                                return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
    19801980
    19811981                        $term_data['parent'] = $content_struct['parent'];
    19821982                }
    19831983
    1984                 if ( isset( $content_struct['description'] ) )
     1984                if ( !empty( $content_struct['description'] ) )
    19851985                        $term_data['description'] = $content_struct['description'];
    19861986
    1987                 if ( isset( $content_struct['slug'] ) )
     1987                if ( !empty( $content_struct['slug'] ) )
    19881988                        $term_data['slug'] = $content_struct['slug'];
    19891989
    19901990                $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data );
    19911991
    19921992                if ( is_wp_error( $term ) )
    19931993                        return new IXR_Error( 500, $term->get_error_message() );
    19941994
    19951995                if ( ! $term )
    19961996                        return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) );
    19971997
    19981998                return true;
    19991999        }
    20002000
    20012001        /**
    20022002         * Delete a term.
    class wp_xmlrpc_server extends IXR_Serve 
    25652565
    25662566                if ( ! $user = $this->login( $username, $password ) )
    25672567                        return $this->error;
    25682568
    25692569                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    25702570                do_action( 'xmlrpc_call', 'wp.editProfile' );
    25712571
    25722572                if ( ! current_user_can( 'edit_user', $user->ID ) )
    25732573                        return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) );
    25742574
    25752575                // holds data of the user
    25762576                $user_data = array();
    25772577                $user_data['ID'] = $user->ID;
    25782578
    25792579                // only set the user details if it was given
    2580                 if ( isset( $content_struct['first_name'] ) )
     2580                if ( !empty( $content_struct['first_name'] ) )
    25812581                        $user_data['first_name'] = $content_struct['first_name'];
    25822582
    2583                 if ( isset( $content_struct['last_name'] ) )
     2583                if ( !empty( $content_struct['last_name'] ) )
    25842584                        $user_data['last_name'] = $content_struct['last_name'];
    25852585
    2586                 if ( isset( $content_struct['url'] ) )
     2586                if ( !empty( $content_struct['url'] ) )
    25872587                        $user_data['user_url'] = $content_struct['url'];
    25882588
    2589                 if ( isset( $content_struct['display_name'] ) )
     2589                if ( !empty( $content_struct['display_name'] ) )
    25902590                        $user_data['display_name'] = $content_struct['display_name'];
    25912591
    2592                 if ( isset( $content_struct['nickname'] ) )
     2592                if ( !empty( $content_struct['nickname'] ) )
    25932593                        $user_data['nickname'] = $content_struct['nickname'];
    25942594
    2595                 if ( isset( $content_struct['nicename'] ) )
     2595                if ( !empty( $content_struct['nicename'] ) )
    25962596                        $user_data['user_nicename'] = $content_struct['nicename'];
    25972597
    2598                 if ( isset( $content_struct['bio'] ) )
     2598                if ( !empty( $content_struct['bio'] ) )
    25992599                        $user_data['description'] = $content_struct['bio'];
    26002600
    26012601                $result = wp_update_user( $user_data );
    26022602
    26032603                if ( is_wp_error( $result ) )
    26042604                        return new IXR_Error( 500, $result->get_error_message() );
    26052605
    26062606                if ( ! $result )
    26072607                        return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) );
    26082608
    26092609                return true;
    26102610        }
    26112611
    26122612        /**
    26132613         * Retrieve page.
    class wp_xmlrpc_server extends IXR_Serve 
    48054805                $password       = $args[2];
    48064806                $content_struct = $args[3];
    48074807                $publish        = isset( $args[4] ) ? $args[4] : 0;
    48084808
    48094809                if ( !$user = $this->login($username, $password) )
    48104810                        return $this->error;
    48114811
    48124812                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    48134813                do_action( 'xmlrpc_call', 'metaWeblog.newPost' );
    48144814
    48154815                $page_template = '';
    48164816                if ( !empty( $content_struct['post_type'] ) ) {
    48174817                        if ( $content_struct['post_type'] == 'page' ) {
    48184818                                if ( $publish )
    48194819                                        $cap  = 'publish_pages';
    4820                                 elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] )
     4820                                elseif ( !empty( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] )
    48214821                                        $cap  = 'publish_pages';
    48224822                                else
    48234823                                        $cap = 'edit_pages';
    48244824                                $error_message = __( 'Sorry, you are not allowed to publish pages on this site.' );
    48254825                                $post_type = 'page';
    48264826                                if ( !empty( $content_struct['wp_page_template'] ) )
    48274827                                        $page_template = $content_struct['wp_page_template'];
    48284828                        } elseif ( $content_struct['post_type'] == 'post' ) {
    48294829                                if ( $publish )
    48304830                                        $cap  = 'publish_posts';
    4831                                 elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] )
     4831                                elseif ( !empty( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] )
    48324832                                        $cap  = 'publish_posts';
    48334833                                else
    48344834                                        $cap = 'edit_posts';
    48354835                                $error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
    48364836                                $post_type = 'post';
    48374837                        } else {
    48384838                                // No other post_type values are allowed here
    48394839                                return new IXR_Error( 401, __( 'Invalid post type' ) );
    48404840                        }
    48414841                } else {
    48424842                        if ( $publish )
    48434843                                $cap  = 'publish_posts';
    4844                         elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'])
     4844                        elseif ( !empty( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'])
    48454845                                $cap  = 'publish_posts';
    48464846                        else
    48474847                                $cap = 'edit_posts';
    48484848                        $error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
    48494849                        $post_type = 'post';
    48504850                }
    48514851
    48524852                if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) )
    48534853                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) );
    48544854                if ( !current_user_can( $cap ) )
    48554855                        return new IXR_Error( 401, $error_message );
    48564856
    48574857                // Check for a valid post format if one was given
    4858                 if ( isset( $content_struct['wp_post_format'] ) ) {
     4858                if ( !empty( $content_struct['wp_post_format'] ) ) {
    48594859                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
    48604860                        if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
    48614861                                return new IXR_Error( 404, __( 'Invalid post format' ) );
    48624862                        }
    48634863                }
    48644864
    48654865                // Let WordPress generate the post_name (slug) unless
    48664866                // one has been provided.
    48674867                $post_name = "";
    48684868                if ( isset($content_struct['wp_slug']) )
    48694869                        $post_name = $content_struct['wp_slug'];
    48704870
    48714871                // Only use a password if one was given.
    48724872                if ( isset($content_struct['wp_password']) )
    48734873                        $post_password = $content_struct['wp_password'];
    48744874
    48754875                // Only set a post parent if one was provided.
    48764876                if ( isset($content_struct['wp_page_parent_id']) )
    48774877                        $post_parent = $content_struct['wp_page_parent_id'];
    48784878
    48794879                // Only set the menu_order if it was provided.
    48804880                if ( isset($content_struct['wp_page_order']) )
    48814881                        $menu_order = $content_struct['wp_page_order'];
    48824882
    48834883                $post_author = $user->ID;
    48844884
    48854885                // If an author id was provided then use it instead.
    4886                 if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) {
     4886                if ( !empty( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) {
    48874887                        switch ( $post_type ) {
    48884888                                case "post":
    48894889                                        if ( !current_user_can( 'edit_others_posts' ) )
    48904890                                                return new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) );
    48914891                                        break;
    48924892                                case "page":
    48934893                                        if ( !current_user_can( 'edit_others_pages' ) )
    48944894                                                return new IXR_Error( 401, __( 'You are not allowed to create pages as this user.' ) );
    48954895                                        break;
    48964896                                default:
    48974897                                        return new IXR_Error( 401, __( 'Invalid post type' ) );
    48984898                        }
    48994899                        $author = get_userdata( $content_struct['wp_author_id'] );
    49004900                        if ( ! $author )
    49014901                                return new IXR_Error( 404, __( 'Invalid author ID.' ) );
    49024902                        $post_author = $content_struct['wp_author_id'];
    49034903                }
    49044904
    4905                 $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null;
    4906                 $post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null;
     4905                $post_title = !empty( $content_struct['title'] ) ? $content_struct['title'] : null;
     4906                $post_content = !empty( $content_struct['description'] ) ? $content_struct['description'] : null;
    49074907
    49084908                $post_status = $publish ? 'publish' : 'draft';
    49094909
    49104910                if ( isset( $content_struct["{$post_type}_status"] ) ) {
    49114911                        switch ( $content_struct["{$post_type}_status"] ) {
    49124912                                case 'draft':
    49134913                                case 'pending':
    49144914                                case 'private':
    49154915                                case 'publish':
    49164916                                        $post_status = $content_struct["{$post_type}_status"];
    49174917                                        break;
    49184918                                default:
    49194919                                        $post_status = $publish ? 'publish' : 'draft';
    49204920                                        break;
    49214921                        }
    class wp_xmlrpc_server extends IXR_Serve 
    49794979                                                $ping_status = 'open';
    49804980                                                break;
    49814981                                        default:
    49824982                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
    49834983                                                break;
    49844984                                }
    49854985                        }
    49864986                } else {
    49874987                        $ping_status = get_default_comment_status( $post_type, 'pingback' );
    49884988                }
    49894989
    49904990                if ( $post_more )
    49914991                        $post_content = $post_content . '<!--more-->' . $post_more;
    49924992
    49934993                $to_ping = null;
    4994                 if ( isset( $content_struct['mt_tb_ping_urls'] ) ) {
     4994                if ( !empty( $content_struct['mt_tb_ping_urls'] ) ) {
    49954995                        $to_ping = $content_struct['mt_tb_ping_urls'];
    49964996                        if ( is_array($to_ping) )
    49974997                                $to_ping = implode(' ', $to_ping);
    49984998                }
    49994999
    50005000                // Do some timestamp voodoo
    50015001                if ( !empty( $content_struct['date_created_gmt'] ) )
    50025002                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    50035003                        $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    50045004                elseif ( !empty( $content_struct['dateCreated']) )
    50055005                        $dateCreated = $content_struct['dateCreated']->getIso();
    50065006
    50075007                if ( !empty( $dateCreated ) ) {
    50085008                        $post_date = iso8601_to_datetime( $dateCreated );
    50095009                        $post_date_gmt = get_gmt_from_date( $post_date );
    50105010                } else {
    50115011                        $post_date = '';
    50125012                        $post_date_gmt = '';
    50135013                }
    50145014
    50155015                $post_category = array();
    5016                 if ( isset( $content_struct['categories'] ) ) {
     5016                if ( !empty( $content_struct['categories'] ) ) {
    50175017                        $catnames = $content_struct['categories'];
    50185018
    50195019                        if ( is_array($catnames) ) {
    50205020                                foreach ($catnames as $cat) {
    50215021                                        $post_category[] = get_cat_ID($cat);
    50225022                                }
    50235023                        }
    50245024                }
    50255025
    50265026                $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');
    50275027
    50285028                $post_ID = $postdata['ID'] = get_default_post_to_edit( $post_type, true )->ID;
    50295029
    50305030                // Only posts can be sticky
    5031                 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
     5031                if ( $post_type == 'post' && !empty( $content_struct['sticky'] ) ) {
    50325032                        $data = $postdata;
    50335033                        $data['sticky'] = $content_struct['sticky'];
    50345034                        $error = $this->_toggle_sticky( $data );
    50355035                        if ( $error ) {
    50365036                                return $error;
    50375037                        }
    50385038                }
    50395039
    50405040                if ( isset($content_struct['custom_fields']) )
    50415041                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    50425042
    50435043                if ( isset ( $content_struct['wp_post_thumbnail'] ) ) {
    50445044                        if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false )
    50455045                                return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
    50465046
    50475047                        unset( $content_struct['wp_post_thumbnail'] );
    50485048                }
    50495049
    50505050                // Handle enclosures
    50515051                $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    50525052                $this->add_enclosure_if_new($post_ID, $thisEnclosure);
    50535053
    50545054                $this->attach_uploads( $post_ID, $post_content );
    50555055
    50565056                // Handle post formats if assigned, value is validated earlier
    50575057                // in this function
    5058                 if ( isset( $content_struct['wp_post_format'] ) )
     5058                if ( !empty( $content_struct['wp_post_format'] ) )
    50595059                        set_post_format( $post_ID, $content_struct['wp_post_format'] );
    50605060
    50615061                $post_ID = wp_insert_post( $postdata, true );
    50625062                if ( is_wp_error( $post_ID ) )
    50635063                        return new IXR_Error(500, $post_ID->get_error_message());
    50645064
    50655065                if ( !$post_ID )
    50665066                        return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.'));
    50675067
    50685068                /**
    50695069                 * Fires after a new post has been successfully created via the XML-RPC MovableType API.
    50705070                 *
    50715071                 * @since 3.4.0
    50725072                 *
    50735073                 * @param int   $post_ID ID of the new post.
    class wp_xmlrpc_server extends IXR_Serve 
    51675167                if ( ! $postdata || empty( $postdata[ 'ID' ] ) )
    51685168                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    51695169
    51705170                if ( ! current_user_can( 'edit_post', $post_ID ) )
    51715171                        return new IXR_Error( 401, __( 'Sorry, you do not have the right to edit this post.' ) );
    51725172
    51735173                // Use wp.editPost to edit post types other than post and page.
    51745174                if ( ! in_array( $postdata[ 'post_type' ], array( 'post', 'page' ) ) )
    51755175                        return new IXR_Error( 401, __( 'Invalid post type' ) );
    51765176
    51775177                // Thwart attempt to change the post type.
    51785178                if ( ! empty( $content_struct[ 'post_type' ] ) && ( $content_struct['post_type'] != $postdata[ 'post_type' ] ) )
    51795179                        return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
    51805180
    51815181                // Check for a valid post format if one was given
    5182                 if ( isset( $content_struct['wp_post_format'] ) ) {
     5182                if ( !empty( $content_struct['wp_post_format'] ) ) {
    51835183                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
    51845184                        if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
    51855185                                return new IXR_Error( 404, __( 'Invalid post format' ) );
    51865186                        }
    51875187                }
    51885188
    51895189                $this->escape($postdata);
    51905190
    51915191                $ID = $postdata['ID'];
    51925192                $post_content = $postdata['post_content'];
    51935193                $post_title = $postdata['post_title'];
    51945194                $post_excerpt = $postdata['post_excerpt'];
    51955195                $post_password = $postdata['post_password'];
    51965196                $post_parent = $postdata['post_parent'];
    51975197                $post_type = $postdata['post_type'];
    class wp_xmlrpc_server extends IXR_Serve 
    52095209                // Only set a post parent if one was given.
    52105210                if ( isset($content_struct['wp_page_parent_id']) )
    52115211                        $post_parent = $content_struct['wp_page_parent_id'];
    52125212
    52135213                // Only set the menu_order if it was given.
    52145214                if ( isset($content_struct['wp_page_order']) )
    52155215                        $menu_order = $content_struct['wp_page_order'];
    52165216
    52175217                $page_template = null;
    52185218                if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type )
    52195219                        $page_template = $content_struct['wp_page_template'];
    52205220
    52215221                $post_author = $postdata['post_author'];
    52225222
    52235223                // Only set the post_author if one is set.
    5224                 if ( isset( $content_struct['wp_author_id'] ) ) {
     5224                if ( !empty( $content_struct['wp_author_id'] ) ) {
    52255225                        // Check permissions if attempting to switch author to or from another user.
    52265226                        if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) {
    52275227                                switch ( $post_type ) {
    52285228                                        case 'post':
    52295229                                                if ( ! current_user_can( 'edit_others_posts' ) ) {
    52305230                                                        return new IXR_Error( 401, __( 'You are not allowed to change the post author as this user.' ) );
    52315231                                                }
    52325232                                                break;
    52335233                                        case 'page':
    52345234                                                if ( ! current_user_can( 'edit_others_pages' ) ) {
    52355235                                                        return new IXR_Error( 401, __( 'You are not allowed to change the page author as this user.' ) );
    52365236                                                }
    52375237                                                break;
    52385238                                        default:
    52395239                                                return new IXR_Error( 401, __( 'Invalid post type' ) );
    class wp_xmlrpc_server extends IXR_Serve 
    52875287                        } else {
    52885288                                switch ( (int) $content_struct["mt_allow_pings"] ) {
    52895289                                        case 0:
    52905290                                                $ping_status = 'closed';
    52915291                                                break;
    52925292                                        case 1:
    52935293                                                $ping_status = 'open';
    52945294                                                break;
    52955295                                        default:
    52965296                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
    52975297                                                break;
    52985298                                }
    52995299                        }
    53005300                }
    53015301
    5302                 if ( isset( $content_struct['title'] ) )
     5302                if ( !empty( $content_struct['title'] ) )
    53035303                        $post_title =  $content_struct['title'];
    53045304
    5305                 if ( isset( $content_struct['description'] ) )
     5305                if ( !empty( $content_struct['description'] ) )
    53065306                        $post_content = $content_struct['description'];
    53075307
    53085308                $post_category = array();
    5309                 if ( isset( $content_struct['categories'] ) ) {
     5309                if ( !empty( $content_struct['categories'] ) ) {
    53105310                        $catnames = $content_struct['categories'];
    53115311                        if ( is_array($catnames) ) {
    53125312                                foreach ($catnames as $cat) {
    53135313                                        $post_category[] = get_cat_ID($cat);
    53145314                                }
    53155315                        }
    53165316                }
    53175317
    5318                 if ( isset( $content_struct['mt_excerpt'] ) )
     5318                if ( !empty( $content_struct['mt_excerpt'] ) )
    53195319                        $post_excerpt =  $content_struct['mt_excerpt'];
    53205320
    5321                 $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null;
     5321                $post_more = !empty( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null;
    53225322
    53235323                $post_status = $publish ? 'publish' : 'draft';
    5324                 if ( isset( $content_struct["{$post_type}_status"] ) ) {
     5324                if ( !empty( $content_struct["{$post_type}_status"] ) ) {
    53255325                        switch( $content_struct["{$post_type}_status"] ) {
    53265326                                case 'draft':
    53275327                                case 'pending':
    53285328                                case 'private':
    53295329                                case 'publish':
    53305330                                        $post_status = $content_struct["{$post_type}_status"];
    53315331                                        break;
    53325332                                default:
    53335333                                        $post_status = $publish ? 'publish' : 'draft';
    53345334                                        break;
    53355335                        }
    53365336                }
    53375337
    5338                 $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
     5338                $tags_input = !empty( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
    53395339
    53405340                if ( 'publish' == $post_status || 'private' == $post_status ) {
    53415341                        if ( 'page' == $post_type && ! current_user_can( 'publish_pages' ) ) {
    53425342                                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this page.' ) );
    53435343                        } elseif ( ! current_user_can( 'publish_posts' ) ) {
    53445344                                return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) );
    53455345                        }
    53465346                }
    53475347
    53485348                if ( $post_more )
    53495349                        $post_content = $post_content . "<!--more-->" . $post_more;
    53505350
    53515351                $to_ping = null;
    5352                 if ( isset( $content_struct['mt_tb_ping_urls'] ) ) {
     5352                if ( !empty( $content_struct['mt_tb_ping_urls'] ) ) {
    53535353                        $to_ping = $content_struct['mt_tb_ping_urls'];
    53545354                        if ( is_array($to_ping) )
    53555355                                $to_ping = implode(' ', $to_ping);
    53565356                }
    53575357
    53585358                // Do some timestamp voodoo.
    53595359                if ( !empty( $content_struct['date_created_gmt'] ) )
    53605360                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
    53615361                        $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    53625362                elseif ( !empty( $content_struct['dateCreated']) )
    53635363                        $dateCreated = $content_struct['dateCreated']->getIso();
    53645364
    53655365                if ( !empty( $dateCreated ) ) {
    53665366                        $post_date = iso8601_to_datetime( $dateCreated );
    53675367                        $post_date_gmt = get_gmt_from_date( $post_date, 'GMT' );
    class wp_xmlrpc_server extends IXR_Serve 
    53695369                        $post_date     = $postdata['post_date'];
    53705370                        $post_date_gmt = $postdata['post_date_gmt'];
    53715371                }
    53725372
    53735373                // We've got all the data -- post it.
    53745374                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
    53755375
    53765376                $result = wp_update_post($newpost, true);
    53775377                if ( is_wp_error( $result ) )
    53785378                        return new IXR_Error(500, $result->get_error_message());
    53795379
    53805380                if ( !$result )
    53815381                        return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
    53825382
    53835383                // Only posts can be sticky
    5384                 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
     5384                if ( $post_type == 'post' && !empty( $content_struct['sticky'] ) ) {
    53855385                        $data = $newpost;
    53865386                        $data['sticky'] = $content_struct['sticky'];
    53875387                        $data['post_type'] = 'post';
    53885388                        $error = $this->_toggle_sticky( $data, true );
    53895389                        if ( $error ) {
    53905390                                return $error;
    53915391                        }
    53925392                }
    53935393
    53945394                if ( isset($content_struct['custom_fields']) )
    53955395                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    53965396
    53975397                if ( isset ( $content_struct['wp_post_thumbnail'] ) ) {
    53985398
    53995399                        // Empty value deletes, non-empty value adds/updates.
    class wp_xmlrpc_server extends IXR_Serve 
    54015401                                delete_post_thumbnail( $post_ID );
    54025402                        } else {
    54035403                                if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false )
    54045404                                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
    54055405                        }
    54065406                        unset( $content_struct['wp_post_thumbnail'] );
    54075407                }
    54085408
    54095409                // Handle enclosures.
    54105410                $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    54115411                $this->add_enclosure_if_new($post_ID, $thisEnclosure);
    54125412
    54135413                $this->attach_uploads( $ID, $post_content );
    54145414
    54155415                // Handle post formats if assigned, validation is handled earlier in this function.
    5416                 if ( isset( $content_struct['wp_post_format'] ) )
     5416                if ( !empty( $content_struct['wp_post_format'] ) )
    54175417                        set_post_format( $post_ID, $content_struct['wp_post_format'] );
    54185418
    54195419                /**
    54205420                 * Fires after a post has been successfully updated via the XML-RPC MovableType API.
    54215421                 *
    54225422                 * @since 3.4.0
    54235423                 *
    54245424                 * @param int   $post_ID ID of the updated post.
    54255425                 * @param array $args    An array of arguments to update the post.
    54265426                 */
    54275427                do_action( 'xmlrpc_call_success_mw_editPost', $post_ID, $args );
    54285428
    54295429                return true;
    54305430        }
    54315431