Skip to content

Instantly share code, notes, and snippets.

View badabingbreda's full-sized avatar

Didou Schol badabingbreda

  • Breda, Netherlands
View GitHub Profile
@badabingbreda
badabingbreda / toolbox_example_add_sc_attr.php
Created June 18, 2018 18:39
Toolbox Example - Add sc_attr default settings
<?php
add_filter( 'toolbox/helpers/sc_attr/type=new_fieldtype' , 'toolbox::return_shortcode_attr_default' , 10, 1 );
@badabingbreda
badabingbreda / toolbox_example_extending_timber_posts_data.php
Created June 18, 2018 17:25
Toolbox Example - extending timber posts data
<?php
add_filter( 'toolbox_timber_posts_data' , 'my_custom_data' ,10 ,1 );
function my_custom_data( $data ) {
$data['mydata'] = array(
'firstname' => 'John',
'lastname' => 'Doe'
);
@badabingbreda
badabingbreda / toolbox_example_custom_text_codefield_filter.php
Created June 17, 2018 17:01
Toolbox Example - Custom Text Codefield Filter
<?php
add_filter( 'toolbox/helpers/get_acf_field/type=text', 'my_text_codefield_filter', 10, 5 );
/**
* Your custom filter for a text-field with the name 'codefield'
*/
public static function my_text_codefield_filter( $string , $field_object , $value , $atts = null , $postid = null ) {
// check if the requested fieldname is 'codefield' and the type of the field_object is 'text'
// if so, append and prepend the string by <code></code>
@badabingbreda
badabingbreda / toolbox_example_default_text_filter.php
Created June 17, 2018 16:42
Toolbox Example - default text filter
<?php
/**
* Default return function for a text or unknown fieldtype
*/
public static function acf_return_text( $string , $field_object , $value , $atts = null , $postid = null ) {
if ( is_array( $value ) ) return $string;
return $string . $value;
}
@badabingbreda
badabingbreda / toolbox_example_adding_youtubepicker_fieldtype.php
Created June 12, 2018 19:11
toolbox - Example Adding the Youtubepicker Fieldtype
<?php
add_filter( 'toolbox/helpers/settings/type=youtubepicker' , 'toolboxConnectors::settings_text', 10, 2 );
add_filter( 'toolbox/helpers/sc_attr/type=youtubepicker' , 'toolbox::return_shortcode_attr_default' , 10, 1 );
// add_filter( 'toolbox/helpers/get_acf_field/type=youtubepicker' , 'toolbox::post_object_to_array' , 20, 5 );
add_filter( 'toolbox/helpers/get_acf_field/type=youtubepicker' , 'display_youtubepicker' , 10, 5 );
/**
@badabingbreda
badabingbreda / toolbox-using-acf-fields.twig
Created June 11, 2018 20:32
Toolbox - How to use an ACF field on your ACF Field Module
{% for item in __field__ %}
<h3>{{item.title}}</h3>
<p>{{item.preview(100)}}</p>
{% endfor %}
@badabingbreda
badabingbreda / toolbox_example_timber_posts_query_filter.php
Created June 8, 2018 20:07
toolbox - Timber Posts example query filter
<?php
/**
* pass in the query and make sure to return it at the end
*/
function my_query_filter( $query ) {
if (isset($_GET['bedrooms']) && $_GET['bedrooms'] !== '') {
$query[ 'meta_query' ][0]['relation'] = 'AND';
$query[ 'meta_query' ][0][] = array(
'key' => 'bedrooms',
@badabingbreda
badabingbreda / toolbox-Twig-Extend.php
Created June 7, 2018 20:23
Example code to extend Timber/Twig with custom filters and functions
<?php
class toolboxTwigExtend {
public static function init() {
add_filter( 'timber/twig', __CLASS__ . '::add_to_twig' );
}
public static function add_to_twig( $twig ) {
@badabingbreda
badabingbreda / auto_table_of_contents.js
Created May 25, 2018 22:40
Auto TOC - create TOC from H4-H5 hierarchy
(function($) {
$(document).ready(function(){
var $toc = $('#toc'), // toc id
appendthis = ''; // build the toc
$toc.html(''); // clear receiving <div id="toc"></div>
@badabingbreda
badabingbreda / toolbox_example_cond_filter_geo_detect.php
Last active May 20, 2018 08:09
Toolbox Example - Conditional Filter GeoIP Detection
<?php
add_action( 'toolbox_add_conditional_options' , 'add_geo_detect', 10, 1 );
function add_geo_detect() {
toolboxExtender::add_conditional_option(
// filter name
'geo_detect',
// option key and title
array('key'=> 'geo_check' , 'title' => __('Geo Check', 'textdomain') ),