Skip to content

Instantly share code, notes, and snippets.

View matgargano's full-sized avatar

Mat Gargano matgargano

View GitHub Profile
<?php
/*
Plugin Name: TEST NOTICE
*/
function test_notice(){
add_action( 'admin_notices', function (){
echo '<div class="updated"><p>Activated</p></div>';
} );
<?php
add_filter('query_vars', function($vars){
$vars[] = 'featured';
return $vars;
});
add_action('init', function(){
add_rewrite_rule('sponsors/test/?$', 'index.php?post_type=sponsors&featured=true', 'top');
body {
padding:100px;
}
.top {
position:absolute;
top:0;
left:0;
}
<?php
add_filter('query_vars', function($vars){
$vars[] = 'customendpoint';
return $vars;
});
/* set up rewrite rule */
add_action('init', function(){
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!
}