Skip to content

Commit

Permalink
Merge pull request #179 from mediasanctuary/qrcode-cli-format
Browse files Browse the repository at this point in the history
wp cli format option for qr codes
  • Loading branch information
dphiffer authored Mar 13, 2024
2 parents 16fd2fb + 028669d commit 5967ae0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions wp-content/themes/mediasanctuary/lib/qrcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,28 @@ function qr_code_url($id) {
$redirect_url = get_permalink($id);
$image_url = qr_code_url($id);

if ($assoc_args['format'] == 'json') {
if (empty($assoc_args['format'])) {
WP_CLI::success("Created QR code \"$title\" (post ID $id)");
WP_CLI::log("Image URL: $image_url");
WP_CLI::log("Redirect URL: $redirect_url");
WP_CLI::log("Target URL: $target_url");
} else if ($assoc_args['format'] == 'json') {
echo wp_json_encode([
'id' => $id,
'title' => $title,
'target_url' => $target_url,
'image_url' => $image_url,
'redirect_url' => $redirect_url,
'image_url' => $image_url
'target_url' => $target_url
], JSON_PRETTY_PRINT);
} else {
WP_CLI::success("Created QR code \"$title\" (post ID $id) redirecting to $target_url");
WP_CLI::log("Redirect URL: $redirect_url");
WP_CLI::log("Image URL: $image_url");
} else if ($assoc_args['format'] == 'csv') {
$stdout = fopen('php://output', 'w');
fputcsv($stdout, [
$id,
$title,
$image_url,
$redirect_url,
$target_url
]);
}

return true;
Expand Down

0 comments on commit 5967ae0

Please sign in to comment.