Title: wp_ajax_edit_theme_plugin_file
Published: November 20, 2017
Last modified: February 24, 2026

---

# wp_ajax_edit_theme_plugin_file()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#see-also)
 * [Source](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#wp--skip-link--target)

Handles editing a theme or plugin file via AJAX.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#see-also)󠁿

 * [wp_edit_theme_plugin_file()](https://developer.wordpress.org/reference/functions/wp_edit_theme_plugin_file/)

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#source)󠁿

    ```php
    function wp_ajax_edit_theme_plugin_file() {
    	$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().

    	if ( is_wp_error( $r ) ) {
    		wp_send_json_error(
    			array_merge(
    				array(
    					'code'    => $r->get_error_code(),
    					'message' => $r->get_error_message(),
    				),
    				(array) $r->get_error_data()
    			)
    		);
    	} else {
    		wp_send_json_success(
    			array(
    				'message' => __( 'File edited successfully.' ),
    			)
    		);
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/ajax-actions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/ajax-actions.php#L4901)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/ajax-actions.php#L4901-L4921)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_edit_theme_plugin_file()](https://developer.wordpress.org/reference/functions/wp_edit_theme_plugin_file/)`wp-admin/includes/file.php` |

Attempts to edit a file for a theme or plugin.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [wp_unslash()](https://developer.wordpress.org/reference/functions/wp_unslash/)`wp-includes/formatting.php` |

Removes slashes from a string or recursively removes slashes from strings within an array.

  | 
| [wp_send_json_error()](https://developer.wordpress.org/reference/functions/wp_send_json_error/)`wp-includes/functions.php` |

Sends a JSON response back to an Ajax request, indicating failure.

  | 
| [wp_send_json_success()](https://developer.wordpress.org/reference/functions/wp_send_json_success/)`wp-includes/functions.php` |

Sends a JSON response back to an Ajax request, indicating success.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 4 more](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_edit_theme_plugin_file/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.9.0](https://developer.wordpress.org/reference/since/4.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_ajax_edit_theme_plugin_file%2F)
before being able to contribute a note or feedback.