WC_Email::admin_options │ public │ WC 1.0.0
Admin Options.
Setup the email settings screen. Override this in your email.
Метод класса: WC_Email{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
$WC_Email = new WC_Email(); $WC_Email->admin_options();
Список изменений
| С версии 1.0.0 | Введена. |
Код WC_Email::admin_options() WC Email::admin options WC 10.4.3
<?php
public function admin_options() {
// Do admin actions.
$this->admin_actions();
?>
<?php wc_back_header( $this->get_title(), __( 'Return to emails', 'woocommerce' ), admin_url( 'admin.php?page=wc-settings&tab=email' ) ); ?>
<?php echo wpautop( wp_kses_post( $this->get_description() ) ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped ?>
<?php
/**
* Action hook fired before displaying email settings.
*
* @param string $email The email object
*/
do_action( 'woocommerce_email_settings_before', $this );
?>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
</table>
<?php
/**
* Action hook fired after displaying email settings.
*
* @param string $email The email object
*/
do_action( 'woocommerce_email_settings_after', $this );
?>
<?php
if ( current_user_can( 'edit_themes' ) && ( ! empty( $this->template_html ) || ! empty( $this->template_plain ) ) ) {
?>
<div id="template">
<?php
$templates = array(
'template_html' => __( 'HTML template', 'woocommerce' ),
'template_plain' => __( 'Plain text template', 'woocommerce' ),
);
foreach ( $templates as $template_type => $title ) :
$template = $this->get_template( $template_type );
if ( empty( $template ) ) {
continue;
}
$local_file = $this->get_theme_template_file( $template );
$core_file = $this->template_base . $template;
$template_file = apply_filters( 'woocommerce_locate_core_template', $core_file, $template, $this->template_base, $this->id );
$template_dir = apply_filters( 'woocommerce_template_directory', 'woocommerce', $template );
?>
<div class="template <?php echo esc_attr( $template_type ); ?>">
<h4><?php echo wp_kses_post( $title ); ?></h4>
<?php if ( file_exists( $local_file ) ) : ?>
<p>
<a href="#" class="button toggle_editor"></a>
<?php if ( is_writable( $local_file ) ) : // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable ?>
<a href="<?php echo esc_url( wp_nonce_url( remove_query_arg( array( 'move_template', 'saved' ), add_query_arg( 'delete_template', $template_type ) ), 'woocommerce_email_template_nonce', '_wc_email_nonce' ) ); ?>" class="delete_template button">
<?php esc_html_e( 'Delete template file', 'woocommerce' ); ?>
</a>
<?php endif; ?>
<?php
/* translators: %s: Path to template file */
printf( esc_html__( 'This template has been overridden by your theme and can be found in: %s.', 'woocommerce' ), '<code>' . esc_html( trailingslashit( basename( get_stylesheet_directory() ) ) . $template_dir . '/' . $template ) . '</code>' );
?>
</p>
<div class="editor" style="display:none">
<textarea class="code" cols="25" rows="20"
<?php
if ( ! is_writable( $local_file ) ) : // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable
?>
readonly="readonly" disabled="disabled"
<?php else : ?>
data-name="<?php echo esc_attr( $template_type ) . '_code'; ?>"<?php endif; ?>><?php echo esc_html( file_get_contents( $local_file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents ?></textarea>
</div>
<?php elseif ( file_exists( $template_file ) ) : ?>
<p>
<a href="#" class="button toggle_editor"></a>
<?php
$emails_dir = get_stylesheet_directory() . '/' . $template_dir . '/emails';
$templates_dir = get_stylesheet_directory() . '/' . $template_dir;
$theme_dir = get_stylesheet_directory();
if ( is_dir( $emails_dir ) ) {
$target_dir = $emails_dir;
} elseif ( is_dir( $templates_dir ) ) {
$target_dir = $templates_dir;
} else {
$target_dir = $theme_dir;
}
if ( is_writable( $target_dir ) ) : // phpcs:ignore WordPress.VIP.FileSystemWritesDisallow.file_ops_is_writable
?>
<a href="<?php echo esc_url( wp_nonce_url( remove_query_arg( array( 'delete_template', 'saved' ), add_query_arg( 'move_template', $template_type ) ), 'woocommerce_email_template_nonce', '_wc_email_nonce' ) ); ?>" class="button">
<?php esc_html_e( 'Copy file to theme', 'woocommerce' ); ?>
</a>
<?php endif; ?>
<?php
/* translators: 1: Path to template file 2: Path to theme folder */
printf( esc_html__( 'To override and edit this email template copy %1$s to your theme folder: %2$s.', 'woocommerce' ), '<code>' . esc_html( plugin_basename( $template_file ) ) . '</code>', '<code>' . esc_html( trailingslashit( basename( get_stylesheet_directory() ) ) . $template_dir . '/' . $template ) . '</code>' );
?>
</p>
<div class="editor" style="display:none">
<textarea class="code" readonly="readonly" disabled="disabled" cols="25" rows="20"><?php echo esc_html( file_get_contents( $template_file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents ?></textarea>
</div>
<?php else : ?>
<p><?php esc_html_e( 'File was not found.', 'woocommerce' ); ?></p>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php
$handle = 'wc-admin-settings-email';
wp_register_script( $handle, '', array( 'jquery' ), WC_VERSION, array( 'in_footer' => true ) );
wp_enqueue_script( $handle );
wp_add_inline_script(
$handle,
"jQuery( 'select.email_type' ).on( 'change', function() {
const val = jQuery( this ).val();
jQuery( '.template_plain, .template_html' ).show();
if ( val != 'multipart' && val != 'html' ) {
jQuery('.template_html').hide();
}
if ( val != 'multipart' && val != 'plain' ) {
jQuery('.template_plain').hide();
}
}).trigger( 'change' );
const view = '" . esc_js( __( 'View template', 'woocommerce' ) ) . "';
const hide = '" . esc_js( __( 'Hide template', 'woocommerce' ) ) . "';
jQuery( 'a.toggle_editor' ).text( view ).on( 'click', function() {
let label = hide;
if ( jQuery( this ).closest(' .template' ).find( '.editor' ).is(':visible') ) {
label = view;
}
jQuery( this ).text( label ).closest(' .template' ).find( '.editor' ).slideToggle();
return false;
} );
jQuery( 'a.delete_template' ).on( 'click', function() {
if ( window.confirm('" . esc_js( __( 'Are you sure you want to delete this template file?', 'woocommerce' ) ) . "') ) {
return true;
}
return false;
});
jQuery( '.editor textarea' ).on( 'change', function() {
const name = jQuery( this ).attr( 'data-name' );
if ( name ) {
jQuery( this ).attr( 'name', name );
}
});"
);
}
}