Skip to content

Instantly share code, notes, and snippets.

View userabuser's full-sized avatar
💭
What's good?

userabuser

💭
What's good?
View GitHub Profile
@userabuser
userabuser / share-rewrite-base.php
Last active December 17, 2021 21:19
Allow products and terms from multiple taxonomies to share rewrite base /product for rule
<?php
// option 1
add_action('parse_request', function () {
global $wp_rewrite, $wp, $wp_query;
if (isset($wp->query_vars['product'], $wp->query_vars['post_type']) && $wp->query_vars['post_type'] === 'product') {
$matched = false;
@userabuser
userabuser / add-submenu-item-classes.php
Last active December 15, 2021 18:19
Add classes to add_submenu_item menu items in WordPress
<?php
add_action( 'admin_menu', function() {
$parent_slug = 'options-general.php'; // customize to suit
$menu_slug = 'my-submenu-item'; // customize to suit
$position = 6; // customize to suit
add_submenu_page(
$parent_slug,
@userabuser
userabuser / wp-get-timezone-choices.php
Last active December 15, 2021 14:48
Returns an associative array of timezone choices grouped by continent or context.
<?php
if ( ! function_exists( 'wp_util_get_timezone_choices' ) ) :
/**
* Returns an associative array of timezone choices grouped by continent or context.
*
* WordPress does not provide a static list of timezone choices or core function to return
* an array of timezone choices that have been optionally translated and free from their
* surrounding HTML markup as otherwise returned by WP core function wp_timezone_choice().
Test
@userabuser
userabuser / laravel-custom-blade-directive.php
Last active May 2, 2021 13:32
Custom Laravel Blade Directive for use with @yield and @section (Laravel)
<?php
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
@userabuser
userabuser / wp-logger.php
Last active February 19, 2016 04:29
Dirty little logger function for WordPress (mu-plugins)
/**
* By pass the need to define up to three constants, WP_DEBUG, WP_DEBUG_LOG
* and WP_DEBUG_DISPLAY by setting the error_log ini value so that any time
* logger() is called data is written to debug.log.
*/
ini_set('log_errors', 1);
ini_set('error_log', WP_CONTENT_DIR . '/debug.log');
/**
@userabuser
userabuser / wp-after-delete-user.php
Last active April 14, 2018 10:19
Perform an action after a user is deleted with access to additional user data (role, name, email, etc) in addition to user ID. (WordPress)
<?php
/*
* The deleted_user hook fires after a user is deleted and receives
* only one arguement, the $user_id but there is no way to check,
* based on the $user_id, if the user belongs to a specific user role
* as the user no longer exists. Solution: add deleted_user action within
* the delete_user callback function which fires prior to a user being
* deleted and inject a closure on the deleted_user callback.
*
* http://wordpress.stackexchange.com/q/99959/13418