I want to overwrite the “metaWeblog.newMediaObject” xmlrpc call so the file is saved remotely. From mw_newMediaObject in class-wp-xmlrpc-server.php, i see that there is a hook:
do_action('xmlrpc_call', 'metaWeblog.newMediaObject');
So I should be able to do something in my plugin like:
add_action ('xmlrpc_call', 'myWewMediaObject');
function myWewMediaObject ($method) {
if ($method=='metaWeblog.newMediaObject') {
//perform some custom action
}
}
However, since the do_action call is at the beginning of the mw_newMediaObject function, I am unsure how to stop the execution after my plugin function exists.
Please let me know if I am on the right track and if there is another way to do this.
1 Answer
Actually, that hook just lets you tie in to the beginning of executing that function, it doesn’t let you override anything.
If you want to replace this function entirely, I recommend two different options:
1. Don’t use it
Just define your own XMLRPC method (myNamespace.newMediaObject
) and call that instead.
2. Replace it
You can tie in to the xmlrpc_methods
filter the same way you would to add a new method and can replace the callback for metaWeblog.newMediaObject
:
add_filter( 'xmlrpc_methods', 'myMediaHandler' );
function myMediaHandler( $methods ) {
$methods[ 'metaWeblog.newMediaObject' ] = 'myMediaObject';
return $methods;
}
function myMediaObject( $args ) {
// ... custom functionality
}
Just be sure to maintain the same format with the $args array and to call/apply the same actions/filters in your custom method so that you don’t run into any surprises.