패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.2.1

flutter_wordpress

이 라이브러리는 애플리케이션이 WordPress 웹사이트와 상호 작용할 수 있도록 WordPress REST-API-V2를 사용합니다.

30일 다운로드
65
좋아요
120
Pub 점수
40

패키지 설치

flutter pub add flutter_wordpress

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

flutter_wordpress 패키지는 Flutter 애플리케이션에서 WordPress REST API v2를 사용하여 WordPress 웹사이트와 상호작용할 수 있도록 합니다. 이는 게시물, 페이지, 댓글 및 기타 콘텐츠를 구조화된 방식으로 가져오는 방법을 제공하여 WordPress 백엔드에서 데이터를 가져오는 동적 앱을 쉽게 만들 수 있게 해줍니다. 복잡한 커스텀 API 없이 기존의 WordPress 사이트를 모바일 앱에 통합하고자 하는 개발자를 위해 설계되었습니다.

사용 사례

  • WordPress에서 블로그 게시물 가져오기
  • 페이지 및 사용자 지정 콘텐츠 표시
  • 사용자 댓글 통합
  • WordPress 사이트를 위한 모바일 앱 빌드
  • 웹과 모바일 간의 콘텐츠 동기화

주요 기능

  • REST API v2 통합
  • 간단한 데이터 가져오기 방법
  • 게시물, 페이지 및 댓글을 지원합니다
  • 경량이며 구현하기 쉬움
  • 표준 워드프레스 설정과 호환됩니다

적합한 대상

  • WordPress를 사용하는 모바일 앱 개발자
  • 콘텐츠 기반 앱
  • 블로그 플랫폼
  • 공개 콘텐츠를 포함한 웹사이트
  • 빠른 워드프레스 통합을 원하는 개발자

고려 사항

  • REST API가 활성화된 WordPress 사이트 필요
  • 인증되지 않은 경우 공용 엔드포인트로 제한됨
  • 내장 캐싱 또는 오프라인 지원 없음
  • 외부 서버의 안정성에 의존
  • 개인 콘텐츠에 대한 인증에는 추가 설정이 필요합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Flutter Wordpress

pub.dev

This library uses WordPress REST API V2 to provide a way for your application to interact with your WordPress website.

Tutorial - by Ritesh Sharma

Screenshots

Requirements

For authentication and usage of administrator level REST APIs, you need to use either of the two popular authentication plugins in your WordPress site:

  1. Application Passwords
  2. JWT Authentication for WP REST API (recommended)

Getting Started

1. Import library
First:

Find your pubspec.yaml in the root of your project and add flutter_wordpress: ^0.2.0 under dependencies:

Second:
import 'package:flutter_wordpress/flutter_wordpress.dart' as wp;
2. Instantiate WordPress class
wp.WordPress wordPress;

// adminName and adminKey is needed only for admin level APIs
wordPress = wp.WordPress(
  baseUrl: 'http://localhost',
  authenticator: wp.WordPressAuthenticator.JWT,
  adminName: '',
  adminKey: '',
);
3. Authenticate User
Future<wp.User> response = wordPress.authenticateUser(
  username: 'ChiefEditor',
  password: 'chiefeditor@123',
);

response.then((user) {
  createPost(user);
}).catchError((err) {
  print('Failed to fetch user: $err');
});
4. Fetch Posts
Future<List<wp.Post>> posts = wordPress.fetchPosts(
  postParams: wp.ParamsPostList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 20,
    order: wp.Order.desc,
    orderBy: wp.PostOrderBy.date,
  ),
  fetchAuthor: true,
  fetchFeaturedMedia: true,
  fetchComments: true,
  postType: 'post'
);
5. Fetch Users
Future<List<wp.User>> users = wordPress.fetchUsers(
  params: wp.ParamsUserList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 30,
    order: wp.Order.asc,
    orderBy: wp.UsersOrderBy.name,
    roles: ['subscriber'],
  ),
);
6. Fetch Comments
Future<List<wp.Comment>> comments = wordPress.fetchComments(
  params: wp.ParamsCommentList(
    context: wp.WordPressContext.view,
    pageNum: 1,
    perPage: 30,
    includePostIDs: [1],
  ),
);
7. Create User
Future<void> createUser({@required String email, @required String username, @required String password, @required List<String> roles}) async {
    await widget.wordPress.createUser(
      user: wp.User(
        email: email,
        password: password,
        username: username,
        roles: roles
      )
    ).then((p) {
      print('User created successfully ${p}');
    }).catchError((err) {
      print('Failed to create user: $err');
    });
  }
