Skip to content

Instantly share code, notes, and snippets.

Hiranthi Herlaar hiranthi

View GitHub Profile
@hiranthi
hiranthi / mu-plugin-file.php
Created Mar 22, 2019
Pretend another theme is active in the WP dashboard to maintain access to everything when something in your theme messes everything up (or whatevs).
View mu-plugin-file.php
<?php
add_filter( 'template', 'onx_change_theme' );
add_filter( 'option_template', 'onx_change_theme' );
add_filter( 'option_stylesheet', 'onx_change_theme' );
add_filter( 'pre_option_stylesheet', 'onx_change_theme' );
function onx_change_theme( $theme )
{
if ( is_admin() && ( function_exists( 'wp_get_current_user' ) ) )
{
@hiranthi
hiranthi / elementor-redirect.php
Created Mar 13, 2019
Redirect Editors & Authors from the 'edit page' page to the Elementor editor. Helps keeping the Elementor-stuff intact :)
View elementor-redirect.php
<?php
function onx_redirect_edit_page_to_elementor()
{
global $post, $pagenow;
if ( ! isset( $post->ID ) || current_user_can( 'manage_options' ) ) return;
if ( ( ( $pagenow == 'post.php' ) && ( get_post_type() == 'page' ) ) && ( current_user_can( 'editor' ) || current_user_can( 'author' ) ) )
{
@hiranthi
hiranthi / base.txt
Last active Mar 10, 2019
WP-CLI stuff :)
View base.txt
# Paths: DirectAdmin
# USER: change to correct username
# DOMAIN: change to the correct domainname
# Core stuff
$ wp core version --path=/home/USER/domains/DOMAIN/public_html/
$ wp core download --skip-content --force --version=latest --path=/home/USER/domains/DOMAIN/public_html/
$ wp core update-db --path=/home/USER/domains/DOMAIN/public_html/ --dry-run
$ wp core verify-checksums --path=/home/USER/domains/DOMAIN/public_html/
@hiranthi
hiranthi / zipcode-2.php
Last active Jan 29, 2019
Zipcode validation for Gravity Forms (5 digits, 2 approaches).
View zipcode-2.php
<?php
# just add the needed form IDs to the array
$forms = array( '6', '7' );
# looping through the array to add an 'add_filter' for each
foreach ( $forms as $i => $form )
add_filter( "gform_field_validation_{$form}", 'custom_zip_validation', 10, 4 );
# the function
@hiranthi
hiranthi / zipcode-2.php
Created Jan 23, 2019
Zipcode validation for Gravity Forms (5 digits, 2 approaches).
View zipcode-2.php
<?php
# just add the needed form IDs to the array
$forms = array( '6', '7' );
# looping through the array to add an 'add_filter' for each
foreach ( $forms as $i => $form )
add_filter( "gform_field_validation_{$form}", 'custom_zip_validation', 10, 4 );
# the function
@hiranthi
hiranthi / functions.php
Last active Jan 23, 2019
New encryption with Gravity Forms
View functions.php
<?php
function my_custom_gravityforms_encrypt( $to_encrypt )
{
if ( '' === $to_encrypt ) return null;
if ( function_exists('openssl_encrypt') && function_exists('openssl_random_pseudo_bytes') )
{
$iv = openssl_random_pseudo_bytes( openssl_cipher_iv_length( 'aes-256-cbc' ) );
$encrypted = openssl_encrypt( $to_encrypt, 'aes-256-cbc', MY_CUSTOM_GF_ENCRYPTION_KEY, 0, $iv );
View flush-redis-cache.php
<?php
# Check: https://onexa.nl/wordpress/toolbar-link-redis-object-cache/
/**
* Add a link to the Admin Toolbar to easily flush the Redis cache (Redis Object Cache plugin)
*
* @author Hiranthi Herlaar, onexa.nl
*
* @var $wp_admin_bar > https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
@hiranthi
hiranthi / woo-checkout.php
Last active Apr 3, 2019
WooCommerce checkout steps
View woo-checkout.php
<?php
/**
* Display the checkout steps so the customer knows where they are.
*
* The output uses classes of Bootstrap 4 and the icons of FontAwesome (Free)
**/
function onx_woocommerce_checkout_steps()
{
echo '<nav id="woo-checkout-steps" class="nav nav-pills nav-justified mb-4" role="navigation">';
@hiranthi
hiranthi / decrypt-2.php
Last active Jan 30, 2019
Encrypt & decrypt Gravity Forms velden
View decrypt-2.php
<?php
# Like on: https://docs.gravityforms.com/gform_get_input_value/
add_filter( 'gform_get_input_value', 'gf_custom_decode_field', 10, 4 );
function gf_custom_decrypt_field( $value, $entry, $field, $input_id )
{
return GFCommon::decrypt( $value );
}
// end gf_custom_decrypt_field
@hiranthi
hiranthi / functions.php
Created Feb 17, 2018
Get current WP sidebar
View functions.php
<?php
if ( ! function_exists( 'get_current_sidebar' ) )
{
function get_current_sidebar ( $widget_id )
{
$sidebars_widgets = get_option('sidebars_widgets', array());
if ( is_array( $sidebars_widgets ) && isset( $sidebars_widgets['array_version'] ) )
unset( $sidebars_widgets['array_version'] );
You can’t perform that action at this time.