Skip to content

Instantly share code, notes, and snippets.

Avatar

Julio Potier JulioPotier

View GitHub Profile
View pre_option_
add_filter( 'pre_option_image_default_align', '__image_default_align' );
function __image_default_align() {
return 'left';
}
add_filter( 'pre_option_image_default_link_type', '__image_default_link_type' );
function __image_default_link_type() {
return 'none';
}
View animal
<?php
/*
Plugin Name: Add "Animal" custom taxonomy
Description: Add the new custom taxonomy "animal", don't forget to flush your permalinks!
Author: Julio Potier
Author URI: http://boiteaweb.fr
*/
/* !---------------------------------------------------------------------------- */
/* ! REGISTER TAXONOMIES */
View gist:8a3bf51e913e5d7d17f7
echo '<span>Familles<br>';
$terms_id = _get_term_hierarchy( 'animal' );
$post_terms = get_the_terms( $post->ID, 'animal' );
$terms_id = array_intersect_key( $terms_id, $post_terms );
foreach ( $terms_id as $parent => $enfants ) {
$term_links = rtrim( $term_links, ', ' );
if ( ! empty( $term_links) ){
$term_links .= '<br />';
}
$term = get_term( $parent, 'animal' );
View gist:cd263e84f077266ade3b
add_filter( 'preprocess_comment', 'baw_no_double_thread' );
function baw_no_double_thread( $comment )
{
if ( current_user_can( 'administrator' ) ) {
return $comment;
}
global $wpdb;
if ( ! $comment['comment_parent'] ) {
$c = $wpdb->get_var( $wpdb->prepare( 'SELECT comment_ID FROM '.$wpdb->comments.' WHERE comment_post_ID = %d AND comment_author_email = %s AND comment_parent = 0', $comment->comment_post_ID, $comment['comment_author_email'] ) );
if ( (int) $c > 0 ) {
View gist:1207324668fc59255dee
add_action( 'wp_footer', 'infinite_load' );
function infinite_load() {
$paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
?>
<script>
jQuery(document).ready(function($){
if( window.history && history.pushState ) {
var $page = <?php echo $paged; ?>;
View Purge Transients by @rarst
add_action( 'wp_scheduled_delete', 'delete_expired_db_transients' );
function delete_expired_db_transients() {
if ( wp_using_ext_object_cache() ) { // magic
return;
}
global $wpdb;
$time = isset( $_SERVER['REQUEST_TIME'] ) ? (int) $_SERVER['REQUEST_TIME'] : time();
@JulioPotier
JulioPotier / gist:0b967039693c4b666eef
Created Dec 22, 2014
template comment paged for wordpress
View gist:0b967039693c4b666eef
add_filter( 'template_include', 'template_comment_paginated' );
function template_comment_paginated( $template )
{
if ( (int) get_query_var( 'cpage' ) > 0 &&
false !== ( $_template = str_replace( '.php', '-paged.php', $template ) ) &&
file_exists( $_template ) )
{
return $_template;
}
return $template;
View gist:968e509cbbece5beddff
add_filter( 'wp_redirect', 'baw_hack_delete_post_redirect' );
function baw_hack_delete_post_redirect( $url ) {
$ref = wp_get_referer();
if ( strpos( $ref, admin_url() ) === false
&& isset( $_GET['action'], $_GET['post'] )
&& ( ( 'delete' == $_GET['action'] && check_admin_referer('delete-post_' . $_GET['post'] ) )
|| ( 'trash' == $_GET['action'] && check_admin_referer('trash-post_' . $_GET['post'] ) )
)
) {
return home_url();
@JulioPotier
JulioPotier / wooc2311.php
Created Jun 11, 2015
Patch WooCommerce 2.3.10 -> 2.3.11
View wooc2311.php
<?php
/*
Plugin Name: Patch WooCommerce 2.3.10 -> 2.3.11 - Object Inhection Vulnerability
Author: SecuPress
*/
add_action( 'plugins_loaded', 'patch_woocommerce_2310', 1 );
function patch_woocommerce_2310() {
if ( isset( $_REQUEST['cm'] ) ) {
$raw_custom = $_REQUEST['cm'];
$custom = sanitize_text_field( stripslashes( $_REQUEST['cm'] ) );
View gist:2714688
<?php
/*
* Plugin Name: Password Reset Removed
* Description: Removes the ability for non admin users to change/reset their passwords.
* Version: 1.1
* Author: Derek Herman ; Modified by Juliobox (boiteaweb.fr)
* Author URI: http://valendesigns.com
*/
add_filter( 'show_password_fields', 'baw_prr_i_am_admin' );
add_filter( 'allow_password_reset', 'baw_prr_i_am_admin' );