PluginProbe
User Submitted Posts – Enable Users to Submit Posts from the Front End / 20230809
User Submitted Posts – Enable Users to Submit Posts from the Front End v20230809
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 20230809, at library/shortcode-access.php

91 lines 2.1 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 $caps = array_map('trim', explode(',', $cap));
20
21 foreach ($caps as $c) {
22 if (current_user_can($c) && !is_null($content) && !is_feed()) return do_shortcode($content);
23 }
24 return $deny;
25 }
26 add_shortcode('usp_access', 'usp_access');
27 endif;
28
29
30
31 /*
32 Shortcode: show content to visitors
33 Syntax: [usp_visitor deny=""][/usp_visitor]
34 Can use {tag} to output <tag>
35 */
36 if (!function_exists('usp_visitor')) :
37 function usp_visitor($attr, $content = null) {
38 extract(shortcode_atts(array(
39 'deny' => '',
40 ), $attr));
41
42 $deny = str_replace("{", "<", $deny);
43 $deny = str_replace("}", ">", $deny);
44
45 if ((!is_user_logged_in() && !is_null($content)) || is_feed()) return do_shortcode($content);
46 return $deny;
47 }
48 add_shortcode('usp_visitor', 'usp_visitor');
49 endif;
50
51
52
53 /*
54 Shortcode: show content to members
55 Syntax: [usp_member deny=""][/usp_member]
56 Can use {tag} to output <tag>
57 */
58 if (!function_exists('usp_member')) :
59 function usp_member($attr, $content = null) {
60 extract(shortcode_atts(array(
61 'deny' => '',
62 ), $attr));
63
64 $deny = str_replace("{", "<", $deny);
65 $deny = str_replace("}", ">", $deny);
66
67 if (is_user_logged_in() && !is_null($content) && !is_feed()) return do_shortcode($content);
68 return $deny;
69 }
70 add_shortcode('usp_member', 'usp_member');
71 endif;
72
73
74
75 /*
76 Shortcode Empty Paragraph Fix
77 */
78 if (!function_exists('usp_shortcode_empty_p_fix')) :
79 function usp_shortcode_empty_p_fix($content) {
80 $array = array(
81 '<p>[' => '[',
82 ']</p>' => ']',
83 ']<br />' => ']',
84 ']<br>' => ']'
85 );
86 $content = strtr($content, $array);
87 return $content;
88 }
89 add_filter('the_content', 'usp_shortcode_empty_p_fix');
90 endif;
91