Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
jon13

Use of Local Storage in multiple plugins

My situation, I think, is a common one. I have two plugins that each use Local storage with Admin Columns Pro to automatically load columns, each of those plugins for a particular content type.

My code looks like this:

add_filter( 'acp/storage/file/directory/writable', '__return_false' ); //! CHANGE TO __return_true TO MAKE CHANGES
add_filter( 'acp/storage/file/directory', 'apartmentsync_acp_storage_file_directory' );
function apartmentsync_acp_storage_file_directory( $path ) {
	// Use a writable path, directory will be created for you
    return APARTMENTSYNC_DIR . '/acp-settings';
}

And it’s working great when either of these plugins are used. However, when BOTH plugins are used, only one of the content types loads its columns (the one that loads last).

I think what I need is your advanced setup here:
https://docs.admincolumns.com/article/58-how-to-setup-local-storage

However, the code sample applies to themes, not plugins, and unfortunately is just unscrutable to be as to what it does. It also appears to be targeting where things are *stored*, but I’m not sure if it’s allowing for multiple different load locations.

Would it be possible for someone to write a code sample that fits this sort of situation? Ive tried and failed, unfortunately. I’d wager that this is a relatively common need, as the people using ACP, I’d think, would also be likely to be developing plugins for setting up various content types (e.g. I have a staff plugin, a partners plugin, jobs plugin, etc.).

7 months, 2 weeks ago
jon13

Oh, and I’ll definitely still be working on this, as I have a conflict right now I need to get resolved. If I do, I’ll be happy to post sample code in this thread.

7 months, 2 weeks ago
Stefan
Developer

You’re correct that you need to use the Advanced setup, since this only allows you to use multiple storage locations.
The example is set with rules and a variable for the write status (where you use a hook in your example). Although the example is indeed written for a theme, the only difference for a plugin will be the location, which you already have with a define. You can use the following snippet for your first plugin and write a similar hook for your other plugin.

add_filter( 'acp/storage/repositories', function ( $repositories, $factory ) {
	$repositories['plugin_x'] = $factory->create( APARTMENTSYNC_DIR . '/acp-settings', false );

	return $repositories;
}, 20, 2 );

In the example, I made the storage read-only. But if you’re developing, you probably make them writable. When you have both plugins activated on your dev environment, you could use rules as in the example on the documentation to decide where certain column sets will be stored. I hope this will gives you an idea of how to use the advanced setup to setup multiple storage location (for read only in this case)

7 months, 2 weeks ago

You must be logged in to reply to this topic.