MyBookTable includes an easy-to-use API for developers to add and modify the stores that the plugin supports. This is done mostly through the mbt_stores filter, which filters over the array of all stores. This allows you to insert a new store by adding an element to the array, remove an existing store by removing it’s element, or modify a store by changing it’s element data.
Adding a New Store
Only two pieces of information are required to add a new store to the array, the store’s slug and it’s name. The slug is simply a shortened name for the store that is used to identify that particular store in code. This can be whatever you want, but it’s recommended that it be less than 16 characters and that it use only lowercase a-z and _ characters. The name is the user-facing store name that is displayed in various places on the front-end.
Example:
function add_my_store($stores) {
$stores[‘my_store’] = array(‘name’ => ‘Store Name’);
return $stores;
}
add_filter(‘mbt_stores’, ‘add_my_store’);
You can save any information you want in the Buy Button’s data, but there are some array keys that are used for specific things in the plugin:
name: The user-facing ‘nice’ name of the store.
editor_desc: Used to override the default description used in the Buy Button editor for the store.
search: This is an optional field that should contain the URL for the search page of the store. This will be displayed on the Buy Button Editor of the store to allow users to quickly search for the book they are creating the Buy Button for.
Note: You will probably have to Override the Buy Button Output for your store in order to have it show up properly. By default, MyBookTable only looks in the plugin’s built in images folder for buy button images, so a new store will not have a buy button image associated with it.
Modifying or Removing a Store
Modifying or removing existing stores is an easy process, simply change the appropriate array element in the desired way.
Example:
function change_my_stores($stores) {
unset($stores[‘unwanted_store’]);
$stores[‘my_store’][‘name’] = ‘New Store Name’;
return $stores;
}
add_filter(‘mbt_stores’, ‘change_my_stores’);