#!/bin/bash # WordPress posting script # config: EDITOR=vim USER="" # WP user to create the post PASSWORD="" # application password generated for your WP user SERVER="" # server hostname, optionally with subdirectories STATUS="draft" # one of publish,future,draft,pending,private CATEGORIES="" # comma separated integer IDs of categories TAGS="" # comma separated integer IDs of tags TMPFILE=/tmp/wordpress-post.txt # location of a temporary file with the post text source ~/.config/wordpress-rest-curl/config.sh # let the user create the post $EDITOR $TMPFILE || exit 1 # load the file if it exists [[ -e $TMPFILE ]] || exit 1 CONTENT=`cat $TMPFILE` echo "--- START POST ---" echo $CONTENT echo "--- END POST ---" echo "User: $USER" echo "Server: $SERVER" echo "Status: $STATUS" echo "Categories: $CATEGORIES" echo "Tags: $TAGS" echo read -p "Press enter to confirm..." # push the post! curl --user "$USER:$PASSWORD" -X POST \ --data-urlencode "content=$CONTENT" \ --data-urlencode "status=$STATUS" \ --data-urlencode "categories=$CATEGORIES" \ --data-urlencode "tags=$TAGS" \ "https://$SERVER/wp-json/wp/v2/posts/" || exit 1 # backup the posted data (temporarily until it is auto-removed) mv $TMPFILE $TMPFILE.posted