Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / antispam-email-shortcode.php
Created May 28, 2015 08:43
WordPress : Shortcode antispam email - add file in wp-content/mu-plugins folder
<?php
/**
* Anti Spam Email
* [email][email protected][/email]
**/
function tp_hide_email_shortcode( $atts , $content = null )
{
if ( ! is_email( $content ) ) {
return;
}
@thierrypigot
thierrypigot / is-mobile.js
Created June 9, 2015 14:44
The best way to detect a mobile device in jQuery
var isMobile = false; //initiate as false
// device detection
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1
@thierrypigot
thierrypigot / fuji_get_post_by_distance.php
Created June 10, 2015 18:44
Requête de récupération des posts en fonction de coordonnées. Les posts sont dans une table avec : post_id, lat, lng
/**
* Get all post id's ordered by distance from given point
*
* @param string $post_type The post type of posts you are searching
* @param float $search_lat The latitude of where you are searching
* @param float $search_lng The Longitude of where you are searching
* @param string $orderby What order do you want the ID's returned as? ordered by distance ASC or DESC?
* @return array $wpdb->get_col() array of ID's in ASC or DESC order as distance from point
*/
function fuji_revendeur_getPostIDsByRange( $search_lat = 51.499882, $search_lng = -0.126178, $orderby = "ASC", $limit = 10, $services = false )
@thierrypigot
thierrypigot / fuji_save_latlng_meta.php
Created June 10, 2015 18:47
Sauvegarde les lat / lng en postmeta. Utilise le champ ACF GoogleMaps de base, qui a pour nom "localisation"
/**
* Save _lat _lng
*
**/
add_action( 'save_post', 'stl_store_meta_save' );
function stl_store_meta_save( $post_id )
{
global $wpdb;
$table = $wpdb->prefix .'geodatastore';
@thierrypigot
thierrypigot / fuji_extend_cpt_admin_search.php
Created June 10, 2015 18:54
Permet, en admin, de rechercher sur les postmeta, en plus du title
//************** SEARCH FILTER **************//
add_filter('posts_join', 'revendeurs_search_join' );
function revendeurs_search_join ($join){
global $pagenow, $wpdb;
// I want the filter only when performing a search on edit page of Custom Post Type named "revendeurs"
if ( is_admin() && $pagenow=='edit.php' && $_GET['post_type']=='revendeurs' && $_GET['s'] != '')
{
$join .='LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
}
return $join;
@thierrypigot
thierrypigot / dtc.php
Created June 23, 2015 15:01
Font chier ces spammeurs !
<?php
$host = gethostbyaddr( $_SERVER['REMOTE_ADDR'] );
if( strstr( $host, 'pnet.pl' ) )
{
ob_end_clean();
header("HTTP/1.0 404 Not Found");
header('location:http://www.dtc.fr/');
die();
}
@thierrypigot
thierrypigot / gravity-forms.php
Last active November 8, 2024 11:28
Permet d'interpréter les caractères html dans le label des fields.
<?php
// [update : sécurité des sorties]
add_filter( 'gform_field_content', 'tp_subsection_field', 10, 5 );
function tp_subsection_field( $content, $field, $value, $lead_id, $form_id )
{
// Limiter les balises HTML autorisées dans les labels (gras, images, etc.)
$allowed_html = array(
'strong' => array(),
'em' => array(),
'b' => array(),
@thierrypigot
thierrypigot / confirmation.txt
Last active August 29, 2015 14:25
Permets de compter la valeur la plus sélectionnée dans un formulaire Gravity Forms
/**
* Exemple de formulaire
* Qx = Question
* - Réponse : valeur
*
**/
Q1 : Tu aimes quel animal ?
- Cheval : cheval
- Papillon : papillon
- Ours : ours
@thierrypigot
thierrypigot / acf-rename-option-page.php
Created July 22, 2015 08:55
Permets de changer le nom de la page d'options ACF
<?php
if( function_exists( 'acf_set_options_page_menu') )
{
acf_set_options_page_menu( __( 'Calculator', 'domainname' ) );
}
@thierrypigot
thierrypigot / check-acf.php
Created July 22, 2015 09:30
Vérification de la présence ACF et du plugin ACF Gallery
<?php
if( !class_exists( 'acf' ) || !function_exists( 'acfgp_register_fields' ) )
{
function tp_acf_admin_error_notice()
{
$plugin = get_plugin_data( __FILE__ );
echo '<div class="error"><p><strong>'. $plugin['Name'] .'</strong> need <strong>ACF</strong> and <strong>ACF Gallery Field</strong> plugin to work :(</p></div>';
}
add_action( 'admin_notices', 'tp_acf_admin_error_notice' );