Created
December 22, 2021 12:08
-
-
Save ellenbauer/674b5233bed08d75fa6b09725e96af1b to your computer and use it in GitHub Desktop.
Aino functions.php with Custom Woo Login shortcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'aino_setup' ) ) : | |
function aino_setup() { | |
// Adding support for featured images. | |
add_theme_support( 'post-thumbnails' ); | |
set_post_thumbnail_size( 1800, 99999 ); | |
// Adds custom image sizes. | |
add_image_size( 'aino-thumb', 1800, 1012, true ); // Image Ratio 16:9. | |
// Register Navigation menus. | |
register_nav_menus( | |
array( | |
'primary' => esc_html__( 'Primary Menu', 'aino' ), | |
) | |
); | |
// Add support for Block Styles. | |
add_theme_support( 'wp-block-styles' ); | |
// Enqueue editor styles. | |
add_editor_style( array( 'assets/build/css/editor.css', aino_fonts_url() ) ); | |
// Remove core block patterns. | |
remove_theme_support( 'core-block-patterns' ); | |
// Add support for the WooCommerce. | |
add_theme_support( 'woocommerce', array( | |
'thumbnail_image_width' => 600, | |
'single_image_width' => 1200, | |
) ); | |
// Disable WooCommerce default styling. | |
add_filter( 'woocommerce_enqueue_styles', '__return_false' ); | |
remove_theme_support( 'wc-product-gallery-zoom' ); | |
remove_theme_support( 'wc-product-gallery-lightbox' ); | |
remove_theme_support( 'wc-product-gallery-slider' ); | |
} | |
endif; | |
add_action( 'after_setup_theme', 'aino_setup' ); | |
/** | |
* Enqueue scripts and styles. | |
*/ | |
function aino_scripts() { | |
// Enqueue fonts stylesheet. | |
wp_enqueue_style( 'aino-fonts', aino_fonts_url(), array(), wp_get_theme()->get( 'Version' ) ); | |
// Theme stylesheet. | |
wp_enqueue_style( 'aino-style', get_template_directory_uri() . '/assets/build/css/main.css', array(), wp_get_theme()->get( 'Version' ) ); | |
} | |
add_action( 'wp_enqueue_scripts', 'aino_scripts' ); | |
/** | |
* Get Google fonts and save locally with WPTT Webfont Loader. | |
*/ | |
function aino_fonts_url() { | |
$font_families = array( | |
'Arimo:ital,wght@0,400;0,700;1,400;1,700', | |
'PT+Serif:ital,wght@0,400;0,700;1,400;1,700' | |
); | |
$fonts_url = add_query_arg( array( | |
'family' => implode( '&family=', $font_families ), | |
'display' => 'swap', | |
), 'https://fonts.googleapis.com/css2' ); | |
require_once get_theme_file_path( 'inc/wptt-webfont-loader.php' ); | |
return wptt_get_webfont_url( esc_url_raw( $fonts_url ) ); | |
} | |
// Separate WooCommerce User Registration form | |
function aino_separate_wc_registration_form() { | |
if ( is_admin() ) return; | |
if ( is_user_logged_in() ) return; | |
ob_start(); | |
// Form copied from /woocommerce/myaccount/form-login.php (version 4.1.0) Update as needed. | |
do_action( 'woocommerce_before_customer_login_form' ); ?> | |
<?php if ( 'yes' === get_option( 'woocommerce_enable_myaccount_registration' ) ) : ?> | |
<div class="u-columns col2-set" id="customer_login"> | |
<div class="u-column2 col-2"> | |
<?php endif; ?> | |
<form method="post" class="woocommerce-form woocommerce-form-register register" <?php do_action( 'woocommerce_register_form_tag' ); ?> > | |
<?php do_action( 'woocommerce_register_form_start' ); ?> | |
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?> | |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> | |
<label for="reg_username"><?php esc_html_e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="reg_username" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?> | |
</p> | |
<?php endif; ?> | |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> | |
<label for="reg_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input type="email" class="woocommerce-Input woocommerce-Input--text input-text" name="email" id="reg_email" autocomplete="email" value="<?php echo ( ! empty( $_POST['email'] ) ) ? esc_attr( wp_unslash( $_POST['email'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?> | |
</p> | |
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?> | |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> | |
<label for="reg_password"><?php esc_html_e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input type="password" class="woocommerce-Input woocommerce-Input--text input-text" name="password" id="reg_password" autocomplete="new-password" /> | |
</p> | |
<?php else : ?> | |
<p><?php esc_html_e( 'A password will be sent to your email address.', 'woocommerce' ); ?></p> | |
<?php endif; ?> | |
<?php do_action( 'woocommerce_register_form' ); ?> | |
<p class="woocommerce-form-row form-row"> | |
<?php wp_nonce_field( 'woocommerce-register', 'woocommerce-register-nonce' ); ?> | |
<button type="submit" class="woocommerce-Button woocommerce-button button woocommerce-form-register__submit" name="register" value="<?php esc_attr_e( 'Sign up', 'woocommerce' ); ?>"><?php esc_html_e( 'Sign up', 'woocommerce' ); ?></button> | |
</p> | |
<?php do_action( 'woocommerce_register_form_end' ); ?> | |
</form> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'woocommerce_registration_form', 'aino_separate_wc_registration_form' ); | |
// Separate WooCommerce User Login form | |
function aino_separate_wc_login_form() { | |
if ( is_admin() ) return; | |
if ( is_user_logged_in() ) return; | |
ob_start(); | |
// Form copied from /woocommerce/myaccount/form-login.php (version 4.1.0) Update as needed. | |
do_action( 'woocommerce_before_customer_login_form' ); ?> | |
<?php if ( 'yes' === get_option( 'woocommerce_enable_myaccount_registration' ) ) : ?> | |
<div class="u-columns col2-set" id="customer_login"> | |
<div class="u-column1 col-1"> | |
<?php endif; ?> | |
<form class="woocommerce-form woocommerce-form-login login" method="post"> | |
<?php do_action( 'woocommerce_login_form_start' ); ?> | |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> | |
<label for="username"><?php esc_html_e( 'Username or email address', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="<?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?>" /><?php // @codingStandardsIgnoreLine ?> | |
</p> | |
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> | |
<label for="password"><?php esc_html_e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label> | |
<input class="woocommerce-Input woocommerce-Input--text input-text" type="password" name="password" id="password" autocomplete="current-password" /> | |
</p> | |
<?php do_action( 'woocommerce_login_form' ); ?> | |
<p class="form-row"> | |
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox woocommerce-form-login__rememberme"> | |
<input class="woocommerce-form__input woocommerce-form__input-checkbox" name="rememberme" type="checkbox" id="rememberme" value="forever" /> <span><?php esc_html_e( 'Remember me', 'woocommerce' ); ?></span> | |
</label> | |
<?php wp_nonce_field( 'woocommerce-login', 'woocommerce-login-nonce' ); ?> | |
<button type="submit" class="woocommerce-button button woocommerce-form-login__submit" name="login" value="<?php esc_attr_e( 'Log in', 'woocommerce' ); ?>"><?php esc_html_e( 'Log in', 'woocommerce' ); ?></button> | |
</p> | |
<p class="woocommerce-LostPassword lost_password"> | |
<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php esc_html_e( 'Lost your password?', 'woocommerce' ); ?></a> | |
</p> | |
<?php do_action( 'woocommerce_login_form_end' ); ?> | |
</form> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'woocommerce_login_form', 'aino_separate_wc_login_form' ); | |
// Separate WooCommerce User reset password form | |
function aino_separate_wc_resetpassword_form() { | |
if ( is_admin() ) return; | |
if ( is_user_logged_in() ) return; | |
ob_start(); | |
// Form copied from /woocommerce/myaccount/form-login.php (version 4.1.0) Update as needed. | |
do_action( 'woocommerce_before_lost_password_form' ); ?> | |
<form method="post" class="woocommerce-ResetPassword lost_reset_password"> | |
<p><?php echo apply_filters( 'woocommerce_lost_password_message', esc_html__( 'Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.', 'woocommerce' ) ); ?></p><?php // @codingStandardsIgnoreLine ?> | |
<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first"> | |
<label for="user_login"><?php esc_html_e( 'Username or email', 'woocommerce' ); ?></label> | |
<input class="woocommerce-Input woocommerce-Input--text input-text" type="text" name="user_login" id="user_login" autocomplete="username" /> | |
</p> | |
<div class="clear"></div> | |
<?php do_action( 'woocommerce_lostpassword_form' ); ?> | |
<p class="woocommerce-form-row form-row"> | |
<input type="hidden" name="wc_reset_password" value="true" /> | |
<button type="submit" class="woocommerce-Button button" value="<?php esc_attr_e( 'Reset password', 'woocommerce' ); ?>"><?php esc_html_e( 'Reset password', 'woocommerce' ); ?></button> | |
</p> | |
<?php wp_nonce_field( 'lost_password', 'woocommerce-lost-password-nonce' ); ?> | |
</form> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode( 'woocommerce_resetpassword_form', 'aino_separate_wc_resetpassword_form' ); | |
// Redirect to Download after registration | |
add_filter( 'woocommerce_registration_redirect', 'custom_redirection_after_registration', 10, 1 ); | |
function custom_redirection_after_registration( $redirection_url ){ | |
// Change the redirection Url | |
$redirection_url = home_url('/download/'); | |
return $redirection_url; // Always return something | |
} | |
// Theme Block Patterns. | |
require get_template_directory() . '/inc/block-patterns.php'; | |
// Theme Block Styles. | |
require get_template_directory() . '/inc/block-styles.php'; | |
/** | |
* TGMPA plugin activation. | |
*/ | |
require_once get_template_directory() . '/inc/classes/class-tgm-plugin-activation.php'; | |
add_action( 'tgmpa_register', 'aino_register_required_plugins' ); | |
/** | |
* Register the required plugins for this theme. | |
*/ | |
function aino_register_required_plugins() { | |
/* | |
* Array of plugin arrays. Required keys are name and slug. | |
*/ | |
$plugins = array( | |
array( | |
'name' => 'Aino Blocks - Creative Block Collection', | |
'slug' => 'aino-blocks', | |
'required' => false, | |
), | |
); | |
/* | |
* Array of configuration settings. Amend each line as needed. | |
*/ | |
$config = array( | |
'id' => 'aino', // Unique ID for hashing notices for multiple instances of TGMPA. | |
'default_path' => '', // Default absolute path to bundled plugins. | |
'menu' => 'tgmpa-install-plugins', // Menu slug. | |
'has_notices' => true, // Show admin notices or not. | |
'dismissable' => true, // If false, a user cannot dismiss the nag message. | |
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag. | |
'is_automatic' => false, // Automatically activate plugins after installation or not. | |
'message' => '', // Message to output right before the plugins table. | |
); | |
tgmpa( $plugins, $config ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment