Skip to content

Instantly share code, notes, and snippets.

👨‍💻
Probably coding right now...

Alessandro Tesoro alessandrotesoro

👨‍💻
Probably coding right now...
Block or report user

Report or block alessandrotesoro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alessandrotesoro
alessandrotesoro / acf_filter_select_menu
Created Mar 3, 2014
Filter Advanced Custom Fields Plugin Select Field with all created menu, modify "field_name" with the name of the select field.
View acf_filter_select_menu
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 Aug 29, 2015
Ajax Search And Autosuggest For WordPress
View custom.js
jQuery('#s').suggest(ajax.url + '?action=tdp_ajax_search_query');
@alessandrotesoro
alessandrotesoro / gist:9367358
Created Mar 5, 2014
Use minified libraries if SCRIPT_DEBUG is turned off
View gist:9367358
// 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 Mar 5, 2014
Filter wp comment types dropdown for custom comments types
View gist:9369769
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 Mar 6, 2014
WordPress programmatically filter menu items given a location
View gist:9390054
/**
* 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>';
}
View gist:c6a55809b6a7207e490d
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 Sep 26, 2014
Example of throwing errors during post creation
View gist:4e119a97367bcb88a639
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 Aug 29, 2015
WPRM Show all items within the menu for the wprm_menu shortcode.
View gist:ed11aa848c3205e6e2e1
/**
* 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 Nov 13, 2014
WPRM: Allows Bookings Managers to access the calendar page in WP Restaurant Manager Pro Plugin.
View gist:c814a64c915326339f5b
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 Dec 3, 2014
Display all users into the "Author" box
View gist:5ed2dc1e4ec425c98c18
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>';
}
You can’t perform that action at this time.