@@ -89,18 +89,28 @@ public function rewrite_bulk_action_handler( $redirect_to, $doaction, $post_ids
8989 }
9090
9191 $ counter = 0 ;
92+ $ skipped = 0 ;
9293 if ( \is_array ( $ post_ids ) ) {
9394 foreach ( $ post_ids as $ post_id ) {
9495 $ post = \get_post ( $ post_id );
95- if ( ! empty ( $ post ) && $ this ->permissions_helper ->should_rewrite_and_republish_be_allowed ( $ post ) ) {
96- $ new_post_id = $ this ->post_duplicator ->create_duplicate_for_rewrite_and_republish ( $ post );
97- if ( ! \is_wp_error ( $ new_post_id ) ) {
98- ++$ counter ;
99- }
96+ if ( empty ( $ post ) || ! $ this ->permissions_helper ->should_rewrite_and_republish_be_allowed ( $ post ) ) {
97+ continue ;
98+ }
99+ if ( ! \current_user_can ( 'edit_post ' , $ post_id ) ) {
100+ ++$ skipped ;
101+ continue ;
102+ }
103+ $ new_post_id = $ this ->post_duplicator ->create_duplicate_for_rewrite_and_republish ( $ post );
104+ if ( ! \is_wp_error ( $ new_post_id ) ) {
105+ ++$ counter ;
100106 }
101107 }
102108 }
103- return \add_query_arg ( 'bulk_rewriting ' , $ counter , $ redirect_to );
109+ $ redirect_to = \add_query_arg ( 'bulk_rewriting ' , $ counter , $ redirect_to );
110+ if ( $ skipped > 0 ) {
111+ $ redirect_to = \add_query_arg ( 'bulk_rewriting_skipped ' , $ skipped , $ redirect_to );
112+ }
113+ return $ redirect_to ;
104114 }
105115
106116 /**
@@ -118,21 +128,32 @@ public function clone_bulk_action_handler( $redirect_to, $doaction, $post_ids )
118128 }
119129
120130 $ counter = 0 ;
131+ $ skipped = 0 ;
121132 if ( \is_array ( $ post_ids ) ) {
122133 foreach ( $ post_ids as $ post_id ) {
123134 $ post = \get_post ( $ post_id );
124- if ( ! empty ( $ post ) && ! $ this ->permissions_helper ->is_rewrite_and_republish_copy ( $ post ) ) {
125- if ( \intval ( \get_option ( 'duplicate_post_copychildren ' ) !== 1 )
126- || ! \is_post_type_hierarchical ( $ post ->post_type )
127- || ( \is_post_type_hierarchical ( $ post ->post_type ) && ! Utils::has_ancestors_marked ( $ post , $ post_ids ) )
128- ) {
129- if ( ! \is_wp_error ( \duplicate_post_create_duplicate ( $ post ) ) ) {
130- ++$ counter ;
131- }
132- }
135+ if ( empty ( $ post ) || $ this ->permissions_helper ->is_rewrite_and_republish_copy ( $ post ) ) {
136+ continue ;
137+ }
138+ if ( \intval ( \get_option ( 'duplicate_post_copychildren ' ) ) === 1
139+ && \is_post_type_hierarchical ( $ post ->post_type )
140+ && Utils::has_ancestors_marked ( $ post , $ post_ids )
141+ ) {
142+ continue ;
143+ }
144+ if ( ! \current_user_can ( 'edit_post ' , $ post_id ) ) {
145+ ++$ skipped ;
146+ continue ;
147+ }
148+ if ( ! \is_wp_error ( \duplicate_post_create_duplicate ( $ post ) ) ) {
149+ ++$ counter ;
133150 }
134151 }
135152 }
136- return \add_query_arg ( 'bulk_cloned ' , $ counter , $ redirect_to );
153+ $ redirect_to = \add_query_arg ( 'bulk_cloned ' , $ counter , $ redirect_to );
154+ if ( $ skipped > 0 ) {
155+ $ redirect_to = \add_query_arg ( 'bulk_cloned_skipped ' , $ skipped , $ redirect_to );
156+ }
157+ return $ redirect_to ;
137158 }
138159}
0 commit comments