ap_set_media_post_parent( integer|array $media_id, integer $post_parent, false|int $user_id = false )
Description #
Set parent post for an attachment.
Parameters #
- $media_idinteger | array (Required) Attachment ID.
- $post_parentinteger (Required) Post parent id.
- $user_idfalse | int (Optional) User id. Default value: false
Source #
File: includes/upload.php
function ap_set_media_post_parent( $media_id, $post_parent, $user_id = false ) { if ( ! is_array( $media_id ) ) { $media_id = array( $media_id ); } if ( false === $user_id ) { $user_id = get_current_user_id(); } foreach ( (array) $media_id as $id ) { $attach = get_post( $id ); if ( $attach && 'attachment' === $attach->post_type && $user_id == $attach->post_author ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual $postarr = array( 'ID' => $attach->ID, 'post_parent' => $post_parent, 'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $attach->guid ) ), ); wp_update_post( $postarr ); } } ap_update_post_attach_ids( $post_parent ); ap_update_user_temp_media_count( $user_id ); }
Expand full source code Collapse full source code View on GitHub: includes/upload.php:416
Add your comment