dismiss_notice(); $this->consent(); // This is the last thing to run. No impact on performance or anything else. add_action( 'wp_footer', array( $this, 'maybe_send_data' ), 99999 ); } /** * Maybe send data. * * @access public * @since 3.0.36 * @return void */ public function maybe_send_data() { // Check if the user has consented to the data sending. if ( ! get_option( 'kirki_telemetry_optin' ) ) { return; } // Only send data once/month. We use an option instead of a transient // because transients in some managed hosting environments don't properly update // due to their caching implementations. $sent = get_option( 'kirki_telemetry_sent' ); if ( ! $sent || $sent < time() - MONTH_IN_SECONDS ) { $this->send_data(); update_option( 'kirki_telemetry_sent', time() ); } } /** * Sends data. * * @access private * @since 3.0.36 * @return void */ private function send_data() { // Ping remote server. wp_remote_post( 'https://wplemon.com/?action=kirki-stats', array( 'method' => 'POST', 'blocking' => false, 'body' => array_merge( array( 'action' => 'kirki-stats', ), $this->get_data() ), ) ); } /** * The admin-notice. * * @access private * @since 3.0.36 * @return void */ public function admin_notice() { // Early exit if the user has dismissed the consent, or if they have opted-in. if ( get_option( 'kirki_telemetry_no_consent' ) || get_option( 'kirki_telemetry_optin' ) ) { return; } $data = $this->get_data(); ?>
table_styles(); } /** * Builds and returns the data or uses cached if data already exists. * * @access private * @since 3.0.36 * @return array */ private function get_data() { // Get the theme. $theme = wp_get_theme(); // Format the PHP version. $php_version = phpversion( 'tidy' ); if ( ! $php_version ) { $php_version = array_merge( explode( '.', phpversion() ), array( 0, 0 ) ); $php_version = "{$php_version[0]}.{$php_version[1]}"; } // Build data and return the array. return array( 'phpVer' => $php_version, 'themeName' => $theme->get( 'Name' ), 'themeAuthor' => $theme->get( 'Author' ), 'themeURI' => $theme->get( 'ThemeURI' ), 'fieldTypes' => $this->get_field_types(), ); } /** * Get the field-types used. * * @access private * @since 3.0.36 * @return array */ public function get_field_types() { $types = array(); foreach ( Kirki::$fields as $field ) { if ( isset( $field['type'] ) ) { $types[] = $field['type']; } } return $types; } /** * Dismisses the notice. * * @access private * @since 3.0.36 * @return void */ private function dismiss_notice() { // Check if this is the request we want. if ( isset( $_GET['_wpnonce'] ) && isset( $_GET['kirki-hide-notice'] ) ) { if ( 'telemetry' === sanitize_text_field( wp_unslash( $_GET['kirki-hide-notice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Check the wp-nonce. if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) ) ) { // All good, we can save the option to dismiss this notice. update_option( 'kirki_telemetry_no_consent', true ); } } } } /** * Dismisses the notice. * * @access private * @since 3.0.36 * @return void */ private function consent() { // Check if this is the request we want. if ( isset( $_GET['_wpnonce'] ) && isset( $_GET['kirki-consent-notice'] ) ) { if ( 'telemetry' === sanitize_text_field( wp_unslash( $_GET['kirki-consent-notice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Check the wp-nonce. if ( wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) ) ) { // All good, we can save the option to dismiss this notice. update_option( 'kirki_telemetry_optin', true ); } } } } /** * Prints the table styles. * * Normally we'd just use the .widefat CSS class for the table, * however apparently there's an obscure bug in WP causing this: https://github.com/aristath/kirki/issues/2067 * This CSS is a copy of some styles from common.css in wp-core. * * @access private * @since 3.0.37 * @return void */ private function table_styles() { ?>