Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Divi Restrict Content Via Custom Filter
<?php
/**
* Custom filter for "Restricting Content" via divi section.
* In the divi section "Restrict" Toggle, restrict content via "Custom WordPress Filter"
* Use the name "my_custom_filter" as the name of the filter. Note: You can name the filter however you like.
* Just ensure that you use the same filter name here as well.
*
* This filter take 3 arguments
* $original_content - A text representing the original "inner" contents of the divi section. Its in shortcode format
* $address - An integer presenting the address of the divi module. For example 0, 1, 2 ect.
* $props - An array of divi module properties. In this case its the properties of the divi section.
*/
add_filter('my_custom_filter',
function (
// original inner section content - text is in shortcode format.
$original_content,
// divi module address: integer value - for example 0, 1, 2, 3
$address,
// divi section props array
$props
) {
// Here we have written a logic to show the content if user is logged in. Else we display a simple message.
// One can write any custom logic instead.
if (is_user_logged_in()) {
return $original_content;
} else {
// Note: I am wrapping the h4 with et_pb_row so that the inner content of the divi section has atleast one row.
return '[et_pb_row]<h4>Since you are not logged in, you cannot access content of this section</h4>[/et_pb_row]';
}
},
10,
3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment