do_rename function does not exist
-
Hello,
I am very new to wordpress development and I am trying to use the plugin to create a REST endpoint that will allow my users to rename media. Here is what my route registration looks like:
add_action( 'rest_api_init', 'custom_routes'); function custom_routes(){ register_rest_route('custom/media/v1', 'rename_media',array( 'methods' => array( 'POST' ), 'callback' => 'media_rename', 'args' => array('media_id' => 'string', 'new_name' => 'string') )); } function media_rename($request) { $params = wp_parse_args( $request->get_params(), [ 'media_id' => '-1', 'new_name' => '' ] ); $args = array( 'media_id' => $params['media_id'], 'new_name' => $params['new_name'] ); $result = -1; if (function_exists('do_rename')) { $result = do_rename($args['media_id'], $args['new_name']); } if ($result != 1) { return new WP_Error( 'empty_category', 'no image found', array('status' => 404) ); } $response = new WP_REST_Response($params['new_name']); $response->set_status(200); return $response; }
`
However, when I call
function_exists('do_rename')
from mymedia_rename
function it returns false. If I don’t do the check and try to calldo_rename
then I get an internal server error. Any insight as to what I am doing wrong or how I can fix this?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘do_rename function does not exist’ is closed to new replies.