diff --git a/includes/compatibility.php b/includes/compatibility.php index e34e139490..5cf15f9b86 100644 --- a/includes/compatibility.php +++ b/includes/compatibility.php @@ -71,6 +71,11 @@ function pmpro_compatibility_checker() { 'check_type' => 'constant', 'check_value' => 'BLUEHOST_PLUGIN_VERSION', ], + [ + 'file' => 'wp-bakery.php', + 'check_type' => 'function', + 'check_value' => 'vc_add_param' + ], ]; foreach ( $compat_checks as $value ) { diff --git a/includes/compatibility/wp-bakery.php b/includes/compatibility/wp-bakery.php new file mode 100644 index 0000000000..be63a28425 --- /dev/null +++ b/includes/compatibility/wp-bakery.php @@ -0,0 +1,90 @@ + 'textfield', + 'heading' => 'Paid Memberships Pro - Require Membership Level', + 'param_name' => 'pmpro_levels', + 'value' => '', + 'description' => __( 'Enter comma-separated level IDs. Set to "0" to show this content for 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' => __( 'Displays a no access message to non-members.', '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( $output, $atts ) { + + // Don't run if we're in the VC editor. + if ( vc_is_inline() ) { + return $output; + } + + // Return content if no levels are set. + if ( empty( $atts['pmpro_levels'] ) ) { + return $output; + } + + // Get the levels that can see this content. + $restricted_levels = $atts['pmpro_levels']; + $levels_array = explode( ",", $restricted_levels ); + + // Get the show no access message setting. + $show_no_access_message = ( ! empty( $atts['pmpro_no_access_message'] ) ) ? $atts['pmpro_no_access_message'] : 'Yes'; + + // Check if the current user has access to this content. + if ( ! pmpro_hasMembershipLevel( $levels_array ) ) { + $access = false; + } else { + $access = true; + } + + // Allow filtering of the access. + $access = apply_filters( 'pmpro_wpbakery_has_access', $access, $output, $levels_array, $atts ); + + // Show the content or not. + if ( ! $access ) { + // User doesn't have access. Don't show the content. + // Optionally show the no access message. + if ( $show_no_access_message === 'Yes' ) { + return pmpro_get_no_access_message( NULL, $levels_array ); + } + } else { + // User has access. Show the content. + return $output; + } + +} diff --git a/includes/compatibility/wp-bakery/vc_column_text.php b/includes/compatibility/wp-bakery/vc_column_text.php new file mode 100644 index 0000000000..8e5390d3e8 --- /dev/null +++ b/includes/compatibility/wp-bakery/vc_column_text.php @@ -0,0 +1,42 @@ +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 = ' +
+
+ ' . wpb_js_remove_wpautop( $content, true ) . ' +
+
+'; + +/** + * Paid Memberships Pro will check to see if any levels are required, and show/hide the content as expected. + */ +if ( ! empty( $atts['pmpro_levels'] ) ) { + $output = pmpro_wpbakery_show_content( $output, $atts ); +} +echo $output;