wp_edit_theme_plugin_file example

$file = $plugin_files[0];
}

$file      = validate_file_to_edit( $file$plugin_files );
$real_file = WP_PLUGIN_DIR . '/' . $file;

// Handle fallback editing of file when JavaScript is not available. $edit_error     = null;
$posted_content = null;

if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
    $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
    if ( is_wp_error( $r ) ) {
        $edit_error = $r;
        if ( check_ajax_referer( 'edit-plugin_' . $file, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
            $posted_content = wp_unslash( $_POST['newcontent'] );
        }
    } else {
        wp_redirect(
            add_query_arg(
                array(
                    'a'      => 1, // This means "success" for some reason.                     'plugin' => $plugin,
                    
wp_send_json_success( $status );
}

/** * Handles editing a theme or plugin file via AJAX. * * @since 4.9.0 * * @see wp_edit_theme_plugin_file() */
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()
            )
        );
    }
$relative_file = wp_unslash( $file );
    $file          = $theme->get_stylesheet_directory() . '/' . $relative_file;
}

validate_file_to_edit( $file$allowed_files );

// Handle fallback editing of file when JavaScript is not available. $edit_error     = null;
$posted_content = null;

if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
    $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
    if ( is_wp_error( $r ) ) {
        $edit_error = $r;
        if ( check_ajax_referer( 'edit-theme_' . $stylesheet . '_' . $relative_file, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
            $posted_content = wp_unslash( $_POST['newcontent'] );
        }
    } else {
        wp_redirect(
            add_query_arg(
                array(
                    'a'     => 1, // This means "success" for some reason.                     'theme' => $stylesheet,
                    
Home | Imprint | This part of the site doesn't use cookies.