zaus / forms-3rdparty-xpost

Converts external submission from [Forms: 3rdparty Integration](http://wordpress.org/plugins/forms-3rdparty-integration/) plugin to XML post; optionally can add custom headers (to allow SOAP submissions).
4 stars 2 forks source link

CDATA tag #12

Closed Rocket0L4F closed 8 years ago

Rocket0L4F commented 9 years ago

First of all, thanks for this incredibly useful plugin :) !

Quick question (I've posted the same on wordpress.org/support): the webservice I'm currently sending data to wants me to wrap the entire XML in a CDATA-tag (don't ask me why). Would this somehow be possible?

Thanks in advance!

zaus commented 9 years ago

errr...weird.

You just need to hook after Xpost has done its work:

class Forms3rdpartyXpost_AsCData {
    const B = 'Forms3rdPartyIntegration';

    function __construct() {
        // hook even later than xpost so we can manipulate final output
        add_filter(self::B.'_service_filter_args', array(&$this, 'post_args'), 15, 3);
    }

    function post_args($args, $service, $form) {
        $args['body'] = sprintf('<![CDATA[%s]]>', $args['body']);
        return $args;
    }

}
new Forms3rdpartyXpost_AsCData(); // engage!

Throw that in your functions.php or a plugin file.

Rocket0L4F commented 9 years ago

Hey zaus, thanks for your reply, and sorry for the slow response (little holiday off the grid :) ).

I've thrown the above code in my child theme's functions.php, but I'm afraid I don't see any change in my debug POST output (no CDATA-tags wrapped aroud the XML).

The code looks good, but maybe I'm missing something? Sorry, bit of a php-noob here ;)

Thanks again!

zaus commented 9 years ago

Oh sorry, I think I forgot to instantiate the class, so the hook never got called. I've updated the sample.

zaus commented 9 years ago

You can also try the new format 'mask' option with v1.2 to explicitly control the output rather than let it generate the xml.

zaus commented 8 years ago

Can I assume Resolved? Will reopen if not...