Skip to content

Instantly share code, notes, and snippets.

@huubl
huubl / adjust_offset_pagination.php
Created March 9, 2020 15:35
Changing the posts per page on first page
add_action( 'pre_get_posts', 'query_offset', 1 );
function query_offset( &$query ) {
// Before anything else, make sure this is the right query...
if ( ! ( $query->is_home() || is_main_query() ) || is_admin() ) {
return;
}
// First, define your desired offset...
$offset = -1;
@huubl
huubl / gravity-form.php
Created July 11, 2020 11:39 — forked from wkw/gravity-form.php
Custom: Gravity Forms WP API Submission and GF API form entry creation plus send notifications
<?php
/**
* Add WP API endpoint for form submission, then create new
* Gravity Forms entry and send notifications.
*/
// rest api endpoint for forms submission
add_action( 'rest_api_init', function () {
register_rest_route( 'ahr/v1', '/forms', array(
'methods' => 'POST',
@huubl
huubl / Gravity_Boots.php
Created July 30, 2020 15:48 — forked from craigiswayne/Gravity_Boots.php
Bootstrap 3 styles for Gravity Forms
if( !is_admin() && class_exists('\DOMDocument' ) ){
/**
* Checks if a gravity form has been submitted
* @return bool
*/
function form_submitted(){
return isset( $_POST['gform_submit'] ) && '1' === $_POST['gform_submit'];
}
@huubl
huubl / setup.php
Last active August 30, 2020 13:39 — forked from Xilonz/setup.php
Sage Wordpress Query Loop for Blade templates
/**
* Add this to your setup.php
* Usage @loop( $wp_query ) or $loop and end with @endloop
* the new $loop variable is available
*
* Create @loop Blade directive
*/
\Roots\app('blade.compiler')->directive('loop', function ($query = null) {
global $wp_query;
if (!$query) $query = $wp_query;
@huubl
huubl / Vimexx.php
Created August 31, 2020 16:38 — forked from Achterstraat/Vimexx.php
Heb je het óók he-le-maal gehad met Vimexx? Gebruik dan dit script om makkelijk én snel de overstap te realiseren, alle data binnen enkele seconden over naar je nieuwe hostingpartij!
<?php
/*
First, create API Projects at https://www.vimexx.nl/api
Second, replace all vars between [] with credentials from previous step!
Third, see below;
$vimexx = (new \Vimexx([account], 'wefact'));
var_export($vimexx->post('/domains'));
var_dump($vimexx->client('whmcs')->post('/domain/dns', ['sld' => 'achterstraat', 'tld' => 'com']));
var_export($vimexx->client('wefact')->post('/domains'));
*/
@huubl
huubl / pause-gifs.css
Created September 24, 2020 10:28 — forked from mrcoles/pause-gifs.css
A lightweight approach to pausing gifs on a webpage.
/** .pause-gif */
.wrap-pause-gif {
position: relative;
text-align: center;
}
.pause-gif {
visibility: hidden;
}
<?php
/*
Plugin Name: Programmatically add Gravity Forms
Plugin URI: https://daan.kortenba.ch/programmatically-add-gravity-forms/
Description: Programmatically add persistent Gravity Forms forms.
Author: Daan Kortenbach
Version: 0.1
Author URI: https://daan.kortenba.ch/
License: GPLv2 or later
*/
@huubl
huubl / Rating.php
Created December 1, 2020 13:08 — forked from Log1x/Rating.php
Rating component
<?php
namespace App\View\Components;
use Roots\Acorn\View\Component;
class Rating extends Component
{
/**
* The rating value.
@huubl
huubl / ACF Gutenberg get block fields
Created December 13, 2020 16:08 — forked from jenssogaard/ACF Gutenberg get block fields
Helper class for ACF and Gutenberg. Get blocks fields by passing block_id and post_id.
<?php
namespace JensSogaard;
class BlockHelper
{
/**
* Gets ACF fields for a specific block on a given post
* @author Jens Soegaard <jens@jenssogaard.com>
*/
public function getBlockFromPage(string $block_id, int $post_id)
@huubl
huubl / wp-video-thumbnail-attachments.php
Created March 17, 2021 19:16 — forked from RadGH/wp-video-thumbnail-attachments.php
WP Utility functions to get youtube/vimeo images and store their thumbnails as attachments
<?php
function video_get_service( $video_url ) {
if ( stristr( $video_url, 'vimeo.com') ) {
return 'vimeo';
}
if ( stristr( $video_url, 'youtube.com' ) || stristr( $video_url, 'youtu.be' ) ) {
return 'youtube';
}