Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/metaboxes.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Require Membership Meta Box
4
+
*/
5
+
function pmpro_page_meta() {
6
+
global $post, $wpdb;
7
+
$membership_levels = pmpro_getAllLevels( true, true );
8
+
$membership_levels = pmpro_sort_levels_by_order( $membership_levels );
9
+
$page_levels = $wpdb->get_col( "SELECT membership_id FROM {$wpdb->pmpro_memberships_pages} WHERE page_id = '" . intval( $post->ID ) . "'" );
10
+
11
+
// Build the selectors for the #memberships list based on level count.
12
+
$pmpro_memberships_checklist_classes = array( 'list:category', 'categorychecklist', 'form-no-clear');
13
+
if ( count( $membership_levels ) > 9 ) {
14
+
$pmpro_memberships_checklist_classes[] = "pmpro_scrollable";
15
+
}
16
+
$pmpro_memberships_checklist_classes = implode( ' ', array_unique( $pmpro_memberships_checklist_classes ) );
17
+
18
+
if ( count( $membership_levels ) > 1 ) { ?>
19
+
<p><?php esc_html_e( 'Select:', 'paid-memberships-pro' ); ?> <a id="pmpro-memberships-checklist-select-all" href="javascript:void(0);"><?php esc_html_e( 'All', 'paid-memberships-pro' ); ?></a> | <a id="pmpro-memberships-checklist-select-none" href="javascript:void(0);"><?php esc_html_e( 'None', 'paid-memberships-pro' ); ?></a></p>
20
+
<script type="text/javascript">
21
+
jQuery('#pmpro-memberships-checklist-select-all').on('click',function(){
22
+
jQuery('#pmpro-memberships-checklist input').prop('checked', true);
23
+
});
24
+
jQuery('#pmpro-memberships-checklist-select-none').on('click',function(){
25
+
jQuery('#pmpro-memberships-checklist input').prop('checked', false);
26
+
});
27
+
</script>
28
+
<?php } ?>
29
+
<ul id="pmpro-memberships-checklist" class="<?php echo esc_attr( $pmpro_memberships_checklist_classes ); ?>">
30
+
<input type="hidden" name="pmpro_noncename" id="pmpro_noncename" value="<?php echo esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) )?>" />
31
+
<?php
32
+
$in_member_cat = false;
33
+
foreach( $membership_levels as $level ) {
34
+
?>
35
+
<li id="membership-level-<?php echo esc_attr( $level->id ); ?>">
36
+
<label class="selectit">
37
+
<input id="in-membership-level-<?php echo esc_attr( $level->id ); ?>" type="checkbox" <?php if(in_array($level->id, $page_levels)) { ?>checked="checked"<?php } ?> name="page_levels[]" value="<?php echo esc_attr( $level->id ) ;?>" />
38
+
<?php
39
+
echo esc_html( $level->name );
40
+
//Check which categories are protected for this level
41
+
$protectedcategories = $wpdb->get_col( "SELECT category_id FROM $wpdb->pmpro_memberships_categories WHERE membership_id = '" . intval( $level->id ) . "'");
42
+
//See if this post is in any of the level's protected categories
43
+
if( in_category( $protectedcategories, $post->id ) ) {
44
+
$in_member_cat = true;
45
+
echo ' *';
46
+
}
47
+
?>
48
+
</label>
49
+
</li>
50
+
<?php
51
+
}
52
+
?>
53
+
</ul>
54
+
<?php
55
+
if( 'post' == get_post_type( $post ) && $in_member_cat ) { ?>
56
+
<p class="pmpro_meta_notice">* <?php esc_html_e("This post is already protected for this level because it is within a category that requires membership.", 'paid-memberships-pro' );?></p>
57
+
<?php
58
+
}
59
+
?>
60
+
<?php
61
+
do_action( 'pmpro_after_require_membership_metabox', $post );
62
+
?>
63
+
<?php
64
+
}
65
+
66
+
/**
67
+
* Saves meta options when a page is saved.
68
+
*/
69
+
function pmpro_page_save( $post_id ) {
70
+
global $wpdb;
71
+
72
+
if( empty( $post_id ) ) {
73
+
return false;
74
+
}
75
+
76
+
// Post is saving somehow with our meta box not shown.
77
+
if ( ! isset( $_POST['pmpro_noncename'] ) ) {
78
+
return $post_id;
79
+
}
80
+
81
+
// Verify the nonce.
82
+
if ( ! wp_verify_nonce( sanitize_key( $_POST['pmpro_noncename'] ), plugin_basename( __FILE__ ) ) ) {
83
+
return $post_id;
84
+
}
85
+
86
+
// Don't try to update meta fields on AUTOSAVE.
87
+
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
88
+
return $post_id;
89
+
}
90
+
91
+
// Check permissions.
92
+
if( ! empty( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
93
+
if ( ! current_user_can( 'edit_page', $post_id ) ) {
94
+
return $post_id;
95
+
}
96
+
} else {
97
+
if ( ! current_user_can( 'edit_post', $post_id ) ) {
98
+
return $post_id;
99
+
}
100
+
}
101
+
102
+
// OK, we're authenticated. We need to find and save the data.
103
+
if( ! empty( $_POST['page_levels'] ) ) {
104
+
$mydata = array_map( 'intval', $_POST['page_levels'] );
105
+
} else {
106
+
$mydata = array();
107
+
}
108
+
109
+
// Add new memberships for this page.
110
+
if( is_array( $mydata ) ) {
111
+
pmpro_update_post_level_restrictions( $post_id, $mydata );
112
+
}
113
+
114
+
return $mydata;
115
+
}
116
+
add_action( 'save_post', 'pmpro_page_save' );
117
+
118
+
/**
119
+
* Wrapper to add meta boxes for classic editor.
120
+
*/
121
+
function pmpro_page_meta_wrapper() {
122
+
// If the block editor is being used, skip adding the meta boxes.
123
+
$current_screen = get_current_screen();
124
+
if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
125
+
return;
126
+
}
127
+
128
+
// Add meta box for each restrictable post type.
129
+
$restrictable_post_types = apply_filters( 'pmpro_restrictable_post_types', array( 'page', 'post' ) );
130
+
foreach( $restrictable_post_types as $post_type ) {
131
+
add_meta_box( 'pmpro_page_meta', __( 'Require Membership', 'paid-memberships-pro' ), 'pmpro_page_meta', $post_type, 'side', 'high' );
132
+
}
133
+
}
134
+
add_action( 'add_meta_boxes', 'pmpro_page_meta_wrapper' );
135
+