elegantthemes / Divi-Beta

8 stars 0 forks source link

How To Filter The Props Of Exisiting Divi 5 Module #69

Open UmerCheema-WPD opened 4 months ago

UmerCheema-WPD commented 4 months ago

If we want to filter the props of the contact form module, we can achieve this in Divi 4 using add_filter('et_pb_module_shortcode_attributes', 'my_callback_function').

How can we achieve this in Divi 5.0? Is there any alternate hook for this?

Hook

apply_filters( 'et_pb_module_shortcode_attributes', $this->props, $attrs, $render_slug, $_address, $content );

Code Example

/**
 * Filter and modify the attributes of the ET PB Contact Form module.
 *
 * @param array $props The current properties of the module.
 * @param array $attrs The attributes passed to the shortcode.
 * @param string $render_slug The render slug of the module.
 * @param string $_address Not used.
 * @param string $content The content inside the module shortcode.
 *
 * @return array Modified properties of the module.
 */
if (!function_exists('filter_et_pb_contact_form_attributes')):
    function filter_et_pb_contact_form_attributes($props, $attrs, $render_slug, $_address, $content)
    {
        // Return if Frontend Builder is enabled
        if (function_exists('et_fb_is_enabled') && et_fb_is_enabled()) {
            return $props;
        }
        // Return if Backend Builder is enabled
        if (function_exists('et_builder_bfb_enabled') && et_builder_bfb_enabled()) {
            return $props;
        }
        // Return if in admin area or during an Ajax request
        if (is_admin() || wp_doing_ajax()) {
            return $props;
        }
        // Return if the render slug does not match 'et_pb_contact_form'
        if ('et_pb_contact_form' !== $render_slug) {
            return $props;
        }
        // Add Default title if empty
        if (empty($props['title'])) {
            $props['title'] = 'Get in Touch with Us';
        }

        return $props;
    }

    add_filter('et_pb_module_shortcode_attributes', 'filter_et_pb_contact_form_attributes', 10, 5);
endif;

Screenshot

Filter Attributes