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

How to add a default value to get_option if it’s used as a variable?

So I originally suggested normalizing the options array; i.e. merging saved values with the default values. And this does solve the “undefined index” notice: $my_options = wp_parse_args( get_option( ‘my_options’ ), [ ‘my_background_color_option’ => ‘#000’, // … other args. ] ); But to make sure that an option is not empty (e.g. not ”, false, null, … Read more

When to call add_filter

Yes, you can do this like that. You can call foo_init_setup on init or on wp hook and it will work just fine. I would call it as late as possible, I guess. This way you won’t affect loading time for requests that don’t end with page rendering (for example when template_redirect is used for … Read more