Skip to content

Instantly share code, notes, and snippets.

View antoniofrignani's full-sized avatar
👨‍💻

Antonio Frignani antoniofrignani

👨‍💻
View GitHub Profile
@antoniofrignani
antoniofrignani / gist:2867537
Created June 4, 2012 09:50
[WP] - Add select menu to filter by custom field in admin
// http://wpsnipp.com/index.php/functions-php/add-select-menu-to-filter-by-custom-field-in-admin/
add_filter( 'parse_query', 'ba_admin_posts_filter' );
add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
function ba_admin_posts_filter( $query )
{
global $pagenow;
if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_NAME']) && $_GET['ADMIN_FILTER_FIELD_NAME'] != '') {
$query->query_vars['meta_key'] = $_GET['ADMIN_FILTER_FIELD_NAME'];
if (isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '')
@antoniofrignani
antoniofrignani / gist:2867534
Created June 4, 2012 09:49
[WP] - Unregister default widgets
// http://wpsnipp.com/index.php/calendar/unregister-default-widgets/
// unregister all default WP Widgets
function unregister_default_wp_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
@antoniofrignani
antoniofrignani / gist:2867532
Created June 4, 2012 09:49
[WP] - Filter search results by post type
// http://wpsnipp.com/index.php/functions-php/filter-search-results-by-post-type/
function search_posts_filter( $query ){
if ($query->is_search){
$query->set('post_type',array('post','custom_post_type1', 'custom_post_type2'));
}
return $query;
}
add_filter('pre_get_posts','search_posts_filter');
@antoniofrignani
antoniofrignani / gist:2867527
Created June 4, 2012 09:48
[WP] - Search a specific post type
// http://wpsnipp.com/index.php/posts/search-a-specific-post-type/
function SearchFilter($query) {
if ($query->is_search) {
// Insert the specific post type you want to search
$query->set('post_type', 'feeds');
}
return $query;
}
// This filter will jump into the loop and arrange our results before they're returned
@antoniofrignani
antoniofrignani / gist:2867523
Created June 4, 2012 09:47
[WP] - Attach images with simple thumbnail selection metabox
// http://wpsnipp.com/index.php/functions-php/attach-images-with-simple-thumbnail-selection-metabox/
add_action("admin_init", "images_init");
add_action('save_post', 'save_images_link');
function images_init(){
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
add_meta_box("my-images", "Pictures", "images_link", $post_type, "normal", "low");
}
}
@antoniofrignani
antoniofrignani / gist:2867522
Created June 4, 2012 09:45
[WP] - Search category with dropdown
<form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
<div>
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
in <?php wp_dropdown_categories( 'show_option_all=All Categories' ); ?>
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
@antoniofrignani
antoniofrignani / gist:2867521
Created June 4, 2012 09:44
[WP] - Add youtube thumbnail posts with custom metabox
// http://wpsnipp.com/index.php/functions-php/add-youtube-thumbnail-posts-with-custom-metabox/
add_action("admin_init", "youtube_init");
add_action('save_post', 'save_youtube_link');
function youtube_init(){
add_meta_box("youtube", "Youtube thumbnail code", "youtube_link", "post", "normal", "high");
}
function youtube_link(){
global $post;
$custom = get_post_custom($post->ID);
@antoniofrignani
antoniofrignani / gist:2867520
Created June 4, 2012 09:43
[WP] - highlight post_states within admin posts and pages
// http://wpsnipp.com/index.php/functions-php/highlight-post_states-within-admin-posts-and-pages/
function custom_post_states( $post_states ) {
foreach ( $post_states as &$state ){
$state = '<span class="'.strtolower( $state ).' states">' . str_replace( ' ', '-', $state ) . '</span>';
}
return $post_states;
}
add_filter( 'display_post_states', 'custom_post_states' );
function custom_post_states_css(){
@antoniofrignani
antoniofrignani / gist:2867487
Created June 4, 2012 09:40
[WP] - Update: Create custom post status messages in admin
// http://wpsnipp.com/index.php/functions-php/update-create-custom-post-status-mesasges-in-admin/
// for layout fixes: http://pastebin.com/zNHEZMKR
add_filter( 'display_post_states', 'custom_post_state' );
function custom_post_state( $states ) {
global $post;
$show_custom_state = get_post_meta( $post->ID, '_status' );
// We are using "None" as a way to disable this feature for the current post.
if ( $show_custom_state && $show_custom_state[0] != 'None' ) $states[] = '<span class="custom_state ' . strtolower( $show_custom_state[0] ) . '">' . $show_custom_state[0] . '</span>';
@antoniofrignani
antoniofrignani / gist:2867480
Created June 4, 2012 09:39
[WP] - Prevent direct file access to functions.php
// Prevent direct file access to functions.php
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'functions.php' == basename($_SERVER['SCRIPT_FILENAME']))
{
die ('No access!');
}