Skip to content

Instantly share code, notes, and snippets.

@marceltt
Created May 29, 2017 03:46
Show Gist options
  • Save marceltt/e732285e195fa539245b7b5af19fdf4c to your computer and use it in GitHub Desktop.
Save marceltt/e732285e195fa539245b7b5af19fdf4c to your computer and use it in GitHub Desktop.
Better integrate Flamingo admin menu with Contact Form 7
<?php
add_action( 'admin_menu', '_wp_flamingo_humility', 999 );
function _wp_flamingo_humility() {
// Only do if Contact Form 7 is active
if ( !is_plugin_active( 'contact-form-7/wp-contact-form-7.php' ) ) return;
// More descriptive CF7 menu label
$wpcf7_menu = _get_menu_index_by_slug( 'wpcf7' );
$GLOBALS['menu'][$wpcf7_menu][0] = __('Forms', 'textdomain');
// Optional: Hide CF7 "Integration" submenu
remove_submenu_page( 'wpcf7', 'wpcf7-integration' );
// Only do if Flamingo is active
if ( !is_plugin_active( 'flamingo/flamingo.php' ) ) return;
// Drop default Flamingo admin menu
remove_menu_page('flamingo');
// Add "Inbound Messages" link to CF7 Menu with better menu label
add_submenu_page(
'wpcf7',
__( 'Flamingo Inbound Messages', 'flamingo' ),
__( 'Submissions', 'flamingo' ),
'flamingo_edit_inbound_messages',
'admin.php?page=flamingo_inbound'
);
}
// Fix menu highlighting for Flamingo when moved to CF7 submenu
add_filter( 'parent_file', '_wp_flamingo_menu_highlight' );
function _wp_flamingo_menu_highlight( $parent_file ) {
if (isset($_GET['page']) && $_GET['page'] == 'flamingo_inbound'){
$GLOBALS['plugin_page'] = 'wpcf7';
$GLOBALS['submenu_file'] = 'admin.php?page=flamingo_inbound';
}
return $parent_file;
}
// Helper function to find admin menu index by slug
function _get_menu_index_by_slug( $location = '' ) {
foreach ( $GLOBALS['menu'] as $index => $menu_item ) {
if ( $location === $menu_item[2] ) {
return $index;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment