WordPress at Your Fingertips
function is not described

WC_Email::save_template() protected WC 2.4.0

Save the email templates.

{} It's a method of the class: WC_Email{}

No Hooks.

Return

null. Nothing.

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.

Code of WC_Email::save_template() WC 5.9.0

protected function save_template( $template_code, $template_path ) {
	if ( current_user_can( 'edit_themes' ) && ! empty( $template_code ) && ! empty( $template_path ) ) {
		$saved = false;
		$file  = get_stylesheet_directory() . '/' . WC()->template_path() . $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;
		}
	}
}