How to filter the visible stock image providers select

In the StockPack plugin at the time of this post, all the providers are available by default in the provider selector. This is so that you can search stock images from Adobe Stock, Unsplash, Pixabay, and Depositphotos without leaving the WordPress admin. You can now change that with the stockpack providers filter.

Remove a provider from the list

The filter we introduced is called `stockpack_providers` and it feeds the providers array allowing easy change.

Here’s an example of removing Pixabay from the list by using the stockpack providers filter:


function stockpack_providers( $providers ) {
	return [
		'Deposit Photos' => __( 'Deposit Photos', 'stockpack' ),
		'Adobe Stock'    => __( 'Adobe Stock', 'stockpack' ),
		'Unsplash'       => __( 'Unsplash', 'stockpack' ),

add_filter( 'stockpack_providers', 'stockpack_providers', 20, 1 );

Hide the provider selector

If you want to hide the provider selector you can just return an empty array. In that case, the default will be the only option, and the select will disappear.

To control the default you need to access and select the one you need.

Here’s the code to remove the providers select from StockPack:


function stockpack_providers( $providers ) {
	return [];

add_filter( 'stockpack_providers', 'stockpack_providers', 20, 1 );

When should you use the stockpack providers filter

As StockPack grows, more and more providers will be added, so this will come in handy, as having too many options might be confusing for some users.

If you are a development agency and you would like to offer this to the clients you build websites for, you might restrict their choices so they can get more focused, but also if you provide some credits as part of your development package.

The stockpack provider filter can also be used with user levels and capabilities in case you want some of the editors to have access to some free providers while others would have access to paid providers.

If you are in doubt you can also reach us via support and we will be happy to help. You might also be interested to learn that StockPack allows you to add stock images in Elementor.

Leave a Comment