WordPress.org

Ready to get started?Download WordPress

Forums

500 Internal Server Error on Menu Saving (15 posts)

  1. soam
    Member
    Posted 2 years ago #

    We have around 185+ items which includes parent and sub menu items for the MAIN NAV.

    We are on wordpress 3.3.1 .

    Everytime we want to add a new menu, we are unable to do it.

    When we add it and click on SAVE, the page processes for like 5-7 minutes and then shows 500 Internal server error and the new menu never gets added.

    What wrong with wordpress ?

    Its so frustrating.

    [No bumping. If it's that urgent, consider hiring someone.]

  2. Tara
    Member
    Posted 2 years ago #

    - Error 500 is very generic and can be caused by numerous underlying issues. Your first step should be locating error log for your hosting account or asking support to help with that.
    -it may indicate .htaccess issue. Regenerate .htaccess, and be sure the encoding in your text editor is Unicode No BOM.
    -It may also indicate a problem with the configuration on the server. Usually your hosting company tech support can help.

  3. esmi
    Forum Moderator
    Posted 2 years ago #

    We have around 185+ items which includes parent and sub menu items for the MAIN NAV.

    185! Oh - be serious! Your server won't be able to handle them all.

  4. soam
    Member
    Posted 2 years ago #

    why not ?

    185 is not that big number.

    I have seen sites, who has numerous drop down items , lots of child items in the menus.

    How are they doing this ?

    WHy such limitation in wordpress ?

  5. Ov3rfly
    Member
    Posted 2 years ago #

    Had the same problem with WordPress 3.2.1 and a bigger menu (about 90-100 items).

    Tried many things and the only real solution was to edit /wp-includes/nav-menu.php and /wp-admin/nav-menues.php and /wp-admin/includes/nav-menu.php and remove the (in the site in question unused) fields 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes' and 'menu-item-xfn' from the <form> in admin-interface (the html visible inputs and hidden fields), and in the wp_update_nav_menu_item() from $defaults and update_post_meta() loop for processing and from $post_fields at $action == 'update'.

    This is not a simple hack but works fine if you know what you are doing.

    I consider that issue as a serious problem within WordPress and can't recommend it for bigger sites any more since I discovered this.

    I did not test this with WP 3.3 yet, no update yet with this site, because I still see a lot of complains about even worse admin-performance compared to WP 3.2.1

    Note: If you search for 500 error in WordPress.org, you'll find many posts about this...

  6. soam
    Member
    Posted 2 years ago #

    Damn, so does the WP core guys know about this ?

    This is a serious issue then.

    I really dont want to hack anything from core. Just need to know, why its happening.

  7. Ov3rfly
    Member
    Posted 2 years ago #

    Reason: The problem happens because a lot of data in visible and hidden fields is passed from the menu html <form> to the php-code and on many server-configurations the available memory and/or time is exhausted while processing that data.

    There are various reports in official bug tracker, forums etc. but most just say 'y u no less entries' or 'buy a dedicated server'.

    Hacking the kernel was also my last option, but the site was live already and customer had to add more menu-items, dedicated server was too expensive, so it was the only option.

    Some more technical background: The above method shaves 4 visible inputs and 4 hidden fields per menu-entry which are in above case about 800 variables less to handle for the php-code. Additionally the above method does not even look at these fields any more in php which also makes it consume less time and memory.

    PS. If somebody is interested in the above kernel-patches, I can supply the 3 patched files for 3.2.1, no problem...

  8. soam
    Member
    Posted 2 years ago #

    Please do. I need the path files .

    This is so frustrating.

    WordPress lacks so many core features, which should come out of the box.
    No good and pathetic support.

    A core problem has not been solved for years . What a joke!

  9. Ov3rfly
    Member
    Posted 2 years ago #

    wordpress-3.2.1/wp-admin/nav-menus.php

    333 (old):

    $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description', 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' );

    333 (new):

    $post_fields = array( 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 'menu-item-title', 'menu-item-url', 'menu-item-description' /* , 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' */ );

    383 (old):

    do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
    
    $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>';
    unset( $menu_items, $unsorted_menu_items );

    383 (new):

    // do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
    
    // $messages[] = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>';
    // unset( $menu_items, $unsorted_menu_items );

    391 (new, end script here...):

    exit('<a href="./nav-menus.php">Continue...</a>');

    wordpress-3.2.1/wp-admin/includes/nav-menu.php

    140 (old):

    <p class="description description-thin">
    	<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
    		<?php _e( 'Title Attribute' ); ?><br />
    		<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
    	</label>
    </p>
    <p class="field-link-target description description-thin">
    	<label for="edit-menu-item-target-<?php echo $item_id; ?>">
    		<?php _e( 'Link Target' ); ?><br />
    		<select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]">
    			<option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option>
    			<option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option>
    		</select>
    	</label>
    </p>
    <p class="field-css-classes description description-thin">
    	<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
    		<?php _e( 'CSS Classes (optional)' ); ?><br />
    		<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
    	</label>
    </p>
    <p class="field-xfn description description-thin">
    	<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
    		<?php _e( 'Link Relationship (XFN)' ); ?><br />
    		<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
    	</label>
    </p>

    140 (new):

    <p class="description description-thin">
    <?php /* <label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
    		<?php _e( 'Title Attribute' ); ?><br />
    		<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
    	</label>	*/ ?>
    </p>
    <?php /* <p class="field-link-target description description-thin">
    	<label for="edit-menu-item-target-<?php echo $item_id; ?>">
    		<?php _e( 'Link Target' ); ?><br />
    		<select id="edit-menu-item-target-<?php echo $item_id; ?>" class="widefat edit-menu-item-target" name="menu-item-target[<?php echo $item_id; ?>]">
    			<option value="" <?php selected( $item->target, ''); ?>><?php _e('Same window or tab'); ?></option>
    			<option value="_blank" <?php selected( $item->target, '_blank'); ?>><?php _e('New window or tab'); ?></option>
    		</select>
    	</label>
    </p>
    <p class="field-css-classes description description-thin">
    	<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
    		<?php _e( 'CSS Classes (optional)' ); ?><br />
    		<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
    	</label>
    </p>
    <p class="field-xfn description description-thin">
    	<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
    		<?php _e( 'Link Relationship (XFN)' ); ?><br />
    		<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
    	</label>
    </p>	*/ ?>

    267 (old):

    $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
    $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
    $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
    $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';

    267 (new):

    // $output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
    // $output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
    // $output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( implode( ' ', $item->classes ) ) .'" />';
    // $output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';

    1023 (old):

    'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),
    'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),
    'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),
    'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),

    1023 (new):

    // 'menu-item-attr-title' => ( isset( $_item_object_data['menu-item-attr-title'] ) ? $_item_object_data['menu-item-attr-title'] : '' ),
    // 'menu-item-target' => ( isset( $_item_object_data['menu-item-target'] ) ? $_item_object_data['menu-item-target'] : '' ),
    // 'menu-item-classes' => ( isset( $_item_object_data['menu-item-classes'] ) ? $_item_object_data['menu-item-classes'] : '' ),
    // 'menu-item-xfn' => ( isset( $_item_object_data['menu-item-xfn'] ) ? $_item_object_data['menu-item-xfn'] : '' ),

    wordpress-3.2.1/wp-includes/nav-menu.php

    286 (old):

    $defaults = array(
    	'menu-item-db-id' => $menu_item_db_id,
    	'menu-item-object-id' => 0,
    	'menu-item-object' => '',
    	'menu-item-parent-id' => 0,
    	'menu-item-position' => 0,
    	'menu-item-type' => 'custom',
    	'menu-item-title' => '',
    	'menu-item-url' => '',
    	'menu-item-description' => '',
    	'menu-item-attr-title' => '',
    	'menu-item-target' => '',
    	'menu-item-classes' => '',
    	'menu-item-xfn' => '',
    	'menu-item-status' => '',
    );

    286 (new):

    $defaults = array(
    	'menu-item-db-id' => $menu_item_db_id,
    	'menu-item-object-id' => 0,
    	'menu-item-object' => '',
    	'menu-item-parent-id' => 0,
    	'menu-item-position' => 0,
    	'menu-item-type' => 'custom',
    	'menu-item-title' => '',
    	'menu-item-url' => '',
    	'menu-item-description' => '',
    /*	'menu-item-attr-title' => '',
    	'menu-item-target' => '',
    	'menu-item-classes' => '',
    	'menu-item-xfn' => '',		*/
    	'menu-item-status' => '',
    );

    343 (old):

    $post = array(
    	'menu_order' => $args['menu-item-position'],
    	'ping_status' => 0,
    	'post_content' => $args['menu-item-description'],
    	'post_excerpt' => $args['menu-item-attr-title'],
    	'post_parent' => $original_parent,
    	'post_title' => $args['menu-item-title'],
    	'post_type' => 'nav_menu_item',
    );

    343 (new):

    $post = array(
    	'menu_order' => $args['menu-item-position'],
    	'ping_status' => 0,
    	'post_content' => $args['menu-item-description'],
    	// 'post_excerpt' => $args['menu-item-attr-title'],
    	'post_parent' => $original_parent,
    	'post_title' => $args['menu-item-title'],
    	'post_type' => 'nav_menu_item',
    );

    383 (old):

    update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
    
    $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
    $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );

    383 (new):

    /*
    update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
    
    $args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
    $args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
    */

    You can also remove the description accordingly, it is not used in most themes and can cause quite much database/post-data as well...

  10. soam
    Member
    Posted 2 years ago #

    Can you send me your file directly , so I can replace and test ?

    Im afraid to so many changes, as the site might break and I cant afford that :(

  11. Ov3rfly
    Member
    Posted 2 years ago #

    Decided not to post already patched files but the above detailed change-instructions instead. Reasons for this:

    1. With these instructions also 3.3.x and other version users can implement the changes.

    2. Changes to core files should be understood well before use and not just be used by blindly overwriting a few files.

    Note: If you don't have a backup- oder testing-site, do not alter the core in any way.

  12. rmvalues
    Member
    Posted 2 years ago #

    Hi Ov3rfly, I tried your method, but still received error 500, my error log :

    ******************************
    mod_fcgid: read data timeout in 31 seconds, referer: myurl/wp-admin/nav-menus.php
    Premature end of script headers: nav-menus.php, referer: myurl/wp-admin/nav-menus.php
    ******************************

    any other idea to help ?

    thanks

  13. Ov3rfly
    Member
    Posted 2 years ago #

    Which WordPress version are you using?
    How many menu-items do you have?
    Does the error also appear if you disable all plugins?

  14. ditler
    Member
    Posted 1 year ago #

    Finally it is solved in WordPress 3.5

    Thank the team! Seems it has been taken care of at http://core.trac.wordpress.org/ticket/14134

    I was on pins and needles for this bugfix to come...

  15. a4jp.com
    Member
    Posted 1 year ago #

    I just renamed the .htaccess file in Dreamweaver and a new file was made automatically. That fixed my code 500 problem.

Topic Closed

This topic has been closed to new replies.

About this Topic