Fix still creating json if wp commands fail

This commit is contained in:
2024-08-12 10:16:34 +10:00
parent 74f4787cc5
commit 01e1e2f33e

View File

@@ -17,8 +17,9 @@ if test -f "$media_path"; then
else
echo "Could not find $media_path.json, uploading media!"
id=$(wp media import "$media_path" --porcelain $WP_FLAGS)
url=$(wp rest attachment get "$id" --field=source_url $WP_FLAGS | sed 's/127.0.0.1/streetspeoplelove.org/')
raw_url=$(wp rest attachment get "$id" --field=source_url $WP_FLAGS)
if [ $? -eq 0 ]; then
url=$(echo "$raw_url" | sed 's/127.0.0.1/streetspeoplelove.org/')
jq -n --arg id $id --arg url "$url" '{"id": $id, "url": $url}' > "$media_path.json"
cat "$media_path.json"
fi