ap_user_can_edit_question( boolean|integer $post_id = false, boolean|integer $user_id = false )
Description #
Check if user can edit a question.
Parameters #
- $post_idboolean | integer (Optional) Question ID. Default value: false
- $user_idboolean | integer (Optional) User ID. Default value: false
Changelog #
Source #
File: includes/class/roles-cap.php
function ap_user_can_edit_question( $post_id = false, $user_id = false ) { if ( false === $user_id ) { $user_id = get_current_user_id(); } if ( is_super_admin( $user_id ) || user_can( $user_id, 'ap_edit_others_question' ) ) { return true; } if ( false !== $post_id ) { $question = ap_get_post( $post_id ); } else { global $post; $question = $post; } // Check post_type. if ( ! $question || 'question' !== $question->post_type ) { return false; } /** * Filter to hijack ap_user_can_edit_question. This filter will be applied if filter * returns a boolean value. To baypass 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_question', '', $question->ID, $user_id ); if ( true === $filter ) { return true; } elseif ( false === $filter ) { return false; } // Do not allow to edit if moderate. if ( 'moderate' === $question->post_status ) { return false; } if ( ! ap_user_can_read_question( $question->ID, $user_id ) ) { return false; } if ( $user_id == $question->post_author && user_can( $user_id, 'ap_edit_question' ) ) { // 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:413
Add your comment