8. Create Post
  void createPost({@required wp.User user}) {
    final post = widget.wordPress.createPost(
      post: new wp.Post(
        title: 'First post as a Chief Editor',
        content: 'Blah! blah! blah!',
        excerpt: 'Discussion about blah!',
        authorID: user.id,
        commentStatus: wp.PostCommentStatus.open,
        pingStatus: wp.PostPingStatus.closed,
        status: wp.PostPageStatus.publish,
        format: wp.PostFormat.standard,
        sticky: true,
      ),
    );

    post.then((p) {
      print('Post created successfully with ID: ${p.id}');
    }).catchError((err) {
      print('Failed to create post: $err');
    });
  }
9. create Comment
  void createComment({@required int userId, @required int postId}) {
    final comment = widget.wordPress.createComment(
      comment: new wp.Comment(
        author: userId,
        post: postId,
        content: "First!",
        parent: 0,
      ),
    );

    comment.then((c) {
      print('Comment successfully posted with ID: ${c.id}');
    }).catchError((err) {
      print('Failed to comment: $err');
    });
  }
10. Update Comment
Future<void> updateComment({@required int id, @required int postId, @required wp.User user}) async {
    await widget.wordPress.updateComment(
      comment: new wp.Comment(
        content: "Comment Updated2!",
        author: user.id,
        post: postId,
      ),
      id: id,
    ).then((c) {
      print('Comment updated successfully "$c"');
    }).catchError((err) {
      print('Failed to update Comment: $err');
    });
  }
11. Update Post
Future<void> updatePost({@required int id, @required int userId}) async {
    await widget.wordPress.updatePost(
      post: new wp.Post(
        title: 'First post as a Chief Editor',
        content: 'Blah! blah! blah!',
        excerpt: 'Discussion about blah!',
        authorID: userId,
        commentStatus: wp.PostCommentStatus.open,
        pingStatus: wp.PostPingStatus.closed,
        status: wp.PostPageStatus.publish,
        format: wp.PostFormat.standard,
        sticky: true,
      ),
      id: id, //
    ).then((p) {
      print('Post updated successfully with ID ${p}');
    }).catchError((err) {
      print('Failed to update post: $err');
    });
  }
12. Update User
Future<void> updateUser({@required int id, @required String username, @required String email}) async {
    await widget.wordPress.updateUser(
      user: new wp.User(
        description: "This is description for this user",
        username: username,
        id: id,
        email: email
      ),
      id: id,
    ).then((u) {
      print('User updated successfully $u');
    }).catchError((err) {
      print('Failed to update User: $err');
    });
  }
13. Delete Comment
Future<void> deleteComment({@required int id}) async {
    await widget.wordPress.deleteComment(id: id).then((c) {
      print('Comment Deleted successfully: $c');
    }).catchError((err) {
      print('Failed to Delete comment: $err');
    });
  }
14. Delete Post
  Future<void> deletePost({@required int id}) async {
    await widget.wordPress.deletePost(id: id).then((p) {
      print('Post Deleted successfully: $p');
    }).catchError((err) {
      print('Failed to Delete post: $err');
    });
  }
15. Delete User
  Future<void> deleteUser({@required int id, @required int reassign}) async {
    await widget.wordPress.deleteUser(id: id, reassign: reassign).then((u) {
      print('User Deleted successfully: $u');
    }).catchError((err) {
      print('Failed to Delete user: $err');
    });
  }
16. Upload Media
  uploadMedia(File image) async {
  var media = await wordPress.uploadMedia(image).then((m) {
    print('Media uploaded successfully: $m');
  }).catchError((err) {
    print('Failed to upload Media: $err');
  });
  int mediaID = media['id'];  
}

Future Work

  1. Implementing OAuth 2.0 authentication.

Contributors

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.