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 / 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/
@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 / 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 / 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 / truncated_content_shortcode.css
Last active February 25, 2016 10:48
A wordpress shortcode to display the current post truncated content. I did this shortcode to use with Paid Member Subscriptions in the first place...
/* truncated content styles : add this to the child theme style.css */
div.truncated_content {
position: relative;
}
div.truncated_content:before {
content: '';
position: absolute;
width: 100%;
height: 100px;
height: 100%;
@smeric
smeric / sanitize-filename.php
Last active July 15, 2016 23:17 — forked from herewithme/sanitize-filename.php
WordPress - No french punctuation and accents for filename
<?php
/*
Plugin Name: No french punctuation and accents for filename
Description: Remove all french punctuation and accents from the filename of upload for client limitation (Safari Mac/IOS)
Plugin URI: http://www.beapi.fr
Version: 1.0
Author: BeAPI
Author URI: http://www.beapi.fr
This program is free software; you can redistribute it and/or
@smeric
smeric / automatically-disable-content-access.php
Last active September 9, 2016 15:30
Make Woocommerce Membership public content go private after a certain amount of time.
<?php
/*
To allow temporary access to content with Woocommerce Membership,
you have to check this checkbox : "Check this box if you want to
force the content to be public regardless of any restriction rules
that may apply now or in the future."
Here is a way to make this access temporary without having to edit
you post to uncheck the checkbox each and every day on each new publicly
released content. Let the WordPress cron job uncheck it for you :)
@smeric
smeric / extend-woocommerce-memberships-period.php
Created October 6, 2016 12:47
WooCommerce Memberships : allow renewal for active memberships even before membership expiration.
<?php
/**
* Allow membership renewal for active memberships
*/
add_filter( 'wc_memberships_valid_membership_statuses_for_renewal', 'my_valid_membership_statuses_for_renewal' );
function my_valid_membership_statuses_for_renewal( $statuses = array() ) {
$statuses[] = 'active';
return $statuses;
}
@smeric
smeric / yoast-seo-social-images-sizes.php
Created October 11, 2016 13:36
Overwrite Yoast SEO Facebook & Twitter sharing images declaration with a custom one.
<?php
/**
* Std image size for social sharing.
**/
add_action( 'after_setup_theme', 'mytheme_setup_theme' );
function mytheme_setup_theme() {
add_image_size( 'social-800x420', 800, 420, true );
}
/**
@smeric
smeric / woocommerce-overwrite-default-thumbnail-sizes.php
Created October 11, 2016 13:43
Overwrite default thumbnails sizes after WooCommerce installation
<?php
add_action( 'after_setup_theme', 'mytheme_woocommerce_set_image_dimensions' );
function mytheme_woocommerce_set_image_dimensions() {
// Do not set sizes multiple times
if ( ! get_option( 'mytheme_shop_image_sizes_set' ) ) {
$catalog = array(
'width' => '768', // px
'height' => '', // px
'crop' => 0 // no-crop
);