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-misc.php

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

187 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // User Submitted Posts - Shortcodes misc.
2
3 /*
4 Shortcode: Reset form button
5 Returns the markup for a reset-form button
6 Syntax: [usp-reset-button class="aaa,bbb,ccc" value="Reset form" url="https://example.com/usp-pro/submit/"]
7 Attributes:
8 class = classes for the parent element (optional, default: none)
9 value = link text (optional, default: "Reset form")
10 url = the URL where your form is displayed (can use %%current%% for current URL)
11 custom = any attributes or custom code for the link element
12
13 */
14 function usp_reset_button_shortcode($args) {
15
16 extract(shortcode_atts(array(
17 'class' => '',
18 'value' => __('Reset form', 'usp'),
19 'url' => '#please-check-shortcode',
20 'custom' => '',
21 ), $args));
22
23 $protocol = is_ssl() ? 'https://' : 'http://';
24
25 $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
26
27 $current = isset($_SERVER['REQUEST_URI']) ? $protocol . $host . $_SERVER['REQUEST_URI'] : '';
28
29 $url = preg_replace('/%%current%%/', $current, $url);
30
31 $url = remove_query_arg(array('usp_reset_form', 'post_id', 'success', 'usp-error'), $url);
32
33 $href = get_option('permalink_structure') ? $url .'?usp_reset_form=true"' : $url .'&usp_reset_form=true';
34
35 $class = empty($class) ? '' : ' class="'. esc_attr($class) .'"';
36
37 $output = '<p'. $class .'><a href="'. esc_url($href) .'"'. esc_attr($custom) .'>'. esc_html($value) .'</a></p>';
38
39 return $output;
40
41 }
42 add_shortcode('usp-reset-button', 'usp_reset_button_shortcode');
43
44
45
46 /*
47 Displays a list of all user submitted posts
48 Bonus: includes any posts submitted by the Pro version of USP :)
49 Shortcode:
50 [usp_display_posts userid="current"] : displays all submitted posts by current logged-in user
51 [usp_display_posts userid="1"] : displays all submitted posts by registered user with ID = 1
52 [usp_display_posts userid="Pat Smith"] : displays all submitted posts by author name "Pat Smith"
53 [usp_display_posts userid="all"] : displays all submitted posts by all users/authors
54 [usp_display_posts userid="all" numposts="5"] : limit to 5 posts
55
56 Note that the Pro version of USP provides many more options for the display-posts shortcode:
57
58 https://plugin-planet.com/usp-pro-display-list-submitted-posts/
59
60 */
61 function usp_display_posts($attr = array(), $content = null) {
62
63 global $post;
64
65 extract(shortcode_atts(array(
66
67 'userid' => 'all',
68 'post_type' => 'post',
69 'numposts' => -1,
70
71 ), $attr));
72
73 if (ctype_digit($userid)) {
74
75 $args = array(
76 'author' => $userid,
77 'posts_per_page' => $numposts,
78 'post_type' => $post_type,
79 'meta_key' => 'is_submission',
80 'meta_value' => '1'
81 );
82
83 } elseif ($userid === 'all') {
84
85 $args = array(
86 'posts_per_page' => $numposts,
87 'post_type' => $post_type,
88 'meta_key' => 'is_submission',
89 'meta_value' => '1'
90 );
91
92 } elseif ($userid === 'current') {
93
94 $args = array(
95 'author' => get_current_user_id(),
96 'posts_per_page' => $numposts,
97 'post_type' => $post_type,
98 'meta_key' => 'is_submission',
99 'meta_value' => '1'
100 );
101
102 } else {
103
104 $args = array(
105 'posts_per_page' => $numposts,
106 'post_type' => $post_type,
107
108 'meta_query' => array(
109
110 'relation' => 'AND',
111
112 array(
113 'key' => 'is_submission',
114 'value' => '1'
115 ),
116 array(
117 'key' => 'user_submit_name',
118 'value' => $userid
119 )
120 )
121 );
122
123 }
124
125 $args = apply_filters('usp_display_posts_args', $args);
126
127 $submitted_posts = get_posts($args);
128
129 $display_posts = '<ul>';
130
131 foreach ($submitted_posts as $post) {
132
133 setup_postdata($post);
134
135 $display_posts .= '<li><a href="'. get_the_permalink() .'" title="'. esc_attr__('View full post', 'usp') .'">'. get_the_title() .'</a></li>';
136
137 }
138
139 $display_posts .= '</ul>';
140
141 wp_reset_postdata();
142
143 return $display_posts;
144
145 }
146 add_shortcode('usp_display_posts', 'usp_display_posts');
147
148
149
150 /*
151 Shortcode: [usp_gallery]
152 Displays a gallery of submitted images for the current post
153 Syntax: [usp_gallery size="" before="" after="" number="" id=""]
154 Notes:
155 Use curly brackets to output angle brackets
156 Use single quotes in before/after attributes
157 See usp_get_images() for inline notes and more infos
158 */
159 if (!function_exists('usp_gallery')) :
160
161 function usp_gallery($attr, $content = null) {
162
163 extract(shortcode_atts(array(
164
165 'size' => 'thumbnail',
166 'before' => '{a href="%%url%%"}{img src="',
167 'after' => '" /}{/a}',
168 'number' => false,
169 'id' => false,
170
171 ), $attr));
172
173 $images = usp_get_images($size, $before, $after, $number, $id);
174
175 $gallery = '';
176
177 foreach ($images as $image) $gallery .= $image;
178
179 $gallery = $gallery ? '<div class="usp-image-gallery">'. $gallery .'</div>' : '';
180
181 return $gallery;
182
183 }
184 add_shortcode('usp_gallery', 'usp_gallery');
185
186 endif;
187