Category: Developer Guides

  • 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;
    }
    
  • 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