enabling php code on selected pages
-
Hi All,
I’m putting together a custom module for the Divi pagebuilder as a plugin. This “theme” let’s you select different modules – fill in some text or an image, etc… in order to build up a page. The module I am extending is the “Code” module. As it stands, the code module is simple a textarea into which you can put HTML or JS in script tags that will be outputted in the DOM. I am adding in codemirror with theming and linting options. One person requested that I also include the ability to add php. So now I am trying to figure out how to be able to apply a filter to the_content of just pages where this particular module is in use. I think it would be too scary to apply the filter to the_content of all pages. How would you all approach this? I am pasting the code of the base module so that you can take a look at what I have to work with.
class ET_Builder_Module_Code extends ET_Builder_Module { function init() { $this->name = esc_html__( 'Code', 'et_builder' ); $this->slug = 'et_pb_code'; $this->fb_support = true; $this->use_row_content = true; $this->decode_entities = true; $this->whitelisted_fields = array( 'raw_content', 'admin_label', 'module_id', 'module_class', 'max_width', 'max_width_tablet', 'max_width_phone', ); } function get_fields() { $fields = array( 'raw_content' => array( 'label' => esc_html__( 'Content', 'et_builder' ), 'type' => 'textarea', 'option_category' => 'basic_option', 'description' => esc_html__( 'Here you can create the content that will be used within the module.', 'et_builder' ), 'is_fb_content' => true, ), 'max_width' => array( 'label' => esc_html__( 'Max Width', 'et_builder' ), 'type' => 'text', 'option_category' => 'layout', 'tab_slug' => 'advanced', 'mobile_options' => true, 'validate_unit' => true, ), 'max_width_tablet' => array( 'type' => 'skip', 'tab_slug' => 'advanced', ), 'max_width_phone' => array( 'type' => 'skip', 'tab_slug' => 'advanced', ), 'disabled_on' => array( 'label' => esc_html__( 'Disable on', 'et_builder' ), 'type' => 'multiple_checkboxes', 'options' => array( 'phone' => esc_html__( 'Phone', 'et_builder' ), 'tablet' => esc_html__( 'Tablet', 'et_builder' ), 'desktop' => esc_html__( 'Desktop', 'et_builder' ), ), 'additional_att' => 'disable_on', 'option_category' => 'configuration', 'description' => esc_html__( 'This will disable the module on selected devices', 'et_builder' ), ), 'admin_label' => array( 'label' => esc_html__( 'Admin Label', 'et_builder' ), 'type' => 'text', 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ), ), 'module_id' => array( 'label' => esc_html__( 'CSS ID', 'et_builder' ), 'type' => 'text', 'option_category' => 'configuration', 'tab_slug' => 'custom_css', 'option_class' => 'et_pb_custom_css_regular', ), 'module_class' => array( 'label' => esc_html__( 'CSS Class', 'et_builder' ), 'type' => 'text', 'option_category' => 'configuration', 'tab_slug' => 'custom_css', 'option_class' => 'et_pb_custom_css_regular', ), ); if ( et_fb_is_enabled() || et_fb_is_retrieving_builder_data() ) { $fields["max_width_last_edited"] = array( 'type' => 'skip', 'tab_slug' => 'advanced', ); } return $fields; } function shortcode_callback( $atts, $content = null, $function_name ) { $module_id = $this->shortcode_atts['module_id']; $module_class = $this->shortcode_atts['module_class']; $max_width = $this->shortcode_atts['max_width']; $max_width_tablet = $this->shortcode_atts['max_width_tablet']; $max_width_phone = $this->shortcode_atts['max_width_phone']; $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name ); $this->shortcode_content = et_builder_replace_code_content_entities( $this->shortcode_content ); if ( '' !== $max_width_tablet || '' !== $max_width_phone || '' !== $max_width ) { $max_width_values = array( 'desktop' => $max_width, 'tablet' => $max_width_tablet, 'phone' => $max_width_phone, ); et_pb_generate_responsive_css( $max_width_values, '%%order_class%%', 'max-width', $function_name ); } $output = sprintf( '<div%2$s class="et_pb_code et_pb_module%3$s"> %1$s </div> <!-- .et_pb_code -->', $this->shortcode_content, ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ), ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ) ); return $output; } } new ET_Builder_Module_Code;
- The topic ‘enabling php code on selected pages’ is closed to new replies.