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:

<?php

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 );

You will need to add the code in your theme’s functions.php file or a site-specific plugin.

The code works by specifying which providers to be shown, so it’s important to note that this will keep the list based on options you add.

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 https://stockpack.co/providers and select the one you need.

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

<?php

function stockpack_providers( $providers ) {
	return [];
}

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

Keep only free options

To only keep free options in the providers selector, you can use this code:

<?php
function stockpack_providers( $providers ) {
    
return [
    ‘Pexels’ => __( ‘Pexels’, ‘stockpack’ ),
    ‘Pixabay’ => __( ‘Pixabay’, ‘stockpack’ ),
    ‘Unsplash’ => __( ‘Unsplash’, ‘stockpack’ ),
    ];
    
}

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.

2 thoughts on “How to filter the visible stock image providers select”

  1. This is good to know, but could be clearer — especially for those of us who are not developers.
    1) It’d be good to mention where the reader should add the code. (I assumed functions.php, and added it there via the Code Snippets plugin.)
    2) The code does not “Remove a provider from the list” — it defines which providers are *in* the list, which the exact opposite action. (It also means that any providers you add in future won’t show up until the reader becomes aware of it and edits their code again.)

    Still, I used this information to achieve what I wanted, which was to list on the licence-free providers from those currently available:

    function stockpack_providers( $providers ) {
    return [
    ‘Pexels’ => __( ‘Pexels’, ‘stockpack’ ),
    ‘Pixabay’ => __( ‘Pixabay’, ‘stockpack’ ),
    ‘Unsplash’ => __( ‘Unsplash’, ‘stockpack’ ),
    ];
    }

    add_filter( ‘stockpack_providers’, ‘stockpack_providers’, 20, 1 );

    Reply

Leave a Comment