Category: Developer Docs

  • PageBuilderSandwich:: get_all_shortcodes

    Gets all the available shortcodes tags in the site.

    Usage

    $all_shortcodes = PageBuilderSandwich::get_all_shortcodes()
    

    Parameters

    None.

    Returns

    Array. An array of all the detected shortcode tags.

  • pbs.save.payload

    pbs.save.payload

    Called right before the editor saves the contents. You can use this to place additional data to send during saving (this doesn’t save the data, just sends it via Ajax to the backend)

    Parameters

    payload

    FormData object. The data sent via Ajax for saving.

    Example

    wp.hooks.addAction( 'pbs.save.payload', function( payload ) {
    
    	// Add data to be sent during saving.
    	payload.append( 'my_data', 'My Data' );
    }
    
  • pbs.init

    pbs.init

    Called when the PBS editor finishes loading (not called when the user clicks on the start editing button)

    Example

    Do something after PBS loads

    wp.hooks.addAction( 'pbs.init', function() {
    	console.log( 'PBS is ready!' );
    }
  • pbs.iframe.resized

    pbs.iframe.resized

    Triggered when the user changes between the different responsive views.

    Parameters

    None.

  • Bundling PBS Inside a Theme You’re Selling

    Bundling PBS Inside a Theme You’re Selling

    If you are a theme developer, including PBS in your theme can greatly increase the value of your product.

    Contact us at [email protected], let’s collaborate!

  • How to Stop PBS From Showing Up

    How to Stop PBS From Showing Up

    You can prevent PB Sandwich from showing up in the front-end using the pbs_is_editable_by_user filter.

    For example, to stop PB Sandwich from showing up in a Custom Post Type identified by the slug slider, you can add this piece of code in your functions.php

    add_filter( 'pbs_is_editable_by_user', 'stop_pbs_in_sliders' );
    
    function stop_pbs_in_sliders( $editable ) {
    	if ( is_singular( 'slider' ) ) {
    		return false;
    	}
    	return $editable;
    }
    

    To stop PB Sandwich for a specific page/post, you can use the post ID to check:

    add_filter( 'pbs_is_editable_by_user', 'stop_pbs_for_123' );
    
    function stop_pbs_for_123( $editable ) {
    	global $post;
    	if ( is_singular() && ! empty( $post ) ) {
    		if ( '123' === $post->ID ) {
    			return false;
    		}
    	}
    	return $editable;
    }
    
  • PBSEditor.isEditing

    PBSEditor.isEditing

    Check whether PBS is turned on and in editing mode.

    Usage

    if ( PBSEditor.isEditing() ) {
    	// Do something when editing.
    }

    Parameters

    None.

    Returns

    Boolean. True when currently editing, false when not editing.

  • pbs_saved_content

    pbs_saved_content

    Called after the content is saved. This is called when a save was initiated from the PBS editor.

    Parameters

    None

  • PageBuilderSandwich:: is_editable_by_user

    Used to check whether PBS is loaded in the front-end for the current post

    Usage

    PageBuilderSandwich::is_editable_by_user()
    

    Parameters

    None.

    Returns

    Boolean. True if PBS can edit the post, false otherwise.

  • Javascript Hooks

    Javascript Hooks

    The bulk of Page Builder Sandwich is Javascript, and we’ve added a bunch of methods so that developers can extend and add more functionality to our page builder.

    To make things easier to developers, we’ve patterned things to how WordPress does things – via hooks!

    In WordPress, you typically use the functions add_filter() and add_action() to modify or add to the behavior of WP. Similarly in PBS, you can use wp.hooks.addFilter() and wp.hooks.addAction().

    The way you use them is also the same: use filters to modify stuff, and use actions to perform additional stuff. Those two function calls are essentially the same as with their PHP counterparts, except they run in Javascript.

    So as not to be confused between PHP hooks and Javascript hooks, we’ve named the Javascript hooks with a “period-case” (invented word). PHP hooks all use snake case:

    • pbs.save.payload – “period-case”, a JS hook
    • pbs_save_content_data – snake case, a PHP hook

    Refer to the Javascript Actions and Javascript Filters categories on the left menu to browse all the hooks.

    Credits

    For those curious, we’re using  https://github.com/carldanley/WP-JS-Hooks to add those nifty hook calls in Javascript