Skip to content

Instantly share code, notes, and snippets.

Avatar
somone said this would be easy. someone LIED.

Norcross norcross

somone said this would be easy. someone LIED.
View GitHub Profile
@norcross
norcross / test-css-string.php
Last active March 4, 2022 18:23
test a string to see if it's a valid CSS unit, either by itself or by removing the integers
View test-css-string.php
<?php
function confirm_css_unit( $string ) {
// First check for a null or allowed strings.
if ( empty( $string ) || null === $string || in_array( $string, [ 'auto', 'fit-content', 'inherit' ] ) ) {
return $string;
}
// Pull out the numerical portion.
$value = preg_replace( '~\D~', '', $string );
@norcross
norcross / WooUpgradeTestSuiteCest.php
Last active March 7, 2019 14:22
Run various acceptance tests for WooCommerce
View WooUpgradeTestSuiteCest.php
<?php
/**
* WooCommerce Upgrade Test Suite
*
* A set of acceptance tests for a standard WooCommerce store.
*
* https://gist.github.com/norcross/4d45f1902bfb2f1f4cf79997a47d9d03
*/
// It'll error out sometimes without this ¯\_(ツ)_/¯ .
@norcross
norcross / admin-notice-class.php
Created July 27, 2017 15:45 — forked from monkeymonk/Notice.php
WordPress Admin Notice Helper Class
View admin-notice-class.php
<?php
/**
* Helper to work with Wordpress admin notices
*
* @example
* Notice::success('All is good!');
*
* @example
* Notice::warning('Do something please.', true);
@norcross
norcross / admin-bar-debug-display.php
Last active July 7, 2017 20:24
Add a "view debug log" link in the WP admin bar
View admin-bar-debug-display.php
<?php
/**
* If we requested the log file, grabit and spit it out.
*
* @return HTML
*/
function rkv_adminbar_display_debug_log() {
// Bail without the query string or not on admin.
if ( ! is_admin() || empty( $_GET['viewlog'] ) ) {
@norcross
norcross / dpp-add-nunito.php
Created April 21, 2017 15:38
add a new font to the Google Fonts array
View dpp-add-nunito.php
<?php
add_filter( 'gppro_webfont_stacks', 'dpp_add_nunito_font', 50 );
/**
* Add the Nunito font to the webfont data stack.
*
* @param array $webfonts The existing data array.
*
* @return array $webfonts The modified data array.
*/
@norcross
norcross / disable-username-login.php
Last active July 11, 2017 19:44
Force a redirect if a certain username is attempted.
View disable-username-login.php
<?php
add_filter( 'authenticate', 'rkv_disable_username_logins', 20, 3 );
/**
* Disable admin username and redirect to Google (or another site).
*
* @param object $user The WP_User object.
* @param string $username The entered username.
* @param string $password The entered password.
*
@norcross
norcross / remove-avatar-user-table.php
Created March 28, 2016 19:52
Remove user avatars from the admin user table
View remove-avatar-user-table.php
<?php
add_filter( 'pre_get_avatar', 'rkv_remove_avatar_from_list', 10, 3 );
/**
* Remove the avatars from just the admin user list table.
*
* @param string $avatar HTML for the user's avatar. Default null.
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
* @param array $args Arguments passed to get_avatar_url(), after processing.
*
@norcross
norcross / social-link-array.php
Last active February 25, 2016 20:12
Use custom social links
View social-link-array.php
@norcross
norcross / rkv-admin-links.php
Last active July 9, 2017 01:06
create links in the WP admin bar for development
View rkv-admin-links.php
@norcross
norcross / csv-export-example.php
Created August 9, 2015 20:14
a basic CSV export example
View csv-export-example.php
<?php
/**
* Devin CSV Export
*
* Contains our export processing
*/
/*
Copyright 2015 Reaktiv Studios
This program is free software; you can redistribute it and/or modify