0 && time() - $since < 30 * DAY_IN_SECONDS ? 1 : 0 ); } /** The daily count, only while the owner has said yes. Returns whether a request was sent. */ public static function send() { $url = self::url(); if ( ! self::enabled() || '' === $url ) { return false; } wp_safe_remote_post( $url, array( 'timeout' => 5, 'redirection' => 0, 'limit_response_size' => 4096, // The default user agent includes the site URL; send nothing that identifies the site. 'user-agent' => 'Tablewright/' . TABLEWRIGHT_VERSION, 'headers' => array( 'X-Install-Id' => self::install_id(), 'X-Site-Info' => self::site_info(), ), 'body' => '', ) ); return true; } /** Whether the current admin screen is one of Tablewright's own. */ private static function own_screen() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen ) { return false; } return Tablewright_Plugin::CPT === $screen->post_type || false !== strpos( (string) $screen->id, 'tablewright' ); } /** The question, once, on Tablewright's own screens only, until the owner answers. */ public static function ask() { if ( ! current_user_can( 'manage_options' ) || false !== get_option( self::ASKED ) || ! self::own_screen() ) { return; } $link = function ( $choice ) { return wp_nonce_url( admin_url( 'admin-post.php?action=tablewright_stats_choice&choice=' . $choice ), 'tablewright_stats_choice' ); }; printf( '
', esc_html__( 'Help improve Tablewright?', 'tablewright' ), esc_html__( 'Share anonymous stats once a day: a random number made on this site, your WordPress and PHP versions (like 6.8 and 8.3) and whether Pro is on. Never your address, email or content. Quick Launch Studio sees which country the request comes from but does not keep your IP address. You can change this any time under Tablewright → Settings.', 'tablewright' ), esc_url( $link( 'yes' ) ), esc_html__( 'Yes, share anonymous stats', 'tablewright' ), esc_url( $link( 'no' ) ), esc_html__( 'No thanks', 'tablewright' ) ); } public static function handle_choice() { check_admin_referer( 'tablewright_stats_choice' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'tablewright' ), 403 ); } $yes = isset( $_GET['choice'] ) && 'yes' === sanitize_key( wp_unslash( $_GET['choice'] ) ); $s = Tablewright_Plugin::get_settings(); $s['share_stats'] = $yes ? 1 : 0; update_option( 'tablewright_settings', $s ); self::choose( $yes ); wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url( 'edit.php?post_type=' . Tablewright_Plugin::CPT ) ); exit; } /** Settings → "Share anonymous stats" saved: remember the answer. */ public static function settings_saved( $old, $new ) { $was = is_array( $old ) && ! empty( $old['share_stats'] ); $now = is_array( $new ) && ! empty( $new['share_stats'] ); if ( $was !== $now || false === get_option( self::ASKED ) ) { self::choose( $now ); } } /** Store the answer; switching off forgets the random id. */ public static function choose( $yes ) { update_option( self::ASKED, $yes ? 'yes' : 'no', false ); if ( ! $yes ) { delete_option( self::INSTALL_ID ); delete_option( self::INSTALL_SINCE ); wp_clear_scheduled_hook( self::CRON ); } } }