Skip to content

Instantly share code, notes, and snippets.

View JulioPotier's full-sized avatar

Julio Potier JulioPotier

View GitHub Profile
<?php
add_filter( 'mepr-validate-login', 'secupress_support_11052021_no_admins' );
function secupress_support_11052021_no_admins( $errors ) {
if ( ! isset( $_SERVER['REQUEST_METHOD'], $_POST['log'] ) || 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
return $errors;
}
// Check for login by email address
$by = is_email( $_POST['log'] ) ? 'email' : 'login';
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 April 27, 2019 20:22
Compatibilité de la fonction wp_open_body() pour tous les thèmes
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 );
} );
}
<?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';
<?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' );
}
}
<?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' );
}
<?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')
*/
<?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')
*/
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 December 7, 2017 11:00
SecuPress Pro Hide Licence Keys
<?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;
}