Download the PHP package jmichaelward/set-post-thumbs without Composer
On this page you can find all versions of the php package jmichaelward/set-post-thumbs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jmichaelward/set-post-thumbs
More information about jmichaelward/set-post-thumbs
Files in jmichaelward/set-post-thumbs
Package set-post-thumbs
Short Description A simple WP-CLI command to query posts for their content and set the first found image as the post thumbnail.
License GPL-3.0-or-later
Informations about the package set-post-thumbs
Set Post Thumbs
A simple WP-CLI command to query posts for their content and set the first found image as the post thumbnail.
Installation
Preferred
There are two preferred ways to install this package:
First, using WP-CLI's package installer command. Simply run wp package install jmichaelward/set-post-thumbs
in the command line, then you're good to go.
Second, you can similarly install it using Composer. In the terminal, enter:
Assuming you're already using Composer's class autoloader in your WordPress project, then you can then call the
function JMichaelWard\SetPostThumbs\init_thumbnail_command()
inside an
mu-plugins
PHP file, an active plugin, or your theme's functions.php
file.
Alternate
Alternately, you can clone down this repository. Then, require the set-post-thumbs.php
file relative to your file
path. This will make the JMichaelWard\SetPostThumbs\init_thumbnail_command()
method available to your project.
Usage
Once active, this package registers a thumbnail
command with WP-CLI. A brief synopsis of the available subcommands is
below. Please run wp help thumbnail
to see the full set of options.
Without options, this will attempt to set a post thumbnail on the first 500 posts WordPress can find without a featured
image. You may request that this processes on all posts by passing the --all
flag, or a specified amount of posts by
using --amount=<amount>
. Posts are the default post type, but you can specify other post types with the
--post_type
flag.
Passing unset
will return a list of post IDs that were processed, but which the command was unable to set a featured
image.
Passing multiple
will return a list of post IDs that were processed and where a featured image was set, but where the
posts contained multiple images in the content.
As before, passing the --post_type
flag will query the selected post type.
This command queries all posts which have metadata generated by the above commands, then subsequently removes that
metadata. I recommend running this command after assigning your featured images with this tool to clear out the
unnecessary metadata, as it's primarily used for reporting with the wp thumbnail show
command.
Extending the command
The ThumbnailCommand
class located in the src/
directory makes the above commands available to you. By default,
the thumbnail
command looks for images within your post content and assigns the first one it finds as the post's
featured image. However, your site may have image data located in other places that you may wish to use to set as a
featured image. The ThumbnailCommand
class is designed to be extended so that you can create your own command from
this scenario. The maybe_set_featured_image
method should be your primary starting point for extension.