-
Notifications
You must be signed in to change notification settings - Fork 382
Expand file tree
/
Copy pathwp-bakery.php
More file actions
83 lines (66 loc) · 2.29 KB
/
wp-bakery.php
File metadata and controls
83 lines (66 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
}
}