Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
@mklasen
mklasen / acf-test-block.php
Created May 8, 2019 08:46
Simple ACF Gutenberg Block
<?php
/* Plugin Name: ACF 5.8 Test
*/
class ACF_Test_Block {
public $_name = 'test-acf-block';
public function __construct() {
add_action( 'acf/init', [ $this, 'register_block' ] );
@mklasen
mklasen / woocommerce-countries-for-gravityforms.php
Last active May 29, 2019 13:21
Woocommerce countries for Gravity Forms
<?php
add_filter( 'gform_countries', 'gform_use_wc_countries' );
function gform_use_wc_countries() {
if( class_exists( 'WC') ) {
return WC()->countries->countries;
}
}
@mklasen
mklasen / functions.php
Created July 4, 2019 08:14
Replace the loading spinner in Gravity Forms by a CSS spinner
class MyTheme {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_filter( 'gform_ajax_spinner_url', array($this, 'replace_gform_spinner'), 10, 2 );
}
@mklasen
mklasen / rest-increase-per-page-posts.php
Last active July 8, 2019 07:28
Increases the maximum results that are returned by the WordPress Rest API
<?php
class Sample {
public function __construct() {
$this->hooks();
}
private function hooks() {
add_filter( 'rest_post_collection_params', [ $this, 'increase_maximum_rest_posts' ] );
}
private function increase_maximum_rest_posts( $params ) {
@mklasen
mklasen / command-line.sh
Created August 9, 2019 11:09
Migrate a database from local to staging/production with WP CLI and SSH
##
# This assumes the following folder structure
# Local environment:
# ./app/
# ./app/www/
# ./_db_dumps/
#
# Production/staging environment:
# ./wordpress/current/
# ./_db_dumps/
@mklasen
mklasen / functions.php
Created August 11, 2019 12:46
Easy Digital Downloads: Make software updates for free downloads possible without checking the license key
<?php
/**
* Accept any license key for free downloads.
* This assumes that license creation is enabled for the free download
*/
add_filter( 'edd_sl_id_license_match', function ( $license_match, $download_id ) {
$download = edd_get_download( $download_id );
if ( method_exists( $download, 'is_free' ) ) {
@mklasen
mklasen / editor-tool-neurony.js
Created August 22, 2019 11:59
Editor Tool Integration
<html>
<head>
<script type="text/javascript">
function addToCart() {
var data = [
{
product_id: 218,
customize_hash: 'erg5eyu2r245710',
quantity: 48
}
@mklasen
mklasen / functions.php
Created September 24, 2019 16:28
Disable Domain checking when testing WP's / EDD's updating mechanisms locally
<?php
add_filter('edd_sl_api_request_verify_ssl', '__return_false');
add_filter('https_ssl_verify', '__return_false');
add_filter('https_local_ssl_verify', '__return_false');
add_filter('http_request_host_is_external', '__return_true');
@mklasen
mklasen / functions.php
Created September 24, 2019 16:32
Serve updates with EDD for free downloads
<?php
class EDD_Updates_Without_Licenses {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_filter( 'edd_sl_id_license_match', array( $this, 'check_free_license' ), 10, 4 );
@mklasen
mklasen / class-extend-endpoint.php
Last active September 27, 2019 08:27
Extend the Woocommerce REST API (with authentication)
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Sample_Extend_Endpoint extends WC_REST_Controller {
protected $namespace = 'wc/v3';