WC_Email::save_template
Save the email templates.
Method of the class: WC_Email{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->save_template( $template_code, $template_path );
- $template_code(string) (required)
- Template code.
- $template_path(string) (required)
- Template path.
Changelog
| Since 2.4.0 | Introduced. |
WC_Email::save_template() WC Email::save template code WC 10.8.1
protected function save_template( $template_code, $template_path ) {
if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template_path ) ) {
$saved = false;
$file = $this->get_theme_template_file( $template_path );
$code = wp_unslash( $template_code );
if ( is_writeable( $file ) ) { // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writeable
$f = fopen( $file, 'w+' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen
if ( false !== $f ) {
fwrite( $f, $code ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite
fclose( $f ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
$saved = true;
}
}
if ( ! $saved ) {
$redirect = add_query_arg( 'wc_error', rawurlencode( __( 'Could not write to template file.', 'woocommerce' ) ) );
wp_safe_redirect( $redirect );
exit;
}
wc_clear_template_cache();
}
}