Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
@danielbachhuber
danielbachhuber / gist:1433377
Created December 5, 2011 12:03
Ad Zone Manager pseudo demo code
<?php
/**
* Ad Zone Manager - Test examples
* Making it easier to manage advertising snippets in Wordpress
*/
/**
* Register your Ad Zones
*/
@danielbachhuber
danielbachhuber / gist:1507607
Created December 21, 2011 20:40
Ad Code Manager, pseudo code two
<?php
$script = 'http://ad.doubleclick.net/adj/%site_name%/%ad_zone%;s1=%ad_zone%;s2=;pid=[unique_page_id];fold=atf;kw=;test=;ltv=ad;pos=top;dcopt=ist;tile=1;sz=300x250;ord=%page_random%?';
$where = array(
'is_search' => true,
'query_include' => 'apple',
);
$url_vars = array(
'site_name' => 'ltv.witi.home',
'ad_zone' => 'homepage',
@danielbachhuber
danielbachhuber / gist:1622010
Created January 16, 2012 17:50
Sample Ad Code Manager registrations
<?php
add_filter( 'acm_output_html', function( $html ) {
return '<img src="%url%" />';
});
add_action( 'after_setup_theme', 'db_register_ad_codes' );
function db_register_ad_codes() {
$ad_codes = array(
@danielbachhuber
danielbachhuber / gist:1636361
Created January 18, 2012 23:00
Filter canonical redirects so we can support full page URLs
<?php
add_filter( 'redirect_canonical', 'grist_disable_redirect_for_full_pall', 10, 2 );
function grist_disable_redirect_for_full_pall( $redirect_url, $requested_url ) {
$url_endings = array(
'full',
'pall',
);
if ( is_singular() && in_array( trim( strtolower( substr( $requested_url, -5 ) ), '/' ), $url_endings ) )
return trailingslashit( $requested_url );
@danielbachhuber
danielbachhuber / gist:1649460
Created January 20, 2012 20:45
Populate editorial metadata fields when creating a new post
<?php
/**
* A quick snippet to indicate how you might be able to populate Edit Flow editorial metadata fields when creating a new post
* Please keep in mind: I haven't tested this code, so it may need a bit of fixing before it actually works
*
* @see http://wordpress.org/support/topic/plugin-edit-flow-auto-populate-editorial-metadata-using-wp_insert_post
*/
// ... All of your form processing to prepare the data for wp_insert_post()
@danielbachhuber
danielbachhuber / gist:1666271
Created January 23, 2012 23:14
Grist's guest authors plugin
<?php
/* Plugin Name: Grist Authors
* Description: Handles a special 'Author' post type and co-authors for posts.
* Author: Andrew Nacin
* Author URI: http://andrewnacin.com/
*/
class Grist_Authors {
static function init() {
@danielbachhuber
danielbachhuber / gist:1760666
Created February 7, 2012 16:47
Include author matches in search results
<?php
/**
* Include posts from authors in the search results where
* either their display name or user login matches the query string
*
* @author danielbachhuber
*/
add_filter( 'posts_search', 'db_filter_authors_search' );
function db_filter_authors_search( $posts_search ) {
@danielbachhuber
danielbachhuber / gist:1764918
Created February 8, 2012 03:19
Get the editorial metadata value for a given term
<?php
/**
* Output the value for an editorial metadata term
* @see http://wordpress.org/support/topic/plugin-edit-flow-exporting-editorial-metadata
*/
function photo_credit() {
global $edit_flow;
// Don't cause any fatal errors if Edit Flow or editorial metadata are deactivated
if ( !is_object( $edit_flow ) || $edit_flow->helpers->module_enabled( 'editorial-metadata' ) )
@danielbachhuber
danielbachhuber / acm-dfp-setup.ml
Created February 9, 2012 19:40
ACM readme rough draft
=== Ad Code Manager ===
Contributors: danielbachhuber, rinatkhaziev, automattic
Tags: advertising, ad codes
Requires at least: 3.1
Tested up to: 3.3.1
Stable tag: 0.1
Manage your ad codes through the WordPress admin in a safe and easy way.
== Description ==
@danielbachhuber
danielbachhuber / gist:1819334
Created February 13, 2012 19:23
Edit Flow WP.com helper file
<?php
/**
* Don't load caps on install for WP.com. Instead, let's add
* them with the WP.com + core caps approach
*/
add_filter( 'ef_kill_add_caps_to_role', '__return_true' );
add_filter( 'ef_view_calendar_cap', function() { return 'edit_posts'; } );
add_filter( 'ef_view_story_budget_cap', function() { return 'edit_posts'; } );
add_filter( 'edit_post_subscriptions', function() { return 'edit_others_posts'; } );
add_filter( 'edit_usergroups', function() { return 'manage_options'; } );