Skip to content

Instantly share code, notes, and snippets.

View timkinnane's full-sized avatar

Tim Kinnane timkinnane

View GitHub Profile
@timkinnane
timkinnane / wp_insert_admin.sql
Created November 19, 2012 05:02
Wordpress, insert admin user to database
# Adds a user and gives admin permissions to Wordpress database
# Change db_wordpress to DB name
# Change wp_ to your table prefix
# Change username, pass, nicename, email, url, displayname and pass to your new user info
# Change date to whenever you want the registered date to be
INSERT INTO `db_wordpress`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES (NULL, 'username', MD5('pass'), 'nicename', 'email', 'url', '2010-10-08 00:00:00', '', '0', 'displayname');
# Find the userid that was just created (int)
@timkinnane
timkinnane / wp_install.sh
Created April 7, 2013 23:36
Wordpress, install via ssh
# First connect to host via SSH - cd to public_html or httpdocs
# Download latest WP to host (zip or tar.gz)
wget http://wordpress.org/latest.tar.gz
# Extract it
tar xzvf latest.tar.gz
# Move it out of 'wordpress' directory
mv wordpress/* ~/public_html
@timkinnane
timkinnane / wp_update_url.sql
Created April 7, 2013 23:36
Wordpress, find and replace url in database.
UPDATE wp_options SET option_value = REPLACE (option_value, 'http://oldurl','http://newurl');
UPDATE wp_posts SET guid = REPLACE (guid,'http://orldurl','http://newurl');
# Change "wp_" to your database's table prefix
# Change oldurl, newurl (oldurl is the one in the database already)
@timkinnane
timkinnane / shortcode.php
Created April 7, 2013 23:36
Wordpress shortcode example
<?php
// MyShortcode usage [myshortcode greeting="Hello" who="World"]
function myshortcode_func( $atts, $content = null ) {
// use given attributes or defined defaults
extract( shortcode_atts( array(
'greeting' => '',
'who' => ''
), $atts ) );
@timkinnane
timkinnane / date_range_regex.php
Created April 7, 2013 23:37
Generate date range regex, PHP.
function get_daterange_regex( $from, $to, $input_format ) {
// get the difference in months
$date1 = DateTime::createFromFormat( $from, $input_format );
$date2 = DateTime::createFromFormat( $to, $input_format );
$interval = $date1->diff($date2);
$months = $interval->m;
// get an array of the interveening months
$all_months = array();
@timkinnane
timkinnane / rsync_public_html.sh
Created June 21, 2013 00:56
Rsync site to new host
# migrate from host to dest server - requires pass
rsync -zav --delete --progress public_html/ user@host:public_html/
@timkinnane
timkinnane / move_db.sh
Created June 21, 2013 01:09
SSH, export and move MySQL database to remote host
mkdir -p db_export_tmp
mysqldump --add-drop-table -efK -u DB_USER -pPASS DB_NAME > tmp/DB_NAME.sql
mysql -h host -u DB_USER -pPASS DB_NAME < tmp/DB_NAME.sql
rm -rf db_export_tmp
@timkinnane
timkinnane / wpadmin_data_table.js
Last active January 25, 2017 10:36
dataTable takes an array of key/value objects and return table of elements. e.g from parsed JSON. Requires jQuery. Widefat class is used for Wordpress admin pages, but its not a WP specific function.
jQuery(document).ready(function($) {
function dataTable(data) {
var response_table = $('<table class="widefat"></table>');
var header = $('<thead><tr></tr></thead>');
for(var k in data[0]) {
header.append('<th>'+k+'</th>');
}
response_table.append(header);
@timkinnane
timkinnane / Remove old uploads.sh
Last active December 22, 2015 04:48
Remove old uploads in gravity forms. e.g. Schedule as cron job after backups.
# find uploads > not web files > files only > older than 6 months
find ~/public_html/wp-content/uploads/gravity_forms/* -not -name "*.html" -not -name "*.php" -type f -mtime +182
# Find > delete
find ~/public_html/wp-content/uploads/gravity_forms/* -not -name "*.html" -not -name "*.php" -type f -mtime +182 -exec rm {} \;
@timkinnane
timkinnane / Parent-sibling htaccess files
Last active August 29, 2015 14:06
htaccess for two Wordpress installs in side by side subfolders, one resolving to primary domain, one to subdomain.
## Example DOMAIN.TLD serves MAIN folder
## SUB folder served from SUB.DOMAIN.TLD
## --- public_html/ .htaccess --- ##
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?DOMAIN.TLD/$
RewriteRule ^$ /MAIN/ [L]
# Remove WWW (optional)