Skip to content

Instantly share code, notes, and snippets.

Avatar

Julio Potier JulioPotier

View GitHub Profile
View gist:5238fd962059ddf590dfefca72e02434
function human_filesize( $bytes, $decimals = 2 ) {
$sz = 'BKMGTP';
$factor = floor( ( strlen( $bytes ) - 1 ) / 3 );
return sprintf( "%.{$decimals}f", $bytes / pow( 1024, $factor ) ) . @$sz[ $factor ];
}
add_filter( 'media_send_to_editor', 'baw_media_to_shortcode', 10, 3 );
function baw_media_to_shortcode( $html, $id, $attachment ) {
$media_type = strtolower( pathinfo( $attachment['url'], PATHINFO_EXTENSION ) );
switch ( $media_type ) {
@JulioPotier
JulioPotier / wp_open_body_compatilibity.php
Created Apr 27, 2019
Compatibilité de la fonction wp_open_body() pour tous les thèmes
View wp_open_body_compatilibity.php
add_action( 'get_header', 'baw_wp_body_open_buffer' );
function baw_wp_body_open_buffer() {
ob_start();
do_action( 'wp_body_open' );
$wp_body_open_content = ob_get_clean();
ob_start( function( $buffer ) use( $wp_body_open_content ) {
return preg_replace( '(<body.*>)', "$0\n$wp_body_open_content", $buffer );
} );
}
View add upgrade notice
<?php
if ( ! isset( $remote_version ) ) {
return;
}
$body = get_transient( 'secupress_updates_message' );
if ( ! isset( $body[ $remote_version ] ) ) {
$url = 'https://plugins.svn.wordpress.org/secupress/trunk/readme.txt';
View better changelog
<?php
add_action( 'admin_init', 'secupress_hook_changelog' );
function secupress_hook_changelog() {
if ( isset( $_GET['tab'], $_GET['plugin'], $_GET['section'] )
&& 'secupress' === $_GET['plugin'] && 'changelog' === $_GET['section'] && 'plugin-information' === $_GET['tab'] ) {
remove_action( 'install_plugins_pre_plugin-information', 'install_plugin_information' );
add_action( 'install_plugins_pre_plugin-information', 'secupress_hack_changelog' );
}
}
View _secupress_htmlentities_get.php
<?php
/*
Plugin Name: SecuPress htmlentities $_GET array
Author: SecuPress
Author URI: https://secupress.pro
*/
foreach ( $_GET as &$g ) {
$g = htmlentities( $g, ENT_QUOTES, 'UTF-8' );
}
View gist:050fa23e33510f27543d49435b401f36
<?php
add_shortcode( 'script_foo', 'sc_script_foo_cb' );
function sc_script_foo_cb( $atts, $content ) {
echo '<script type="text/javascript" src="https://example.com/foo.js" />';
}
/*
Then in your content just use [script_foo] (the first parameter from 'add_shortcode')
*/
View gist:29e86b9aeee62c5b0151ed104dfec496
<?php
add_shortcode( 'script_foo', 'sc_script_foo_cb' );
function sc_script_foo_cb( $atts, $content ) {
echo '<script type="text/javascript" src="https://example.com/foo.js" />';
}
/*
Puis dans votre contenu utilisez simplement [script_foo] (le premier paramètre de 'add_shortcode')
*/
View gist:8425920d137dbbc56c47aa3537abb082
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && 'menu-quick-search' == $_POST['action'] ) {
add_filter( 'wp_setup_nav_menu_item', 'sp_wp_setup_nav_menu_item' );
function sp_wp_setup_nav_menu_item( $menu_item ) {
if ( isset( $menu_item->post_title ) ) {
$menu_item->post_title = $menu_item->post_title . ' (' . pll_get_post_language( $menu_item->ID ) . ')';
}
return $menu_item;
}
}
@JulioPotier
JulioPotier / sp_hide_licence.php
Last active Dec 7, 2017
SecuPress Pro Hide Licence Keys
View sp_hide_licence.php
<?php
/*
Plugin Name: Hide Licence Keys
*/
add_filter( 'secupress.global_settings.modules', 'secupress_hide_licence_keys' );
function secupress_hide_licence_keys( $modules ) {
unset( $modules[0] );
return $modules;
}
@JulioPotier
JulioPotier / gist:756f6873d6231133fc756095c8295a58
Created May 4, 2017
Patch WordPress Reset Password Vulnerability
View gist:756f6873d6231133fc756095c8295a58
add_filter( 'wp_mail_from', 'baw_fix_wp_474_mail_reset_vulnerability' );
function baw_fix_wp_474_mail_reset_vulnerability( $from_email ) {
return 'wordpress@example.com';
}
You can’t perform that action at this time.