11<?php
22
3+ define ('XMLRPC_REQUEST ' , true );
4+
5+ // Some browser-embedded clients send cookies. We don't want them.
6+ $ _COOKIE = array ();
7+
38# fix for mozBlog and other cases where '<?xml' isn't on the very first line
49$ HTTP_RAW_POST_DATA = trim ($ HTTP_RAW_POST_DATA );
510
@@ -179,16 +184,16 @@ function blogger_getUsersBlogs($args) {
179184 return $ this ->error ;
180185 }
181186
182- $ user = new WP_User (0 , $ user_login );
183- $ is_admin = $ user -> has_cap ('level_8 ' );
187+ set_current_user (0 , $ user_login );
188+ $ is_admin = current_user_can ('level_8 ' );
184189
185190 $ struct = array (
186191 'isAdmin ' => $ is_admin ,
187192 'url ' => get_settings ('home ' ) . '/ ' ,
188193 'blogid ' => '1 ' ,
189194 'blogName ' => get_settings ('blogname ' )
190195 );
191-
196+ error_log ( print_r ( $ struct , 1 ), 3 , ' /tmp/xmlrpc ' );
192197 return array ($ struct );
193198 }
194199
@@ -317,8 +322,8 @@ function blogger_getTemplate($args) {
317322 return $ this ->error ;
318323 }
319324
320- $ user = new WP_User (0 , $ user_login );
321- if ( !$ user -> has_cap ('edit_themes ' ) ) {
325+ set_current_user (0 , $ user_login );
326+ if ( !current_user_can ('edit_themes ' ) ) {
322327 return new IXR_Error (401 , 'Sorry, this user can not edit the template. ' );
323328 }
324329
@@ -352,8 +357,8 @@ function blogger_setTemplate($args) {
352357 return $ this ->error ;
353358 }
354359
355- $ user = new WP_User (0 , $ user_login );
356- if ( !$ user -> has_cap ('edit_themes ' ) ) {
360+ set_current_user (0 , $ user_login );
361+ if ( !current_user_can ('edit_themes ' ) ) {
357362 return new IXR_Error (401 , 'Sorry, this user can not edit the template. ' );
358363 }
359364
@@ -390,9 +395,8 @@ function blogger_newPost($args) {
390395 }
391396
392397 $ cap = ($ publish ) ? 'publish_posts ' : 'edit_posts ' ;
393-
394- $ user = new WP_User (0 , $ user_login );
395- if ( !$ user ->has_cap ($ cap ) )
398+ $ user = set_current_user (0 , $ user_login );
399+ if ( !current_user_can ($ cap ) )
396400 return new IXR_Error (401 , 'Sorry, you can not post on this weblog or category. ' );
397401
398402 $ post_status = ($ publish ) ? 'publish ' : 'draft ' ;
@@ -445,8 +449,8 @@ function blogger_editPost($args) {
445449
446450 $ this ->escape ($ actual_post );
447451
448- $ user = new WP_User (0 , $ user_login );
449- if ( !$ user -> has_cap ('edit_post ' , $ post_ID ) )
452+ set_current_user (0 , $ user_login );
453+ if ( !current_user_can ('edit_post ' , $ post_ID ) )
450454 return new IXR_Error (401 , 'Sorry, you do not have the right to edit this post. ' );
451455
452456 extract ($ actual_post );
@@ -489,8 +493,8 @@ function blogger_deletePost($args) {
489493 return new IXR_Error (404 , 'Sorry, no such post. ' );
490494 }
491495
492- $ user = new WP_User (0 , $ user_login );
493- if ( !$ user -> has_cap ('edit_post ' , $ post_ID ) )
496+ set_current_user (0 , $ user_login );
497+ if ( !current_user_can ('edit_post ' , $ post_ID ) )
494498 return new IXR_Error (401 , 'Sorry, you do not have the right to delete this post. ' );
495499
496500 $ result = wp_delete_post ($ post_ID );
@@ -525,8 +529,8 @@ function mw_newPost($args) {
525529 return $ this ->error ;
526530 }
527531
528- $ user = new WP_User (0 , $ user_login );
529- if ( !$ user -> has_cap ('publish_posts ' ) )
532+ $ user = set_current_user (0 , $ user_login );
533+ if ( !current_user_can ('publish_posts ' ) )
530534 return new IXR_Error (401 , 'Sorry, you can not post on this weblog or category. ' );
531535
532536 $ post_author = $ user ->ID ;
@@ -605,8 +609,8 @@ function mw_editPost($args) {
605609 return $ this ->error ;
606610 }
607611
608- $ user = new WP_User (0 , $ user_login );
609- if ( !$ user -> has_cap ('edit_post ' , $ post_ID ) )
612+ set_current_user (0 , $ user_login );
613+ if ( !current_user_can ('edit_post ' , $ post_ID ) )
610614 return new IXR_Error (401 , 'Sorry, you can not edit this post. ' );
611615
612616 $ postdata = wp_get_single_post ($ post_ID , ARRAY_A );
@@ -844,9 +848,8 @@ function mw_newMediaObject($args) {
844848 if ( !$ this ->login_pass_ok ($ user_login , $ user_pass ) )
845849 return $ this ->error ;
846850
847- $ user = new WP_User (0 , $ user_login );
848-
849- if ( !$ user ->has_cap ('upload_files ' ) ) {
851+ set_current_user (0 , $ user_login );
852+ if ( !current_user_can ('upload_files ' ) ) {
850853 logIO ('O ' , '(MW) User does not have upload_files capability ' );
851854 $ this ->error = new IXR_Error (401 , 'You are not allowed to upload files to this site. ' );
852855 return $ this ->error ;
@@ -984,8 +987,8 @@ function mt_setPostCategories($args) {
984987 return $ this ->error ;
985988 }
986989
987- $ user = new WP_User (0 , $ user_login );
988- if ( !$ user -> has_cap ('edit_post ' , $ post_ID ) )
990+ set_current_user (0 , $ user_login );
991+ if ( !current_user_can ('edit_post ' , $ post_ID ) )
989992 return new IXR_Error (401 , 'Sorry, you can not edit this post. ' );
990993
991994 foreach ($ categories as $ cat ) {
@@ -1066,8 +1069,8 @@ function mt_publishPost($args) {
10661069 return $ this ->error ;
10671070 }
10681071
1069- $ user = new WP_User (0 , $ user_login );
1070- if ( !$ user -> has_cap ('edit_post ' , $ post_ID ) )
1072+ set_current_user (0 , $ user_login );
1073+ if ( !current_user_can ('edit_post ' , $ post_ID ) )
10711074 return new IXR_Error (401 , 'Sorry, you can not edit this post. ' );
10721075
10731076 $ postdata = wp_get_single_post ($ post_ID ,ARRAY_A );
@@ -1282,4 +1285,4 @@ function pingback_extensions_getPingbacks($args) {
12821285
12831286$ wp_xmlrpc_server = new wp_xmlrpc_server ();
12841287
1285- ?>
1288+ ?>
0 commit comments