How to create a test that calls is_front_page in phpunit?

The is_front_page() function calls wp_query::is_front_page(). If you scroll down to look at the source, you will see the code you’re looking to trigger: elseif ( ‘page’ == get_option( ‘show_on_front’) && get_option( ‘page_on_front’ ) && $this->is_page( get_option( ‘page_on_front’ ) ) ) return true; To meet that condition, you’ll just need to do this in the code … Read more

Using wp_send_json to return HTML

I can’t tell what the $my_page, $my_page, or $shipHelper variables are supposed to do, but you can use an output buffer to capture the output of your DisplayEventInfoBox function. You can try the following: function myAJAXFn() { ob_start(); DisplayEventInfoBox($my_page, $shipHelper); $my_html = ob_get_contents(); ob_end_clean(); wp_send_json_success( array(‘page’=>$my_html) ); }

How to add date range in woocommerce with code

I just figure out how to do it with a bit of reverse engineering, hopefuly this helps someone : $availability = array(); $availability[0][‘type’] = ‘time:range’; $availability[0][‘bookable’] = ‘yes’; //Default priority $availability[0][‘priority’] = 10; //case ‘time:range’ $availability[0][‘from’] = wc_booking_sanitize_time( $hours ); $availability[0][‘to’] = wc_booking_sanitize_time( $hours ); $availability[0][‘from_date’] = wc_clean( $date ); $availability[0][‘to_date’] = wc_clean( $date ); … Read more

“Warning: count()” error on php 7.2

Yes, I already knew the cause of what you’re experiencing: The $page and $pages global variable have not been set up and a call to get_the_content or get_the_excerpt would return that error: count(pages) That said, pages global variable is set to null, calling count(pages) triggers that error because a null value cannot be counted. To … Read more

How to set custom cookies before output

Depends on whether or not you need to check against WordPress’ user authentication. If you need to know whether they’re a logged in user, hook onto ‘init’. Otherwise, the sooner the better. If it’s something that should fire on every page load, and only checks for existence of the cookie and doesn’t need to tap … Read more

How do I override the Message-ID header of wp_mail function?

You can filter the $phpmailer object. Something like this should do the trick (not tested): add_action( ‘phpmailer_init’, ‘wpse_52555_msg_id’ ); function wpse_52555_msg_id( &$phpmailer ) { $msg_id = get_post_meta( get_the_ID(), ‘messageID’, TRUE ); ” !== $msg_id and $phpmailer->MessageID = $msg_id . ‘@test.com’; }

Set media upload attachment link to none and hide it in WP v3.5

Include this small plugin, activate and test. A tested version in 3.6-alpha, works only on click on a thumbnail. <?php /** * Plugin Name: Remove Attachment Link-To and set to value ‘none’ */ add_action( ‘admin_footer-post-new.php’, ‘wpse_76214_script’ ); add_action( ‘admin_footer-post.php’, ‘wpse_76214_script’ ); function wpse_76214_script() { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $( ‘li.attachment’ ).live( ‘click’, function( … Read more

wp_delete_auto_drafts() deletes links in menus

This is what normal query run by wp_get_associated_nav_menu_items() looks like: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.id = wp_postmeta.post_id ) WHERE 1 = 1 AND wp_posts.post_type=”nav_menu_item” AND (( wp_posts.post_status <> ‘trash’ AND wp_posts.post_status <> ‘auto-draft’ )) AND (( wp_postmeta.meta_key = ‘_menu_item_object_id’ AND Cast(wp_postmeta.meta_value AS CHAR) = ‘3111’ )) GROUP BY wp_posts.id ORDER … Read more