Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardising Page Builders - Divi #3146

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 214 additions & 25 deletions includes/compatibility/divi.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,90 @@ public static function toggle( $modules ) {
}

public static function row_settings( $settings ) {

$settings['pmpro_enable'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Enable Paid Memberships Pro module visibility?', 'paid-memberships-pro' ),
'type' => 'yes_no_button',
'options' => array(
'off' => __( 'No', 'paid-memberships-pro' ),
'on' => __( 'Yes', 'paid-memberships-pro' ),
),
'toggle_slug' => 'paid-memberships-pro',
);

$settings['pmpro_visibility'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Content Visibility', 'paid-memberships-pro' ),
'type' => 'select',
'options' => array(
'hide' => __( 'Hide', 'paid-memberships-pro' ),
'show' => __( 'Show', 'paid-memberships-pro' ),
),
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
),
);

$settings['pmpro_segment'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Show Content To', 'paid-memberships-pro' ),
'type' => 'select',
'options' => array(
'all' => __( 'All Members', 'paid-memberships-pro' ),
'specific' => __( 'Specific Membership Levels', 'paid-memberships-pro' ),
'logged_in' => __( 'Logged-In Users', 'paid-memberships-pro' ),
),
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
'pmpro_visibility' => 'show',
),
);

$settings['pmpro_segment_hide'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Hide Content From', 'paid-memberships-pro' ),
'type' => 'select',
'options' => array(
'all' => __( 'All Members', 'paid-memberships-pro' ),
'specific' => __( 'Specific Membership Levels', 'paid-memberships-pro' ),
'logged_in' => __( 'Logged-In Users', 'paid-memberships-pro' ),
),
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
'pmpro_visibility' => 'hide',
),
);

$settings['paid-memberships-pro'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Restrict Row by Level', 'paid-memberships-pro' ),
'label' => __( 'Show module for specific levels', 'paid-memberships-pro' ),
'description' => __( 'Enter comma-separated level IDs.', 'paid-memberships-pro' ),
'type' => 'text',
'default' => '',
'option_category' => 'configuration',
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
'pmpro_segment' => 'specific',
),
);

$settings['paid-memberships-pro-hide'] = array(
'tab_slug' => 'custom_css',
'label' => __( 'Hide module for specific levels', 'paid-memberships-pro' ),
'description' => __( 'Enter comma-separated level IDs.', 'paid-memberships-pro' ),
'type' => 'text',
'default' => '',
'option_category' => 'configuration',
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
'pmpro_segment_hide' => 'specific',
),
);

$settings['pmpro_show_no_access_message'] = array(
Expand All @@ -50,6 +125,9 @@ public static function row_settings( $settings ) {
'on' => __( 'Yes', 'paid-memberships-pro' ),
),
'toggle_slug' => 'paid-memberships-pro',
'show_if' => array(
'pmpro_enable' => 'on',
),
);

return $settings;
Expand All @@ -61,35 +139,146 @@ public static function restrict_content( $output, $props, $attrs, $slug ) {
if ( et_fb_is_enabled() ) {
return $output;
}

// if ( 'et_pb_row' !== $slug || 'et_pb_section' !== $slug ) {
// return $output;
// }

if( !isset( $props['paid-memberships-pro'] ) ){
return $output;
}

$level = $props['paid-memberships-pro'];

if ( empty( trim( $level ) ) || trim( $level ) === '0' ) {
return $output;
}

if( strpos( $level, "," ) ) {
//they specified many levels
$levels = explode( ",", $level );
} else {
//they specified just one level
$levels = array( $level );
}


if( ! isset( $props['pmpro_enable'] ) || 'on' !== $props['pmpro_enable'] ){
return $output;
}

if( isset( $props['pmpro_visibility'] ) && 'show' === $props['pmpro_visibility'] ){

if( isset( $props['pmpro_segment'] ) && 'all' === $props['pmpro_segment'] ){

if( pmpro_hasMembershipLevel() ){
return $output;
} else {
if( isset( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ){
return pmpro_get_no_access_message( NULL, array() );
} else {
return '';
}
}

}

if( isset( $props['pmpro_segment'] ) && 'specific' === $props['pmpro_segment'] ){

$level = $props['paid-memberships-pro'];

if ( empty( trim( $level ) ) || trim( $level ) === '0' ) {
return $output;
}

if( strpos( $level, "," ) ) {
//they specified many levels
$levels = explode( ",", $level );
} else {
//they specified just one level
$levels = array( $level );
}

if( pmpro_hasMembershipLevel( $levels ) ){
return $output;
} else {
if ( ! empty( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ) {
return pmpro_get_no_access_message( NULL, $levels );
} else {
return '';
}

}

}

if( isset( $props['pmpro_segment'] ) && 'logged_in' === $props['pmpro_segment'] ){

if( is_user_logged_in() ){
return $output;
} else {
if ( ! empty( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ) {
return pmpro_get_no_access_message( NULL, $levels );
} else {
return '';
}

}

}

} else {

if( isset( $props['pmpro_segment_hide'] ) && 'all' === $props['pmpro_segment_hide'] ){

if( ! pmpro_hasMembershipLevel() ){
return $output;
} else {
if( isset( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ){
return pmpro_get_no_access_message( NULL, array());
} else {
return '';
}
}

}

if( isset( $props['pmpro_segment_hide'] ) && 'specific' === $props['pmpro_segment_hide'] ){

$level = $props['paid-memberships-pro'];

if ( empty( trim( $level ) ) || trim( $level ) === '0' ) {
return $output;
}

if( strpos( $level, "," ) ) {
//they specified many levels
$levels = explode( ",", $level );
} else {
//they specified just one level
$levels = array( $level );
}

if( ! pmpro_hasMembershipLevel( $levels ) ){
return $output;
} else {
if ( ! empty( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ) {
return pmpro_get_no_access_message( NULL, $levels );
} else {
return '';
}

}

}

if( isset( $props['pmpro_segment_hide'] ) && 'logged_in' === $props['pmpro_segment_hide'] ){

if( ! is_user_logged_in() ){
return $output;
} else {
if ( ! empty( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ) {
return pmpro_get_no_access_message( NULL, $levels );
} else {
return '';
}

}

}

return $output;

}

return $output;

if( pmpro_hasMembershipLevel( $levels ) ){
return $output;
} else {
if ( ! empty( $props['pmpro_show_no_access_message'] ) && 'on' === $props['pmpro_show_no_access_message'] ) {
return pmpro_get_no_access_message( NULL, $levels );
} else {
return '';
}

}
}

/**
Expand Down