How to set role specific use for marketpress plugin

I need to have a user (Similar to Author)that can only adjust their own post, and their own products. It seems like i have to make the user an editor before they can deal with products. However I do not want them dealing with pages etc.

Is there an easy way to set this up? or is there a plugin that will help do it?

Thanks,

Steve

  • Jonathan
    • The Bug Hunter

    Hi @qtree-systems,

    You can hook into the mp_register_post_type filter. Here’s the filter in the source code:

    register_post_type('product' , apply_filters('mp_register_post_type', array(
    'labels' => array(
    'name' => __('Products', 'mp'),
    'singular_name' => __('Product', 'mp'),
    'menu_name' => __('Products', 'mp'),
    'all_items' => __('Products', 'mp'),
    'add_new' => __('Create New', 'mp'),
    'add_new_item' => __('Create New Product', 'mp'),
    'edit_item' => __('Edit Product', 'mp'),
    'edit' => __('Edit', 'mp'),
    'new_item' => __('New Product', 'mp'),
    'view_item' => __('View Product', 'mp'),
    'search_items' => __('Search Products', 'mp'),
    'not_found' => __('No Products Found', 'mp'),
    'not_found_in_trash' => __('No Products found in Trash', 'mp'),
    'view' => __('View Product', 'mp')
    ),
    'description' => __('Products for your e-commerce store.', 'mp'),
    'public' => true,
    'show_ui' => true,
    'publicly_queryable' => true,
    'capability_type' => 'page',
    'hierarchical' => false,
    'menu_icon' => $icon,
    'rewrite' => array(
    'slug' => $this->get_setting('slugs->store') . '/' . $this->get_setting('slugs->products'),
    'with_front' => false
    ),
    'query_var' => true,
    'supports' => array(
    'title',
    'editor',
    'author',
    'excerpt',
    'revisions',
    'thumbnail',
    ),
    'taxonomies' => array(
    'product_category',
    'product_tag',
    ),
    )));

    You want to change the capability_type to post instead of page.

  • qtree-systems
    • Site Builder, Child of Zeus

    You want to change the capability_type to post instead of page.

    ‘capability_type’ => ‘page’,

    If I change this to

    ‘capability_type’ => ‘post’,

    Will that give “Authors” the ability to see the products menu’s?

    If so that is all I need done. the only author on the site will be the owner. I really do not want him editing pages, it make way too much work for me to troubleshoot and fix.

  • Jonathan
    • The Bug Hunter

    Yes :slight_smile:

    And you’ll also need to change the “order” capability type to post instead of page using the following filter:

    apply_filters('mp_orders_capability', 'page')

    Otherwise, he’ll be able to see products but not orders.

  • qtree-systems
    • Site Builder, Child of Zeus

    Sorry for the delay I have been out of town.

    Changed marketpress.php from page to post – (worked perfectly!)

    'capability_type' => 'post',

    Changed marketpress.php from page to post – (Had no effect)

    apply_filters('mp_orders_capability', 'post')

    The edit to the filters code did not open the order menu to the Author Login

    We are halfway there!! any suggestions on what to do next??

    Thanks,

    Steve

  • Jonathan
    • The Bug Hunter

    Hiya @qtree-systems,

    Sorry for the delay in my response. So there’s some additional code that’s required here. In marketpress.php find the add_menu_items() function (around line 629) and replace with the following. I’ll make sure I get this added in the next version of MarketPress so it won’t break anything on your site if you update. :slight_smile:

    function add_menu_items() {
    //only process the manage orders page for editors and above and if orders hasn't been disabled
    $order_cap = apply_filters('mp_orders_cap', 'edit_others_posts');

    if (current_user_can($order_cap) && !$this->get_setting('disable_cart')) {
    $num_posts = wp_count_posts('mp_order'); //get pending order count
    $count = $num_posts->order_received + $num_posts->order_paid;
    if ( $count > 0 )
    $count_output = ' <span class="update-plugins"><span class="updates-count count-' . $count . '">' . $count . '</span></span>';
    else
    $count_output = '';
    $orders_page = add_submenu_page('edit.php?post_type=product', __('Manage Orders', 'mp'), __('Manage Orders', 'mp') . $count_output, $order_cap, 'marketpress-orders', array(&$this, 'orders_page'));
    }

    $page = add_submenu_page('edit.php?post_type=product', __('Store Settings', 'mp'), __('Store Settings', 'mp'), 'manage_options', 'marketpress', array(&$this, 'admin_page'));
    add_action( 'admin_print_scripts-' . $page, array(&$this, 'admin_script_settings') );
    add_action( 'admin_print_styles-' . $page, array(&$this, 'admin_css_settings') );

    if ( !defined('WPMUDEV_REMOVE_BRANDING') ) {
    add_action( "load-{$page}", array( &$this, 'add_help_tab' ) );
    }
    }

    Once you do that, put the following in your theme’s functions.php file

    add_filter('mp_orders_cap', create_function('$s', 'return "edit_posts";'));

    Also, as far as changing the capability type like you did before you’ll want to make sure you use add_filter(). Don’t change any core files because if you ever update you’ll break any changes you’ve made. :slight_smile:

  • qtree-systems
    • Site Builder, Child of Zeus

    Installed new update for Marketpress.

    Changed following back in maketpress.php because update reset to “page”

    'capability_type' => 'post',

    apply_filters('mp_orders_capability', 'post')

    all works fine..

    I considered moving the file to the child theme, but that would really bypass most updates.

    Thanks,

    Steve

  • Jonathan
    • The Bug Hunter

    Hey Steve,

    Instead of modifying marketpress.php you’ll want to add the following your theme’s functions.php file:

    add_filter('mp_orders_capability', create_function('$s', 'return "post";'));

    This way when you update nothing will break on you like this time. :slight_smile:

  • qtree-systems
    • Site Builder, Child of Zeus

    Do I replace

    add_filter('mp_orders_cap', create_function('$s', 'return "edit_posts";'));

    or just add

    add_filter('mp_orders_capability', create_function('$s', 'return "post";'));

    to the code?

    AND

    do I need to set marketpress.php back to “Page”?

    Thanks,

    Steve

  • qtree-systems
    • Site Builder, Child of Zeus

    I have made the same changes to a different site and had to read/re-read these post several times to remember how so I thought I would post a quick summery to make it easier for me and anyone else that wanted to make the same change.

    Current Versions

    WordPress – Version 3.9.1

    Marketpress – Version 2.9.4.3

    Edit – maketpress.php

    Found in following directory – wp-content/plugins/marketpress

    Replaced “Page” with “Post”

    'capability_type' => 'post',

    apply_filters('mp_orders_capability', 'post')

    Edit – functions.php

    Found in following directory – wp-content/themes/”theme Folder”

    Added following code – around line 30 just after list of define’s

    add_filter('mp_orders_cap', create_function('$s', 'return "edit_posts";'));

    add_filter('mp_orders_capability', create_function('$s', 'return "post";'));

    I hope this helps someone I know I will refer back to it :slight_smile:

    This seems to work, let me know if there is a better way

    Steve

  • Rahul Verma
    • The Incredible Code Injector

    Hello,

    I hope you are well today.

    You need to modify /plugins/marketpress/marketpress-includes/marketpress-stats.php on line 23 as below code.

    Before :

    if ( !current_user_can('manage_options') )
    return;

    After :

    if ( !current_user_can('manage_options') and !current_user_can('edit_others_posts') )
    return;

    Please note that, this changes will be lost in next update. So it’s worth to note down this changes somewhere and apply again after your

    I hope that helps. Please feel free to ask if you have more questions on the same.

    Best Regards

    Sandeep Kumar

  • qtree-systems
    • Site Builder, Child of Zeus

    Store Statistics widget on dashboard – permissions

    /plugins/marketpress/marketpress-includes/marketpress-stats.php

    Around line 43 code for register dashboard

    function register_dashboard_widget() {

    Admin – No edit needed this is the default

    if ( !current_user_can(‘manage_options’:wink: )

    Editor

    if ( !current_user_can('manage_options') and !current_user_can('edit_others_posts') )

    Author

    if ( !current_user_can('manage_options') and !current_user_can('publish_posts') )

    Contributor

    if ( !current_user_can('manage_options') and !current_user_can('edit_posts') )

  • qtree-systems
    • Site Builder, Child of Zeus

    is there a way to make the changes to maketpress.php from page to post without loosing it in every update?

    I know I can move the file over to a child theme, however I would also hate to miss a critical update to maketpress.php

    Thanks,

    Steve

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.