Skip to content

Instantly share code, notes, and snippets.

@chrono-meter
chrono-meter / wp-spoofing-hostport.php
Created October 26, 2023 00:39
Spoofing host and port for WordPress environment
View wp-spoofing-hostport.php
<?php
/**
* Spoofing host and port for WordPress environment.
* To use this, include from your "wp-config.php" file.
* Note that this functions is not intended to be used in production.
*
* @see \is_ssl()
* @link https://ngrok.com/docs/using-ngrok-with/wordpress/
*/
@chrono-meter
chrono-meter / wp-elfinder-googledrive.php
Last active November 27, 2020 19:03
Sample: Call elFinder from WordPress plugin.
View wp-elfinder-googledrive.php
<?php
/**
* Class GdriveFolderViewer
*
* @see https://github.com/nao-pon/flysystem-google-drive#usage-to-with-elfinder
* composer require nao-pon/elfinder-flysystem-driver-ext nao-pon/flysystem-google-drive:~1.1
*
*/
class GdriveFolderViewer {
@chrono-meter
chrono-meter / wc-builtin-shortcode-stock-filter.php
Created July 26, 2020 00:48
WooCommerce: Add stock filter function to builtin shortcodes.
View wc-builtin-shortcode-stock-filter.php
<?php
/**
* Description: WooCommerce: Add stock filter function to builtin shortcodes.
* Author: chrono-meter@gmx.net
* Version: v20200727
*
* @link https://docs.woocommerce.com/document/woocommerce-shortcodes/
*
* Example:
* [products stock="instock"]
View cmb2_initial_value.php
<?php
/**
* CMB2 delete value instead of saving empty value. So fields with default value cannot hold empty value.
* This example works around this issue by adding new field parameter `initial value'.
*
* Example:
* $cmb->add_field( array(
* 'name' => 'Title for publish',
* 'initial_value' => '%d product(s) published',
@chrono-meter
chrono-meter / cmb2-option-example.php
Last active December 22, 2021 21:02
CMB2 option example
View cmb2-option-example.php
<?php
/**
* Plugin Name: CMB2 option test
* Author: chrono-meter@gmx.net
* Version: 20211223
*
* @link https://github.com/CMB2/CMB2-Snippet-Library/search?q=object_types&unscoped_q=object_types
* @see add_menu_page()
*
* to get variables: cmb2_get_option('myprefix_network_options', 'key', 'default')
@chrono-meter
chrono-meter / wp-meta-thumbnail.php
Created June 16, 2019 18:16
WordPress | Thumbnail images in search results
View wp-meta-thumbnail.php
<?php
/**
* Thumbnail images in search results
*
* @see https://support.google.com/customsearch/answer/1626955
*/
add_action( 'wp_head', function() {
if ( is_single() && '' !== ($thumbnail_id = get_post_thumbnail_id()) && false !== ($image = wp_get_attachment_image_src( $thumbnail_id ))) {
echo "<meta name=\"thumbnail\" content=\"{$image[0]}\">";
@chrono-meter
chrono-meter / wc-fix-pa-creation.php
Created February 5, 2019 09:45
FIX: WooCommerce doesn't support attribute taxonomy creation on non startup.
View wc-fix-pa-creation.php
<?php
/**
* @wordpress-plugin
* Plugin Name: FIX: WooCommerce doesn't support attribute taxonomy creation on non startup.
* Depends: WooCommerce
* Plugin URI:
* Description:
* Version: 1.0.0
* Author: chrono-meter@gmx.net
* Author URI: mailto:chrono-meter@gmx.net
@chrono-meter
chrono-meter / wc-fix-pa-rewrite-slug.php
Last active February 5, 2019 09:36
FIX: WooCommerce generates non appropriate rewrite slug for product attributes with non latin language slug.
View wc-fix-pa-rewrite-slug.php
<?php
/**
* @wordpress-plugin
* Plugin Name: FIX: WooCommerce generates non appropriate rewrite slug for product attributes with CJK language slug.
* Depends: WooCommerce
* Plugin URI:
* Description:
* Version: 1.0.0
* Author: chrono-meter@gmx.net
* Author URI: mailto:chrono-meter@gmx.net
View wxr.py
#!/usr/bin/env python3
from xml.etree import ElementTree
from pathlib import Path
import io
import datetime
import email.utils
__author__ = 'chrono-meter@gmx.net'
__version__ = '1.0.0'
__license__ = 'Python Software Foundation License'
View touch-wp-crom.py
#!/usr/bin/env python3
import requests
from urlpath import URL # https://pypi.org/project/urlpath/
import argparse
import logging
logger = logging.getLogger(__name__)
# https://www.peterbe.com/plog/best-practice-with-retries-with-requests
def Session(*args, **kwargs):