This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Filter to prevent "Undefined array key 'width'" warning in wp_calculate_image_srcset | |
* | |
* @param array $sources The image sources. | |
* @param array $size_array The size array. | |
* @param string $image_src The image source URL. | |
* @param array $image_meta The image meta data. | |
* @param int $attachment_id The attachment ID. | |
* @return array Modified image sources. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('rest_api_init', 'register_custom_order_billing_shipping_fields'); | |
function register_custom_order_billing_shipping_fields() { | |
// Extend billing fields | |
register_rest_field('shop_order', 'billing', array( | |
'get_callback' => 'get_order_billing_fields', | |
'update_callback' => null, | |
'schema' => null, | |
)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Check if a user has a specific role | |
*/ | |
function user_has_role( string $role, $user_id = null ) { | |
if ( is_numeric( $user_id ) ) { | |
$user = get_user_by( 'id', $user_id ); | |
} else { | |
$user = wp_get_current_user(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get page by template file name | |
*/ | |
function get_page_id_by_template( $template ) { | |
$args = [ | |
'post_type' => 'page', | |
'fields' => 'ids', | |
'nopaging' => true, | |
'meta_key' => '_wp_page_template', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get the first term of a post by id | |
*/ | |
function get_first_term_by_id( int $post_id, string $taxonomy, string $output = 'term_id' ) { | |
$terms = get_the_terms( $post_id, $taxonomy ); | |
if ( ! empty( $terms ) ){ | |
$term = array_shift( $terms ); | |
} | |
return $term->$output; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Registers the improved pages widget | |
*/ | |
function add_improved_pages_widget() { | |
register_widget( 'Improved_Pages_Widget' ); | |
} | |
add_action( 'widget_init', 'add_improved_pages_widget' ); |