Skip to content

Instantly share code, notes, and snippets.

@BenKalsky
Last active April 4, 2023 12:52
Show Gist options
  • Save BenKalsky/b81d937586c14042493a56dbbfc6315a to your computer and use it in GitHub Desktop.
Save BenKalsky/b81d937586c14042493a56dbbfc6315a to your computer and use it in GitHub Desktop.
Code Snippets for WordPress
////
// Code Snippets for functions.php
////
// Disable plugin auto-update email notification
add_filter('auto_plugin_update_send_email', '__return_false');
// Disable theme auto-update email notification
add_filter('auto_theme_update_send_email', '__return_false');
// Disable WordPress core auto-update email notification
add_filter( 'auto_core_update_send_email', 'wpb_stop_auto_update_emails', 10, 4 );
function wpb_stop_update_emails( $send, $type, $core_update, $result ) {
if ( ! empty( $type ) && $type == 'success' ) {
return false;
}
return true;
}
// Reorder Multiple Columns in Elementor
function ben_add_responsive_column_order( $element, $args ) {
$element->add_responsive_control(
'responsive_column_order',
[
'label' => __( 'Responsive Column Order', 'ben-elementor-extras' ),
'type' => \Elementor\Controls_Manager::NUMBER,
'separator' => 'before',
'selectors' => [
'{{WRAPPER}}' => '-webkit-order: {{VALUE}}; -ms-flex-order: {{VALUE}}; order: {{VALUE}};',
],
]
);
}
add_action( 'elementor/element/column/layout/before_section_end', 'ben_add_responsive_column_order', 10, 2 );
// Elementor Telephone Validation Formatting
// https://github.com/elementor/elementor/issues/5738
add_action( 'elementor_pro/forms/validation/tel', function( $field, $record, $ajax_handler ) {
// Match this format XXXXXXXXX, 123456789
if ( preg_match( '/[0-9]{9}/', $field['value'] ) !== 1 ) {
$ajax_handler->add_error( $field['id'], 'Please make sure the phone number is in XXXXXXXXX format, eg: 123456789' );
}
}, 10, 3 );
// Remove/change the delay of Elementor's drop-down menu
add_action( 'wp_footer', function () { ?>
<script>
jQuery(document).ready(function($) {
// Get the menu instance
// Ultimately smartmenus is expecting a <ul> input, so you need to target the <ul> of the drop-down you're trying to affect.
var $menu = $('.elementor-nav-menu:first');
// Get rid of the existing menu
$menu.smartmenus('destroy');
// Re-instantiate the new menu, with no delay settings
$menu.smartmenus( {
subIndicatorsText: '',
subIndicatorsPos: 'append',
subMenusMaxWidth: '1000px',
hideDuration: 200, // the length of the fade-out animation
hideTimeout: 150, // timeout before hiding the sub menus
showTimeout: 0, // timeout before showing the sub menus
});
});
</script>
<?php } );
////
// Code Snippets for wp-config.php
////
// Disable Cron in every page load
define('DISABLE_WP_CRON', true);
// Add this line to ADVANCED CRON (Cloudways): */15 * * * * wget -q -O - https://www.domain.com/wp-cron.php?doing_wp_cron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment