%s', admin_url( 'options-general.php?page=pomelo-analytics' ), __( 'Settings', 'pomelo-analytics' ) ); array_unshift( $links, $settings_link ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'pomelo_settings_link' ); /** * Time zone of the Pomelo site attached by the connection, which decides the * days of its reports. The WordPress time zone when it is not known. * * @return DateTimeZone */ function pomelo_get_site_timezone() { $connection = get_option( 'pomelo_connection', array() ); $zone = is_array( $connection ) ? (string) ( $connection['timezone'] ?? '' ) : ''; if ( '' !== $zone ) { try { return new DateTimeZone( $zone ); } catch ( Exception $e ) { unset( $e ); } } return wp_timezone(); } /** * Return the configured Pomelo site id. * * The legacy option name is kept as a read fallback for early beta installs. * * @return string */ function pomelo_get_site_id() { $site_id = get_option( 'pomelo_site_id', '' ); if ( ! empty( $site_id ) ) { return $site_id; } $legacy_site_id = get_option( 'pomelo_property_key', '' ); if ( is_string( $legacy_site_id ) && 0 === strpos( $legacy_site_id, 'site_' ) ) { return $legacy_site_id; } return ''; } /** * URL of a Pomelo dashboard page, in the administrator's language. * * @param string $path Path after the language, for example "settings/account#emails". * @param array $args Query arguments. * @return string */ function pomelo_app_url( $path = '', $args = array() ) { $locale = substr( get_user_locale(), 0, 2 ); $locale = in_array( $locale, array( 'fr', 'en' ), true ) ? $locale : 'en'; $hash = ''; if ( false !== strpos( $path, '#' ) ) { list( $path, $hash ) = explode( '#', $path, 2 ); $hash = '#' . $hash; } $url = POMELO_APP_BASE . '/' . $locale . ( '' !== $path ? '/' . ltrim( $path, '/' ) : '' ); if ( ! empty( $args ) ) { $url = add_query_arg( array_map( 'rawurlencode', $args ), $url ); } return $url . $hash; } /** * Activation hook. */ function pomelo_activate() { add_option( 'pomelo_site_id', '', '', false ); add_option( 'pomelo_property_key', '', '', false ); add_option( 'pomelo_api_token', '', '', false ); add_option( 'pomelo_advanced_settings', array(), '', false ); add_option( 'pomelo_verification_token', '', '', false ); } register_activation_hook( __FILE__, 'pomelo_activate' );