morganestes
9/7/2014 - 12:58 AM

move Yoast Google Analytics top-level nav to a sub menu

move Yoast Google Analytics top-level nav to a sub menu

/**
 * move the main settings page for Yoast Google Analytics
 * from it's own parent menu into a submenu page in either
 * the Yoast SEO menu or in the general settings
 *
 * @return null
 */

function rkv_yoast_ga_menu() {
    // check for the Yoast GA class in the event the plugin
    // has been removed
    if ( ! class_exists( 'Yoast_GA_Options' ) ) {
        return;
    }
    // set the path
    $path   = plugin_dir_path( GAWP_FILE );
    // first remove the top level menu item
    remove_menu_page( 'yst_ga_dashboard' );
    // check for Yoast SEO plugin first
    // and if present, add the item there
    if ( function_exists( 'wpseo_auto_load' ) ) {
        add_submenu_page( 'wpseo_dashboard', __( 'Google Analytics', 'google-analytics-for-wordpress' ), __( 'Google Analytics', 'google-analytics-for-wordpress' ), 'manage_options', 'yst_ga_settings', 'rkv_yoast_ga_page' );
    } else {
        // Yoast SEO not installed, just put it into main settings
        add_options_page( __( 'Yoast Google Analytics', 'google-analytics-for-wordpress' ), __( 'Yoast Google Analytics', 'google-analytics-for-wordpress' ), 'manage_options', 'admin.php?page=yst_ga_settings', 'rkv_yoast_ga_page' );
    }
}

add_action( 'admin_menu', 'rkv_yoast_ga_menu', 2001 );

/**
 * call the files required for the Yoast GA page to
 * render properly
 * @return null
 */
function rkv_yoast_ga_page() {
    // check for the defined file in the event that the plugin
    // has been removed
    if ( ! defined( 'GAWP_FILE' ) ) {
        return;
    }
    // set the path
    $path   = plugin_dir_path( GAWP_FILE );
    // load our two files
    require_once( $path . 'admin/class-admin-ga-js.php' );
    require_once( $path . 'admin/pages/settings.php' );
}