Skip to content

Instantly share code, notes, and snippets.

@dannyockilson
dannyockilson / wordpress.sql
Created May 27, 2014 17:18
SQL Queries for Wordpress
/* Switch off comments and remove for already created posts */
UPDATE {{database}}.{{prefix}}posts SET comment_status = 'closed' WHERE comment_status = 'open';
UPDATE {{database}}.{{prefix}}options SET option_value = 'closed' WHERE option_name = 'default_comment_status';
/* Lost password on localhost/no mail server */
UPDATE {{database}}.{{prefix}}users
SET password = MD5('{{password}}')
WHERE user_id = 1; /* normally replace with relevant user ID */
/* Somethings broke - deactivate all plugins and use default theme */
@dannyockilson
dannyockilson / gist:79865d873bf8575bd52c
Created June 5, 2014 10:52
Add "Ordinal Suffix" to a number (ie 1->1st)
function iadw_get_ordinal_suffix($number){
$ends = array('th','st','nd','rd','th','th','th','th','th','th');
if (($number %100) >= 11 && ($number%100) <= 13)
$abbreviation = $number. 'th';
else
$abbreviation = $number. $ends[$number % 10];
return $abbreviation;
}
@dannyockilson
dannyockilson / privacy.php
Last active August 29, 2015 14:02
Wordpress Private site
function iadw_login_redirection(){
auth_redirect();
}
add_action( 'wp_head', 'iadw_login_redirection' );
/* to allow visitors to access your home page only just switch the function to
* if(!is_home()) auth_redirect();
*/
@dannyockilson
dannyockilson / media-categories
Created July 3, 2014 10:40
Enable Media Categories Wordpress
<?php
/* add this on init hook */
register_taxonomy_for_object_type( 'category', 'attachment' );
?>
@dannyockilson
dannyockilson / laravel
Created September 3, 2014 11:41
Laravel Testing Batch File (note %WEBROOT% is specified as my WAMP root dir)
@echo off
set /p project=What project are you running?
cd %WEBROOT%\%project%
doskey ls = dir
doskey codecept = vendor\bin\codecept run
doskey codeceptf = vendor\bin\codecept run functional
doskey migrate = php artisan migrate
doskey migrateback = php artisan migrate:rollback
@dannyockilson
dannyockilson / ignore_ctrl
Last active August 29, 2015 14:17
Quick Snippet
// Used Chrome dev tools to find the click event being triggered
$("article.lesson-block").find(".full-center").on("click", function(event) {
// check for ctrl or metakey (mac cmd)
if (!event.ctrlKey && !event.metaKey) {
// if not do your stuff
var t = $(this).parents(".lesson-block").find(".lesson-block-title a").attr("href");
location = t
}
})
@dannyockilson
dannyockilson / config.php
Created April 23, 2015 13:34
quick env example
<?php
// add variables to $_ENV
putenv("TOKEN=USER-API-TOKEN");
putenv("TEAM=USER-TEAM");
putenv("USERNAME=USER-NAME");
// Etc....
// then from your main file
getenv('TOKEN'); // etc
@dannyockilson
dannyockilson / talk-notes.md
Last active September 14, 2015 11:22
Notes from Continuous PHP talk

Continuous Integration

Every branch is tested on every commit/merge Small batches of features in agile sprint style

Continuous Deploy

Adds a release step, build package from branch and deploy Allows quick re-deployment of previous versions if things go wrong Keeps all deploys consistent, dependencies etc are all same versions

@dannyockilson
dannyockilson / lipsum shortcode
Created May 17, 2013 14:33
Wordpress Function to add [lipsum] | [lipsum amount="int"] | [lipsum type="{ paras | words | bytes | lists }"]
function lipsum_shortcode($atts) {
extract(shortcode_atts(array('amount' => 1, 'type' => 'paras'), $atts));
$lipsum = simplexml_load_file("http://www.lipsum.com/feed/xml?amount=$amount&what=$type")->lipsum;
return $lipsum;
}
add_shortcode('lipsum', 'lipsum_shortcode');
@dannyockilson
dannyockilson / of_section_hider
Last active December 17, 2015 11:59
Hide sections of options when using Wordpress Options Framework http://wptheming.com/options-framework-theme/
// In options.php
$options[] = array(
'name' => __('Example Hide', 'options_framework_theme'),
'desc' => __('Example Hide Multiple Fields', 'options_framework_theme'),
'id' => 'example_showhidden',
'type' => 'checkbox');
$options[] = array(
'name' => __('Example Hidden 1', 'options_framework_theme'),