Skip to content

Instantly share code, notes, and snippets.

View kLOsk's full-sized avatar
:octocat:
back in black

Daniel Klose kLOsk

:octocat:
back in black
View GitHub Profile
@kLOsk
kLOsk / functions.php
Created July 31, 2020 13:36
facetwp date url vars
<?php
//load current cw plus 4 weeks on front page date facet
add_filter( 'facetwp_preload_url_vars', function( $url_vars ) {
if ( '' == FWP()->helper->get_uri() ) {//frontpage
if ( empty( $url_vars['date_facet'] ) ) {
$week = date("W");
$year = date("Y");
$start_day = date("Y-m-d", strtotime("{$year}-W{$week}-1"));//return monday of this week
$end_day = date("Y-m-d", strtotime("{$year}-W{$week}-7 +3 weeks")); //return sunday in 4 weeks
//error_log($start_day);
<?php
/**
* Disable header links
*/
/**
* Clean up wp_head()
*
* Remove unnecessary <link>'s
* Remove inline CSS and JS from WP emoji support
<?php
/**
Plugin Name: WooCommerce Extended Coupon Features PRO Daily Extension
Description: Extends WooCommerce Extended Coupon Features by adding coupons that are only valid on certain days
Author: Daniel Klose
Version: 1.0
Author URI: http://www.daniel-klose.com/
*/
add_action( 'wjecf_init_plugins', 'setup_my_wjecf_example_plugin' );
@kLOsk
kLOsk / functions.php
Created November 6, 2018 05:34
wc vendors PLL rewrite fix test
function DK_pll_rewrite_basic() {
add_rewrite_rule('(en|de)/(dashboard)/(product)/?$', 'index.php?lang=$matches[1]&pagename=dashboard&object=product', 'top');
add_rewrite_rule('(en|de)/(dashboard)/(product)/(edit)/?$', 'index.php?lang=$matches[1]&pagename=dashboard&object=product&action=edit', 'top');
//add_rewrite_rule('(en|ja)/(product-category)/(.+?)/?$', 'index.php?post_type=product&product_cat=$matches[3]', 'top');
}
add_action('init', 'DK_pll_rewrite_basic', 10, 0);
<?php
add_filter('pll_redirect_home', 'home_redirection', 10);
function home_redirection($redirect) {
//$user_agent = $_SERVER['HTTP_USER_AGENT'];
//if(strpos( $user_agent, 'Yeti') !== false) {
$redirect = 'http://gogoespana.test/kr/';
//}
return $redirect;
//return false;
<?php
/*
* Test Redirect for Naver Search Engine
*/
function gogoes_redirect_naver() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos( $user_agent, 'Yeti') !== false) {
wp_redirect( pll_home_url('kr'), 301 );
//header('Location: ' . pll_home_url('kr'), true, 301);
exit;
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( '' !== $query->get( 'facetwp' ) ) {
$is_main_query = (bool) $query->get( 'facetwp' );
}
return $is_main_query;
}, 10, 2 );
$args = array(
'post_type' => array( 'smart-tours' ),
'posts_per_page'=>-1,
'orderby' => 'rand',
'facetwp' => true
);
@kLOsk
kLOsk / polylang_pro_synchronize_wc_product.php
Last active June 4, 2018 21:29
Copy and synchronice a WooCommerce product programmatically with Polylang from frontend
<?php
/**
* I had a hard time accessing the Polylang PLL_Admin methods from the frontend. Instantiating classes manually didnt work.
* Luckily the Polylang boss jumped in and provided this solution. This shold also be working with other Polylang methods
* that can normally only be executed from admin side.
*/
$pll = new PLL_Admin( PLL()->links_model );
$pll->add_filters();
$pll_pro = new Polylang_Pro();
$pll_pro->load_modules( $pll );
@kLOsk
kLOsk / gist:2b0123c2fca5538eb3f6ab8856411301
Last active October 31, 2017 23:24
WP Post Views for WPEngine - Count Post Views in WordPress without plugin
<?php
if ( ! defined("POST_VIEWS_KEY") ) {
define("POST_VIEWS_KEY", "post_views_count");
}
// function to display number of posts.
function get_post_views( $post_id ){