Skip to content

Instantly share code, notes, and snippets.

View vyskoczilova's full-sized avatar

Karolína Vyskočilová vyskoczilova

View GitHub Profile
@taufik-nurrohman
taufik-nurrohman / php-html-css-js-minifier.php
Last active February 23, 2024 04:30
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/x.minify>
namespace x\minify\_ { // start namespace
$n = __NAMESPACE__;
\define($n . "\\token_boolean", '\b(?:true|false)\b');
\define($n . "\\token_number", '-?(?:(?:\d+)?\.)?\d+');
@jackabox
jackabox / filter.md
Created May 14, 2015 11:14
Filtering custom post types by an ACF field.

Filtering posts via an ACF field.

  • Define the acf key
  • grab the choices
  • create a select with choices
  • request on the meta key/meta value
@spyesx
spyesx / string-to-slug.js
Last active March 15, 2024 12:05
String to slug in JS (wordpress sanitize_title)
var string_to_slug = function (str)
{
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/_,:;";
var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn------";
for (var i=0, l=from.length ; i<l ; i++)
@WPprodigy
WPprodigy / wc-ninja-manipulate-shipping-rates.php
Created October 26, 2015 09:26
Example code for manipulating shipping rates in WooCommerce
function wc_ninja_manipulate_shipping( $rates, $package ) {
// All available rates and their costs
//print_r($rates);
// All products in the cart and their costs
//print_r($package);
// Example of manipulating the cost of
// a shipping method based on the above variables.
if ( isset( $rates['flat_rate'] ) ) {
@mathetos
mathetos / plugin.php
Last active April 13, 2023 16:48
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
@JodiWarren
JodiWarren / acfpro-composer.json
Last active March 31, 2020 16:42
Advanced Custom Fields PRO for Composer
{
"repositories": [
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
"version": "5.0",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@Tusko
Tusko / functions.php
Last active February 27, 2022 13:46
WP Ajax search (ACF included)
<?php
/* Wordpress Custom Search by title, ACF, post_meta */
// Wordpress ?s= redirect to /search/
function wpa_search_redirect() {
global $wp_rewrite;
if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) { return; }
$search_base = $wp_rewrite->search_base;
if (is_search() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$search_base}/") === false) {
wp_redirect(home_url("/{$search_base}/" . urlencode(get_query_var('s'))));
@mikejolley
mikejolley / functions.php
Created March 10, 2016 09:39
WooCommerce Disable guest checkout for certain products
<?php
// Code goes in theme functions.php or a custom plugin
add_filter( 'pre_option_woocommerce_enable_guest_checkout', 'conditional_guest_checkout_based_on_product' );
function conditional_guest_checkout_based_on_product( $value ) {
$restrict_ids = array( 1, 2, 3 ); // Replace with product ids which cannot use guest checkout
if ( WC()->cart ) {
$cart = WC()->cart->get_cart();
@psalz
psalz / detect_single_choice_attributes.js
Created April 5, 2016 20:00
Woocommerce Composite Products: Detect single choice attributes
"use strict";
(function ($) {
/**
* Detects all component attributes that have only a single value option and adds the '.single-choice' class
* to the respective table row. Additionally, a <span> with the class '.single-choice-label' is added, containing
* the options name.
*
* If executed twice, the previous changes are reverted first (in order to account for possible scenario changes).
* Default values or previous selections are saved and restored if the option becomes available again.