Support » Plugins » wp.newComment (XML-RPC) bug?

  • Hello, I hope that I’m in the right forum.

    Here’s my problem. I’m trying to post comments with the WP XML-RPC API.

    http://codex.wordpress.org/XML-RPC_wp#wp.newComment
    The problem is I want these comments to appears under the name of the commenter, but they always appear under the name of the administrator.

    I have changed the settings in WP to allow to comments without registration. I have also installed the plugin that allow anonymous comment from XML-RPC.

    http://www.thepicklingjar.com/code/anonymous-xmlrpc-comments/

    The only thing that is working is hacking the source, specifically this file:

    xmlrpc.php

    In the function wp_newComment, I added this line in this block of code:

    if ( ! get_post($post_id) )
    			return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    
    		$comment['comment_post_ID'] = $post_id;
    
        // emm: dirty hack: 2009-08-25
        $logged_in = FALSE;
    
    		if ( $logged_in ) {
    			$comment['comment_author'] = $wpdb->escape( $user->display_name );
    			$comment['comment_author_email'] = $wpdb->escape( $user->user_email );
    			$comment['comment_author_url'] = $wpdb->escape( $user->user_url );

    With this small hack, everything work fines with XML-RPC, and I can see the comment under the name/email of the commenter. Plus I can moderate the comment posted via XML-RPC. Also, it doesn’t seem to affect the commenting capabilities of WP when using a Web browser.

    I’m not a WP hacker, so, maybe I have missed something. But I still get the feeling that something is going wrong, and I wanted to check here before submitting a bug on the WP bug tracker.

    http://codex.wordpress.org/Reporting_Bugs

    TIA

    Cheers
    -Emmanuel

Viewing 5 replies - 1 through 5 (of 5 total)
  • Are you providing a valid username and password for these comments? That seems like the only way that $logged_in would get set to true. If these comments are anonymous the username & password should be blank. That would make the login fail, leaving $logged_in set to false.

    Thread Starter emmanueldcarie

    (@emmanueldcarie)

    Hello Joseph,

    Thanks for replying.

    Are you providing a valid username and password for these comments?

    If you are talking here about the admin of the WP blog, yes, I provide valid creds, but if you are talking about the commenter, which is different from the admin, no, they are not registered on this WP blog, and I don’t want them to need to be registered.

    The WP blog is used as a resource to post some articles that are shown in another interface (a widget on Portaneo Posh, a gadget on Orkut and iGoogle).

    The widget/gadget interface communicate via Ajax with a CodeIgniter project which uses the WP XML-RPC API to retrieve a WP article and its comments. Then CodeIgniter return back the articles and the comments to the widget/gadget.

    The WP blog is really used as a backend, not to be seen by the commenter that ignore that we use WP.

    To be clear, the commenter is not the administrator.

    The commenter need to provide a name and an email.

    The commenter need NOT to be registered in WP.

    The commenter need to have his/her comment approved by an administrator in WP before being published.

    The commenter never goes to the WP blog, only the admin to manage the comment.

    Hope this make sense to you.

    Cheers
    -Emmanuel

    If you are passing in a valid username & password for the second and third arguments to the wp.newComment XML-RPC method then the login will always succeed (even for anonymous comments) and WP will use the email, URL, name values for that user over the ones submitted as part of the comment.

    I suggest leaving the username and password arguments blank when calling wp.newComment. Then then login will fail, but with the right filter in place anonymous comments are still allowed. So the email, URL and name submitted with the comment will be used.

    Interesting that you are using WordPress as a back end for this, do you have a write up on how you put this all together?

    Thread Starter emmanueldcarie

    (@emmanueldcarie)

    Hello Joseph,

    Thanks for the tip. It’s working perfectly now.

    I did a write up on what I’m doing.

    WordPress As Back End For Posh Widgets and OpenSocial Gadgets

    http://lettre13.com/2009/08/26/wordpress-as-back-end-for-posh-widgets-and-opensocial-gadgets/

    Cheers
    -Emmanuel

    Nice. Good to see WP being used in other ways like this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp.newComment (XML-RPC) bug?’ is closed to new replies.