11<?php
22
3- if ( !class_exists ('CPT_WPLF_Submission ' ) ) :
3+ if ( ! class_exists ( 'CPT_WPLF_Submission ' ) ) :
44
55class CPT_WPLF_Submission {
66 /**
@@ -26,15 +26,16 @@ private function __construct() {
2626 add_action ( 'add_meta_boxes ' , array ( $ this , 'add_meta_boxes_cpt ' ) );
2727
2828 // edit.php view
29- add_filter ( 'manage_edit-wplf-submission_columns ' , array ( $ this , 'custom_columns_cpt ' ), 100 , 1 );
30- add_action ( 'manage_posts_custom_column ' , array ( $ this , 'custom_columns_display_cpt ' ), 10 , 2 );
29+ add_filter ( 'manage_edit-wplf-submission_columns ' , array ( $ this , 'custom_columns_cpt ' ), 100 , 1 );
30+ add_action ( 'manage_posts_custom_column ' , array ( $ this , 'custom_columns_display_cpt ' ), 10 , 2 );
3131 add_action ( 'restrict_manage_posts ' , array ( $ this , 'form_filter_dropdown ' ) );
3232 add_filter ( 'pre_get_posts ' , array ( $ this , 'filter_by_form ' ) );
3333
3434 // add custom bulk actions
35- add_filter ( 'bulk_actions-edit-wplf-submission ' , array ( $ this , 'register_wplf_submission_bulk_actions ' ) );
36- add_filter ( 'handle_bulk_actions-edit-wplf-submission ' , array ( $ this , 'wplf_submission_bulk_action_handler ' ), 10 , 3 );
3735 add_action ( 'admin_notices ' , array ( $ this , 'wplf_submission_bulk_action_admin_notice ' ) );
36+ add_filter ( 'bulk_actions-edit-wplf-submission ' , array ( $ this , 'register_wplf_submission_bulk_actions ' ) );
37+ add_filter ( 'handle_bulk_actions-edit-wplf-submission ' ,
38+ array ( $ this , 'wplf_submission_bulk_action_handler ' ), 10 , 3 );
3839 }
3940
4041 public static function register_cpt () {
@@ -51,7 +52,7 @@ public static function register_cpt() {
5152 'all_items ' => __ ( 'Submissions ' , 'wp-libre-form ' ),
5253 'search_items ' => __ ( 'Search Submissions ' , 'wp-libre-form ' ),
5354 'not_found ' => __ ( 'No submissions found. ' , 'wp-libre-form ' ),
54- 'not_found_in_trash ' => __ ( 'No submissions found in Trash. ' , 'wp-libre-form ' )
55+ 'not_found_in_trash ' => __ ( 'No submissions found in Trash. ' , 'wp-libre-form ' ),
5556 );
5657
5758 $ args = array (
@@ -67,7 +68,7 @@ public static function register_cpt() {
6768 'has_archive ' => false ,
6869 'hierarchical ' => false ,
6970 'menu_position ' => null ,
70- 'supports ' => array ( 'title ' , 'custom-fields ' )
71+ 'supports ' => array ( 'title ' , 'custom-fields ' ),
7172 );
7273
7374 register_post_type ( 'wplf-submission ' , $ args );
@@ -78,15 +79,17 @@ public static function register_cpt() {
7879 * Custom column display for Submission CPT in edit.php
7980 */
8081 function custom_columns_display_cpt ( $ column , $ post_id ) {
81- if ( 'referrer ' === $ column ) {
82- if ( $ referrer = get_post_meta ($ post_id , 'referrer ' , true ) ) {
82+ if ( 'referrer ' === $ column ) {
83+ if ( $ referrer = get_post_meta ( $ post_id , 'referrer ' , true ) ) {
8384 echo '<a href=" ' . esc_url_raw ( $ referrer ) . '"> ' . esc_url ( $ referrer ) . '</a> ' ;
8485 }
8586 }
86- if ( 'form ' === $ column ) {
87- if ( $ form_id = get_post_meta ($ post_id , '_form_id ' , true ) ) {
87+ if ( 'form ' === $ column ) {
88+ if ( $ form_id = get_post_meta ( $ post_id , '_form_id ' , true ) ) {
8889 $ form = get_post ( $ form_id );
89- echo '<a href=" ' . get_edit_post_link ( $ form_id , '' ) . '" target="_blank"> ' . esc_html ( $ form ->post_title ) . '</a> ' ;
90+ echo '<a href=" ' . esc_url_raw ( get_edit_post_link ( $ form_id , '' ) ). '" target="_blank"> ' ;
91+ echo esc_html ( $ form ->post_title );
92+ echo '</a> ' ;
9093 }
9194 }
9295 }
@@ -111,35 +114,36 @@ function custom_columns_cpt( $columns ) {
111114 function form_filter_dropdown () {
112115 global $ pagenow ;
113116
114- $ allowed = array (" wplf-submission " ); // show filter on these post types (currently only one?)
115- $ allowed = apply_filters (" wplf-dropdown-filter " , $ allowed );
116- $ post_type = get_query_var (" post_type " );
117+ $ allowed = array ( ' wplf-submission ' ); // show filter on these post types (currently only one?)
118+ $ allowed = apply_filters ( ' wplf-dropdown-filter ' , $ allowed );
119+ $ post_type = get_query_var ( ' post_type ' );
117120
118- if ( 'edit.php ' != $ pagenow || !in_array ($ post_type , $ allowed) ) {
121+ if ( 'edit.php ' !== $ pagenow || ! in_array ( $ post_type , $ allowed, true ) ) {
119122 return ;
120123 }
121124
122- $ transient = get_transient (" wplf-form-filter " );
125+ $ transient = get_transient ( ' wplf-form-filter ' );
123126
124- if ( $ transient) {
127+ if ( $ transient ) {
125128 $ forms = $ transient ;
126- }
127-
128- else {
129+ } else {
129130 $ forms = get_posts ( array (
130131 'post_per_page ' => '-1 ' ,
131132 'post_type ' => 'wplf-form ' ,
132133 ) );
133134
134- set_transient (" wplf-form-filter " , $ forms , 15 * MINUTE_IN_SECONDS );
135+ set_transient ( ' wplf-form-filter ' , $ forms , 15 * MINUTE_IN_SECONDS );
135136 }
136137
137138?>
138139<label for="filter-by-form" class="screen-reader-text">Filter by form</label>
139140<select name="form" id="filter-by-form">
140- <option value="0"><?php _e ('All Forms ' , 'wp-libre-form ' ); ?> </option>
141- <?php foreach ( $ forms as $ form ) : ?>
142- <option value="<?php echo $ form ->ID ; ?> " <?php echo isset ( $ _REQUEST ['form ' ] ) && $ _REQUEST ['form ' ] == $ form ->ID ? 'selected ' : '' ; ?> ><?php echo $ form ->post_title ; ?> </option>
141+ <option value="0"><?php esc_html_e ( 'All Forms ' , 'wp-libre-form ' ); ?> </option>
142+ <?php foreach ( $ forms as $ form ) : ?>
143+ <option
144+ value="<?php echo intval ( $ form ->ID ); ?> "
145+ <?php echo isset ( $ _REQUEST ['form ' ] ) && intval ( $ _REQUEST ['form ' ] ) === $ form ->ID ? 'selected ' : '' ; ?>
146+ ><?php esc_html ( $ form ->post_title ); ?> </option>
143147 <?php endforeach ; ?>
144148</select>
145149<?php
@@ -151,15 +155,15 @@ function form_filter_dropdown() {
151155 function filter_by_form ( $ query ) {
152156 global $ pagenow ;
153157
154- if ( 'edit.php ' != $ pagenow ) {
158+ if ( 'edit.php ' != = $ pagenow ) {
155159 return $ query ;
156160 }
157161
158- if ( $ query ->get ( 'post_type ' ) != 'wplf-submission ' ) {
162+ if ( $ query ->get ( 'post_type ' ) != = 'wplf-submission ' ) {
159163 return $ query ;
160164 }
161165
162- if ( isset ( $ _REQUEST ['form ' ] ) && ! empty ( $ _REQUEST ['form ' ] ) ) {
166+ if ( isset ( $ _REQUEST ['form ' ] ) && ! empty ( $ _REQUEST ['form ' ] ) ) {
163167 $ query ->set ( 'meta_key ' , '_form_id ' );
164168 $ query ->set ( 'meta_value ' , intval ( $ _REQUEST ['form ' ] ) );
165169 }
@@ -168,16 +172,16 @@ function filter_by_form( $query ) {
168172 }
169173
170174 function register_wplf_submission_bulk_actions ( $ bulk_actions ) {
171- $ bulk_actions ['wplf_resend_copy ' ] = __ ('Resend email copy ' , 'wp-libre-form ' );
175+ $ bulk_actions ['wplf_resend_copy ' ] = __ ( 'Resend email copy ' , 'wp-libre-form ' );
172176 return $ bulk_actions ;
173177 }
174178
175179 function wplf_submission_bulk_action_handler ( $ redirect_to , $ doaction , $ post_ids ) {
176- if ( $ doaction !== 'wplf_resend_copy ' ) {
180+ if ( $ doaction !== 'wplf_resend_copy ' ) {
177181 return $ redirect_to ;
178182 }
179183
180- foreach ( $ post_ids as $ post_id ) {
184+ foreach ( $ post_ids as $ post_id ) {
181185 $ return = new stdClass ();
182186 $ return ->ok = 1 ;
183187
@@ -189,14 +193,18 @@ function wplf_submission_bulk_action_handler( $redirect_to, $doaction, $post_ids
189193 }
190194
191195 function wplf_submission_bulk_action_admin_notice () {
192- if ( !empty ( $ _REQUEST ['wplf_resent ' ] ) ) {
196+ if ( ! empty ( $ _REQUEST ['wplf_resent ' ] ) ) {
193197 $ count = intval ( $ _REQUEST ['wplf_resent ' ] );
194- printf ( '<div id="wplf-submission-bulk-resend-message" class="notice notice-success"><p> ' .
195- _n ( 'Resent email copy of %s submission. ' ,
196- 'Resent email copy of %s submissions. ' ,
197- $ count ,
198- 'wp-libre-form '
199- ) . '</p></div> ' , $ count );
198+ printf (
199+ '<div id="wplf-submission-bulk-resend-message" class="notice notice-success"><p> ' .
200+ esc_html__ (
201+ _n ( 'Resent email copy of %s submission. ' ,
202+ 'Resent email copy of %s submissions. ' ,
203+ $ count ),
204+ 'wp-libre-form '
205+ ) . '</p></div> ' ,
206+ intval ( $ count )
207+ );
200208 }
201209 }
202210
@@ -228,13 +236,13 @@ function metabox_submission() {
228236 <table class="wp-list-table widefat striped">
229237 <thead>
230238 <tr>
231- <th><strong><?php _e ( 'Field ' , 'wp-libre-form ' ); ?> </strong></th>
232- <th><strong><?php _e ( 'Value ' , 'wp-libre-form ' ); ?> </strong></th>
239+ <th><strong><?php esc_html_e ( 'Field ' , 'wp-libre-form ' ); ?> </strong></th>
240+ <th><strong><?php esc_html_e ( 'Value ' , 'wp-libre-form ' ); ?> </strong></th>
233241 </tr>
234242 </thead>
235243 <tbody>
236- <?php foreach ( $ fields as $ field ) : ?>
237- <?php if ( '_ ' != $ field [0 ] ) : ?>
244+ <?php foreach ( $ fields as $ field ) : ?>
245+ <?php if ( '_ ' != = $ field [0 ] ) : ?>
238246 <?php
239247 $ value = $ postmeta [ $ field ][0 ];
240248
@@ -243,9 +251,12 @@ function metabox_submission() {
243251
244252 // if the field ends with '_attachment' and there is an attachment url that corresponds to the id, show a link
245253 $ attachment_suffix = '_attachment ' ;
246- if ( substr ( $ field , -strlen ( $ attachment_suffix ) ) === $ attachment_suffix && wp_get_attachment_url ( $ value ) ) {
247- $ link_text = __ ( 'View Attachment ' , 'wp-libre-form ' );
248- $ possible_link = '<a target="_blank" href=" ' . get_edit_post_link ( $ value ) . '" style="float:right"> ' . $ link_text . '</a> ' ;
254+ if ( substr ( $ field , -strlen ( $ attachment_suffix ) ) === $ attachment_suffix ) {
255+ if ( wp_get_attachment_url ( $ value ) ) {
256+ $ link_text = __ ( 'View Attachment ' , 'wp-libre-form ' );
257+ $ possible_link = '<a target="_blank" href=" ' . get_edit_post_link ( $ value ) . '" style="float:right"> ' ;
258+ $ possible_link .= $ link_text . '</a> ' ;
259+ }
249260 }
250261
251262 // Show a link if the field corresponds to a URL
@@ -257,8 +268,8 @@ function metabox_submission() {
257268 }
258269 ?>
259270 <tr>
260- <th><strong><?php echo $ field ; ?> </strong> <?php echo $ possible_link ; ?> </th>
261- <?php if ( strlen ( $ value ) > 60 || strpos ( $ value , "\n" ) ) : ?>
271+ <th><strong><?php echo esc_html ( $ field ) ; ?> </strong> <?php echo wp_kses ( $ possible_link ) ; ?> </th>
272+ <?php if ( strlen ( $ value ) > 60 || strpos ( $ value , "\n" ) ) : ?>
262273 <td><textarea style="width:100%" readonly><?php echo esc_textarea ( $ value ); ?> </textarea></td>
263274 <?php else : ?>
264275 <td><input style="width:100%" type="text" value="<?php esc_attr_e ( $ value ); ?> " readonly></td>
0 commit comments