Skip to content

Instantly share code, notes, and snippets.

View MZAWeb's full-sized avatar

Daniel Dvorkin MZAWeb

View GitHub Profile
@MZAWeb
MZAWeb / 0_reuse_code.js
Created May 13, 2014 16:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
add_role('school_admin', 'School Administrator', array(
'read' => true,
'edit_school' => true,
'edit_pages' => true,
'edit_posts' => true)
);
@MZAWeb
MZAWeb / gist:2131168
Created March 20, 2012 04:00
XML-RPC Wrapper
<?php
if (!class_exists("MZAXMLRPC")){
abstract class MZAXMLRPC {
protected $calls = Array();
protected $namespace = "myxmlrpc";
function __construct($namespace){
@MZAWeb
MZAWeb / gist:3194851
Created July 28, 2012 21:23
Exclusive search for p2p
<?php
add_action( 'pre_get_posts', 'query_for_recipe_search' );
function query_for_recipe_search( $query ) {
if ( is_recipe_search() && is_main_query() ) {
$ingredients = isset( $_GET["search_ingredients"] ) ? $_GET["search_ingredients"] : NULL;
if ( is_array( $ingredients ) ) {
global $wpdb;
@MZAWeb
MZAWeb / gist:3229799
Created August 1, 2012 18:59
The Events Calendar: maybeAddEventTitle
<?php
public function maybeAddEventTitle( $title, $sep = NULL ) {
if ( get_query_var( 'eventDisplay' ) == 'upcoming' ) {
$new_title = apply_filters( 'tribe_upcoming_events_title', __( "Upcoming Events", 'tribe-events-calendar' ) . ' ' . $sep . ' ' . $title, $sep );
} elseif ( get_query_var( 'eventDisplay' ) == 'past' ) {
$new_title = apply_filters( 'tribe_past_events_title', __( "Past Events", 'tribe-events-calendar' ) . ' ' . $sep . ' ' . $title, $sep );
} elseif ( get_query_var( 'eventDisplay' ) == 'month' ) {
if ( get_query_var( 'eventDate' ) ) {
$title_date = date_i18n( "F, Y", strtotime( get_query_var( 'eventDate' ) ) );
@MZAWeb
MZAWeb / gist:3229874
Created August 1, 2012 19:12
The Events Calendar: Change calendar HTML title
<?php
/*
* Parameters:
* $title: the original title (ie: Events for July, 2012)
* $separator: I believe it will be always null for this filter
* $date: The selected month in string format (ie: July, 2012)
*/
function richard_modify_calendar_title( $title, $separator, $date ) {
$new_title = 'Here goes your custom title for the date: ' . $date;
@MZAWeb
MZAWeb / gist:3232646
Created August 2, 2012 02:30
my_tribe_meta_event_cats (list without link)
<?php
function my_tribe_meta_event_cats() {
$tribe_ecp = TribeEvents::instance();
$terms = get_the_terms( get_the_ID(), $tribe_ecp->get_event_taxonomy() );
if ( $terms ) {
$term_names = wp_list_pluck( $terms, 'name' );
$label = "Category";
if ( count( $term_names ) > 1 ) {
@MZAWeb
MZAWeb / gist:3415684
Created August 21, 2012 13:59
Hide events cat from the front end
<?php
add_filter( 'parse_tribe_event_query', 'hide_my_private_category', 999 );
function hide_my_private_category( $query ) {
/*
* First we create the tax_query for excluding
* all the events that have the term 'hidden'.
* Change that 'hidden' for the slug of the term
* you want to hide from the Front End.
@MZAWeb
MZAWeb / gist:3476084
Created August 26, 2012 08:13
INCLUDE ALL THE STRINGS!
#if HAVE_STRING_H
#include <string.h>
#else
#include <strings.h>
#endif
@MZAWeb
MZAWeb / gist:3483555
Created August 26, 2012 20:56
array_intersect_assoc
<?php
function my_array_compare( $val1, $val2 ) {
return ( $val1["parent_entry_id"] == $val2["parent_entry_id"] );
}
$first = array( array( "parent_entry_id" => 123 ), array( "parent_entry_id" => 987 ), );
$second = array( array( "parent_entry_id" => 123 ),