Title: do_rename function does not exist
Last modified: September 1, 2022

---

# do_rename function does not exist

 *  Resolved [hannahestes](https://wordpress.org/support/users/hannahestes/)
 * (@hannahestes)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/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 my `media_rename` function
   it returns false. If I don’t do the check and try to call `do_rename` then I 
   get an internal server error. Any insight as to what I am doing wrong or how 
   I can fix this?
    -  This topic was modified 3 years, 9 months ago by [hannahestes](https://wordpress.org/support/users/hannahestes/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/do_rename-function-does-not-exist/#post-15972914)
 * Hi [@hannahestes](https://wordpress.org/support/users/hannahestes/),
    the function
   do_rename is a static method wrapped inside the Phoenix_Media_Rename class, so
   you have to call it using Phoenix_Media_Rename::do_rename
 * I will this information to the readme, it is not clear how to call the function.
 * Let me know if you need more information 🙂
    C.

Viewing 1 replies (of 1 total)

The topic ‘do_rename function does not exist’ is closed to new replies.

 * ![](https://ps.w.org/phoenix-media-rename/assets/icon-256x256.png?rev=3120623)
 * [Phoenix Media Rename](https://wordpress.org/plugins/phoenix-media-rename/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/phoenix-media-rename/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/phoenix-media-rename/)
 * [Active Topics](https://wordpress.org/support/plugin/phoenix-media-rename/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/phoenix-media-rename/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/phoenix-media-rename/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * 1 reply
 * 2 participants
 * Last reply from: [crossi72](https://wordpress.org/support/users/crossi72/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/do_rename-function-does-not-exist/#post-15972914)
 * Status: resolved