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.

54 Zeilen
1.4 KiB

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