Skip to content

Instantly share code, notes, and snippets.

@huubl
huubl / wordpress-upload-base64.php
Created October 27, 2022 17:39 — forked from cyberwani/wordpress-upload-base64.php
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
@huubl
huubl / gist:5f4c81d133380489228f3d778a4a2fca
Created September 5, 2022 20:36 — forked from bradp/gist:4999343
WordPress function to convert address to Lat/Long
<?php
function brrad_geocode($street_address,$city,$state){
$street_address = str_replace(" ", "+", $street_address); //google doesn't like spaces in urls, but who does?
$city = str_replace(" ", "+", $city);
$state = str_replace(" ", "+", $state);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=$street_address,+$city,+$state&sensor=false";
$google_api_response = wp_remote_get( $url );
@huubl
huubl / subtitle-extract.md
Created August 11, 2022 12:28 — forked from pavelbinar/extract-subtitles-from-mkv.md
Extract subtitles from .mkv files on Mac OS X

Extract Subtitles From .mkv

These instructions shall work on Mac OS X and Linux.

Install mkvtoolnix (Mac OS X)

Installation via Homebrew:

brew install mkvtoolnix
<?php
/*-----------------------------------------
REWRITE SEARCH URLS
-----------------------------------------*/
// Redirect ?s=xxx to /search/xxx
function redirect_search_url()
{
if (is_search() && !empty($_GET['s'])) {
wp_redirect(home_url('/' . _x('search' /* default search slug */, 'search url slug', THEME_TEXT_DOMAIN) . '/') . urlencode(get_query_var('s')));
@huubl
huubl / disable-acf-blocks-on-edit.js
Created March 8, 2022 10:09 — forked from derweili/disable-acf-blocks-on-edit.js
Disable Links in ACF Block-Edit Method
/*
* Wrap all ACF Blocks in Disabled block to disable all links in edit view
*/
const { createHigherOrderComponent } = wp.compose;
const { Fragment } = wp.element;
import { Disabled } from '@wordpress/components';
const withDisabledCompontent = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
@huubl
huubl / full-codes.js
Created January 31, 2022 16:21 — forked from markhowellsmead/full-codes.js
Extend core Gutenberg blocks with custom attributes and settings. View full tutorials here : https://jeffreycarandang.com/extending-gutenberg-core-blocks-with-custom-attributes-and-controls/
/**
* External Dependencies
*/
import classnames from 'classnames';
/**
* WordPress Dependencies
*/
const { __ } = wp.i18n;
const { addFilter } = wp.hooks;
@huubl
huubl / ACFToArray.php
Created December 15, 2021 13:03 — forked from teolaz/ACFToArray.php
This class is an helpful method to add a caching layer to Advanced Custom Fields. This works adding a new row on database with the entire ACF data serialized for that saved post or option page, and then WITH A SINGLE QUERY done you can have all data back and ready to use.
<?php
/**
* Created by PhpStorm.
* User: Matteo
* Date: 04/07/2018
* Time: 12:52
*/
/**
* Class ACFToArray
@huubl
huubl / functions.php
Created November 1, 2021 09:49 — forked from Jon007/functions.php
Add default Product Attributes to all WooCommerce products
/*
* Example adds certain named Product Attribute fields to the product Edit screen ready for completion.
* (Pre-requisite )
* This saves the Shop Admin having to add them manually.
*
* Why might you want to do this instead of adding Custom fields? There's plenty of nice documentation on adding custom fields
* for example: http://www.remicorson.com/mastering-woocommerce-products-custom-fields/
*
* Well a Product Attributes are a built in WooCommerce feature, using Terms which are a built in Wordpress feature.
* - no add-ons required
@huubl
huubl / class.php
Created November 1, 2021 09:45 — forked from igorbenic/class.php
How to create a Custom WooCommerce Email | https://www.ibenic.com/create-custom-woocommerce-email
<?php
/**
* Class Custom_WC_Email
*/
class Custom_WC_Email {
/**
* Custom_WC_Email constructor.
@huubl
huubl / wp-search-filter-ajax.php
Created August 28, 2021 11:59 — forked from tradesouthwest/wp-search-filter-ajax.php
wordpress filter for searching categories with ajax
<form action="<?php echo site_url() ?>/wp-admin/admin-ajax.php" method="POST" id="filter">
<?php
if( $terms = get_terms( 'category', 'orderby=name' ) ) :
echo '<select name="categoryfilter"><option>Select category...</option>';
foreach ( $terms as $term ) :
echo '<option value="' . $term->term_id . '">' . $term->name . '</option>';
endforeach;
echo '</select>';
endif;