Skip to content

Instantly share code, notes, and snippets.

View phillip-boombox's full-sized avatar

Phillip Dodson phillip-boombox

View GitHub Profile
@phillip-boombox
phillip-boombox / export-mysql.sh
Last active January 19, 2017 20:39
A BASH script to export all MySQL databases to individual files and another to import the files back to MySQL. Adapted from http://stackoverflow.com/a/26096339/3299349 and https://gist.github.com/tenold/aa5e107d93c0f54436cb
#!/bin/bash
USER="root"
ExcludeDatabases="Database|information_schema|performance_schema|mysql"
databases=`mysql -u $USER -e "SHOW DATABASES;" | tr -d "| " | egrep -v $ExcludeDatabases`
for db in $databases; do
echo "Dumping database: $db"
mysqldump -u $USER --databases $db > `date +%Y%m%d`.$db.sql
@phillip-boombox
phillip-boombox / gist:48ce1cef05ca1414b20adb90b8f85c3a
Created January 19, 2017 20:46
Terminal command to download and unpack WordPress
wget http://wordpress.org/latest.tar.gz && tar xfz latest.tar.gz && mv wordpress/* ./ && rmdir ./wordpress/ && rm -f latest.tar.gz
@phillip-boombox
phillip-boombox / .htaccess
Created January 23, 2017 23:28
Force SSL in .htaccess for WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
@phillip-boombox
phillip-boombox / gist:6f23fc6b491de7a4cc02826a50ef4ed7
Last active September 18, 2017 22:56
PHP DOMDocument manipulation sample
// Create new DOMDocument
$cmb2_mb = new DOMDocument();
// Load cmb2 metabox html string into document
$cmb2_mb->loadHTML( $form, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
// Add bootstrap classes to all labels
foreach ( $cmb2_mb->getElementsByTagName( 'label' ) as $node_label ) {
$node_label->setAttribute( 'class', 'control-label' );
}
@phillip-boombox
phillip-boombox / functions.php
Last active June 5, 2021 19:36
WordPress: Required plugins from the plugins repository
add_filter( 'install_plugins_tabs', 'cmfy_required_plugins_tab' );
function cmfy_required_plugins_tab( $tabs ) {
$tabs['cmfy'] = _x( 'Required', 'Plugin Installer', 'cmfy' );
return $tabs;
}
add_action( 'install_plugins_cmfy', 'cmfy_required_plugins_page' );
function cmfy_required_plugins_page() {
$required_plugin_slugs = array(
'cmb2',
@phillip-boombox
phillip-boombox / wp-functions-custom-colors.php
Last active September 27, 2021 22:55
WordPress: Customize TinyMCE text color picker.
<?php
// Custom theme colors
$cmfy_custom_colors = array(
'14bed2' => __( 'Primary blue', 'cmfy' ),
'cadd69' => __( 'Primary green', 'cmfy' ),
'70736f' => __( 'Primary gray', 'cmfy' ),
'f26722' => __( 'Secondary orange', 'cmfy' ),
'fdbb4a' => __( 'Secondary yellow', 'cmfy' ),
);
@phillip-boombox
phillip-boombox / wp-functions-excerpt-character-count.php
Last active December 13, 2017 18:52
WordPress: Add a character counter to post excerpts in admin.
<?php
/**
* Add a character counter to post excerpts in WordPress admin.
* Action: admin_head-post.php, admin_head-post-new.php
* Inspired by @link: https://premium.wpmudev.org/blog/character-counter-excerpt-box/
*/
function cmfy_excerpt_character_counter() {
// If post type does not support excerpt, do nothing
if ( ! post_type_supports( get_post_type(), 'excerpt' ) ) {
return;
@phillip-boombox
phillip-boombox / wp-functions-featured-image-help.php
Last active April 22, 2023 02:51
WordPress: Add help text to the featured image metabox.
@phillip-boombox
phillip-boombox / wp-functions-help-tab.php
Last active December 12, 2017 21:50
WordPress: Add a help tab to an admin screen.
<?php
/**
* Add a help tab to the new/edit post screen.
* Action: admin_head-post.php, admin_head-post-new.php
*/
function cmfy_add_gumbo_help_tab() {
// Get the WP_Screen object
$screen = get_current_screen();
// Adjust / remove this conditional depending on which hook you're firing on
@phillip-boombox
phillip-boombox / full_backup.sh
Created June 27, 2018 18:04
BASH script to make a backup of website files and the database. Useful as a CRON script.
#!/bin/bash
# This script creates a compressed backup archive of the given directory and the given MySQL table. More details on implementation here: http://theme.fm
# Feel free to use this script wherever you want, however you want. We produce open source, GPLv2 licensed stuff.
# Author: Konstantin Kovshenin exclusively for Theme.fm in June, 2011
# Original link: https://theme.fm/a-shell-script-for-a-complete-wordpress-backup/
# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived.
NOW=$(date +"%Y-%m-%d-%H%M")