*/ use RankMath\Helper; defined( 'ABSPATH' ) || exit; /** * Enable the new Analytis module */ function rank_math_1_0_49_enable_new_analytics_module() { $active_modules = get_option( 'rank_math_modules', [] ); if ( is_array( $active_modules ) && in_array( 'search-console', $active_modules, true ) ) { Helper::update_modules( [ 'analytics' => 'on' ] ); rank_math_1_0_49_reconnect_sc_notification(); } } /** * Sync the user roles with new module. */ function rank_math_1_0_49_sync_user_roles() { wp_roles(); foreach ( Helper::get_roles() as $slug => $role ) { $role = get_role( $slug ); if ( ! $role ) { continue; } if ( $role->has_cap( 'rank_math_search_console' ) ) { $role->add_cap( 'rank_math_analytics' ); $role->remove_cap( 'rank_math_search_console' ); } } } /** * Show notice to re-connect if Search Console was previously connected. * * @return bool */ function rank_math_1_0_49_reconnect_sc_notification() { $key = 'rank_math_search_console_data'; $option = get_option( $key, [] ); if ( ! is_array( $option ) || empty( $option['authorized'] ) ) { return; } Helper::add_notification( sprintf( // Translators: placeholders are the opening and closing anchor tags. esc_html__( 'Thank you for updating Rank Math! We\'ve completely revamped our Analytics module with Google Analytics & Google Search Console integrations. For a seamless experience, please re-authenticate your Google account. %1$sClick here to Connect%2$s', 'rank-math' ), '
', '
' ), [ 'type' => 'warning', 'id' => 'rank_math_analytics_reauthenticate', ] ); } rank_math_1_0_49_sync_user_roles(); rank_math_1_0_49_enable_new_analytics_module();