PHP Class Media_Command, wp-cli

## EXAMPLES # Re-generate all thumbnails, without confirmation. $ wp media regenerate --yes Found 3 images to regenerate. 1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760). 2/3 Regenerated thumbnails for "Boardwalk" (ID 757). 3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756). Success: Regenerated 3 of 3 images. # Import a local image and set it to be the featured image for a post. $ wp media import ~/Downloads/image.png --post_id=123 --title="A downloaded picture" --featured_image Success: Imported file '/home/person/Downloads/image.png' as attachment ID 1753 and attached to post 123 as featured image.
Inheritance: extends WP_CLI_Command
ファイルを表示 Open project: wp-cli/wp-cli

Public Methods

Method Description
import ( $args, $assoc_args = [] ) Create attachments from local files or URLs.
regenerate ( $args, $assoc_args = [] ) Regenerate thumbnails for one or more attachments.

Private Methods

Method Description
make_copy ( $path ) wp_tempnam() inexplicably forces a .tmp extension, which spoils MIME type detection
needs_regeneration ( $att_id )
process_regeneration ( $id, $skip_delete, $only_missing, $progress )
remove_old_images ( $att_id )

Method Details

import() public method

## OPTIONS ... : Path to file or files to be imported. Supports the glob(3) capabilities of the current shell. If file is recognized as a URL (for example, with a scheme of http or ftp), the file will be downloaded to a temp file before being sideloaded. [--post_id=] : ID of the post to attach the imported files to. [--title=] : Attachment title (post title field). [--caption=<caption>] : Caption for attachent (post excerpt field). [--alt=<alt_text>] : Alt text for image (saved as post meta). [--desc=<description>] : "Description" field (post content) of attachment post. [--featured_image] : If set, set the imported image as the Featured Image of the post its attached to. [--porcelain] : Output just the new attachment ID. ## EXAMPLES # Import all jpgs in the current user's "Pictures" directory, not attached to any post. $ wp media import ~/Pictures/**\/*.jpg Imported file '/home/person/Pictures/beautiful-youg-girl-in-ivy.jpg' as attachment ID 1751. Imported file '/home/person/Pictures/fashion-girl.jpg' as attachment ID 1752. Success: Imported 2 of 2 images. # Import a local image and set it to be the post thumbnail for a post. $ wp media import ~/Downloads/image.png --post_id=123 --title="A downloaded picture" --featured_image Imported file '/home/person/Downloads/image.png' as attachment ID 1753 and attached to post 123 as featured image. Success: Imported 1 of 1 images. # Import a local image, but set it as the featured image for all posts. # 1. Import the image and get its attachment ID. # 2. Assign the attachment ID as the featured image for all posts. $ ATTACHMENT_ID="$(wp media import ~/Downloads/image.png --porcelain)" $ wp post list --post_type=post --format=ids | xargs -d ' ' -I % wp post meta add % _thumbnail_id $ATTACHMENT_ID Success: Added custom field. Success: Added custom field. # Import an image from the web. $ wp media import http://s.wordpress.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt="Semantic personal publishing" Imported file 'http://s.wordpress.org/style/images/wp-header-logo.png' as attachment ID 1755. Success: Imported 1 of 1 images. </div> </div> <div class="row doc-tags"> <div class="col-md-12"> <div class="tag-block tag-summary"> </div> <div class="tag-block tag-remarks"> </div> <div class="tag-block tag-exception"> </div> <div class="tag-block tag-see"> </div> <div class="tag-block tag-link"> </div> <div class="tag-block tag-deprecated"> </div> <div class="tag-block tag-since"> </div> <div class="tag-block tag-author"> </div> </div> </div> <div class="row"> <div class="col-md-12" style="overflow: auto"> <table class="table table-striped"> <tr> <td colspan="3" class="rendered"> <span class="modifier">public</span > <span class="method-name"><a class="method-link" href="https://doc.hotexamples.com/jp/class/-/Media_Command#method-import">import</a></span> ( <span class="param-name">$args</span>, <span class="param-name">$assoc_args</span> = [] ) </td> </tr> </table> </div> </div> </div> <div class="method-descr-full" id="method-regenerate"> <div class="row"> <div class="col-md-6"> <h3> regenerate() <span class="modifier">public</span > <span>method</span> </h3> </div> <div class="col-md-6 actions"> <a href="https://src.hotexamples.com/jp/method/-/Media_Command/regenerate/-" rel="nofollow" title="Source code of method Media_Command::regenerate"><i class='icon-borderless icon-eye'></i></a> <a rel="nofollow" href="https://doc.hotexamples.com/jp/class/-/Media_Command#method-regenerate" title="Direct link to the method Media_Command::regenerate documentation"><i class='icon-borderless icon-link'></i></a> </div> </div> <div class="row"> <div class="col-md-12"> ## OPTIONS [<attachment-id>...] : One or more IDs of the attachments to regenerate. [--skip-delete] : Skip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false. [--only-missing] : Only generate thumbnails for images missing image sizes. [--yes] : Answer yes to the confirmation message. Confirmation only shows when no IDs passed as arguments. ## EXAMPLES # Regenerate thumbnails for given attachment IDs. $ wp media regenerate 123 124 125 Found 3 images to regenerate. 1/3 Regenerated thumbnails for "Vertical Image" (ID 123). 2/3 Regenerated thumbnails for "Horizontal Image" (ID 124). 3/3 Regenerated thumbnails for "Beautiful Picture" (ID 125). Success: Regenerated 3 of 3 images. # Regenerate all thumbnails, without confirmation. $ wp media regenerate --yes Found 3 images to regenerate. 1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760). 2/3 Regenerated thumbnails for "Boardwalk" (ID 757). 3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756). Success: Regenerated 3 of 3 images. # Re-generate all thumbnails that have IDs between 1000 and 2000. $ seq 1000 2000 | xargs wp media regenerate Found 4 images to regenerate. 1/4 Regenerated thumbnails for "Vertical Featured Image" (ID 1027). 2/4 Regenerated thumbnails for "Horizontal Featured Image" (ID 1022). 3/4 Regenerated thumbnails for "Unicorn Wallpaper" (ID 1045). 4/4 Regenerated thumbnails for "I Am Worth Loving Wallpaper" (ID 1023). Success: Regenerated 4 of 4 images. </div> </div> <div class="row doc-tags"> <div class="col-md-12"> <div class="tag-block tag-summary"> </div> <div class="tag-block tag-remarks"> </div> <div class="tag-block tag-exception"> </div> <div class="tag-block tag-see"> </div> <div class="tag-block tag-link"> </div> <div class="tag-block tag-deprecated"> </div> <div class="tag-block tag-since"> </div> <div class="tag-block tag-author"> </div> </div> </div> <div class="row"> <div class="col-md-12" style="overflow: auto"> <table class="table table-striped"> <tr> <td colspan="3" class="rendered"> <span class="modifier">public</span > <span class="method-name"><a class="method-link" href="https://doc.hotexamples.com/jp/class/-/Media_Command#method-regenerate">regenerate</a></span> ( <span class="param-name">$args</span>, <span class="param-name">$assoc_args</span> = [] ) </td> </tr> </table> </div> </div> </div> </div> </div> </div></div> <footer class="footer"> <div class="container"> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/jp/site/trends?type=php%7Cf">上位の関数</a> | <a href="https://hotexamples.com/jp/site/trends?type=php%7Cc"> 上位のクラス </a> | <a href="https://doc.hotexamples.com/jp/doc/map">ドキュメント</a> | <a href="/site/privacy">個人情報保護方針</a> | <a href="https://cpp.hotexamples.com/direct-sales.html">Advertise with us</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://hotexamples.com/jp/">PHP</a> | <a href="https://csharp.hotexamples.com/jp/">C# (CSharp)</a> | <a href="https://java.hotexamples.com/jp/">Java</a> | <a href="https://golang.hotexamples.com/jp/">Golang</a> | <a href="https://cpp.hotexamples.com/jp/">C++ (Cpp)</a> | <a href="https://python.hotexamples.com/jp/">Python</a> | <a href="https://javascript.hotexamples.com/jp/">JavaScript</a> | <a href="https://typescript.hotexamples.com/jp/">TypeScript</a> </div> </div> <div class="row"> <div class="col-md-12" style="text-align: center"> <a href="https://doc.hotexamples.com/class/-/Media_Command">EN</a> | <a href="https://doc.hotexamples.com/ru/class/-/Media_Command">RU</a> | <a href="https://doc.hotexamples.com/de/class/-/Media_Command">DE</a> | <a href="https://doc.hotexamples.com/fr/class/-/Media_Command">FR</a> | <a href="https://doc.hotexamples.com/es/class/-/Media_Command">ES</a> | <a href="https://doc.hotexamples.com/pt/class/-/Media_Command">PT</a> | <a href="https://doc.hotexamples.com/it/class/-/Media_Command">IT</a> | <a href="https://doc.hotexamples.com/jp/class/-/Media_Command">JP</a> | <a href="https://doc.hotexamples.com/zh/class/-/Media_Command">ZH</a> | <a href="https://doc.hotexamples.com/ko/class/-/Media_Command">KO</a> </div> </div> <div class="row"> <div class="col-md-10 col-md-offset-1"> </div> <div class="col-md-1"> <!--LiveInternet counter--> <script type="text/javascript"><!-- document.write("<a href='//www.liveinternet.ru/click' " + "target=_blank><img src='//counter.yadro.ru/hit?t44.6;r" + escape(document.referrer) + ((typeof (screen) == "undefined") ? "" : ";s" + screen.width + "*" + screen.height + "*" + (screen.colorDepth ? screen.colorDepth : screen.pixelDepth)) + ";u" + escape(document.URL) + ";" + Math.random() + "' alt='' title='LiveInternet' " + "border='0' width='31' height='31'><\/a>"); //--></script><!--/LiveInternet--> </div> </div> </div> </footer> <script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="/assets/30dd86a6f06b64184847037c52c63e07aa3c9a26.js"></script> <script>jQuery(function ($) { jQuery('#search-form').yiiActiveForm([{"id":"searchform-lang","name":"lang","container":".field-searchform-lang","input":"#searchform-lang","enableAjaxValidation":true},{"id":"searchform-search","name":"search","container":".field-searchform-search","input":"#searchform-search","enableAjaxValidation":true,"validate":function (attribute, value, messages, deferred, $form) {yii.validation.required(value, messages, {"message":"Search cannot be blank."});}}], []); });</script></body> </html>