Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // run these with a priority of 5 so they can remove later callbacks
- add_filter( 'fl_builder_row_attributes' , 'remove_toolbox_attr_in_builder' , 5, 2 );
- add_filter( 'fl_builder_column_attributes' , 'remove_toolbox_attr_in_builder' , 5, 2 );
- add_filter( 'fl_builder_module_attributes' , 'remove_toolbox_attr_in_builder' , 5, 2 );
- /**
- * When in the builder, test for certain attributes; if present, stop loading these attributes on that node
- *
- * @param [type] $attrs [description]
- * @param [type] $node [description]
- * @return [type] [description]
- */
- function remove_toolbox_attr_in_builder( $attrs , $node ) {
- if ( !isset( $_GET['fl_builder'] ) ) return $attrs;
- // get the nodetype from the filter hookname
- $nodetype = match_filter_to_nodetype( current_filter() );
- if ( isset( $node->settings->toolbox_custom_attr ) ) {
- for ( $i = 0; $i < count( $node->settings->toolbox_custom_attr );$i++ ):
- if( empty( $node->settings->toolbox_custom_attr[$i])) {continue;}
- switch( $node->settings->toolbox_custom_attr[$i]->my_attr ) {
- // you can add more here by adding more case "attribute-name": instances
- case "uk-parallax":
- case "uk-sticky":
- // case "attribute-name":
- // remove the filter on this nodetype
- remove_filter( "fl_builder_{$nodetype}_attributes" , 'toolboxFilters::check_for_extra_toolbox_attributes' , 10 );
- // add a filter that will reset the removed filters so the next row/col/module runs it again
- add_filter( "fl_builder_{$nodetype}_attributes" , 're_add_attr_in_builder' , 100 , 1 );
- // bail so we don't add more filters
- return $attrs;
- break;
- }
- endfor;
- }
- return $attrs;
- }
- /**
- * callback to return the nodetype from the passed in filter hookname
- * @param [type] $filter [description]
- * @return [type] [description]
- */
- function match_filter_to_nodetype( $filter ) {
- $re = '/fl_builder_([a-z]{0,})_attributes/';
- preg_match($re, $filter, $matches );
- return $matches[1];
- }
- /**
- * Re-add the filter after the fact; remove itself
- *
- * @param [type] $attrs [description]
- * @return [type] [description]
- */
- function re_add_attr_in_builder( $attrs ) {
- // get the nodetype from the filter hookname
- $nodetype = match_filter_to_nodetype( current_filter() );
- // re-add the removed filter
- add_filter( "fl_builder_{$nodetype}_attributes" , 'toolboxFilters::check_for_extra_toolbox_attributes' , 10 , 3 );
- // remove this method once it has been run
- remove_filter( "fl_builder_{$nodetype}_attributes" , __METHOD__ , 100 );
- // don't forget to return the attrs
- return $attrs;
- }
Add Comment
Please, Sign In to add comment