Skip to content

Instantly share code, notes, and snippets.

@kumaxim
Created April 28, 2022 21:24
Show Gist options
  • Select an option

  • Save kumaxim/4ab087b4eb4ded64e6a8e17819efad41 to your computer and use it in GitHub Desktop.

Select an option

Save kumaxim/4ab087b4eb4ded64e6a8e17819efad41 to your computer and use it in GitHub Desktop.
Run WP_CLI command from PHP code
<?php
// Import image to media library using WP_CLI
// Call the code from your own WP CLI custom command
$image_id = \WP_CLI::runcommand(
sprintf('media import "%s" --preserve-filetime --porcelain',$thumbnail),
['return' => true, 'launch' => false]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment