Skip to content

Instantly share code, notes, and snippets.

View thierrypigot's full-sized avatar

Thierry Pigot thierrypigot

View GitHub Profile
@thierrypigot
thierrypigot / get_language_selector_flags.php
Last active August 29, 2015 13:57
WPML - Language selector
<?php
/**
* WPML - Language selector
* Thierry Pigot
*
* return html
**/
function tp_get_language_selector_flags()
{
$languages = icl_get_languages('skip_missing=0');
@thierrypigot
thierrypigot / equalHeight.js
Last active August 29, 2015 14:05
equalHeight.js
/* Equal Height for html element */
function equalHeight( group )
{
var tallest = 0;
var thisHeight = 0;
group.each(function() {
thisHeight = jQuery(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
@thierrypigot
thierrypigot / tp-test.php
Created August 28, 2014 09:37
Translate WordPress plugin Headers
<?php
/**
* Plugin Name: Thierry Pigot - A awesome plugin!
* Plugin URI: http://www.thierry-pigot.fr/tutoriel/722/traduire-header-plugin-wordpress/
* Description: A brief description of the Plugin.
* Version:1.0
* Author: Thierry Pigot
* Author URI: http://www.thierry-pigot.fr/
* License: GPL2
* Text Domain: tp-test
@thierrypigot
thierrypigot / wp-sitemap-page.php
Last active August 29, 2015 14:05
wp-sitemap-page.php
<?php
extract( shortcode_atts( array(
'wsp_exclude_pages' => trim(get_option('wsp_exclude_pages')),
'wsp_exclude_cpt_page' => get_option('wsp_exclude_cpt_page'),
'wsp_exclude_cpt_post' => get_option('wsp_exclude_cpt_post'),
'wsp_exclude_cpt_archive' => get_option('wsp_exclude_cpt_archive'),
'wsp_exclude_cpt_author' => get_option('wsp_exclude_cpt_author')
), $atts ) );
// Exclude some pages
@thierrypigot
thierrypigot / restrict.php
Created October 10, 2014 10:11
Redirect non admin to front
<?php
/**
* Redirect non admin to front
**/
add_action( 'admin_init', 'tp_demo_redirect_non_admin_users' );
function tp_demo_redirect_non_admin_users()
{
if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_safe_redirect( home_url() );
exit;
@thierrypigot
thierrypigot / hide_adminbar.php
Created October 10, 2014 10:25
Hide adminbar to non admin
<?php
/**
* Hide adminbar to non admin
**/
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar()
{
if( ! current_user_can( 'manage_options' ) && !is_admin() && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] )
{
show_admin_bar(false);
@thierrypigot
thierrypigot / admin-in-fr.php
Last active August 29, 2015 14:09
Admin in FR, front in IT
<?php
add_filter('locale', 'tp_setLocale');
function tp_setLocale($locale) {
if ( !is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'woocommerce_update_order_review' ) {
return 'it_IT';
}
return $locale;
}
@thierrypigot
thierrypigot / admin-search-filter.php
Created November 19, 2014 17:11
Dans l'admin, étendre la recherche des Custom Post Type aux métas, en plus du titre et de la description.
<?php
/*
* Dans cet exemple mon Custom Post Type est "revendeurs"
*/
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'] != '')
<?php
function custom_search_query( $query ) {
if( is_admin() && $query->is_main_query() && $query->query['post_type'] === 'revendeurs' && isset($query->query_vars['s']) )
{
$custom_fields = array(
// put all the meta fields you want to search for here
"raison_sociale",
);
$searchterm = $query->query_vars['s'];
@thierrypigot
thierrypigot / ajax.php
Created January 14, 2015 09:30
Permet de faire des traitement en Ajax, en particulier pour passer des problématiques de timeout.
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {font-family: verdana, arial; font-size: 62.5%; margin: 0 auto; width: 80%;background-color: #f5f5f5;}
#container {background-color: #fff;padding:10px;margin:20px 0;}
h1{font-size: 3em;}
h2{font-size: 2em;}