Skip to content

Instantly share code, notes, and snippets.

View Stephen-Cronin's full-sized avatar

Stephen Cronin Stephen-Cronin

View GitHub Profile
@Stephen-Cronin
Stephen-Cronin / changedb.sh
Created July 16, 2017 12:04
Bash Script to change database using wp-cli
#!/bin/bash
# Bash Script to change database using wp-cli
# Finds any previously exported .sql file and asks the user which one to change to (ie import)
# Recommended usage: Change your system to multiple ideal states and export the db for each (into main wp folder), then use this to switch between states.
# Example: I have db exports for empty installation, theme unit test data, woocommerce demo data, etc.
# Requires wp cli
# Needed on my Windows installation. YOU PROBABLY NEED TO REMOVE THIS IF NOT USING WINDOWS.
shopt -s expand_aliases
alias wp="wp.bat"
@Stephen-Cronin
Stephen-Cronin / resetwp.sh
Last active July 16, 2017 05:53
Bash script to reset a WordPress database
#!/bin/bash
# Bash script to reset a WordPress database once you've messed the data up
# Does not delete themes, plugins, or media, just restores WordPress to an emtpy system, activate plugins, imports data, etc
# Requires wp cli
# Login details. EDIT THESE AS APPROPRIATE.
ADMIN_USER="admin"
ADMIN_PASSWORD="password"
ADMIN_EMAIL="person@domain.com"
@Stephen-Cronin
Stephen-Cronin / functions.php
Created April 13, 2017 03:22
Show callbacks using `comment_text` or `get_comment_text` filters
// to be added in functions.php within the PHP tags
function spc_list_comment_filters() {
// exit if not on a page that show comments (the Comments page or Edit post/page screen)
global $pagenow;
if ( 'edit-comments.php' != $pagenow && 'post.php' != $pagenow ) {
return;
}
// get global variable containing list of registered filters
@Stephen-Cronin
Stephen-Cronin / gist:dfe31f17f01528c2bf1b363cba4eb4d6
Last active September 13, 2016 02:34
Last Updated Column in Google Spreadsheets
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
var r = s.getActiveCell();
if( r.getColumn() != 2 && r.getRow() != 1 ) { //checks the column
var row = r.getRow();
var time = new Date();
var timezone = CalendarApp.getDefaultCalendar().getTimeZone();
time = Utilities.formatDate(time, timezone, "dd/MM/yyyy, hh:mm:ss");
SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
};
@Stephen-Cronin
Stephen-Cronin / comment_auto_approval.php
Last active September 23, 2015 02:33
Automatically approve comments for people with more than 5 comments approved already
<?php
function filter_handler( $approved , $commentdata ) {
// get the comment author name and email and check how many comments that person has approved.
global $wpdb;
$author = $commentdata[ 'comment_author' ];
$email = $commentdata[ 'comment_author_email' ];
$comments_approved = $wpdb->get_var( "SELECT COUNT(comment_approved) FROM $wpdb->comments WHERE comment_author = '$author' AND comment_author_email = '$email' and comment_approved = '1' LIMIT 1" );
// if the author already has more than 5 comments approved, set this to approved, otherwise set as pending
<?php
// To be used by theme authors to avoid duplicate favicon code now that Site Icons have been added to WordPress 4.3
// If a Site Icon hasn't been set or if the `has_site_icon` function doesn't exist (ie older than WordPress 4.3)
if ( ! ( function_exists( 'has_site_icon' ) && has_site_icon() ) ) {
// your theme specific custom favicon code goes here
}