class-shortcodes.php
3.18 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class WPF_Shortcodes {
public function __construct() {
add_shortcode( 'wpf' , array( $this, 'shortcodes'));
add_shortcode( 'wpf_update_tags' , array( $this, 'shortcode_update_tags'));
add_shortcode( 'wpf_update_meta' , array( $this, 'shortcode_update_meta'));
}
/**
* Handles content restriction shortcodes
*
* @access public
* @return mixed
*/
public function shortcodes($atts, $content = '') {
$atts = shortcode_atts( array(
'tag' => '',
'not' => '',
'method' => ''
), $atts, 'wpf' );
global $current_user;
// If admins are excluded from restrictions
if(is_user_logged_in() && wp_fusion()->settings->get('exclude_admins') == true) {
$user = get_userdata( $current_user->ID );
if(in_array('administrator', $user->roles ))
return apply_filters( 'the_content', $content );
}
if($current_filter = get_query_var( 'wpf_tag' )) {
if($current_filter == 'unlock-all') {
return apply_filters( 'the_content', $content );
} elseif($current_filter == 'lock-all') {
return false;
}
}
$user_tags = wp_fusion()->user->get_tags( get_current_user_id() );
if(empty($user_tags))
$user_tags = array();
$proceed_tag = false;
$proceed_not = false;
if(!empty($atts['tag'])) {
$tags = array();
$tags_split = explode(',', $atts['tag']);
// Get tag IDs where needed
foreach($tags_split as $tag) {
if(is_numeric($tag)) {
$tags[] = $tag;
} else {
$tags[] = wp_fusion()->user->get_tag_id(trim($tag));
}
}
foreach($tags as $tag) {
if(in_array($tag, $user_tags)){
$proceed_tag = true;
if($atts['method'] == 'any')
break;
} else {
$proceed_tag = false;
if($atts['method'] != 'any')
break;
}
}
// If we're overriding
if($current_filter = get_query_var( 'wpf_tag' )) {
if($current_filter == $atts['tag']){
$proceed_tag = true;
}
}
} else {
$proceed_tag = true;
}
if (!empty($atts['not'])) {
$tags = array();
$tags_split = explode(',', $atts['not']);
// Get tag IDs where needed
foreach($tags_split as $tag) {
if(is_numeric($tag)) {
$tags[] = $tag;
} else {
$tags[] = wp_fusion()->user->get_tag_id(trim($tag));
}
}
foreach($tags as $tag) {
if(in_array($tag, $user_tags)){
$proceed_not = false;
break;
} else {
$proceed_not = true;
}
}
// If we're overriding
if($current_filter = get_query_var( 'wpf_tag' )) {
if($current_filter == $atts['not']) {
return false;
}
}
} else {
$proceed_not = true;
}
if($proceed_tag == true && $proceed_not == true)
return do_shortcode( $content );
}
/**
* Update tags shortcode
*
* @access public
* @return null
*/
public function shortcode_update_tags($atts) {
if(is_user_logged_in())
wp_fusion()->user->get_tags( get_current_user_id(), true );
}
/**
* Update meta data shortcode
*
* @access public
* @return null
*/
public function shortcode_update_meta($atts) {
if(is_user_logged_in())
wp_fusion()->user->pull_user_meta( get_current_user_id() );
}
}
new WPF_Shortcodes;