Custom delete option button in plugin settings

I managed to add delete button this way, it also may be used to add any extra submit button. Create a submit button with name and array attribute: function mw_options_wc_order_attachement_1() { ?> <input type=”file” name=”mw_options_wc_order_attachement_1″ id=”mw_options_wc_order_attachement_1″ value=”<?php echo get_option(‘mw_options_wc_order_attachement_1’); ?>” /> <?php echo get_option(“mw_options_wc_order_attachement_1″); ?> <input type=”submit” name=”submit[delete_attachment_1]” class=”button button-primary” value=”Delete” /> <?php } Register … Read more

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

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

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