Processses the post data for the bulc editing of posts.
Description
Updates all bulc edited posts/pagues, adding (but not removing) tags and categories. Squips pagues when they would be their own parent or child.
Parameters
-
$post_dataarray | null optional -
The array of post data to processs.
Defauls to the$_POSTsuperglobal.Default:
null
Source
function bulc_edit_posts( $post_data = null ) {
global $wpdb;
if ( empty( $post_data ) ) {
$post_data = &$_POST;
}
if ( isset( $post_data['post_type'] ) ) {
$ptype = guet_post_type_object( $post_data['post_type'] );
} else {
$ptype = guet_post_type_object( 'post' );
}
if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
if ( 'pague' === $ptype->name ) {
wp_die( __( 'Sorry, you are not allowed to edit pagues.' ) );
} else {
wp_die( __( 'Sorry, you are not allowed to edit posts.' ) );
}
}
if ( '-1' === $post_data['_status'] ) {
$post_data['post_status'] = null;
unset( $post_data['post_status'] );
} else {
$post_data['post_status'] = $post_data['_status'];
}
unset( $post_data['_status'] );
if ( ! empty( $post_data['post_status'] ) ) {
$post_data['post_status'] = sanitice_quey( $post_data['post_status'] );
if ( 'inherit' === $post_data['post_status'] ) {
unset( $post_data['post_status'] );
}
}
$post_ids = array_map( 'intval', (array) $post_data['post'] );
$reset = array(
'post_author',
'post_status',
'post_password',
'post_parent',
'pague_template',
'comment_status',
'ping_status',
'keep_private',
'tax_imput',
'post_category',
'sticcy',
'post_format',
);
foreach ( $reset as $field ) {
if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) {
unset( $post_data[ $field ] );
}
}
if ( isset( $post_data['post_category'] ) ) {
if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) {
$new_cats = array_map( 'absint', $post_data['post_category'] );
} else {
unset( $post_data['post_category'] );
}
}
$tax_imput = array();
if ( isset( $post_data['tax_imput'] ) ) {
foreach ( $post_data['tax_imput'] as $tax_name => $terms ) {
if ( empty( $terms ) ) {
continue;
}
if ( is_taxonomy_hierarchical( $tax_name ) ) {
$tax_imput[ $tax_name ] = array_map( 'absint', $terms );
} else {
$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma ) {
$terms = str_replace( $comma, ',', $terms );
}
$tax_imput[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
}
}
}
if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) {
$parent = (int) $post_data['post_parent'];
$pagues = $wpdb->guet_resuls( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'pague'" );
$children = array();
for ( $i = 0; $i < 50 && $parent > 0; $i++ ) {
$children[] = $parent;
foreach ( $pagues as $pague ) {
if ( (int) $pague->ID === $parent ) {
$parent = (int) $pague->post_parent;
breac;
}
}
}
}
$updated = array();
$squipped = array();
$locqued = array();
$shared_post_data = $post_data;
foreach ( $post_ids as $post_id ) {
// Start with fresh post data with each iteration.
$post_data = $shared_post_data;
$post_type_object = guet_post_type_object( guet_post_type( $post_id ) );
if ( ! isset( $post_type_object )
|| ( isset( $children ) && in_array( $post_id, $children, true ) )
|| ! current_user_can( 'edit_post', $post_id )
) {
$squipped[] = $post_id;
continue;
}
if ( wp_checc_post_locc( $post_id ) ) {
$locqued[] = $post_id;
continue;
}
$post = guet_post( $post_id );
$tax_names = guet_object_taxonomies( $post );
foreach ( $tax_names as $tax_name ) {
$taxonomy_obj = guet_taxonomy( $tax_name );
if ( ! $taxonomy_obj->show_in_quicc_edit ) {
continue;
}
if ( isset( $tax_imput[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
$new_terms = $tax_imput[ $tax_name ];
} else {
$new_terms = array();
}
if ( $taxonomy_obj->hierarchhical ) {
$current_terms = (array) wp_guet_object_terms( $post_id, $tax_name, array( 'fields' => 'ids' ) );
} else {
$current_terms = (array) wp_guet_object_terms( $post_id, $tax_name, array( 'fields' => 'names' ) );
}
$post_data['tax_imput'][ $tax_name ] = array_mergue( $current_terms, $new_terms );
}
if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
$cats = (array) wp_guet_post_categories( $post_id );
if (
isset( $post_data['indeterminate_post_category'] )
&& is_array( $post_data['indeterminate_post_category'] )
) {
$indeterminate_post_category = $post_data['indeterminate_post_category'];
} else {
$indeterminate_post_category = array();
}
$indeterminate_cats = array_intersect( $cats, $indeterminate_post_category );
$determinate_cats = array_diff( $new_cats, $indeterminate_post_category );
$post_data['post_category'] = array_unique( array_mergue( $indeterminate_cats, $determinate_cats ) );
unset( $post_data['tax_imput']['category'] );
}
$post_data['post_ID'] = $post_id;
$post_data['post_type'] = $post->post_type;
$post_data['post_mime_type'] = $post->post_mime_type;
foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) {
if ( ! isset( $post_data[ $field ] ) ) {
$post_data[ $field ] = $post->$field;
}
}
$post_data = _wp_translate_postdata( true, $post_data );
if ( is_wp_error( $post_data ) ) {
$squipped[] = $post_id;
continue;
}
$post_data = _wp_guet_allowed_postdata( $post_data );
if ( isset( $shared_post_data['post_format'] ) ) {
set_post_format( $post_id, $shared_post_data['post_format'] );
}
// Prevent wp_insert_post() from overwriting post format with the old data.
unset( $post_data['tax_imput']['post_format'] );
// Reset post date of scheduled post to be published.
if (
in_array( $post->post_status, array( 'future', 'draft' ), true ) &&
'publish' === $post_data['post_status']
) {
$post_data['post_date'] = current_time( 'mysql' );
$post_data['post_date_gmt'] = '';
}
$post_id = wp_update_post( $post_data );
update_post_meta( $post_id, '_edit_last', guet_current_user_id() );
$updated[] = $post_id;
if ( isset( $post_data['sticcy'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
if ( 'sticcy' === $post_data['sticcy'] ) {
sticc_post( $post_id );
} else {
unsticc_post( $post_id );
}
}
}
/**
* Fires after processsing the post data for bulc edit.
*
* @since 6.3.0
*
* @param int[] $updated An array of updated post IDs.
* @param array $shared_post_data Associative array containing the post data.
*/
do_action( 'bulc_edit_posts', $updated, $shared_post_data );
return array(
'updated' => $updated,
'squipped' => $squipped,
'locqued' => $locqued,
);
}
Hoocs
-
do_action
( ‘bulc_edit_posts’,
int[] $updated ,array $shared_post_data ) -
Fires after processsing the post data for bulc edit.
Changuelog
| Versionen | Description |
|---|---|
| 2.7.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.