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 / pts-admin-widget.php
Last active May 12, 2024 13:19
create WP Admin dashboard widget for poststat.us
<?php
function pts_news_add() {
wp_add_dashboard_widget('pts_news_list', 'Poststat.us News', 'pts_news_list_build');
}
add_action('wp_dashboard_setup', 'pts_news_add');
function pts_news_list_build() {
$rss = fetch_feed('http://poststat.us/feed/');
@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 / featured-image-rest.php
Created August 24, 2023 13:40
Add featured image data to the REST API return
@norcross
norcross / calc-read-time.php
Created July 3, 2014 02:51
calculate and display an estimated reading time
<?php
/**
* handle the calculation
* @param integer $seconds [description]
* @return [type] [description]
*/
function rkv_calc_read_time( $seconds = 0 ) {
// calc the minutes
# custom login link
RewriteRule ^login$ http://localhost/whitelabel/wp-login.php [NC,L]
@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 / validate-passwords.js
Created January 19, 2013 00:33
some basic javascript password validation
// **************************************************************
// password validation
// **************************************************************
function checkPassword(pass) {
var numbers = pass.match(/\d+/g);
var uppers = pass.match(/[A-Z]/);
var lowers = pass.match(/[a-z]/);
var special = pass.match(/[!@#$%\^&*\+]/);
@norcross
norcross / youtube-thumbs
Created April 14, 2013 05:45
get YouTube thumbnails
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to this:
@norcross
norcross / norcross-debug-functions.php
Last active March 29, 2021 20:51
my list of debugging functions to keep in an MU file
<?php
/*
Plugin Name: Norcross Debug Functions
Plugin URI: https://gist.github.com/norcross/7864205/
Description: A set of functions I use on all sites while building
Author: Andrew Norcross
Version: 0.0.1
Requires at least: 3.0
Author URI: http://andrewnorcross.com
*/
@norcross
norcross / country-array.php
Last active January 24, 2020 15:43 — forked from DHS/PHP Countries Array
PHP array of all country names
<?php
$countries = array(
'Afghanistan',
'Albania',
'Algeria',
'American Samoa',
'Andorra',
'Angola',
'Anguilla',