Skip to content

Instantly share code, notes, and snippets.

View alessandrotesoro's full-sized avatar
👨‍💻
Probably coding right now...

Alessandro Tesoro alessandrotesoro

👨‍💻
Probably coding right now...
View GitHub Profile
@alessandrotesoro
alessandrotesoro / acf_filter_select_menu
Created March 3, 2014 20:25
Filter Advanced Custom Fields Plugin Select Field with all created menu, modify "field_name" with the name of the select field.
function tdp_filter_field_with_menus( $field ) {
// reset choices
$field['choices'] = array();
$menus = get_terms('nav_menu');
foreach($menus as $menu){
$field['choices'][ $menu->slug ] = $menu->name;
}
// Important: return the field
@alessandrotesoro
alessandrotesoro / custom.js
Last active August 29, 2015 13:57
Ajax Search And Autosuggest For WordPress
jQuery('#s').suggest(ajax.url + '?action=tdp_ajax_search_query');
@alessandrotesoro
alessandrotesoro / gist:9367358
Created March 5, 2014 13:42
Use minified libraries if SCRIPT_DEBUG is turned off
// Use minified libraries if SCRIPT_DEBUG is turned off
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_script( 'my-script-handle', plugin_dir_url( __FILE__ ) . 'assets/my-file' . $suffix . '.js', array( 'jquery' ) );
@alessandrotesoro
alessandrotesoro / gist:9369769
Created March 5, 2014 15:45
Filter wp comment types dropdown for custom comments types
add_filter( 'admin_comment_types_dropdown', 'tdp_admin_comment_types_dropdown' );
function tdp_admin_comment_types_dropdown( $types ) {
//replace parts as needed
$types['your_note_type'] = __( 'Your Note Type', 'your-text-domain' );
return $types;
}
@alessandrotesoro
alessandrotesoro / gist:9390054
Created March 6, 2014 13:47
WordPress programmatically filter menu items given a location
/**
* Filter Menu Items
*/
function tdp_filter_menu_items( $items, $args ) {
if($args->theme_location == 'primary_menu')
{
$items .= '<li class="primary-menu-secondary-item"><a href="#">Menu Item</a></li>';
}
function tdp_remove_script_version( $src ){
return remove_query_arg( 'ver', $src );
}
add_filter( 'script_loader_src', 'tdp_remove_script_version' );
add_filter( 'style_loader_src', 'tdp_remove_script_version' );
@alessandrotesoro
alessandrotesoro / gist:4e119a97367bcb88a639
Created September 26, 2014 10:23
Example of throwing errors during post creation
add_action('save_post', 'wdb_check_thumbnail');
add_action('admin_notices', 'wdb_thumbnail_error');
function wdb_check_thumbnail($post_id) {
// convert to a custom post type
if(get_post_type($post_id) != 'post')
return;
if ( !has_post_thumbnail( $post_id ) ) {
@alessandrotesoro
alessandrotesoro / gist:ed11aa848c3205e6e2e1
Last active August 29, 2015 14:08
WPRM Show all items within the menu for the wprm_menu shortcode.
/**
* Display All items within the menu.
*
* @return $args
*/
function wprm_show_all_items($args) {
$args['posts_per_page'] = -1;
return $args;
@alessandrotesoro
alessandrotesoro / gist:c814a64c915326339f5b
Created November 13, 2014 11:51
WPRM: Allows Bookings Managers to access the calendar page in WP Restaurant Manager Pro Plugin.
function wprm_show_calendar_to_managers() {
return 'publish_wprm_reservations';
}
add_filter( 'wprm_calendar_cap', 'wprm_show_calendar_to_managers' );
@alessandrotesoro
alessandrotesoro / gist:5ed2dc1e4ec425c98c18
Created December 3, 2014 17:56
Display all users into the "Author" box
add_filter('wp_dropdown_users', 'tdp_custom_wp_dropdown_users');
function tdp_custom_wp_dropdown_users($output) {
global $post;
$users = get_users();
$output = "<select id=\"post_author_override\" name=\"post_author_override\" class=\"\">";
$output .= "<option value=\"1\">Admin</option>";
foreach($users as $user) {
$sel = ($post->post_author == $user->ID)?"selected='selected'":'';
$output .= '<option value="'.$user->ID.'"'.$sel.'>'.$user->user_login.'</option>';
}