public/wordpress/wp-content/plugins/wp-courseware/includes/legacy/pages/page-question-pool.php
/**
 * Handle the question deletion from the question pool page.
 *
 * @since 1.0.0
 *
 * @param PageBuilder $page The page rendering object.
 */
Handle the question deletion from the question pool page.

@param PageBuilder $page The page rendering object.
Handle the question deletion from the question pool page . @param PageBuilder $page The page rendering object .
function WPCW_quizzes_handleQuestionDeletion( $page ) {
	global $wpcwdb, $wpdb;
	$wpdb->show_errors();
	$canDeleteQuestion = false;
	$current_user      = wp_get_current_user();
	if ( isset( $_GET['action'] ) && $_GET['action'] == 'delete' && isset( $_GET['question_id'] ) ) {
		$questionID      = $_GET['question_id'];
		$questionDetails = WPCW_questions_getQuestionDetails( $questionID );
		if ( $questionDetails ) {
			if ( user_can( $current_user->ID, 'manage_wpcw_settings' ) ) {
				$canDeleteQuestion = true;
			}
			if ( $questionDetails->question_author == $current_user->ID ) {
				$canDeleteQuestion = true;
			}
			$canDeleteQuestion = apply_filters( 'wpcw_back_permissions_user_can_delete_question', $canDeleteQuestion, $current_user->ID, $questionDetails );
			$canDeleteQuestion   = apply_filters( 'wpcw_permissions_user_can_edit_question', $canDeleteQuestion, $current_user, $questionDetails );
			$cantEditQuestionMsg = apply_filters( 'wpcw_permissions_user_can_edit_question_msg', esc_attr__( 'You are not permitted to delete this question.', 'wp-courseware' ), $current_user, $questionDetails );
			if ( ! $canDeleteQuestion ) {
				$page->showMessage( $cantEditQuestionMsg, true );
				return;
			}
			$question_tags = WPCW_questions_getQuestionDetails( $questionID, $getTagsToo = true );
			foreach ( $question_tags->tags as $question_tag ) {
				WPCW_questions_tags_removeTag( $questionID, $question_tag->question_tag_id );
			}
			$wpdb->query( $wpdb->prepare( "
				DELETE FROM $wpcwdb->quiz_qs_mapping
				WHERE question_id = %d
			", $questionDetails->question_id ) );
			$wpdb->query( $wpdb->prepare( "
				DELETE FROM $wpcwdb->quiz_qs
				WHERE question_id = %d
			", $questionDetails->question_id ) );
			$page->showMessage( sprintf( __( 'The question \'%s\' was successfully deleted.', 'wp-courseware' ), $questionDetails->question_question ) );
		} 
	} 
}
function WPCW_quizzes_handleQuestionDeletion ( $ page ) { global $ wpcwdb , $ wpdb ; $ wpdb -> show_errors ( ) ; $ canDeleteQuestion = false ; $ current_user = wp_get_current_user ( ) ; if ( isset ( $ _GET [ 'action' ] ) && $ _GET [ 'action' ] == 'delete' && isset ( $ _GET [ 'question_id' ] ) ) { $ questionID = $ _GET [ 'question_id' ] ; $ questionDetails = WPCW_questions_getQuestionDetails ( $ questionID ) ; if ( $ questionDetails ) { if ( user_can ( $ current_user -> ID , 'manage_wpcw_settings' ) ) { $ canDeleteQuestion = true ; } if ( $ questionDetails -> question_author == $ current_user -> ID ) { $ canDeleteQuestion = true ; } $ canDeleteQuestion = apply_filters ( 'wpcw_back_permissions_user_can_delete_question' , $ canDeleteQuestion , $ current_user -> ID , $ questionDetails ) ; $ canDeleteQuestion = apply_filters ( 'wpcw_permissions_user_can_edit_question' , $ canDeleteQuestion , $ current_user , $ questionDetails ) ; $ cantEditQuestionMsg = apply_filters ( 'wpcw_permissions_user_can_edit_question_msg' , esc_attr__ ( 'You are not permitted to delete this question.' , 'wp-courseware' ) , $ current_user , $ questionDetails ) ; if ( ! $ canDeleteQuestion ) { $ page -> showMessage ( $ cantEditQuestionMsg , true ) ; return ; } $ question_tags = WPCW_questions_getQuestionDetails ( $ questionID , $ getTagsToo = true ) ; foreach ( $ question_tags -> tags as $ question_tag ) { WPCW_questions_tags_removeTag ( $ questionID , $ question_tag -> question_tag_id ) ; } $ wpdb -> query ( $ wpdb -> prepare ( " 
				DELETE FROM  $ wpcwdb -> quiz_qs_mapping 
				WHERE question_id = %d
			 " , $ questionDetails -> question_id ) ) ; $ wpdb -> query ( $ wpdb -> prepare ( " 
				DELETE FROM  $ wpcwdb -> quiz_qs 
				WHERE question_id = %d
			 " , $ questionDetails -> question_id ) ) ; $ page -> showMessage ( sprintf ( __ ( 'The question \'%s\' was successfully deleted.' , 'wp-courseware' ) , $ questionDetails -> question_question ) ) ; } } }
Handle the question deletion from the question pool page.
Handle the question deletion from the question pool page .
// Vars // Check that the question exists and deletion has been requested // Only do deletion if question details are valid. // Check permissions, this condition allows admins to view all modules even if they are not the author. // Check Author // Back compat filter // Add filters to override // Display message if no access. // Get tags for questions // Remove tags for each question // Delete question from question map // Finally delete question itself // end of if $questionDetails // end of check for deletion action