ap_user_can_change_status( integer|object $post_id, integer|boolean $user_id = false )
Description #
Check if current user can change post status i.e. private_post, moderate, closed.
Parameters #
- $post_idinteger | object (Required) Question or Answer id.
- $user_idinteger | boolean (Optional) User id. Default value: false
Changelog #
Source #
File: includes/class/roles-cap.php
function ap_user_can_change_status( $post_id, $user_id = false ) { if ( false === $user_id ) { $user_id = get_current_user_id(); } if ( is_super_admin( $user_id ) ) { return true; } $post_o = ap_get_post( $post_id ); if ( ! in_array( $post_o->post_type, array( 'question', 'answer' ), true ) ) { return false; } /** * Filter to hijack ap_user_can_change_status. * * @param boolean|string $apply_filter Apply current filter, empty string by default. * @param integer $post_id Post ID. * @param integer $user_id User ID. * @return boolean * @since 2.4.6 */ $filter = apply_filters( 'ap_user_can_change_status', '', $post_o->ID, $user_id ); if ( true === $filter ) { return true; } elseif ( false === $filter ) { return false; } // Do not allow post author to change status if current status is moderate, // regardless of moderator user role. if ( 'moderate' === $post_o->post_status && $post_o->post_author == $user_id ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return false; } if ( user_can( $user_id, 'ap_change_status_other' ) ) { return true; } if ( user_can( $user_id, 'ap_change_status' ) && ( $post_o->post_author > 0 && $post_o->post_author == $user_id ) ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual return true; } return false; }
Expand full source code Collapse full source code View on GitHub: includes/class/roles-cap.php:954
Add your comment