-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[COMPONENTS] wordpress_com. Actions + sources #16461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9964c4a
Initialization
SokolovskyiK b780b29
Add [COMPONENTS] Wordpress.com
SokolovskyiK 79d8a49
CodeRabbit change
SokolovskyiK 2a40c5d
update bnpm-lock.yaml
SokolovskyiK 8fbc421
CodeRabbit change 2
SokolovskyiK fb9ec32
Lint: fix eslint errors in WordPress.com components
SokolovskyiK 68d1235
Fix keys
SokolovskyiK 9e00ce2
Minor fix
SokolovskyiK f62e918
updates
michelle0927 7ed271c
doc link
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
components/wordpress_com/actions/create-post/create-post.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import wordpress from "../../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wordpress_com-create-post", | ||
| name: "Create New Post", | ||
| description: "Creates a new post on a WordPress.com site. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wordpress, | ||
| site: { | ||
| propDefinition: [ | ||
| wordpress, | ||
| "siteId", | ||
| ], | ||
| }, | ||
| title: { | ||
| type: "string", | ||
| label: "Post Title", | ||
| description: "The title of the post", | ||
| }, | ||
| content: { | ||
| type: "string", | ||
| label: "Post Content", | ||
| description: "The content of the post (HTML or text)", | ||
| }, | ||
| status: { | ||
| type: "string", | ||
| label: "Status", | ||
| description: "The status of the post", | ||
| options: [ | ||
| "publish", | ||
| "draft", | ||
| "private", | ||
| "pending", | ||
| ], | ||
| default: "draft", | ||
| optional: true, | ||
| }, | ||
| type: { | ||
| type: "string", | ||
| label: "Post Type", | ||
| description: "The type of the post (post or page). For attachments, use the 'Upload Media' action.", | ||
| options: [ | ||
| { | ||
| label: "Post", | ||
| value: "post", | ||
| }, | ||
| { | ||
| label: "Page", | ||
| value: "page", | ||
| }, | ||
| ], | ||
| default: "post", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const warnings = []; | ||
|
|
||
| const { | ||
| site, | ||
| wordpress, | ||
| ...fields | ||
| } = this; | ||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
| response = await wordpress.createWordpressPost({ | ||
| $, | ||
| site, | ||
| data: { | ||
| ...fields, | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| wordpress.throwCustomError("Could not create post", error, warnings); | ||
| }; | ||
|
|
||
| $.export("$summary", `Post successfully created. ID = ${response?.ID}` + "\n- " + warnings.join("\n- ")); | ||
| }, | ||
| }; | ||
|
|
54 changes: 54 additions & 0 deletions
54
components/wordpress_com/actions/delete-post/delete-post.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import wordpress from "../../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wordpress_com-delete-post", | ||
| name: "Delete Post", | ||
| description: "Deletes a post. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/%24post_ID/delete/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wordpress, | ||
| site: { | ||
| propDefinition: [ | ||
| wordpress, | ||
| "siteId", | ||
| ], | ||
| }, | ||
| postId: { | ||
| propDefinition: [ | ||
| wordpress, | ||
| "postId", | ||
| (c) => ({ | ||
| site: c.site, | ||
| }), | ||
| ], | ||
| description: "The ID of the post you want to delete", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const warnings = []; | ||
|
|
||
| const { | ||
| site, | ||
| wordpress, | ||
| postId, | ||
| } = this; | ||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
| response = await wordpress.deleteWordpressPost({ | ||
| $, | ||
| site, | ||
| postId, | ||
| }); | ||
| } catch (error) { | ||
| wordpress.throwCustomError("Could not delete post", error, warnings); | ||
| }; | ||
|
|
||
| $.export("$summary", `Post ID = ${response?.ID} successfully deleted.` + "\n- " + warnings.join("\n- ")); | ||
| }, | ||
| }; | ||
|
|
||
87 changes: 87 additions & 0 deletions
87
components/wordpress_com/actions/upload-media/upload-media.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { prepareMediaUpload } from "../../common/utils.mjs"; | ||
| import wordpress from "../../wordpress_com.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "wordpress_com-upload-media", | ||
| name: "Upload Media", | ||
| description: "Uploads a media file from a URL to the specified WordPress.com site. [See the documentation](https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/new/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| wordpress, | ||
| site: { | ||
| propDefinition: [ | ||
| wordpress, | ||
| "siteId", | ||
| ], | ||
| }, | ||
| media: { | ||
| type: "any", | ||
| label: "Media URL", | ||
| description: "A direct media URL, or a FormData object with the file attached under the field name 'media[]'.", | ||
| }, | ||
| title: { | ||
| type: "string", | ||
| label: "Title", | ||
| description: "Title of the media", | ||
| optional: true, | ||
| }, | ||
| caption: { | ||
| type: "string", | ||
| label: "Caption", | ||
| description: "Optional caption text to associate with the uploaded media", | ||
| optional: true, | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| description: "A description of the uploaded media", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const warnings = []; | ||
|
|
||
| const | ||
| { | ||
| wordpress, | ||
| site, | ||
| media, | ||
| ...fields | ||
| } = this; | ||
|
|
||
| warnings.push(...wordpress.checkDomainOrId(site)); | ||
|
|
||
| let form; | ||
|
|
||
| // If not form data | ||
| if (wordpress.isFormData(media)) { | ||
| form = media; | ||
|
|
||
| } else { | ||
| form = await prepareMediaUpload(media, fields, $); | ||
| } | ||
|
|
||
| let response; | ||
|
|
||
| try { | ||
| response = await wordpress.uploadWordpressMedia({ | ||
| $, | ||
| contentType: form.getHeaders()["content-type"], | ||
| site, | ||
| data: form, | ||
| }); | ||
|
|
||
| const media = response.media[0]; | ||
|
|
||
| $.export("$summary", `Media "${media.title}" uploaded successfully (ID: ${media.ID})` + "\n- " + warnings.join("\n- ")); | ||
|
|
||
| console.log(response); | ||
| return response; | ||
|
|
||
SokolovskyiK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (error) { | ||
| wordpress.throwCustomError("Failed to upload media", error, warnings); | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.