Custom form action to handle data inside a plugin

admin-post.php is perfect for that. You have to do three things: 1. Set action for your form to admin-post.php <form method=”post” action=”<?php echo admin_url(‘admin-post.php’); ?>”> 2. Add hidden input with name=action <input type=”hidden” name=”action” value=”my_plugin_action” /> 3. Register your callbacks for admin_post_{$action} and admin_post_nopriv_{$action}: add_action( ‘admin_post_my_plugin_action’, ‘my_form_processor’ ); add_action( ‘admin_post_nopriv_my_plugin_action’, ‘my_form_processor’ ); function my_form_processor() { … Read more

Add keywords meta to index.php page

I guess you use metadata to store keywords for other pages. One way if to use some page for the source of homepage keywords. Other is to add theme option for home page keywords: https://blog.templatetoaster.com/wordpress-settings-api-creating-theme-options/ Afterwards: add_action(‘wp_head’, ‘my_wp_head’)); function my_wp_head() { if ( is_front_page() ) { $keywords = get_option(‘homepage_keywords’); echo ‘<meta name=”keywords” value=”‘ . esc_attr($keywords) … Read more

Redirecting to home page after login as custom role WordPress

This is what I’m using, it redirects “shop_managers” to the admin orders page. function my_login_redirect( $redirect_to, $request, $user ){ if (isset($user->roles) && is_array($user->roles)) { if (in_array(‘shop_manager’, $user->roles)) { $redirect_to = ‘/wp-admin/edit.php?post_type=shop_order’; } } return $redirect_to; } add_filter( ‘login_redirect’, ‘my_login_redirect’, 10, 3 ); Obviously, you will need to change ‘shop_managers’ and ‘/wp-admin/edit.php?post_type=shop_order’ to what you need. … Read more

WooCommerce registration password field not displaying

To enable default Password field I just had to check checkbox (When creating an account, automatically generate an account password) under WooComemrce > Settings > Accounts and Privacy. After this default password field started to display on registration page. To add repeat password field I used this hook add_action( ‘woocommerce_register_form’, ‘wc_register_form_password_repeat’ ); function wc_register_form_password_repeat() { … Read more