Skip to content

Instantly share code, notes, and snippets.

View norcross's full-sized avatar
somone said this would be easy. someone LIED.

Norcross norcross

somone said this would be easy. someone LIED.
View GitHub Profile
@norcross
norcross / featured-image-rest.php
Created August 24, 2023 13:40
Add featured image data to the REST API return
@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
<?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
<?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
<?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
<?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
<?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.
<?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
<?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
@norcross
norcross / rkv-admin-links.php
Last active July 9, 2017 01:06
create links in the WP admin bar for development