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

Memberpress functions/documentation

I know it was asked a long time ago. But just a tip for others who see this. You can use global $wpdb in any wordpress file to access the pre-defined class. If you know sql you can create a custom query to find active or inactive memberships from one of the memberpress tables. For … Read more

Preferred way of cacheing a value in php

You want the Transients API: get_transient and set_transient (and get/set_site_transient). These store values in the wp_options table with a namespace and expiry date, so they do persist through page reloads. (As does anything stored in the database, unless you explicitly create per-connection temporary tables.)

AJAX button run function

In order to make this work as you expect, you need to add the following lines in your constructor (depending on the requirements you have) add_action( ‘wp_ajax_myfunction’, array($this, ‘myfunction’) ); add_action( ‘wp_ajax_nopriv_myfunction’, array($this, ‘myfunction’) ); Note that wp_ajax_nopriv_myfunction executes for users that are not logged in. The other executes for logged in users only. You … Read more

How to configure two SMTP Server for wordpress

Disclaimer: this is clumsy, someone might have a better suggestion. But here’s one idea: Leave WordPress configured with your [email protected] settings. Set up Woo with the [email protected] address (WooCommerce -> Settings -> Emails -> From Address). Hook woocommerce_mail_callback with your own function that temporarily hooks phpmailer_init to change the SMTP configuration before calling wp_mail. Or … Read more