Skip to content

Toolbox update to version 1.0

April 9th, 2019

Toolbox is updating from version 0.9.7 to version 1.0.

A lot of work has been put into making Toolbox more awesome, by adding more debugging functions and filters into Twig and adding support for other custom field solutions like Meta Box.

However, making such a big step requires a fundamental change. In order for Toolbox to work consistently for developers we've had to split up the toolbox/helpers filters for each supported field type solution.

This means that the update to version 1.0 that will be available in a few days you will need to review your functions.php if you've added custom filters.

What does this mean for me?

If you don't know what I'm talking about, that's probably good news, you won't notice any change. However, if you or a developer working with the Toolbox plugin and have de-queued or enqueued filters to the settings, attributes or helpers for Toolbox it might change the way the plugin interacts with the user and output.

How to remedy?

The remedy is simple: you need to point to the correct classname. For instance, if you've added the YoutubePicker field type to ACF, you're functions.php may contain something like this:


/**
 * Adding YOUTUBE PICKER field type using Toolbox 0.9.7:
 */

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 );

/**
 * Default behavior for the Youtubepicker fieldtype
 * @param  mixed  $string       [passed in value/string/array/object]
 * @param  array  $field_object [this fields field_object]
 * @param  mixed  $value        [this fields returned_value]
 * @param  array  $atts         [shortcode attributes or users settings]
 * @param  int    $postid       [postid to query]
 * @return mixed                [returned value for next callback or output]
 */
function display_youtubepicker( $string , $field_object , $value , $atts , $postid ) {

    if ( $field_object['multiple'] ) {
        $return = '<div class="uk-child-width-1-3@s uk-grid-small uk-grid-match" uk-grid>';
        for ( $i=0; $i<sizeof($value); $i++ ) {
            $return .= '<div><div>' . $value[$i]['iframe'] . '</div></div>';
        }
        $return .= '</div>';
    } else {
        $return = $value['iframe'];
    }
    return $return;
}

All you need to do is add the custom field type name to the classnames that you're calling using the filters:


/**
 * Adding YOUTUBE PICKER using Toolbox 1.0
 */

add_filter( 'toolbox/helpers/settings/type=youtubepicker' , 'toolboxConnectors_acf::settings_text', 10, 2 );
add_filter( 'toolbox/helpers/sc_attr/type=youtubepicker'  , 'toolbox_acf::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 );

/**
 * Default behavior for the Youtubepicker fieldtype
 * @param  mixed  $string       [passed in value/string/array/object]
 * @param  array  $field_object [this fields field_object]
 * @param  mixed  $value        [this fields returned_value]
 * @param  array  $atts         [shortcode attributes or users settings]
 * @param  int    $postid       [postid to query]
 * @return mixed                [returned value for next callback or output]
 */
function display_youtubepicker( $string , $field_object , $value , $atts , $postid ) {

    if ( $field_object['multiple'] ) {
        $return = '<div class="uk-child-width-1-3@s uk-grid-small uk-grid-match" uk-grid>';
        for ( $i=0; $i<sizeof($value); $i++ ) {
            $return .= '<div><div>' . $value[$i]['iframe'] . '</div></div>';
        }
        $return .= '</div>';
    } else {
        $return = $value['iframe'];
    }
    return $return;
}

Did you notice the subtle change?

"toolboxConnectors::settings_text" becomes "toolboxConnectors_acf::settings_text"

and

"toolbox::return_shortcode_attr_default" becomes "toolbox_acf::return_shortcode_attr_default"

ACF and Meta Box specific callbacks

If you're using Meta Box field types you will - evidently - need to use tooboxConnectors_meta_box::settings_text and toolbox_meta_box::return_shortcode_attr_default.

Your own callbacks don't need to be changed

Please note that this ONLY affects callbacks that are part of Toolbox. If you've added your own callbacks to extend Toolbox's functionality you don't need to make adjustments, and you don't need to change those. You only need to make sure to de-queue and enqueue the Toolbox callbacks that have moved to another class.