true, 'edit_posts' => true, 'edit_published_posts' => true, 'delete_posts' => false, 'publish_posts' => false, 'upload_files' => true, ] ); add_role( 'aiforya_ma_editor', __( 'AIFORYA Editor', 'aiforya-multi-author' ), [ 'read' => true, 'edit_posts' => true, 'edit_published_posts' => true, 'edit_others_posts' => true, 'delete_posts' => true, 'delete_others_posts' => true, 'publish_posts' => false, 'upload_files' => true, ] ); add_role( 'aiforya_ma_publisher', __( 'Publisher AIFORYA', 'aiforya-multi-author' ), [ 'read' => true, 'edit_posts' => true, 'edit_published_posts' => true, 'edit_others_posts' => true, 'delete_posts' => true, 'delete_others_posts' => true, 'delete_published_posts' => true, 'publish_posts' => true, 'upload_files' => true, 'manage_categories' => true, ] ); } public function remove_custom_roles(): void { remove_role( 'aiforya_ma_writer' ); remove_role( 'aiforya_ma_editor' ); remove_role( 'aiforya_ma_publisher' ); } /** * @return array Slug de rôle => libellé lisible. */ public function get_editorial_roles(): array { return [ 'aiforya_ma_writer' => __( 'Writer', 'aiforya-multi-author' ), 'aiforya_ma_editor' => __( 'Editor', 'aiforya-multi-author' ), 'aiforya_ma_publisher' => __( 'Publisher', 'aiforya-multi-author' ), ]; } /* --------------------------------------------------------------------- * Assignation * ------------------------------------------------------------------- */ public function assign_article( int $post_id = 0, int $user_id = 0 ): bool { if ( empty( $post_id ) || empty( $user_id ) ) { return false; } if ( ! get_post( $post_id ) || ! get_user_by( 'id', $user_id ) ) { return false; } $db = Aiforya_Multi_Author_Db::get_instance(); $result = $db->create_assignment( $post_id, $user_id, 'draft' ); if ( is_wp_error( $result ) ) { return false; } wp_update_post( [ 'ID' => $post_id, 'post_author' => $user_id ] ); do_action( 'aiforya_ma_article_assigned', $post_id, $user_id, $result ); return true; } /* --------------------------------------------------------------------- * Statuts * ------------------------------------------------------------------- */ public function change_article_status( int $post_id = 0, string $new_status = '' ): bool { if ( empty( $post_id ) || '' === $new_status ) { return false; } if ( ! get_post( $post_id ) ) { return false; } $db = Aiforya_Multi_Author_Db::get_instance(); $assignment = $db->get_assignment_by_post( $post_id ); if ( ! $assignment ) { return false; } if ( ! in_array( $new_status, $this->get_workflow_statuses(), true ) ) { return false; } if ( ! $db->update_assignment_status( $post_id, $new_status ) ) { return false; } if ( 'published' === $new_status ) { wp_update_post( [ 'ID' => $post_id, 'post_status' => 'publish' ] ); } do_action( 'aiforya_ma_status_changed', $post_id, $new_status, $assignment ); return true; } /** * @return string[] Liste ordonnée des slugs de statut. */ public function get_workflow_statuses(): array { return array_keys( $this->get_status_labels() ); } /** * @return array Slug de statut => libellé lisible. */ public function get_status_labels(): array { return [ 'draft' => __( 'Writing', 'aiforya-multi-author' ), 'in_progress' => __( 'In progress', 'aiforya-multi-author' ), 'ready_for_review' => __( 'In review', 'aiforya-multi-author' ), 'revision_requested' => __( 'Revision requested', 'aiforya-multi-author' ), 'approved' => __( 'Approved', 'aiforya-multi-author' ), 'published' => __( 'Published', 'aiforya-multi-author' ), 'archived' => __( 'Archived', 'aiforya-multi-author' ), ]; } }