• Marcin

    (@marcinkopec)


    Hi,
    I’m creating a plugins. Works well but I have to add created tab/functionaliy not only to admin. I read manuals, watched tutorials and checked how are another plugins coded but I can’t find this command.

    The begining of my plugins is like that:

    // Hook for adding admin menus
    add_action('admin_menu', 'ekspertyzy');
    
    // action function for above hook
    function ekspertyzy() {
    
    // Add a new top-level menu (ill-advised):
    add_menu_page(__('Ekspertyzy'), __('Ekspertyzy'), 'manage_options', 'eksperises', 'ekspertyzy_page' ,'',4);
    }
    
    wp_register_style('myStyleSheet', plugins_url('/ekspertyzy/a_styles.css'), __FILE__);
    wp_enqueue_style( 'myStyleSheet');
    
    // mt_toplevel_page() displays the page content for the custom Test Toplevel menu
    function ekspertyzy_page() {
    //here a code for plugin...
    }

    I was trying to replace

    add_action('admin_menu', 'ekspertyzy');

    with something like

    add_action('admin_menu, author_menu', 'ekspertyzy');

    but didn’t find right command.

    How can I implement this for authors? Not only for admin.
    Regards,
    Marcin

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    The menu authors see is still the admin_menu, except certain things are not shown because of their limited capabilities. This is done using current_user_can() .

    Thus you still add a callback function to the ‘admin_menu’ action, but in that function wrap the code meant only for authors in

    if ( current_user_can('author')) {
       //your author only code
    }

    Thread Starter Marcin

    (@marcinkopec)

    I was trying use it and it returns fatal error.

    Fatal error: Call to undefined function wp_get_current_user().

    This sets access by roles but using this

    add_menu_page(__('Ekspertyzy'), __('Ekspertyzy'), 'author', 'eksperises', 'ekspertyzy_page' ,'',4);

    Exclude admin :/

    Moderator bcworkz

    (@bcworkz)

    Undefined function errors are due to the WP environment not being properly initialized. Unusual for plugins, you must have front end content directly requesting a PHP page?

    For access by both authors and admins pick a capability they both have and use that. Specifying roles does not give the same flexibility as capabilities, which is why capabilities are strongly encouraged over roles.

    Thread Starter Marcin

    (@marcinkopec)

    First of all thank you for respond.
    Finally I run your command successfully however I read few another articles about creating plugins and I did something like this

    add_menu_page(__('Ekspertyzy'), __('Ekspertyzy'), 'edit_published_posts', 'eksperises', 'ekspertyzy_page' ,'',4);

    According to manual edit_published_posts is common part for Authors and Admin permision what solved my task and it looks similar to this what you mentioned about.

    But, if you see anything wrong in this technique just let me know.
    Rest of plugins part I rendered using just condition statesments.
    Regards,
    Marcin

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creatign plugin’ is closed to new replies.