Store Pages interfaces are not invoked.
Reproduction
Requires Power add on to be active.
- Login as admin on WordPress (WP) site.
- Go to Store Locator Plus® | Options
- Enable Pages
- Go to Store Locator Plus® | Locations
- Choose Pages, Create from the bulk actions drop down menu
- Click “to All” next to that menu
Issues
- There is no “Pages” list in the sidebar
- Each location shows a page attached, but if you scroll over to the Pages URL column on the location list page, view or edit does not work.
- Edit brings up this error:
Sorry, you are not allowed to edit posts in this post type.
Resolution
This update requires the SLP (base plugin) to be updated alongside the Power add on.
Note: be sure to update the “requires” in SLP to be the latest power and Power to require latest SLP.
User Access to Store Pages
Need to raise the modification of the store pages attributes from Power add on to fire closer to when SLP creates the attributes. This is when the permissions to access the special post type are assigned.
First, set a filter as soon as the Power add on is loaded.
In \SLPPower::initialize....
add_filter( 'slp_storepage_attributes', [ $this, 'modify_storepage_attributes' ] );
Nothing is active yet, so autoloaders don’t work. They are not fully active until AFTER the entire slp_init routine has complete. Thus we need to got “old school” and require the Power pages class file.
New method... \SLPPower::modify_storepage_attributes
/**
* This needs to happen during \SLP_Actions::init when it is fetching store attributes
* so we can modify the store pages attributes
*
* @param $attributes
* @return mixed
*/
public function modify_storepage_attributes($attributes ) {
require_once('module/pages/SLP_Power_Pages.php');
$this->pages = SLP_Power_Pages::get_instance( false, [ 'addon' => $this ]);
return $this->pages->modify_storepage_attributes( $attributes );
}
Then in the original \SLP_Power_Pages::modify_storepage_attributes , we need to drop any tests to see if “using_pages” is set for the Power add on. That is the option that determines if store pages is active, however that is not even loaded at this point. None of the add on options are loaded yet.
NOTE: NEED TO TESTING TURNING OFF STORE PAGES OPTION
Resolution
Move all the store page attributes into the main SLP registration function: \SLP_Actions::init
These rewrite rules reference Power add on options that likely need to be shifted into the main plugin:
'rewrite' =>
array(
'slug' => $this->addon->options['permalink_starts_with'],
'with_front' => $this->slplus->is_CheckTrue( $this->addon->options['prepend_permalink_blog'] ),
),
- The options from \SLP_Power_Options are stored in the wp_options table in the option_name=’slp-power’.
- They are referenced via $this->addon->options[ <option_key> ] from within the Power add on.
- $this->addon = an instantiated
new SLPlus::locationPostURL = ‘store-page’ this is set to the default that Power has been using as the initial value for the slug for pages.
NOTE: try changing the permalink with store-pages enabled, track how it is registered when the post type is registered.
Findings
Power add on for Store Locator Plus® (relative directory: ./wp-content/plugins/slp-power).
The “Store Pages” Custom Post Type
The base plugin (Store Locator Plus® relative directory: ./wp-content/plugins/store-locator-plus) registers the taxonomy.
The custom SLP “Store Pages” post type and related categorization (taxonomy) is as follows:
\SLPlus::locationPostType = ‘store_page’
\SLPlus::locationTaxonomy = ‘stores’
\SLP_Actions::init registers this taxonomy.
// Register Store Pages Custom Type
register_post_type( SLPlus::locationPostType, $storepage_attributes );
The default attributes for the store page is defined as:
$storepage_attributes = apply_filters( 'slp_storepage_attributes', array(
'labels' => $storepage_labels,
'public' => false,
'has_archive' => true,
'description' => sprintf( __( '%s location pages.', 'store-locator-le' ), SLPLUS_NAME ),
'menu_position' => 32,
'menu_icon' => SLPlus::menu_icon,
'show_in_menu' => current_user_can( 'manage_slp_admin' ),
'capabilities' => array(
'create_posts' => 'do_not_allow',
),
'map_meta_cap' => true,
'supports' => $storepage_features,
) );
With the SLP specific filter ‘slp_storepage_attributes‘ allowing modifications to that.
\SLP_Power_Pages::modify_storepage_attributes modifies that attributes list.
It is invoked by adding the filter (hook) here: \SLP_Power_Pages::add_hooks_and_filters
Which is called via \SLP_Power_Pages::initialize
In the call stack it looks like \SLP_Power_Pages::add_hooks_and_filters is being called.
However, \SLP_Power_Pages::modify_storepage_attributes seems to be skipped.
This could be an order of precedence issue…
- \SLP_Actions::init – sets up the custom post type…
- called early, in the WP init hook at priority 9
from \SLP_Actions::initialize
- called early, in the WP init hook at priority 9
- \SLP_Power_Pages::initialize – which adds the Power tweaks to the attributes…
- called too late, at WP init hook at priority 10
- from \SLP_BaseClass_Addon::initialize
via add_action( ‘init’, [ $this, ‘run_during_init’ ], 10 );- which is fired from \SLPPower::run_during_init
As part of the SLPPower class setup and initialization.
- which is fired from \SLPPower::run_during_init
- from \SLP_BaseClass_Addon::initialize
- called too late, at WP init hook at priority 10
This means the Power modifier (filter) is not ready when SLP needs it.
Note: we cannot move run_during_init to priority 8. This is invoked via a shared class that has been extended. Other objects require that hook be fired AFTER the Store Locator Plus plugin is fully initialized at the WordPress init hook at level 9.