'array', 'sanitize_callback' => 'readercount_sanitize_settings', 'default' => array(), ) ); register_setting( 'readercount', READERCOUNT_KEY_OPTION, array( 'type' => 'string', 'sanitize_callback' => 'readercount_sanitize_key', 'default' => '', ) ); } add_action( 'admin_init', 'readercount_register_settings' ); /** * Cleans the settings form. * * @param mixed $input What the form sent. * @return array */ function readercount_sanitize_settings( $input ) { $input = is_array( $input ) ? $input : array(); $site = isset( $input['site'] ) ? sanitize_text_field( $input['site'] ) : ''; if ( '' !== $site && '' === readercount_site_name( $site ) ) { add_settings_error( READERCOUNT_OPTION, 'readercount-site', __( 'That website address doesn\'t look right, so we\'ve left it empty and will use your site\'s own address.', 'readercount' ) ); } return array( 'enabled' => ! empty( $input['enabled'] ), 'site' => readercount_site_name( $site ), 'skip_editors' => ! empty( $input['skip_editors'] ), ); } /** * Keeps the saved key unless a new one is typed in, or "Remove" is ticked. * * @param mixed $input What the form sent. * @return string */ function readercount_sanitize_key( $input ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- options.php has already checked the form's nonce. if ( ! empty( $_POST['readercount_remove_key'] ) ) { readercount_forget_stats(); return ''; } $key = is_string( $input ) ? trim( sanitize_text_field( $input ) ) : ''; if ( '' === $key ) { return (string) get_option( READERCOUNT_KEY_OPTION, '' ); } if ( ! preg_match( '/^rc_[A-Za-z0-9_-]{8,}$/', $key ) ) { add_settings_error( READERCOUNT_KEY_OPTION, 'readercount-key', __( 'That isn\'t a ReaderCount API key. Keys start with rc_. You can make one on your ReaderCount stats page, under API keys.', 'readercount' ) ); return (string) get_option( READERCOUNT_KEY_OPTION, '' ); } readercount_forget_stats(); return $key; } /** * The settings page. */ function readercount_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } $settings = readercount_settings(); $key = (string) get_option( READERCOUNT_KEY_OPTION, '' ); $site = readercount_site(); $name = READERCOUNT_OPTION; $check = get_transient( 'readercount_check_' . get_current_user_id() ); if ( false !== $check ) { delete_transient( 'readercount_check_' . get_current_user_id() ); } ?>

false, 'message' => $answer->get_error_message(), ); } else { $result = array( 'ok' => ! empty( $answer['ok'] ), 'message' => isset( $answer['message'] ) ? (string) $answer['message'] : __( 'ReaderCount didn\'t answer as expected. Try again in a minute.', 'readercount' ), ); } set_transient( 'readercount_check_' . get_current_user_id(), $result, MINUTE_IN_SECONDS ); wp_safe_redirect( admin_url( 'options-general.php?page=readercount' ) ); exit; } add_action( 'admin_post_readercount_check', 'readercount_handle_check' );