Stop stockpack from loading with stockpack load filter

You can prevent the StockPack plugin from loading on pages you do not want it to load, by default it will only load in the admin side since you might use a image field on any page. You configure where the StockPack plugin will load with the stockpack_load filter.

Here’s the default for the plugin done via the filter:

<?php

add_filter( 'load_stockpack', 'stockpack_load', 10, 1 );

function stockpack_load( $load ) {
	if ( ! is_admin() ) {
		return false;
	}

	return $load;
}

This filter can also be used to limit the plugin for certain users in a more performant way as mentioned by our friends at https://www.cloudmedialab.com/ 

<?php

// Soft Load Stockpack
add_filter( 'load_stockpack', 'cmldmu_stockpack_load', 10, 1 );
function cmldmu_stockpack_load( $load ) {
	//Only load StockPack to back end
	if ( ! is_admin() ) {
		return false;
	}
	//Do not load StockPack unless user has custom capability, or is Administrator (via update_core capability)
	if ( ! ( current_user_can( 'cml_use_adobestock' ) || current_user_can( 'update_core' ) ) ) {
		return false;
	}

	return $load;
}

If you have any questions, feel free to contact us via https://stockpack.co/contact

Leave a Comment