__( 'Permission denied.', 'aiforya-multi-author' ) ], 403 ); return false; } return true; } public function handle_assign_article(): void { if ( ! $this->guard( 'edit_others_posts' ) ) { return; } $post_id = isset( $_POST['post_id'] ) ? intval( wp_unslash( $_POST['post_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. $user_id = isset( $_POST['user_id'] ) ? intval( wp_unslash( $_POST['user_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. if ( ! $post_id || ! $user_id ) { wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'aiforya-multi-author' ) ], 400 ); return; } $user = get_user_by( 'id', $user_id ); if ( ! $user ) { wp_send_json_error( [ 'message' => __( 'User not found.', 'aiforya-multi-author' ) ], 404 ); return; } $workflow = Aiforya_Multi_Author_Workflow::get_instance(); if ( ! $workflow->assign_article( $post_id, $user_id ) ) { wp_send_json_error( [ 'message' => __( 'Assignment failed.', 'aiforya-multi-author' ) ], 500 ); return; } wp_send_json_success( [ 'message' => sprintf( /* translators: %s: author display name. */ __( 'Post assigned to %s.', 'aiforya-multi-author' ), $user->display_name ), 'post_id' => $post_id, 'user_id' => $user_id, 'user_name' => $user->display_name, ] ); } public function handle_change_status(): void { if ( ! $this->guard( 'edit_posts' ) ) { return; } $post_id = isset( $_POST['post_id'] ) ? intval( wp_unslash( $_POST['post_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. $new_status = isset( $_POST['new_status'] ) ? sanitize_text_field( wp_unslash( $_POST['new_status'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. if ( ! $post_id || '' === $new_status ) { wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'aiforya-multi-author' ) ], 400 ); return; } $workflow = Aiforya_Multi_Author_Workflow::get_instance(); if ( ! in_array( $new_status, $workflow->get_workflow_statuses(), true ) ) { wp_send_json_error( [ 'message' => __( 'Invalid status.', 'aiforya-multi-author' ) ], 400 ); return; } if ( ! $workflow->change_article_status( $post_id, $new_status ) ) { wp_send_json_error( [ 'message' => __( 'Status change failed.', 'aiforya-multi-author' ) ], 500 ); return; } wp_send_json_success( [ 'message' => __( 'Status updated.', 'aiforya-multi-author' ), 'post_id' => $post_id, 'new_status' => $new_status, ] ); } public function handle_add_coauthor(): void { if ( ! $this->guard( 'edit_others_posts' ) ) { return; } $post_id = isset( $_POST['post_id'] ) ? intval( wp_unslash( $_POST['post_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. $user_id = isset( $_POST['user_id'] ) ? intval( wp_unslash( $_POST['user_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. if ( ! $post_id || ! $user_id ) { wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'aiforya-multi-author' ) ], 400 ); return; } $db = Aiforya_Multi_Author_Db::get_instance(); $result = $db->add_coauthor( $post_id, $user_id ); if ( is_wp_error( $result ) ) { wp_send_json_error( [ 'message' => $result->get_error_message() ], 500 ); return; } wp_send_json_success( [ 'message' => __( 'Co-author added.', 'aiforya-multi-author' ), 'post_id' => $post_id, 'user_id' => $user_id ] ); } public function handle_remove_coauthor(): void { if ( ! $this->guard( 'edit_others_posts' ) ) { return; } $post_id = isset( $_POST['post_id'] ) ? intval( wp_unslash( $_POST['post_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. $user_id = isset( $_POST['user_id'] ) ? intval( wp_unslash( $_POST['user_id'] ) ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. if ( ! $post_id || ! $user_id ) { wp_send_json_error( [ 'message' => __( 'Invalid parameters.', 'aiforya-multi-author' ) ], 400 ); return; } $db = Aiforya_Multi_Author_Db::get_instance(); if ( ! $db->remove_coauthor( $post_id, $user_id ) ) { wp_send_json_error( [ 'message' => __( 'Removing the co-author failed.', 'aiforya-multi-author' ) ], 500 ); return; } wp_send_json_success( [ 'message' => __( 'Co-author removed.', 'aiforya-multi-author' ), 'post_id' => $post_id, 'user_id' => $user_id ] ); } public function handle_save_settings(): void { if ( ! $this->guard( 'manage_options' ) ) { return; } $db = Aiforya_Multi_Author_Db::get_instance(); $current = $db->get_settings(); $settings = [ 'show_byline' => ! empty( $_POST['show_byline'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. 'notifications_enabled' => ! empty( $_POST['notifications_enabled'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. 'cleanup_on_uninstall' => ! empty( $_POST['cleanup_on_uninstall'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verifie par guard() (check_ajax_referer 'aiforya_ma_admin'), appele en premiere instruction de ce handler. ]; $db->save_settings( wp_parse_args( $settings, $current ) ); wp_send_json_success( [ 'message' => __( 'Settings saved.', 'aiforya-multi-author' ) ] ); } }