Skip to content

@westonruter /acme_story.php secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
<?php
// @todo Put an add_role() here
/**
* Filter the author requests to only include scribe and art posts
* @filter request
* @todo Open up acme_art to be included on the author page when we open up art contributions to the public
*/
function _acme_filter_storyteller_author_request_to_only_include_story_posts( $request ){
if( empty($request['author_name']) ){
return $request;
}
$user = get_user_by('slug', $request['author_name']);
if( !$user ){
return $request;
}
$user = new WP_User($user->ID);
if( in_array('acme_storyteller', $user->roles) ){
$request['post_type'] = array(
'acme_story',
);
}
return $request;
}
if( !is_admin() ){
add_filter( 'request', '_acme_filter_storyteller_author_request_to_only_include_story_posts', 100 );
}
<?php
/**
* Filter the avatar to show the Facebook picture
* @filter get_avatar
*/
function _acme_get_gravatar_filter( $avatar, $id_or_email, $size, $default, $alt ){
if( is_object($id_or_email) && isset($id_or_email->user_id) ){
$id_or_email = $id_or_email->user_id;
}
if( !is_numeric($id_or_email) ){
return $avatar;
}
$user = new WP_User($id_or_email);
if( empty($user) || empty($user->ID) || empty($user->acme_facebook_uid) ){
return $avatar;
}
$avatar = sprintf('<img src="%1$s" alt="%2$s" class="avatar avatar-%3$d" width="%3$d" />',
esc_attr("http://graph.facebook.com/{$user->acme_facebook_uid}/picture?type=large"),
esc_attr($user->display_name),
$size
);
return $avatar;
}
add_filter( 'get_avatar', '_acme_get_gravatar_filter', 100, 5 );
<?php
/**
* Filter post links for FAQ to link to permalink page anchor on FAQ index page
* @filter post_link
*/
function _acme_filter_faq_post_link( $url, $post ){
if( $post->post_type == 'acme_faq' ){
$url = trailingslashit(get_home_url()) . 'faq/#' . $post->post_name;
}
return $url;
}
add_filter( 'post_link', '_acme_filter_faq_post_link', 10, 2 );
/**
* Ensure that requests to single FAQs get directed to the FAQ page targeting the requested FAQ
* @filter request
*/
function _acme_redirect_faq_to_faq_page( $request ){
$is_needing_redirect = (
isset($request['acme_faq'])
&&
!empty($request['name'])
&&
$request['name'] != 'feed'
);
if( $is_needing_redirect ){
$url = trailingslashit(get_home_url()) . 'faq/#' . sanitize_title($request['name']);
wp_redirect($url, 301);
exit;
}
return $request;
}
add_action( 'request', '_acme_redirect_faq_to_faq_page' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.