PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20260916
User Submitted Posts – Enable Users to Submit Posts from the Front End v20260916
20260916 20260810 20260608 20230806 20230809 20230811 20230901 20230902 20230914 20231102 20240319 20240516 20240703 20241026 20250327 20250329 20251121 20251210 20260110 20260113 20260207 20260217 20260407 20260422 trunk All 59 releases
← All changes | library/shortcode-access.php +83 -18 2023110220260916 View file →
@@ -1,86 +1,141 @@
1 1 <?php // User Submitted Posts - Access Control
2 2
3 3 /*
4 - Shortcode: require login based on capability
4 + Shortcode: display content based on user capability
5 5 Syntax: [usp_access cap="read" deny=""][/usp_access]
6 6 Can use {tag} to output <tag>
7 - See @ https://codex.wordpress.org/Roles_and_Capabilities#Capabilities
7 + https://wordpress.org/documentation/article/roles-and-capabilities/
8 8 */
9 +
9 10 if (!function_exists('usp_access')) :
11 +
10 12 function usp_access($attr, $content = null) {
11 - extract(shortcode_atts(array(
12 - 'cap' => 'read',
13 - 'deny' => '',
14 - ), $attr));
15 13
14 + extract(shortcode_atts(array('cap' => 'read', 'deny' => ''), $attr));
15 +
16 + // deny message
17 +
18 + $deny = htmlspecialchars($deny, ENT_QUOTES);
19 +
16 20 $deny = str_replace("{", "<", $deny);
17 21 $deny = str_replace("}", ">", $deny);
18 22
19 - $deny = htmlspecialchars($deny, ENT_QUOTES);
23 + $deny = wp_kses_post($deny);
24 +
25 + // content
26 +
20 27 $content = htmlspecialchars($content, ENT_QUOTES);
21 28
29 + $content = str_replace("{", "<", $content);
30 + $content = str_replace("}", ">", $content);
31 +
32 + $content = wp_kses_post($content);
33 +
34 + //
35 +
22 36 $caps = array_map('trim', explode(',', $cap));
23 37
24 38 foreach ($caps as $c) {
39 +
25 40 if (current_user_can($c) && !is_null($content) && !is_feed()) return do_shortcode($content);
41 +
26 42 }
27 43
28 44 return $deny;
45 +
29 46 }
47 +
30 48 add_shortcode('usp_access', 'usp_access');
49 +
31 50 endif;
32 51
33 52
34 53
35 54 /*
36 - Shortcode: show content to visitors
55 + Shortcode: display content to visitors (not logged in)
37 56 Syntax: [usp_visitor deny=""][/usp_visitor]
38 57 Can use {tag} to output <tag>
39 58 */
59 +
40 60 if (!function_exists('usp_visitor')) :
61 +
41 62 function usp_visitor($attr, $content = null) {
42 - extract(shortcode_atts(array(
43 - 'deny' => '',
44 - ), $attr));
45 63
64 + extract(shortcode_atts(array('deny' => ''), $attr));
65 +
66 + // deny message
67 +
68 + $deny = htmlspecialchars($deny, ENT_QUOTES);
69 +
46 70 $deny = str_replace("{", "<", $deny);
47 71 $deny = str_replace("}", ">", $deny);
48 72
49 - $deny = htmlspecialchars($deny, ENT_QUOTES);
73 + $deny = wp_kses_post($deny);
74 +
75 + // content
76 +
50 77 $content = htmlspecialchars($content, ENT_QUOTES);
51 78
79 + $content = str_replace("{", "<", $content);
80 + $content = str_replace("}", ">", $content);
81 +
82 + $content = wp_kses_post($content);
83 +
84 + //
85 +
52 86 if ((!is_user_logged_in() && !is_null($content)) || is_feed()) return do_shortcode($content);
53 87
54 88 return $deny;
89 +
55 90 }
91 +
56 92 add_shortcode('usp_visitor', 'usp_visitor');
93 +
57 94 endif;
58 95
59 96
60 97
61 98 /*
62 - Shortcode: show content to members
99 + Shortcode: display content to members (logged in)
63 100 Syntax: [usp_member deny=""][/usp_member]
64 101 Can use {tag} to output <tag>
65 102 */
103 +
66 104 if (!function_exists('usp_member')) :
105 +
67 106 function usp_member($attr, $content = null) {
68 - extract(shortcode_atts(array(
69 - 'deny' => '',
70 - ), $attr));
71 107
108 + extract(shortcode_atts(array('deny' => ''), $attr));
109 +
110 + // deny message
111 +
112 + $deny = htmlspecialchars($deny, ENT_QUOTES);
113 +
72 114 $deny = str_replace("{", "<", $deny);
73 115 $deny = str_replace("}", ">", $deny);
74 116
75 - $deny = htmlspecialchars($deny, ENT_QUOTES);
117 + $deny = wp_kses_post($deny);
118 +
119 + // content
120 +
76 121 $content = htmlspecialchars($content, ENT_QUOTES);
77 122
123 + $content = str_replace("{", "<", $content);
124 + $content = str_replace("}", ">", $content);
125 +
126 + $content = wp_kses_post($content);
127 +
128 + //
129 +
78 130 if (is_user_logged_in() && !is_null($content) && !is_feed()) return do_shortcode($content);
79 131
80 132 return $deny;
133 +
81 134 }
135 +
82 136 add_shortcode('usp_member', 'usp_member');
137 +
83 138 endif;
84 139
85 140
86 141
@@ -86,17 +141,27 @@
86 141
87 142 /*
88 143 Shortcode Empty Paragraph Fix
89 144 */
145 +
90 146 if (!function_exists('usp_shortcode_empty_p_fix')) :
147 +
91 148 function usp_shortcode_empty_p_fix($content) {
149 +
92 150 $array = array(
151 +
93 152 '<p>[' => '[',
94 153 ']</p>' => ']',
95 154 ']<br />' => ']',
96 155 ']<br>' => ']'
156 +
97 157 );
158 +
98 159 $content = strtr($content, $array);
160 +
99 161 return $content;
162 +
100 163 }
164 +
101 165 add_filter('the_content', 'usp_shortcode_empty_p_fix');
102 -endif;
166 +
167 +endif;