Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
<?php
/**
* Attempts to retrieve the WP timezone, or if not set, the timezone derived from the gmt_offset.
*
* @access private
* @since 2.2
*
* @return string Timezone string, or if all checks fail, default is 'UTC'.
*/
private function get_core_timezone() {
@DrewAPicture
DrewAPicture / phpunit-assert-contains-only-type.php
Last active January 6, 2021 14:52
PHPUnit assertion function to check the types of all items in an array
<?php>
/**
* Checks if all first-level items in the array are of the given type.
*
* Example:
*
* function test_get_posts_with_no_fields_arg_should_return_array_of_WP_Post_objects() {
* $this-assertContainsOnlyType( 'WP_Post', get_posts() );
* }
*
<?php
/**
* Plugin Name: AffiliateWP - WooCommerce Product Categories Fix
* Plugin URI: https://affiliatewp.com
* Description: Fixes product category 404s when used in conjunction with pretty affiliate URLs.
* Author: AffiliateWP, LLC
* Author URI: https://affiliatewp.com
* Version: 1.0
*
* AffiliateWP Debug is distributed under the terms of the GNU General Public License as published by
add_filter( 'rewrite_rules_array', function( $rules ) {
if ( ! function_exists( 'WC' ) || ! function_exists( 'affiliate_wp' ) ) {
return $rules;
}
if ( true === version_compare( WC()->version, '3.0.0', '>=' ) ) {
$permalinks = wc_get_permalink_structure();
} else {
$permalinks = get_option( 'woocommerce_permalinks' );
<?php
class Beer {
const NAME = 'Beer!';
public static function printed(){
echo 'static Beer:NAME = '. static::NAME . '<br />';
}
}
class Ale extends Beer {
@DrewAPicture
DrewAPicture / class-project-customizer.php
Last active February 18, 2016 04:55
Re-adding core menus and widgets panels back if removed via 'customizer_loaded_components' hook. Note rehooking the nav menus customize_register() method at a later priority.
<?php
require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
$this->wp_customize->widgets = new WP_Customize_Widgets( $this->wp_customize );
require_once( ABSPATH . WPINC . '/class-wp-customize-nav-menus.php' );
$this->wp_customize->nav_menus = new WP_Customize_Nav_Menus( $this->wp_customize );
// Restore setup for nav menus (normally hooked at priority 11).
add_action( 'customize_register', array( $this->wp_customize->nav_menus, 'customize_register' ), 501 );
mysql -u wp -p wp -e "drop database wptests; create database wptests;"
<?php
/*
* If hierarchical is false, and child_of is not empty, pages will (apparently) be returned
* hierarchically anyway in order of creation: 3, 4, 5.
*/
$this->assertEqualSets( array( $page_3, $page_4, $page_5 ), wp_list_pluck( $pages, 'ID' ) );
// How it should work.
$found_pages = wp_list_filter( $pages, array( 'post_parent' => $page_1 ) );
$this->assertEqualSets( array( $page_3, $page_5 ), wp_list_pluck( $found_pages, 'ID' ) );
wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args, $instance, $this ) );
// $nav_menu_args
Array
(
[fallback_cb] =>
[menu] => stdClass Object
(
[term_id] => 176
[name] => Short