wp-cli / media-command Goto Github PK
View Code? Open in Web Editor NEWImports files as attachments, regenerates thumbnails, or lists registered image sizes.
License: MIT License
Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
License: MIT License
Hi, We just updated and have problems regenerating thumbnails in the other languages.
Command: wp media regenerate --only-missing --yes
Old version :
WP-CLI: 1.5.0
WORDPRESS: WordPress 4.9.5
WPML: Version: 3.9.4
New version :
WP-CLI: 1.5.0
WORDPRESS: WordPress 4.9.8
WPML: Version: 4.0.5
Now, the CLI Command only regenerate thumbnails in the MAIN language.
Any clue? Thanks!
When calling wp media import
, it would be useful if an option existed to use the file time instead of the current time when importing files on the current server.
Current use case: I have a non-WordPress site that I am sun setting. I am creating a WordPress site to serve as an archive of all files from the old site. Preserving the file time is important so that admins can search for files by date.
I was working on a large site, 150+k images. and the images need regenerated.
I ran the script for 4-5 days, and it failed at around 80%.
I think it currently process the media entry one by one using ASC order (by IDs) ?
It would be nice to be able to switch the order.
when i use the cli i get the above error.
but when i do it via wordpress admin it works just fine.
and php7 is compiled with gd.
any idea's?
I have newest Wordpress (4.8.1) and Cherry Framework (3.1.5) based theme. When I run import media command:
wp media import wp-content/uploads/2017/08/**\/*.jpg
I get this error:
Fatal error: require_once(): Failed opening required '//includes/getLanguageDict.php' (include_path='phar:///home/totumfacky/bin/wp/vendor/phpunit/php-token-stream:phar:///home/totumfacky/bin/wp/vendor/phpunit/phpunit-mock-objects:phar:///home/totumfacky/bin/wp/vendor/phpunit/php-code-coverage:phar:///home/totumfacky/bin/wp/vendor/phpunit/phpunit:phar:///home/totumfacky/bin/wp/vendor/symfony/yaml:.:/usr/local/share/pear56') in /home/totumfacky/webapps/wp_koga/wp-content/plugins/motopress-content-editor/includes/ce/templates/landing.php on line 3
And this garbage on CLI output:
<div class="alert"><span class="object">id: mp_row, name: Row, icon: , closeType: enclosed, resize: none, position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_row_inner, name: Inner Row, icon: , closeType: enclosed, resize: none, position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_span, name: Column, icon: , closeType: enclosed, resize: none, position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_span_inner, name: Inner Column, icon: , closeType: enclosed, resize: none, position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_text, name: Paragraph, icon: , closeType: enclosed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/text.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_heading, name: Title, icon: , closeType: enclosed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/heading.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_code, name: WordPress Text, icon: , closeType: enclosed, resize: horizontal, position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_quote, name: Quote, icon: , closeType: enclosed, resize: horizontal, position: 40, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/quotes.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_members_content, name: Members Content, icon: , closeType: enclosed, resize: horizontal, position: 50, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/members.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_image, name: Image, icon: , closeType: self-closed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/image.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_image_slider, name: Slider, icon: , closeType: self-closed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/image-slider.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_grid_gallery, name: Grid Gallery, icon: , closeType: self-closed, resize: horizontal, position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/grid-gallery.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_button, name: Button, icon: , closeType: self-closed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/button.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_social_buttons, name: Social Share Buttons, icon: , closeType: enclosed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/social-buttons.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_social_profile, name: Social Buttons, icon: , closeType: self-closed, resize: horizontal, position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/social-profile.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_video, name: Video, icon: , closeType: self-closed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/video.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_audio, name: Audio, icon: , closeType: enclosed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/player.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_gmap, name: Google Maps, icon: , closeType: self-closed, resize: all, position: 60, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/map.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_space, name: Space, icon: , closeType: self-closed, resize: all, position: 50, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/space.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_embed, name: Embed, icon: , closeType: self-closed, resize: horizontal, position: 40, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/code.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_google_chart, name: Chart, icon: , closeType: enclosed, resize: all, position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/chart.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_tabs, name: Tabs, icon: , closeType: enclosed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/tabs.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_tab, name: Tab, icon: , closeType: enclosed, resize: none, position: 0, show: </span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_accordion, name: Accordion, icon: , closeType: enclosed, resize: horizontal, position: 11, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/accordion.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_accordion_item, name: Accordion Section, icon: , closeType: enclosed, resize: none, position: 0, show: </span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/no-object.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_table, name: Table, icon: , closeType: enclosed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/table.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_posts_grid, name: Posts Grid, icon: , closeType: self-closed, resize: horizontal, position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/posts-grid.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_archives, name: Archives, icon: , closeType: self-closed, resize: horizontal, position: 45, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_calendar, name: Calendar, icon: , closeType: self-closed, resize: horizontal, position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_categories, name: Categories, icon: , closeType: self-closed, resize: horizontal, position: 40, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_navmenu, name: Custom Menu, icon: , closeType: self-closed, resize: horizontal, position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_meta, name: Meta, icon: , closeType: self-closed, resize: horizontal, position: 55, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_pages, name: Pages, icon: , closeType: self-closed, resize: horizontal, position: 15, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_posts, name: Recent Posts, icon: , closeType: self-closed, resize: horizontal, position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_comments, name: Recent Comments, icon: , closeType: self-closed, resize: horizontal, position: 25, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_rss, name: RSS, icon: , closeType: self-closed, resize: horizontal, position: 50, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_search, name: Search, icon: , closeType: self-closed, resize: horizontal, position: 35, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_tagcloud, name: Tag Cloud, icon: , closeType: self-closed, resize: horizontal, position: 60, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wp_widgets_area, name: Widgets Area, icon: , closeType: self-closed, resize: horizontal, position: 5, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/object/sidebar.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_grid, name: Grid, icon: , position: 0, show: </span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_text, name: Text, icon: , position: 0, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/text.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_image, name: Image, icon: , position: 10, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/image.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_button, name: Button, icon: , position: 20, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/button.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_media, name: Media, icon: , position: 30, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/media.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_other, name: Other, icon: , position: 40, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/other.png does not exist</li>
</ul>
</li>
</ul>
</div>
<div class="alert"><span class="object">id: mp_wordpress, name: WordPress, icon: , position: 50, show: 1</span>
<ul class="property">
<li>icon:
<ul class="errors">
<li>File //images/ce/group/no-group.png does not exist</li>
<li>File //images/ce/group/wordpress.png does not exist</li>
</ul>
</li>
</ul>
</div>
On an existing production site, it can be a little bit scary to regenerate all image sizes for all images because of the fear of the unknown.
If I've only changed the width / height values for one image size, it would be nice to be able to only regenerate that specific image size.
For instance, if I've changed thumbnail
from 183x183 to 185x185, I could run wp media regenerate --image_size=thumbnail
to solely regenerate thumbnails.
Just an FYI that from WP 5.3 there are couple of functions to find and generate missing image sub-sizes, and the image meta is saved after each sub-size is generated.
For back-compat wp_generate_attachment_metadata()
still returns the whole image meta array after all sub-sizes have been created (if the server doesn't run out of resources), but is not the best way to generate only missing image sub-sizes. See https://core.trac.wordpress.org/ticket/40439 and https://core.trac.wordpress.org/changeset/45538 (testing and suggestions welcome).
Right now the method process_regeneration()
and all other internal methods are declared private. This makes it impossible make a small change to the inner workings of a command.
For example, I want to reduce the log output of the regenerate
command by changing some WP_CLI::log()
calls in the process_regeneration()
method, but this is impossible without overriding the whole regenerate()
method (which doesn't even have visibility).
I would like to propose to:
When running this:
$ wp media regenerate --yes
The command runs on ALL attachments, regardless of file type.
This results in lots of awkward errors when run on audio, video, PDFs, etc. Here's an example:
...
Warning: 23/23 Couldn't regenerate thumbnails for "2012 Guest gallery proposal guidelines" (ID 20).
Error: Only regenerated 16 of 23 images.
In the above example, the media library contains 16 images and 7 non-image files.
It would seem wp regenerate media
is naturally intended only for images and so it would make sense to only run it on a whitelist of filetypes. This would also avoid issues like this one.
Hi!
Great plugin!
How about being able to pull all media files from a production site? That would be awesome.
According to multiple sources starting with version 4.7 of Wordpress there are thumbnails generated for any new PDF that is uploaded into the Medialibrary:
Is it possible to incorporate this thumbnail generation functionality into the regenerate command?
For example:
$ curl http://example.com/large-file.png | wp media import -
Related:
wp-cli/entity-command#96
Some of the examples in the documentation for the wp media
command could be improved by removing cultural references and a couple unnecessary gendered examples. This speaks to some of the changes we’ve seen in WordPress this year, as well as being a consideration for future translators and creating a sense of inclusivity with use of intentional language, even in our documentation.
I’d like to propose reusing other examples in the documentation where possible. I'll submit a pull request to get some feedback from you all.
In specific cases when the files are inside the wp-content folder but not in uploads, is it possible to set their URL according to their real position within wp-content instead to statically set the URL to wp-content/uploads?
My exact issue is, that i have PDF-s for WP Download Manager Pro in wp-content/uploads/download-manager-files but to allow them to be indexed by SearchWP i need to import them into Medialibrary, which in turn needs to either copy them, or by using skip-copy i have to relocate the WPDMPro base directory to wp-content/uploads what is not desired.
Summary
We recently bulk-imported ~4,000 media library items using wp media import
. A while into development after the import, we noticed a problem with the links to these files when inserted into content as they were not using the Amazon S3 URL but the local URL. We're using the pro version of Delicious Brains' Offload WP plugin for that piece. WP sanitizes filenames by replacing spaces with hyphens, among other transformations. Offload WP relies on this functionality and assumes that neither spaces nor + signs will be present in a media library item URL. Here is how the plugin validates a URL: preg_match( '@^(?:https?:)?//[a-zA-Z0-9\-]+@', $string )
.
If the same file is uploaded manually via the Media Library UI, the filename is properly sanitized with the space being replaced with a hyphen.
Steps to repeat
wp media import "/path/to/file/file name.docx" --skip-copy --porcelain
%20
, in filename.Environment
WP is running inside a docker-compose setup using the official wordpress image. WP-CLI is installed inside the wordpress container instead of using the wordpress-cli variant of that image. It's running PHP 7.2.18.
Output from wp cli info
:
OS: Linux 4.15.0-50-generic #54~16.04.1-Ubuntu SMP Wed May 8 15:55:19 UTC 2019 x86_64
Shell:
PHP binary: /usr/local/bin/php
PHP version: 7.2.18
php.ini used:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /var/www/html
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.2.0
Severity — High
If we don't find a way to adjust several hundred URLs in the DB in a way that updates them on S3, we may have to redo hours of additional work that came after this import but before we discovered the issue. wp media import
should utilize the same sanitization methods as importing via the UI.
Expected Behavior
Upon import, filenames with spaces in them will have the spaces replaced with a hyphen.
Actual Behavior
Upon import, filename spaces are left untouched.
Additional Info
This class was used to trigger the wp media import
after using the RecursiveIteratorIterator and RecursiveDirectoryIterator PHP classes to recursively loop over the directories and files to import: https://gist.github.com/livewyer/4019d0b2a10a5e38b1cade765ee1fad3
I also have been talking with Offload WP support. Here's what they said about how their plugin interacts with filenames:
In most cases WP handles the sanitizing and renaming of the file during upload to the Media Library, WP Offload Media then just offloads that file. The primary way WP handles the filename clean up is through
\wp_unique_filename
(from wp-includes/functions.php).When a file is uploaded to the Media Library and "Remove Files From Server" is turned on in WP Offload Media, then WP Offload Media hooks into
wp_unique_filename
and does a quick check to make sure that a previously offloaded and removed file doesn't have a local file path that would clash with the new file if it were to be downloaded. If there's a clash then WP Offload Media uses the same technique as WP to append a correct "version" numeric (such as "-1") to the file's base name. But WP Offload Media doesn't change the filename otherwise, WP has already sanitized and substituted hyphens for spaces etc.
Improve command description in:
https://github.com/wp-cli/media-command/blob/master/src/Media_Command.php
Command: wp media
Current description: Import new attachments or regenerate existing ones.
Proposed description:
Imports files as attachments and regenerates thumbnails.
When regenerating all media, the special-case site-icon
loses its custom sizes
wp media regenerate --yes
Severity - Low
Expected Results: The special case 'site-icon' should be handled as it is in core to generate the correct media sizes
Actual Results: The site-icon image attachment is handled the same as all other uploads, and loses its special sizes, which may cause issues with devices/services looking for/expecting to find images of a particular size. The meta tags output in the site header do link to the newly generated image sizes, but attributes on the meta tags still show the original sizes that were expected to exist.
Core is only expecting this image to ever be set via the customizer, so the case for it is handled in ajax-actions.php which calls on the WP_Site_Icon class from class-wp-site-icon.php.
File and metadata before/after regeneration: https://gist.github.com/dotsam/f31dfed2ee1b64b149883520ee901b43
The following changes need to be made:
.travis.yml
file, the - composer behat
line in the script:
section needs to be changed into the following:- composer behat || composer behat-rerun
composer-json
file, the requirement on wp-cli/wp-cli-tests
needs to be adapted to require at least v2.0.7
:"wp-cli/wp-cli-tests": "^2.0.7"
composer-json
file, the "scripts"
section needs to be extended. Immediately after the line "behat": "run-behat-tests",
, the following line needs to be inserted:"behat-rerun": "rerun-behat-tests",
Here's an example of how this should look like:
Hi is there a way to set up below commands with WP cli as well or is it set by default?
I couldn't find it anywhere.
-Skip regenerating existing correctly sized thumbnails (faster).
-Delete thumbnail files for old unregistered sizes in order to free up server space. This may result in broken images in your posts and pages.
Many thanks
It would be epic if you could only generate media for specific file-types. For example, I've got a client who's site contains a large number of PDFs. I only need to regenerate files with the filetypes "image/jpeg" and "image/png". It would make use in deployments much faster if filetypes not needing thumbnail generation were never checked.
Hi,
I would like to suggest a new feature (subcommand) that would allow to seamlessly replace media file of existing attachment: media replace <file> <attachment_id>
.
For the time being, I use Enable Media Replace whenever I need to replace media file, but it would be great to have a command line equivalent.
Hello,
I use wp media regenerate want to re-thumbnail my featured image.
But it always skipped thumbnail regeneration.
Command-line:
$ wp media regenerate 330575
Found 1 image to regenerate.
1/1 Skipped thumbnail regeneration for "image_201812211157F8" (ID 330575).
Success: Regenerated 0 of 1 images (1 skipped)
I use each ID will be skipped, and why?
How to fix this problem.
Thanks,
mike
I try to post some media file from my local pc to my server.
I configured wp-cli to use ssh to connect.
I tried to import file but I got error about the file does not exist. So It tries to find it on the server machine I guess.
wp media import "/local/path/to/image.jpg" --post_id=1216 --title="Some title" --featured_image --porcelain
Then, I change a bit my command to add -http but it does not change anything.
wp media import "/local/path/to/image.jpg" --post_id=1216 --title="Some title" --featured_image --porcelain --http=http://blog.domain.org/
I keep getting "File does not exit error"
display /local/path/to/image.jpg
Show the picture.
Is there a way to send off file to remote server ?
(my pc and my server are both in my house, I host my blog).
See #5 (comment).
In order to run media tests involving PDF previews, the PHP extension imagick
needs to be installed.
Unfortunately using pecl install
of the latest 3.4.3 version under Ubuntu Precise 12.02 can cause it to randomly seg fault when built against PHP 7.0 (or PHP 7.1).
One would hope that there might be some way or combination of systems/versions etc to make it work.
We have a new PHPCS standard for WP-CLI called WPCliCS
(props @jrfnl). It is part of the wp-cli/wp-cli-tests
package starting with version v2.1.0.
To adopt & enforce this new standard, the following actions need to be taken for this repository:
Create a PR that adds a custom ruleset phpcs.xml.dist
to the repository
phpcs.xml.dist
file.distignore
to ignore phpcs.xml.dist
& phpunit.xml.dist
.gitignore
to ignore phpunit.xml
, phpcs.xml
& .phpcs.xml
^2.1
of the wp-cli/wp-cli-tests
as a dev dependencyMake any required changes to the code that fail the checks from the above ruleset in separate PRs
Merge thre ruleset once all required changes have been processed and merged
A sample PR for a simple repository can be seen here: https://github.com/wp-cli/maintenance-mode-command/pull/3/files
Related wp-cli/wp-cli#5179
We get a lot of bug reports and support reports related to the thumbnail regeneration, where it often is just not clear why the regeneration is being skipped.
The command should be more verbose and add the specific reason for why it decided to skip a given thumbnail regeneration.
Also, it should come with additional --debug
output in case one wants to verify said reasons.
Or maybe it's the other way around, in which case please mark this appropriately.
Anyway, when I do single (or batch) wp-cli media regenerate like so
debian@8cylinder:/var/www/html/wp$ wp media regenerate 12530
it borks my featured image thumbnails on my index page (excerpts) back to the square-ish WP default.
But when I use the WP Gui plugin Regenerate Thumbnails, Version 3.0.2 | By Alex Mills (Viper007Bond), it performs what I consider expected behavior... making the index excerpt thumbs my preferred 720x320 aspect ratio
<?php the_post_thumbnail( 'wide-n-short-featured-720' ); ?>
as I've described in wp-config.php
add_image_size( 'wide-n-short-featured-720', 720, 320, true );
Is it me?
Hi, I have problem with Regenrate thumbnails. I have message:
Found 1 image to regenerate.
1/1 Regenerated thumbnails for "miss-finallll-jpg" (ID 1316609).
Success: Regenerated 1 of 1 images
But when I check db for image sizes there are no sizes set in db, so request for image size gives me back all the time only the default uploaded size. When I try to regenerate in wp admin, then is it working well. I have 64k images, so I am not able to do it in wp-admin. If I check files, the sizes are there generated correct (miss-finallll-768x404.jpg)
The fake SVG file we try to upload for testing the SVG regeneration is rejected by more recent versions of WordPress: https://travis-ci.org/wp-cli/automated-tests/jobs/469306587#L2478-L2488
The following changes need to be made to move the command over to the v2 structure:
composer require wp-cli/wp-cli:^2
composer require --dev wp-cli/wp-cli-tests:^0
.travis.yml
file from wp-cli/wp-cli
:
wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/.travis.yml
"scripts": {
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpunit": "run-php-unit-tests",
"behat": "run-behat-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpunit",
"@behat"
]
},
git rm bin/install-package-tests.sh
git rm bin/test.sh
git rm features/bootstrap/*
git rm features/extra/*
git rm features/steps/*
git rm utils/behat-tags.php
--dev
dependencies.cli *
config *
core *
eval
eval-file
help
composer update
wget https://raw.githubusercontent.com/wp-cli/wp-cli/master/phpcs.xml.dist
composer test
Should media regenerating be so slow? I was only able to do about 800 (out of 13000) images last night. The process is only using 1-3% CPU. Does anyone have any tips to speed this up?
Dear people,
I am not sure if wp import media --post_name=$id
is going to be supported, or which should be the use case for this.
Thanks in advance.
I ran into an issue with the "--skip-delete" option of the "regenerate" command. It deletes the original thumbnails. Could you please look into this?
Thanks
When I run wp media regenerate 10927 --image_size=medium_large
I receive this:
Found 1 image to regenerate.
1/1 No "medium_large" thumbnail regeneration needed for "Bay" (ID 10927).
However, I DO need that image regenerated. Why is it saying I don't, and how do I override?
Hi, i'm interested in doing some sanitation on filenames when doing wp media import
, preferably using a hook. Is that possible?
Currently the 1.1.0 phar (released Feb 1) doesn't contain the command with the --image_size
parameter available.
Even though the docs contain the command the cli reports the parameter as unknown.
Since the media command was last updated on April 19, is it possible that the versions currently bundled are not the lastest?
wp package list
provides no info into this as it is not considered a package.
wp package install|update wp-cli/media-command
doesn't do anything, probably because it is considered to be core?
Also the docs are out of sync:
Moved from wp-cli/wp-cli#4666 by @killown
hi there, could you implement a way to return the file url after import?
Example:
wp media import test.txt --return_url
https://mywordpress.com/test.txt
Following the contrib rules by opening a ticket before issuing a a PR ;)
We've put together a few functions here: https://github.com/DigitalTactics/wp-cli-mediadiff for listing what are likely to be orphan files (files on the file system in the uploads folder which don't (for whatever reason) have corresponding attachment entries - yes we know some plugins manage files here too which don't result in attachments hence the likely); we then have options to move these files to a trash folder for inspection/retention and/or then delete them permanently if appropriate.
We think it makes sense to have our diff command trail off of media command so wp media diff makes sense to us... but what are your thoughts? Is this something you want to include
We may have some more work to on this generally but what's currently there should be of some use already.
A bit backwards - PR submitted earlier: #22
Currently media import uses wp_safe_remote_get which importantly denies import via local domain/IPs. This impliments a flag to allow use of wp_remote_get so that you can import from those locations. Writtent to cope with managing some private domain/LAN sites.
We need to include thumbnail
(and other non-intermediate image sizes) in the following check:
if ( array_diff( get_intermediate_image_sizes(), array_keys( $metadata['sizes'] ) ) ) {
return true;
}
Original report: wp-cli/wp-cli#3859
We're using https://wordpress.org/plugins/do-spaces-sync/ to store all media in Digital Ocean Spaces. The regenerate thumbnails command checks to see if the file exists (see:
media-command/src/Media_Command.php
Line 580 in b69c2b2
The ratio of width to height of the image size could be added to the output of wp media image-size
. I find that the ratio often helps in debugging issues where images aren't quite the right size, and seeing which sizes have the same ratio.
Calculating the ratio is straight forward. More details here: crstauf/query-monitor-extend#1
"(Just on the current ".travis.yml" I think the cache syntax https://github.com/wp-cli/media-command/blob/master/.travis.yml#L16 for caching "$HOME/.composer/.cache" needs to be in a "directories" list like https://github.com/gitlost/media-command/blob/imagick/.travis.yml#L16)."
@gitlost I don't think this is correct for either repo:
• https://travis-ci.org/wp-cli/media-command/jobs/222084435
• https://travis-ci.org/gitlost/media-command/jobs/222084435
Neither of the above jobs have Setting up build cache
or store build cache
sections
You can see both these sections in:
• https://travis-ci.org/paulgibbs/behat-wordpress-extension/jobs/224696788
Do each of the respective repos have Travis CI cache info here to view or do you see an error?
• https://travis-ci.org/wp-cli/media-command/caches
• https://travis-ci.org/gitlost/media-command/caches
Initial tidying: #19
Outstanding: function args.
In media regenerate
a --force
option to always regenerate would be useful eg when you've changed your image editor and/or settings or added a plugin enhancement etc.
Easy to implement, just by-pass Media_Command::needs_regeneration()
.
Current code uses wp_get_attachment_metadata function from Wordpress to retrieve attachment's metadata (1, 2, 3). It silently assumes that returned value is array and makes no checks for it, but function description in Wordpress sources clearly states that returned value is mixed
.
In practice for SVG images returned metadata is empty string and it results into 6 warning messages per image.
It is necessary to add checks for returned information and, maybe, exclude SVG images from regeneration process.
A bit backwards - PR submitted earlier: #21
Currently media import always moves files to the media library folder. This impliments a flag to allow importing to the library without moving on disk. Seems like a common use to me - either in custom workflows when storing some media outside the main directory for some reason (my use case), or in coordination with something like the prospective diff command #6 to import files not in the library but already in the uploads dir.
wp media import https://archive.org/download/testmp3testfile/mpthreetest.mp3
Imported file 'https://archive.org/download/testmp3testfile/mpthreetest.mp3' as attachment ID 37.
Success: Imported 1 of 1 images.
I would expect this wording to be more generic to something like "items" as it is possible that the site does not even allow image mime types to be uploaded.
This line throws an exception when the exif data could not be read for an image:
https://github.com/wp-cli/media-command/blob/master/src/Media_Command.php#L719
We should probably be resilient to this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.