Skip to content

Instantly share code, notes, and snippets.

Stephen Cronin Stephen-Cronin

Block or report user

Report or block Stephen-Cronin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Stephen-Cronin
Stephen-Cronin / changedb.sh
Created Jul 16, 2017
Bash Script to change database using wp-cli
View changedb.sh
#!/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 Jul 16, 2017
Bash script to reset a WordPress database
View resetwp.sh
#!/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 Apr 13, 2017
Show callbacks using `comment_text` or `get_comment_text` filters
View functions.php
// 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 Sep 13, 2016
Last Updated Column in Google Spreadsheets
View gist:dfe31f17f01528c2bf1b363cba4eb4d6
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 Sep 23, 2015
Automatically approve comments for people with more than 5 comments approved already
View comment_auto_approval.php
<?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
View site_icon.php
<?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
}
You can’t perform that action at this time.