tinify / wordpress-plugin

Speed up your WordPress website. Optimize your JPEG and PNG images automatically with TinyPNG.
GNU General Public License v2.0
88 stars 36 forks source link

allow xmlrpc media upload requests to work too ... #6

Closed DavidGoodwin closed 8 years ago

DavidGoodwin commented 8 years ago

Currently the plugin doesn't work for XMLRPC file upload requests - this is a quick and dirty hack that seems to work (at least for me).

You seemingly can't just call Tiny_Settings::admin_init() as the Wordpress XMLRPC stuff doesn't seem to support/setup the various current_user_can() and similar functions.

Using Zend Framework (1.12)'s XmlRpc client the following code now seems to work:

$xmlrpc = new Zend_XmlRpc_Client('http://www.example.com/xmlrpc.php');
$wp = $xmlrpc->getProxy('wp');
$image = array(
    'name' => 'something.jpg', 
    'type' => 'image/jpg',
    'bits' => new Zend_XmlRpc_Value_Base64(file_get_contents('image.jpg'), false),
     'overwrite' => false );

$attachment_info = $wp->uploadFile(1, 'admin', 'secret_password', $image);
var_dump($attachment_info);
middagj commented 8 years ago

Thanks, I merging this, but going to change it to be it less like a hack. This is what the Android and iOS app use, right?

DavidGoodwin commented 8 years ago

Yeah, the mobile apps use xmlrpc.

( But in my case I was trying to write a unit test to check that the tinypng plugin was installed/working correctly. )

( and yes, I'm sure you'd want to rewrite it - I didn't bother with exception handling for a start )