• Resolved daveflyfishing

    (@daveflyfishing)


    I have made a small plugin and all works fine on my localhost dev machine

    When I upload to me live site the admin menu is not shown, it is ok on my localhost

    I have tried to change theme just in case it is something to do with that

    My code is

    function fm2017_setup_menu(){
            add_menu_page( 'Fishing Manager 2017 Plugin Page', 'Fishing Manager 2017', 'manage_options', 'Fishing-Manager-2017', 'fm2017_init' );
    		add_submenu_page("Fishing-Manager-2017", "Manage Venues", "Manage Venues", 0, "Manage-Venues", "fm2017_addvenue");
    		add_submenu_page("Fishing-Manager-2017", "Manage Anglers", "Manage Anglers", 0, "Manage-Anglers", "fm2017_addang");
    		add_submenu_page("Fishing-Manager-2017", "Record Scores", "Record Scores", 0, "Record-Scores", "fm2017_record");
    		}
    add_action('admin_menu', 'fm2017_setup_menu');

    Any help or advice is appreciated

    • This topic was modified 7 years, 9 months ago by bcworkz. Reason: Code fixed
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    I have checked your code and its absolutely fine. It is working on live as well as localhost.

    The problem I think is quotes. In your code you haven’t used single and double quotes. In your code they are other characters which are different then quotes.

    For eg. “Manage Venues” and "Manage Venues". You can see the difference between them.

    I think this is the only possible issue.

    Thanks

    • This reply was modified 7 years, 9 months ago by bcworkz. Reason: straight quotes fixed
    Moderator bcworkz

    (@bcworkz)

    Hello! You all are getting messed up because the forum’s parser changes ‘straight’ quotes to ‘curly’ quotes unless you place code within backticks or use the code button. I’ve fixed your posts this time. Please always do the right thing when posting any code in order to avoid confusion.

    I think the problem may be passing 0 as the capability argument. 0 is probably for user level 0, which is not a true capability. Integer user roles are really out dated. They are still supposed to be recognized for reverse compatibility purposes, but no one should be actively using them. All roles are now named strings. While it’s possible to use roles where a capability is called for, it’s a very poor practice that misses out on the additional power and flexibility provided by capabilities. Pass true capabilities and all will be well ??

    If you change the user level 0 to a capability like 'manage_options', your menus should work fine on a hosted server. I’m unsure why there is different behavior with user levels, it may have to do with automatic type casting or the lack thereof by different versions of PHP.

    Thread Starter daveflyfishing

    (@daveflyfishing)

    Thanks Guys
    It turned out to be down to file location.
    My menu is in a separate file which is included via file_exists and it seemed the location was not found
    Placing all file in the root of my plugin worked so have kept it so

    Many thanks for the help

    Moderator bcworkz

    (@bcworkz)

    Yup, that would do it too ?? I still suggest you avoid using user level arguments and use a proper capability. Level 0 is subscriber role, their only capability is typically ‘read’.

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