Skip to content

Instantly share code, notes, and snippets.

@stephenfeather
Created May 15, 2023 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenfeather/7ff61a51afd4c9a5fd2571aecf666c11 to your computer and use it in GitHub Desktop.
Save stephenfeather/7ff61a51afd4c9a5fd2571aecf666c11 to your computer and use it in GitHub Desktop.
Bash script to serve an asset url w/ optional params to remote wordpress setup for importation via wp_cli - b7cd9ff84718d3ca7fca26ebb60e765d1a0a8d5642722db795522e99a6759a90
#!/bin/bash
#
# upload_and_run.sh
# Author: Stephen Feather
# Copyright (c) 2023 Stephen Feather
# License: CC BY-SA 4.0
if [ -z "$1" ]; then
echo "Error: URL argument is required."
echo "Usage: ./wp_url_import.sh <filename> [--title <title>] [--caption <caption>] [--desc <description>]"
exit 1
fi
# Define default values for the optional parameters
title=""
caption=""
desc=""
# Get the URL from the first argument
image_url="$1"
# Parse named arguments
while [[ $# -gt 1 ]]; do
case "$2" in
--title)
title="$3"
shift 2
;;
--caption)
caption="$3"
shift 2
;;
--desc)
desc="$3"
shift 2
;;
*)
echo "Invalid argument: $2"
exit 1
;;
esac
done
# Specify our default remote args as this is a shellless session
default_args="--allow-root --user=1"
wp @prod media import $image_url --title="$title" --caption="$caption" --desc="$desc" $default_args
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment