NateWr / business-profile

WordPress plugin to display your business's contact details with seo-friendly Schema.org markup.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow non-administrators to manage Business Profile

lmartins opened this issue · comments

On my customers websites I usually give them a slightly lower that full administrator role permissions. This is so that I can protect some sensible areas where they could introduce problems.

Problem is I need to allow them to manage business-profile details but that seems to be accessible only by administrators.

Is there any way I can customize this?

The capability is defined in the big settings object here, which is filtered here. So you could do something like this:

$sap = apply_filters( 'bpfwp_settings_page', $sap );

add_filter( 'bpfwp_settings_page', 'yourcustom_settings' );
function yourcustom_settings( $sap ) {

    // Inspect the $sap object here. The capability will be somewhere there.
    // Just modify it to the cap you'd prefer and then return it.
    //
    // $sap->page->wherever->i->cant->remember['capability'] = 'edit_posts';

    return $sap;
}

Yeah, that whole big $sap is filtered. You'll need to dig in to figure out precisely where the cap gets stored, though.

I've tried with the following:

$sap = apply_filters( 'bpfwp_settings_page', $sap );

add_filter( 'bpfwp_settings_page', 'yourcustom_settings' );
function yourcustom_settings( $sap ) {

    $sap->pages['bpfwp-settings']->capability = 'edit_theme_options';

    return $sap;
}

This does make the option available to non-admin users, but when I try to save any changes I get a screen saying "Cheatin’ uh?". Is this to be expected?

Hmm, that does sound familiar. It's probably something internal to the simple-admin-pages lib.

Yeah, it looks like I fixed a problem like this back in December. It looks like Business Profile is using the latest version of that lib, so it should work.

Sorry, I don't have time to look into this further right now, as I'm coming up on a big deadline. But in theory it ought to work. Have you tried some other caps? Maybe it has to do with the distinction between meta caps and individual caps....

Oh, the obvious thing to check is to make sure you're hooked in really early. The lib actually kicks in registers the page pretty early (admin_init I think), so make sure you're jumping in early.

Also, you can get rid of this line as it's not needed:

$sap = apply_filters( 'bpfwp_settings_page', $sap );

Were you ever able to solve this problem? I tracked down the source of the issue with the Simple Admin Pages library and fixed it there. I've updated the library in the plugin and the fix should go out with the next update -- likely tonight or tomorrow.

Once that fix goes out, you should be able to use code like this to edit the capability, as long as it's executed before admin_init:

add_filter( 'bpfwp_settings_page', 'bp_allow_editor_access' );
function bp_allow_editor_access( $sap ) {

        $sap->pages['bpfwp-settings']->capability = 'edit_pages';

        return $sap;
}

I'm reopening this because I think Editors should be allowed to manage the Business Profile options by default. The manage_options capability should be changed to edit_posts.