Givewp: fix(admin-menu): display Donation forms in Edit Menus tab by default

Created on 5 Sep 2017  路  9Comments  路  Source: impress-org/givewp

Issue Overview

I thought we resolved this with https://github.com/WordImpress/Give/issues/1765 but I'm not seeing it on a fresh install.

Expected Behavior

Donation forms is added by default on plugin install:
2017-09-05_11-53-40

Current Behavior

It's not.

All 9 comments

This works by filtering the user option in order to add add-post-type-give_forms into the $initial_meta_boxes array. This prevents Donation Forms from being hidden by default.

function give_filter_initial_nav_menu_meta_boxes( $result, $option, $user ) {
    global $wp_meta_boxes;

    // Only run if user option is empty (which means first-time visit to Menus page).
    if ( ! empty( $result ) || ! is_array( $wp_meta_boxes ) ) {
        return $result;
    }

    // Include give_forms in the initial meta boxes array.
    $initial_meta_boxes = array( 'add-post-type-page', 'add-post-type-post', 'add-custom-links', 'add-category', 'add-post-type-give_forms' );
    $hidden_meta_boxes = array();

    foreach ( array_keys($wp_meta_boxes['nav-menus']) as $context ) {
        foreach ( array_keys($wp_meta_boxes['nav-menus'][$context]) as $priority ) {
            foreach ( $wp_meta_boxes['nav-menus'][$context][$priority] as $box ) {
                if ( in_array( $box['id'], $initial_meta_boxes ) ) {
                    unset( $box['id'] );
                } else {
                    $hidden_meta_boxes[] = $box['id'];
                }
            }
        }
    }

    $user = wp_get_current_user();
    update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true );

    // Return hidden meta boxes which should no longer include `add-post-type-give_forms`.
    return $hidden_meta_boxes;
}
add_filter( 'get_user_option_metaboxhidden_nav-menus', 'give_filter_initial_nav_menu_meta_boxes', 10, 3 );

I agree with @mehul0810 that a better approach would be to propose a core filter to modify $initial_meta_boxes. Without that filter, I've had to duplicate much of the wp_initial_nav_menu_meta_boxes() function.

Thanks @kevinwhoffman.
I have already created a ticket to WordPress Core. For Reference: https://core.trac.wordpress.org/ticket/41820

Also for future reference, we can simulate "fresh install" behavior by deleting the metaboxhidden_nav-menus user option associated with your account.

Here is the link to actual issue reported: https://core.trac.wordpress.org/ticket/16828

Summary of Slack convo: Move forward with snippet I provided above. Revisit this issue after Trac ticket is resolved to decide if snippet is still needed or can be simplified.

Thanks @mehul0810 for the workaround fix until wp core makes it easier. I've renamed and bumped this off the milestone. We'll circle back post core fix.

@mehul0810 There is a merged PR above that claims to resolve this issue. Please confirm if Donation Forms appear in the Menus screen by default. If so, go ahead and close this out.

I have tested this on a fresh installation of WordPress and Give plugin. The screen option for Donation Forms was already clicked.

This is the screenshot after fresh installation:

checked

This can be closed @ravinderk

Thanks for confirming @Sidsector9

Was this page helpful?
0 / 5 - 0 ratings