ap_user_can_edit_answer( integer $post_id, boolean|integer $user_id = false )
Description #
Check if a user can edit answer on a question.
Parameters #
- $post_idinteger (Required) Answer id.
- $user_idboolean | integer (Optional) User id. Default value: false
Source #
File: includes/class/roles-cap.php
function ap_user_can_edit_answer( $post_id, $user_id = false ) { if ( false === $user_id ) { $user_id = get_current_user_id(); } if ( user_can( $user_id, 'ap_edit_others_answer' ) || is_super_admin( $user_id ) ) { return true; } $answer = ap_get_post( $post_id ); /** * Filter to hijack ap_user_can_edit_answer. This filter will be applied if filter * returns a boolean value. To bypass return an empty string. * * @param string|boolean $filter Apply this filter. * @param integer $question_id Question ID. * @param integer $user_id User ID. */ $filter = apply_filters( 'ap_user_can_edit_answer', '', $answer->ID, $user_id ); if ( true === $filter ) { return true; } elseif ( false === $filter ) { return false; } // Do not allow to edit if moderate. if ( 'moderate' === $answer->post_status ) { return false; } // No point to let user edit answer if they cannot read. if ( ! ap_user_can_read_answer( $answer->ID, $user_id ) ) { return false; } if ( $user_id == $answer->post_author && user_can( $user_id, 'ap_edit_answer' ) ) { // 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:358
Add your comment