Open actual-saurabh opened 5 years ago
remove_action( 'wp_ajax_edit-theme-plugin-file', 'wp_ajax_edit_theme_plugin_file' );
add_action('wp_ajax_edit-theme-plugin-file', 'wp_ajax_edit_theme_plugin_micro_file' );
wp_ajax_edit_theme_plugin_micro_file
will be very similar to wp_ajax_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()
)
);
} else {
wp_send_json_success(
array(
'message' => __( 'File edited successfully.' ),
)
);
}
}
Our function should
function wp_ajax_edit_theme_plugin_micro_file() {
$r = wp_edit_theme_plugin_micro_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.' ),
)
);
}
}
Our custom function wp_edit_theme_plugin_micro_file
is a wrapper for wp_edit_theme_plugin_file
function wp_edit_theme_plugin_micro_file( $args ){
if ( empty( $args['micros'] ) ) {
return wp_edit_theme_plugin_file( $args );
}
// do micro related stuff which is basically the same code as "wp_edit_theme_plugin_file" stripped off the plugin/theme specific stuff
}
Add a button that simply copies the whole micros folder into a new folder with the exact same files. The new folder gets a new suffixed name (-1,-2, etc).
We will later add a way for the user to give a custom name (and therefore, a custom folder name) to the forked micro.
Much later, we'll add the ability to Publish this micro to the feed (and from there to Gists).