Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View brichards's full-sized avatar

Brian Richards brichards

View GitHub Profile
@brichards
brichards / wpinstall.sh
Created February 7, 2022 16:26
A shell function to create a directory, install WordPress, configure SSL via Laravel Valet, an launch the site in Chrome
# Install a new WP site.
# Usage: wpinstall <sitename>
function wpinstall() {
# Make the directory in your local web root
mkdir ~/Sites/www/$@;
cd ~/Sites/www/$@;
# Download, config, and install WordPress using <sitename> for the database, URL, and site title
# Note: You'll need to configure your wp-cli defaults for core config and core install in a wp-cli.yml file
wp core download;
@brichards
brichards / country-list.php
Created November 1, 2021 19:46
PHP multi-dimensional array of 2-letter country codes (ISO 3166-1 alpha-2) and their corresponding english name, 3-letter country code (3166-1 alpha-3), and currency.
// Data courtesy http://country.io/data/
$countries = [
'AD' => [ 'name' => 'Andorra', 'alpha2' => 'AD', 'alpha3' => 'AND', 'currency' => 'EUR', ],
'AE' => [ 'name' => 'United Arab Emirates', 'alpha2' => 'AE', 'alpha3' => 'ARE', 'currency' => 'AED', ],
'AF' => [ 'name' => 'Afghanistan', 'alpha2' => 'AF', 'alpha3' => 'AFG', 'currency' => 'AFN', ],
'AG' => [ 'name' => 'Antigua and Barbuda', 'alpha2' => 'AG', 'alpha3' => 'ATG', 'currency' => 'XCD', ],
'AI' => [ 'name' => 'Anguilla', 'alpha2' => 'AI', 'alpha3' => 'AIA', 'currency' => 'XCD', ],
'AL' => [ 'name' => 'Albania', 'alpha2' => 'AL', 'alpha3' => 'ALB', 'currency' => 'ALL', ],
'AM' => [ 'name' => 'Armenia', 'alpha2' => 'AM', 'alpha3' => 'ARM', 'currency' => 'AMD', ],
'AO' => [ 'name' => 'Angola', 'alpha2' => 'AO', 'alpha3' => 'AGO', 'currency' => 'AOA', ],
@brichards
brichards / customizer.css
Created February 28, 2020 15:15
Custom CSS for WPBlockTalk.com
h3:before {
display: inline-block;
margin-left: -45px;
padding-right: 45px;
width: 30px;
height: 30px;
background: url('https://cldup.com/_NaTHCOsGQ.svg') no-repeat;
content: '';
}
@brichards
brichards / comments-page.php
Created August 7, 2019 20:13
Plugin to make WordPress comments available at <post_url>/comments/.
<?php
/**
* Plugin Name: Comments Page
* Plugin URI: https://WPSessions.com
* Description: Makes comments for a post accessible at <post_url>/comments/.
* Author: Brian Richards
* Author URI: https://rzen.net
* Text Domain: comments-page
* Domain Path: /languages
* Version: 0.1.0
@brichards
brichards / rewrites-1.php
Created February 28, 2016 23:25
In all of the below cases permalinks have been flushed. The endpoint works perfectly fine for all scenarios _except_ the home page.
Using only this, hiting ^/bpa/whatever/ serves blog archive instead of static front page.
<?php
/**
* Create url endpoint for BPA
*
* @since 1.0.0
*/
function cfpurl_rewrite_rules() {

Chatpen

Multiuser chat built with React and Firebase. Note that this is on the Firebase free plan, so if more than 50 users are on it things may go south.

A Pen by Brad Daily on CodePen.

License.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*\.(js|css|png|jpe?g|gif|ico)) http://example.com/$1 [NC,P,L]
</IfModule>
<?php
$url = esc_url( get_post_meta( $post->ID, '_project-url', true ) );
if ( ! empty( $url ) {
printf( '<p>%s</p>', $url );
}
?>
<?php
/**
* Output HTML markup for forum post list.
*
* @since 1.0.0
*
* @param integer $post_count Post count.
*/
function skbp_output_forum_posts_list( $post_count = 5 ) {
#!/usr/bin/php
<?php
echo PHP_EOL;
echo 'Starting unit tests' . PHP_EOL;
exec( 'phpunit', $test_output, $returnCode );
if ( 0 !== $returnCode ) {
echo implode( PHP_EOL, $test_output );
echo PHP_EOL;