Skip to content

Instantly share code, notes, and snippets.

View eksiscloud's full-sized avatar

Jakke Lehtonen eksiscloud

View GitHub Profile
@eksiscloud
eksiscloud / default.vcl
Last active February 7, 2021 14:33
default.vcl for Varnish (Wordpress, Woocommerce, LearnDash)
## Jakke Lehtonen
## by several sources
## Varnish default.vcl for Wordpress, Woocommerce, LearnDash, PMPro, bbPress etc.
## Just for one domain and one server, but can use for several servers AFAIK
#
# Lets's start caching
#
# Marker to tell the VCL compiler that this VCL has been adapted to the 4.0 format.
vcl 4.0;
@eksiscloud
eksiscloud / woocommerce-variations-default-label-at-dropdown.php
Created April 12, 2019 09:25
Change first option in dropdownlist of variations at Woocommerce to some default text
// This snippet must be more or less public domain, because you can find it from several sources
// It is not coded by me, I just copied the snippet from somewhere
// Paste it in functions.php or use some custom functions plugin like Code Snippet
add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'ec_filter_dropdown_args', 10 );
function ec_filter_dropdown_args( $args ) {
$args['show_option_none'] = 'Choose...';
return $args;
}
@eksiscloud
eksiscloud / single-details-date.php
Last active April 17, 2019 09:47
Kallyas, last modified date: components/blog/default-single-modern/single-details-date.php
<?php if(! defined('ABSPATH')){ return; }
/**
* Details date
*/
?>
<span class="kl-blog-post-date updated" <?php echo WpkPageHelper::zn_schema_markup('post_time'); ?>>
<?php
echo "Posted on ";
$date_format = zget_option( 'blog_date_format', 'blog_options', false, 'l, d F Y' );
@eksiscloud
eksiscloud / functions.php
Created April 16, 2019 23:41
Wordpress, shows last modified date before the content
function my_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated entry-meta"><b>Last updated on '. $updated_date . ' at '. $updated_time .'</b></p>';
}
$custom_content .= $content;
return $custom_content;
@eksiscloud
eksiscloud / sync.sh
Created August 1, 2019 23:29
Syncing two wordpress databases using WP-CLI
#!/bin/sh
DEVDIR="web/app/uploads/"
DEVSITE="https://example.dev"
PRODDIR="web@example.com:/srv/www/example.com/shared/uploads/"
PRODSITE="https://example.com"
STAGDIR="web@staging.example.com:/srv/www/example.com/shared/uploads/"
STAGSITE="https://staging.example.com"
@eksiscloud
eksiscloud / .htaccess
Last active October 23, 2019 11:09
Redirect a site to new domain
# Rewriting on
RewriteEngine on
# redirect to same page in the new site as where a user was in the old site
RewriteBase /
RewriteCond %{SERVER_NAME} =old-domain.com [OR]
RewriteCond %{SERVER_NAME} =new-domain.com
RewriteRule ^ http://new.domain.com%{REQUEST_URI} [END,NE,R=301]
@eksiscloud
eksiscloud / remove-category.sh
Created August 2, 2019 22:00
Remove uncategorized from Wordpress posts if there is some other category too
#!/bin/bash
for post in $(wp post list --field=ID)
do
count=$(wp post term list $post 'category' --fields='name' --format="count")
if [ "$count" -gt "1" ]
then wp post term remove $post category 'uncategorized'
fi
done
## chmod 755 remove-category.sh
@eksiscloud
eksiscloud / poista-yleinen.sh
Last active August 2, 2019 22:08
Poistaa Wordpress-artikkelista oletusluokan Yleinen, jos artikkelilla on vähintään yksi toinenkin luokka (WP-CLI)
#!/bin/bash
for post in $(wp post list --field=ID)
do
count=$(wp post term list $post 'category' --fields='name' --format="count")
if [ "$count" -gt "1" ]
then wp post term remove $post category 'yleinen'
fi
done
## chmod 755 poista-yleinen.sh
@eksiscloud
eksiscloud / example.com.conf
Created August 5, 2019 20:19
Very general example.com.conf @ Hitch/Varnish (Apache2, Wordpress, WP Rocket, EWWW, NinjaFirewall)
<VirtualHost 127.0.0.1:8080>
ServerAdmin email@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
@eksiscloud
eksiscloud / functions.php
Last active September 4, 2023 15:23
Delete coupons of Woocommerce when those are expired
/**
* add this in the functions.php of theme/child theme/snippets plugin
* Schedule the daily event if necessary.
*/
function schedule_delete_expired_coupons() {
if ( ! wp_next_scheduled( 'delete_expired_coupons' ) ) {
wp_schedule_event( time(), 'daily', 'delete_expired_coupons' );
}
}
add_action( 'init', 'schedule_delete_expired_coupons' );