Make WordPress cache permanent for some pages until edited

In reality it is very hard to know when a page is affected by an edit. A page contains footer, memus, widgets, shorcodes and meta data which might change “globaly”. Having a general detection which page is affected by any such change is bordering the impossible. Cache expiration in general is just a very hard … Read more

Adding Default Settings to Theme My Login plugin

The data wasn’t fully unserialized and properly made as a multidimensional array wp_parse_args() used unnecessarily. get_option() used unnecessarily. function nls_tml_default_settings() { $nlstml = array( ‘enable_css’ => 1, ‘login_type’ => ‘default’, ‘active_modules’ => array( ‘custom-passwords/custom-passwords.php’, ‘custom-user-links/custom-user-links.php’, ‘recaptcha/recaptcha.php’, ‘security/security.php’, ‘themed-profiles/themed-profiles.php’, ‘user-moderation/user-moderation.php’, ), ‘version’ => ‘6.4.10’, ); update_option( ‘theme_my_login’, $nlstml ); $nlsrecap = array( ‘public_key’ => ‘sitekey’, ‘private_key’ … Read more

Alter post object before display

get_the_content() doesn’t actually return the post_content property from the global $post object. Instead it returns the first page of the global variable $pages, which is set before the_post hook is fired. See L287 of wp-includes/post-template. To reset the $pages global, you can use the setup_postdata() method from the WP_Query object passed from the the_post hook. … Read more

get_object_taxonomies() returns empty array for custom post type

I have run into the same issue. I believe the root cause is the order of execution. For the sake of experiment, I ran get_object_taxonomies() immediately after register_taxonomy(), in fact in the same function and it worked as expected. So what to do? Use add_action() hook to execute get_object_taxonomies() after register_taxonomy(). The correct order of … Read more

How to connect to AWS RDS external database (not for the core WordPress db)

I was able to get a working connection using the following code: function test_connect_to_db() { $servername=”thedatabase.0000000000.location-1.rds.amazonaws.com”; $username=”username”; $password = ‘password’; $dbname=”database”; // Create connection $conn = new mysqli( $servername, $username, $password, $dbname ); // Check connection if ( $conn->connect_error ) { die( ‘Connection failed: ‘ . $conn->connect_error ); } $sql=”SELECT id, firstname, lastname FROM table”; … Read more

how to add custom functionality after woocommerce place order button

You can use woocommerce_after_checkout_validation for custom validation. Following snippet might be helpful for you. //Action to validate add_action(‘woocommerce_after_checkout_validation’, ‘after_checkout_otp_validation’); //The function function after_checkout_otp_validation( $posted ) { // you can use wc_add_notice with a second parameter as “error” to stop the order from being placed if (error) { wc_add_notice( __( “Incorrect OTP!”, ‘text-domain’ ), ‘error’ ); … Read more