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 Part 2
This update requires the SLP (base plugin) to be updated alongside the Power add on.
The registration of the custom post types for locations (aka Store Pages) and the taxonomy (the Store categories) has been moved from the Power add on to the base plugin with all core functionality intact. Previously this registration has resided in the base plugin since version 5 of SLP, but was modified by Power. However, we never provide direct access to the custom post type (Store Pages) unless Power is installed and the “Enable Pages” checkmark is checked; Thus there should be no unintended side effects of enabling the custom post type fully from the start.
This did require moving the page registration until AFTER all options have been loaded from the database, however this appears to have no impact on Store Pages functionality. In fact it may resolve some minor functional issues with this new design.
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.
Resolution Part 1
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.
Power Options Not Ready When Taxonomy Registered
The power options are not ready when the taxonomy is registered.
$power = SLPPower::get_instance();
...
'rewrite' =>
array(
'slug' => $power->options['permalink_starts_with'],
'with_front' => $this->slplus->is_CheckTrue( $power->options['prepend_permalink_blog'] ),
),
At this stage it only holds the DEFAULT values. We need to force a load of these options earlier in the process for this.
Part of the issue here is that the SLP options are loaded AFTER the custom post type has been registered in \SLP_Actions::init
\SLP_Actions::init
if ( ! taxonomy_exists( SLPlus::locationTaxonomy ) ) {
...
register_post_type( SLPlus::locationPostType, $storepage_attributes );
...
do_action( 'slp_init_complete' );
That do_action( ‘slp_init_complete’ ) is what fires the options loading sequence.
For the base plugin this is attached via \SLP_SmartOptions::initialize with add_action( ‘slp_init_complete’, [ $this, ‘slp_init_complete’ ] ); which fires \SLP_SmartOptions::slp_init_complete
For adds ons it is from this base class method: \SLP_BaseClass_Addon::slp_init which is hooked when the add on runs the initialize method: add_action( ‘slp_init_complete’, [ $this, ‘slp_init’ ] );
Moved the Store Pages registration and taxonomy registration to AFTER the options are initialized.