Skip to content

Instantly share code, notes, and snippets.

View smeric's full-sized avatar

Sébastien Méric smeric

View GitHub Profile
@smeric
smeric / add-roles-to-body.php
Created February 19, 2016 20:08
Add user roles as classes to body tag in front and backend.
<?php
/**
* Add user roles as classes to body tag in front and backend.
*/
add_filter( 'body_class','add_roles_to_body' );
add_filter( 'admin_body_class', 'add_roles_to_body' );
function add_roles_to_body( $classes ) {
global $current_user;
foreach ( $current_user->roles as $user_role ) {
@smeric
smeric / gform-generate-username.php
Created February 12, 2016 16:34
Username auto generation for Gravity Form User Registration Add-on
<?php
/**
* Username auto generation for Gravity Form User Registration Add-on
*
* see https://www.gravityhelp.com/documentation/article/gform_username/
*/
add_filter( 'gform_username', 'auto_username', 10, 4 );
function auto_username( $username, $feed, $form, $entry ) {
//$username = strtolower( rgar( $entry, '2.3' ) . rgar( $entry, '2.6' ) );
@smeric
smeric / woocommerce-membership-post-excerpt.php
Created November 23, 2015 14:06
WooCommerce membership custom post excerpt. Instead of using the excerpt this will display the begining of a post for non members.
<?php
/**
* Plugin Name: WooCommerce membership custom post excerpt
* Description: Instead of using the excerpt this will display the begining of a post for non members.
* Version: 0.1
* Author: Sébastien Méric <sebastien.meric@gmail.com>
* Author URI: http://www.sebastien-meric.com/
**/
defined( 'ABSPATH' ) OR exit;
@smeric
smeric / aggregate-feed.php
Created November 12, 2015 23:14 — forked from smajda/aggregate-feed.php
Merge multiple RSS feeds with SimplePie
<?php
/* Merge multiple RSS feeds with SimplePie
*
* Just modify the path to SimplePie and
* modify the $feeds array with the feeds you want
*
* You should probably also change the channel title, link and description,
* plus I added a CC license you may not want
*
* Help from: http://www.webmaster-source.com/2007/08/06/merging-rss-feeds-with-simplepie/
/**
* Smooth scroll :
* <a href="#top" class="go-top">Top</a>
* $( '.go-top' ).click( function( e ){ e.preventDefault(); $( this ).autoscroll( $( this ).attr( 'href' ) ); });
**/
( function( $ ) {
$.fn.autoscroll = function( selector ) {
$( 'html,body' ).animate({
scrollTop: $( selector ).offset().top
}, 200);
@smeric
smeric / add2any_custom_js.php
Last active October 30, 2015 16:17
WordPress AddToAny custom script to : push shared data to datalayer for GTM, re-shape title to remove special characters & use shortlink for Twitter
<?php
/**
* AddToAny : custom script inserted into the document head
*
* Push shared data to datalayer for GTM
* Re-shape title to remove special characters
* Use shortlink for Twitter
*
* see https://www.addtoany.com/ext/google_analytics/
* see https://www.addtoany.com/buttons/customize/wordpress/events
@smeric
smeric / Wordpress RSS 2.0 image enclosure .php
Last active October 14, 2015 14:48 — forked from supermethod/Wordpress RSS 2.0 image enclosure
How to add post image(s) as enclosure(s) to a wordpress RSS feed item - add to functions.php
<?php
/**
* Add post type images to feed items
*/
add_action('rss2_item', 'add_images_in_feed' );
function add_images_in_feed() {
global $post;
// Thumbnail...
$thumbnail_ID = get_post_thumbnail_id( $post->ID );
@smeric
smeric / woocommerce-add-to-cart-before-applying-coupon.php
Last active July 23, 2018 09:16
Made to be used with the "Smart Coupons" WooCommerce extention. If we apply coupon from url and the coupon is dedicated to a specific product, the coupon is not applied if the product is not already in cart. So, before applying the coupon we add this product to cart.
<?php
/**
* Add to cart before applying coupon
*
* Made to be used with the "Smart Coupons" WooCommerce extention.
* If we apply coupon from url and the coupon is dedicated to a specific product, the coupon is not applied if
* the product is not already in cart. So, before applying the coupon we add this product to cart.
*
* @link
* @version 1.0.1
@smeric
smeric / plugin-name include class-plugin-name-loader.php
Last active November 25, 2015 08:08
WordPress-Plugin-Boilerplate
<?php
/**
* Register all actions, filters and shortcodes for the plugin
*
* @link http://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
@smeric
smeric / remove-old-slugs-redirects.php
Last active May 27, 2020 03:45
WordPress plugin. Removes selected old slugs/permalinks from database.
<?php
/**
* Remove old slugs redirects.
*
* Removes selected old slugs/permalinks from database.
*
* @package WordPress_Remove_Old_Slugs_Redirects
* @author Sébastien Méric <sebastien.meric@gmail.com>
* @credit Algoritmika Ltd. <http://www.algoritmika.com>
* @license GPL-2.0+