Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions includes/compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ function pmpro_compatibility_checker() {
'check_type' => 'class',
'check_value' => 'BuddyPress' //BuddyBoss uses this class, too.
],
[
'file' => 'wp-bakery.php',
'check_type' => 'function',
'check_value' => 'vc_add_param'
],
];

foreach ( $compat_checks as $value ) {
Expand Down
83 changes: 83 additions & 0 deletions includes/compatibility/wp-bakery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* WP Bakery Compatibility
*
* @since TBD
*/

/**
* Set the VC directory to our compat folder
*
*/
vc_set_shortcodes_templates_dir( PMPRO_DIR . '/includes/compatibility/wp-bakery' );

/**
* Create a text field that allows you to enter in level ID's that can
* be included/excluded for that element.
*/
function pmpro_wpbakery_levels_parameter() {

return array(
'type' => 'textfield',
'heading' => 'Paid Memberships Pro',
'param_name' => 'pmpro_levels',
'value' => '',
'description' => __( 'Enter a comma separated list of level ID\'s this element should so to. Set 0 to Non-Members.', 'paid-memberships-pro' ),
);

}

function pmpro_wpbakery_show_noaccess_message() {

return array(
'type' => 'dropdown',
'heading' => 'Paid Memberships Pro - Show No Access Message',
'param_name' => 'pmpro_no_access_message',
'value' => array( 'Yes', 'No' ), //Does not accept an associative array, cannot be translated.
'description' => __( 'Choose to show or hide the no access message when a member does not have the required membership level.', 'paid-memberships-pro' ),
);

}

/**
* To add the parameter to additional fields, reference:
* vc_add_param( 'field_type', pmpro_wpbakery_levels_parameter() );
*/
vc_add_param( 'vc_column_text', pmpro_wpbakery_levels_parameter() ); //Text Field
vc_add_param( 'vc_column_text', pmpro_wpbakery_show_noaccess_message() ); //Text Field

/**
* Determines if content should be shown or not
*
* @since TBD
*/
function pmpro_wpbakery_show_content( $content, $atts ) {

if( empty( $atts['pmpro_levels'] ) ) {
return $content;
}

$restricted_levels = $atts['pmpro_levels'];

$show_no_access_message = ( ! empty( $atts['pmpro_no_access_message'] ) ) ? $atts['pmpro_no_access_message'] : 'Yes';

$levels_array = explode( ",", $restricted_levels );

if ( ! pmpro_hasMembershipLevel( $levels_array ) ) {
$access = false;
} else {
$access = true;
}

$access = apply_filters( 'pmpro_wpbakery_has_access', $access, $content, $levels_array, $atts );

if ( ! $access ) {
// Show no content message here or not
if ( $show_no_access_message === 'Yes' ) {
return pmpro_get_no_access_message( NULL, $levels_array );
}
} else {
return $content;
}

}
45 changes: 45 additions & 0 deletions includes/compatibility/wp-bakery/vc_column_text.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}

/**
* Shortcode attributes
* @var $atts
* @var $el_class
* @var $el_id
* @var $css_animation
* @var $css
* @var $content - shortcode content
* Shortcode class
* @var WPBakeryShortCode_Vc_Column_text $this
*/
$el_class = $el_id = $css = $css_animation = '';
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
extract( $atts );

$class_to_filter = 'wpb_text_column wpb_content_element ' . $this->getCSSAnimation( $css_animation );
$class_to_filter .= vc_shortcode_custom_css_class( $css, ' ' ) . $this->getExtraClass( $el_class );
$css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, $class_to_filter, $this->settings['base'], $atts );
$wrapper_attributes = array();
if ( ! empty( $el_id ) ) {
$wrapper_attributes[] = 'id="' . esc_attr( $el_id ) . '"';
}
$output = '
<div class="' . esc_attr( $css_class ) . '" ' . implode( ' ', $wrapper_attributes ) . '>
<div class="wpb_wrapper">
' . wpb_js_remove_wpautop( $content, true ) . '
</div>
</div>
';

/**
* Paid Memberships Pro will check to see if any levels are required, and show/hide the content as expected.
*/
if( ! empty( $atts['pmpro_levels'] ) ) {

$content = pmpro_wpbakery_show_content( $content, $atts );

}

echo $content;