Skip to content

Instantly share code, notes, and snippets.

@runezero
runezero / avf_frontend_search_form_param.php
Created July 21, 2022 06:35
[Disable ajax search] Disables the ajax search in the search pop-up within Enfold #enfold
add_action('avf_frontend_search_form_param', 'av_disable_ajax_search',9);
function av_disable_ajax_search($params)
{
$params['ajax_disable'] = true;
return $params;
}
@runezero
runezero / bartag.php
Created July 20, 2022 14:19
[Shortcode sample] A default WP shortcode reference #wordpress
add_shortcode( 'bartag', 'wpdocs_bartag_func' );
function wpdocs_bartag_func( $atts ) {
$atts = shortcode_atts( array(
'foo' => 'no foo',
'baz' => 'default baz'
), $atts, 'bartag' );
return "foo = {$atts['foo']}";
}
@runezero
runezero / admin_init.php
Created July 20, 2022 12:59
[Admin test hook] A hook to test functions in the admin under account and parameter restrictions #wordpress
<?php
add_action('admin_init', function(){
if(!is_user_logged_in()){
return;
}
if(get_current_user_id() == 1 && isset($_GET['dsm']) && !empty($_GET['dsm'])){
//do your thing
echo 1234;
@runezero
runezero / minify.php
Created July 18, 2022 14:15
[Minify HTML CSS JS files] minify files of the type HTML, CSS or JS to a small format for quicker loading #tools
<?php
/**
* -----------------------------------------------------------------------------------------
* File from `https://gist.github.com/Rodrigo54/93169db48194d470188f`
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
* -----------------------------------------------------------------------------------------
*/
// HTML Minifier
@runezero
runezero / woocommerce_email_before_order_table.php
Last active July 26, 2022 08:36
[Coupon admin email] Add the used coupon code in the email to the shop admin #woocommerce
<?php
add_action( 'woocommerce_email_before_order_table', 'dev_maybe_add_used_coupon_code_admin_emails', 20, 4 );
function dev_maybe_add_used_coupon_code_admin_emails( $order, $sent_to_admin, $plain_text, $email ) {
if ( $sent_to_admin !== false ) {
$coupon_codes = $order->get_used_coupons();
if(!empty($coupon_codes)):
foreach( $coupon_codes as $coupon_code ):
@runezero
runezero / admin-post-validate-metablock.css
Last active July 18, 2022 07:49
[WP Post fill validator] Adds a JS content fill validator to check #wordpress
.dev_plugin_validate_metabox,
.dev_plugin_validate_metabox table{
width: 100%;
}
.dev_plugin_validate_metabox table tr .title{
width:80%;
}
.dev_plugin_validate_metabox table tr .result{
@runezero
runezero / lazyload-images.html
Created July 5, 2022 12:52
[Lazyload viewport] Lazyloads images in the viewport with fallback for non supporting browsers #tools
<!-- Let's load this in-viewport image normally -->
<img src="hero.jpg" alt="…">
<!-- Let's lazy-load the rest of these images -->
<img data-src="unicorn.jpg" alt="…" loading="lazy" class="lazyload">
<img data-src="cats.jpg" alt="…" loading="lazy" class="lazyload">
<img data-src="dogs.jpg" alt="…" loading="lazy" class="lazyload">
<script>
if ('loading' in HTMLImageElement.prototype) {
@runezero
runezero / my_custom_faq.php
Created June 24, 2022 12:06
[FAQ toggle shortcode] add a shortcode to display a FAQ list from a post type title and description #wordpress
add_shortcode('my_custom_faq', function($atts){
$attributes = shortcode_atts( array(
'key' => "",
), $atts );
$args = array(
'post_type' => 'faq',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
@runezero
runezero / avia_add_custom_icon.php
Created June 24, 2022 09:41
[Add Fontello social icons] Add a custom Fontello icon to enfold and use it in a social icon #enfold
// https://fontello.com/
// Upload a custom svg to fontello.com and download the full icon set as a ZIP file
// Upload the downloaded ZIP file in the Enfold settings in "Import/Export > Upload/Select Fontello Font Zip"
// Save the Enfold settings
// Set the font and icon values in the snippet below to use the icon
// Register new icon as a theme icon
function avia_add_custom_icon($icons) {
$icons['tiktok_icon'] = array( 'font' =>'fontello', 'icon' => 'ue800');
return $icons;
@runezero
runezero / preg_replace.php
Created June 21, 2022 13:13
[String to Int] Remove the non numeric values in a string and convert to an Int variable #tools
//replace all non digits in a string
intval(preg_replace('/\D/', '', $string ));