Skip to content

Instantly share code, notes, and snippets.

View matgargano's full-sized avatar

Mat Gargano matgargano

View GitHub Profile
@matgargano
matgargano / permutations.php
Created August 27, 2015 01:58
permutations.php
<?php
function get_permutations( array $values ) {
$n = count($values);
$rec = function ( array $values, &$ret, $n, array $cur = array() ) use ( &$rec ) {
if ( $n > 0 ) {
foreach ( $values as $v ) {
$newCur = $cur;
@matgargano
matgargano / rewrites.php
Created August 27, 2015 13:25
rewrites for all taxonomy combinations
<?php
function eg_add_rewrite_rules() {
global $wp_rewrite;
$post_type = 'post';
if ( ! is_object( $post_type ) ) {
$post_type = get_post_type_object( $post_type );
}
function __construct() {
add_action( 'admin_print_scripts-widgets.php', function(){
if (is_admin()){ //test fails b/c the admin_print_scripts-widget.php is not aware that is_admin() is true...
wp_enqueue_style( 'spw-admin', plugins_url( 'css/' . 'spw-admin.min.css', dirname( __FILE__ ) ), false, 1 );
wp_enqueue_script( 'spw-admin', plugins_url( 'javascripts/' . 'spw-admin.min.js', dirname( __FILE__ ) ), array( 'jquery' ), 1, true );
}
} );
}
matthews-mbp-2:bin mat$ ./install-wp-tests.sh test test test localhost latest
+ install_wp
+ mkdir -p /tmp/wordpress/
+ '[' latest == latest ']'
+ local ARCHIVE_NAME=latest
+ wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/latest.tar.gz
2014-02-06 18:04:20 URL:http://wordpress.org/latest.tar.gz [5869727/5869727] -> "/tmp/wordpress.tar.gz" [1]
+ tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C /tmp/wordpress/
+ wget -nv -O /tmp/wordpress//wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php
2014-02-06 18:04:22 URL:https://raw.github.com/markoheijnen/wp-mysqli/master/db.php [10499/10499] -> "/tmp/wordpress//wp-content/db.php" [1]
// theme code
$contestants = apply_filters('contestants', 'name');
if ( is_array( $contestants ) ) {
foreach($contestants as $contestant){
echo "hello " . $contestant . '<br>';
}
} elseif ( is_string($contestants)){
$user = $this->factory->user->create_and_get( array(
'role' => 'administrator'
) );
wp_set_current_user( $user->ID );
@matgargano
matgargano / gist:10935618
Created April 16, 2014 21:36
add a category term if it doesn't exist (wordpress)
<?php
if ( ! term_exists( 'free-flow', 'category' ) ) {
wp_insert_term( 'Free Flow', 'category',
array(
'description'=> 'Give extra left-right padding to the text block',
'slug' => 'free-flow',
)
);
}
@matgargano
matgargano / gist:10981294
Created April 17, 2014 12:56
Cron on save_post (or whatever action)... (simulates) asynchroncity
add_action( 'save_post', function(){
wp_schedule_single_event( time(), 'action_to_run' );
});
add_action( 'action_to_run', 'function_to_run' );
function function_to_run(){
//asynchronous code to run!
}
@matgargano
matgargano / gist:fea6c14f694f724a8c6d
Created July 2, 2014 13:26
add local ssh key to remote server
cat ~/.ssh/id_rsa.pub | ssh root@your.ip.address "cat >> ~/.ssh/authorized_keys"
<?php
add_action( 'add_meta_boxes', function() {
add_meta_box( 'asdf123_editors', 'Editors', function() {
wp_editor( 'Drag/Drop => True', 'asdf123_editor_1', array(
'drag_drop_upload' => true,
) );