CLI tool for submitting posts to WordPress through its REST API using curl.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

45 Zeilen
1.2 KiB

  1. #!/bin/bash
  2. # WordPress posting script
  3. # config:
  4. EDITOR=vim
  5. USER="" # WP user to create the post
  6. PASSWORD="" # application password generated for your WP user
  7. SERVER="" # server hostname, optionally with subdirectories
  8. STATUS="draft" # one of publish,future,draft,pending,private
  9. CATEGORIES="" # comma separated integer IDs of categories
  10. TAGS="" # comma separated integer IDs of tags
  11. TMPFILE=/tmp/wordpress-post.txt # location of a temporary file with the post text
  12. source ~/.config/wordpress-rest-curl/config.sh
  13. # let the user create the post
  14. $EDITOR $TMPFILE || exit 1
  15. # load the file if it exists
  16. [[ -e $TMPFILE ]] || exit 1
  17. CONTENT=`cat $TMPFILE`
  18. echo "--- START POST ---"
  19. echo $CONTENT
  20. echo "--- END POST ---"
  21. echo "User: $USER"
  22. echo "Server: $SERVER"
  23. echo "Status: $STATUS"
  24. echo "Categories: $CATEGORIES"
  25. echo "Tags: $TAGS"
  26. echo
  27. read -p "Press enter to confirm..."
  28. # push the post!
  29. curl --user "$USER:$PASSWORD" -X POST \
  30. --data-urlencode "content=$CONTENT" \
  31. --data-urlencode "status=$STATUS" \
  32. --data-urlencode "categories=$CATEGORIES" \
  33. --data-urlencode "tags=$TAGS" \
  34. "https://$SERVER/wp-json/wp/v2/posts/" || exit 1
  35. # backup the posted data (temporarily until it is auto-removed)
  36. mv $TMPFILE $TMPFILE.posted