PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20240703
User Submitted Posts – Enable Users to Submit Posts from the Front End v20240703
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
user-submitted-posts / library / shortcode-access.php

shortcode-access.php in User Submitted Posts – Enable Users to Submit Posts from the Front End 20240703, at library/shortcode-access.php

103 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // User Submitted Posts - Access Control
2
3 /*
4 Shortcode: require login based on capability
5 Syntax: [usp_access cap="read" deny=""][/usp_access]
6 Can use {tag} to output <tag>
7 See @ https://codex.wordpress.org/Roles_and_Capabilities#Capabilities
8 */
9 if (!function_exists('usp_access')) :
10 function usp_access($attr, $content = null) {
11 extract(shortcode_atts(array(
12 'cap' => 'read',
13 'deny' => '',
14 ), $attr));
15
16 $deny = str_replace("{", "<", $deny);
17 $deny = str_replace("}", ">", $deny);
18
19 $deny = htmlspecialchars($deny, ENT_QUOTES);
20 $content = htmlspecialchars($content, ENT_QUOTES);
21
22 $caps = array_map('trim', explode(',', $cap));
23
24 foreach ($caps as $c) {
25 if (current_user_can($c) && !is_null($content) && !is_feed()) return do_shortcode($content);
26 }
27
28 return $deny;
29 }
30 add_shortcode('usp_access', 'usp_access');
31 endif;
32
33
34
35 /*
36 Shortcode: show content to visitors
37 Syntax: [usp_visitor deny=""][/usp_visitor]
38 Can use {tag} to output <tag>
39 */
40 if (!function_exists('usp_visitor')) :
41 function usp_visitor($attr, $content = null) {
42 extract(shortcode_atts(array(
43 'deny' => '',
44 ), $attr));
45
46 $deny = str_replace("{", "<", $deny);
47 $deny = str_replace("}", ">", $deny);
48
49 $deny = htmlspecialchars($deny, ENT_QUOTES);
50 $content = htmlspecialchars($content, ENT_QUOTES);
51
52 if ((!is_user_logged_in() && !is_null($content)) || is_feed()) return do_shortcode($content);
53
54 return $deny;
55 }
56 add_shortcode('usp_visitor', 'usp_visitor');
57 endif;
58
59
60
61 /*
62 Shortcode: show content to members
63 Syntax: [usp_member deny=""][/usp_member]
64 Can use {tag} to output <tag>
65 */
66 if (!function_exists('usp_member')) :
67 function usp_member($attr, $content = null) {
68 extract(shortcode_atts(array(
69 'deny' => '',
70 ), $attr));
71
72 $deny = str_replace("{", "<", $deny);
73 $deny = str_replace("}", ">", $deny);
74
75 $deny = htmlspecialchars($deny, ENT_QUOTES);
76 $content = htmlspecialchars($content, ENT_QUOTES);
77
78 if (is_user_logged_in() && !is_null($content) && !is_feed()) return do_shortcode($content);
79
80 return $deny;
81 }
82 add_shortcode('usp_member', 'usp_member');
83 endif;
84
85
86
87 /*
88 Shortcode Empty Paragraph Fix
89 */
90 if (!function_exists('usp_shortcode_empty_p_fix')) :
91 function usp_shortcode_empty_p_fix($content) {
92 $array = array(
93 '<p>[' => '[',
94 ']</p>' => ']',
95 ']<br />' => ']',
96 ']<br>' => ']'
97 );
98 $content = strtr($content, $array);
99 return $content;
100 }
101 add_filter('the_content', 'usp_shortcode_empty_p_fix');
102 endif;
103