PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

remove_menu_page breaks form edit interface

  1. Stylmark
    Member

    I've found that adding this to the admin_init hook will break the Gravity Forms edit form interface:

    function my_func_clear_admin() {
    remove_menu_page('edit-comments.php');
    remove_menu_page('link-manager.php');
    }

    regardless of the function name, having any kind of remove_menu_page function call will cause the edit form screen to throw a javascript error:

    Uncaught SyntaxError: Unexpected identifier in tw-sack.js line 1

    Are there any solutions to this?

    Posted 11 years ago on Sunday September 23, 2012 | Permalink
  2. Hi Stylmark,

    Using the latest version of Gravity Forms and WordPress running TwentyTen, I added this code to my functions.php file and was unable to recreate this issue.

    http://pastie.org/4793301

    Can you do the theme and plugin test and confirm there is not issue there?

    http://www.gravityhelp.com/documentation/page/Testing_for_a_Theme/Plugin_Conflict

    Posted 11 years ago on Monday September 24, 2012 | Permalink
  3. Matt Banks
    Member

    I can duplicate this issue as I just ran into it myself with v1.6.10.1. Form editing works fine in Twenty Twelve and with/without all plugins active, so I switched back to my custom theme and started deleting functions until I found the culprit, and it looks like remove_menu_page() is the one that did it. I'm hiding Posts and Comments for this client since they aren't using them, but I think I'm going to have to leave them in now since it's not allowing form editing.

    Any idea what might be causing this?

    Thanks,
    Matt

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  4. David Peralty

    Can you give us more details, or maybe provide us with the steps to recreate the issue? What version of WordPress are you using? Is it a completely custom theme? Does your theme add any JS to the WP Admin?

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  5. Matt Banks
    Member

    Completely custom theme on WordPress 3.5, all JS is loaded with !is_admin() in the enqueue, so it's only loading on the front end. I tried taking out all theme JS and CSS, but it was still preventing me from editing the form. The only thing that fixed it was taking away the call to remove_menu_page(). Here's the call I'm using in functions.php:

    // Hide Admin Areas that are not used
    add_action( 'admin_init', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
    	remove_menu_page('edit.php');
    	remove_menu_page('edit-comments.php');
    }

    This was the only thing in the theme that made it stop working, so I turned it off for now, but need to get it turned back on if possible.

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  6. David Peralty

    Very strange, I'll pass it on to our developers. Is there any way you would be willing to give us a copy of the theme - even better if its functions.php still had that code so we can see it not working to troubleshoot?

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  7. Matt Banks
    Member

    David - sure I can send the theme. It's still in development and I'm doing it locally on my Mac for a client, so if I can get it to you privately since it's client work, that would be great.

    It's based on my starter theme that I have on Github - https://github.com/mattbanks/WordPress-Starter-Theme

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  8. Matt Banks
    Member

    Also getting the following JS errors when remove_menu_page is on:

    Uncaught SyntaxError: Unexpected token <
    in admin.php:3232

    Uncaught SyntaxError: Unexpected token <
    in admin.php:1

    Uncaught SyntaxError: Unexpected token <
    in tw-sack.min.js:1

    Also, with the code inactive for remove_menu_page, I'm getting the first JS error whenever I edit a form anyway, so something is causing a JS error regardless.

    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  9. Matt Banks
    Member

    I did a but more digging and found out the recommended hook has changed for removing menu pages. I had it hooked to admin_init, which was running entirely too soon. Changed it to hook into admin_menu and it now form editing is not broken!

    Here's the proper revised code that works, in case others see this and wonder what's needed:

    // Hide Admin Areas that are not used
    add_action( 'admin_menu', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
    	remove_menu_page('edit.php');
    	remove_menu_page('edit-comments.php');
    }
    Posted 11 years ago on Thursday December 13, 2012 | Permalink
  10. Thank you for that update.

    Posted 11 years ago on Thursday December 13, 2012 | Permalink

This topic has been resolved and has been closed to new replies.