0 && time() > ( $exp + self::SKEW ) ) { return null; } return $claims; } public static function apply( array $ent, $host ) { $token = isset( $ent['sig'] ) ? (string) $ent['sig'] : ''; $claims = '' === $token ? null : self::verify( $token, $host ); if ( null === $claims ) { $ent['signed'] = false; return $ent; } if ( isset( $claims['tier'] ) ) { $ent['tier'] = (string) $claims['tier']; } if ( array_key_exists( 'expires_at', $claims ) ) { $ent['expires_at'] = $claims['expires_at']; } if ( isset( $claims['site_status'] ) && '' !== (string) $claims['site_status'] ) { if ( ! isset( $ent['site'] ) || ! is_array( $ent['site'] ) ) { $ent['site'] = array(); } $ent['site']['status'] = sanitize_key( (string) $claims['site_status'] ); } $ent['signed'] = true; $ent['signed_exp'] = isset( $claims['exp'] ) ? (int) $claims['exp'] : 0; self::remember_signed(); return $ent; } public static function remember_signed() { if ( '1' !== (string) get_option( self::OPT_EVER_SIGNED, '' ) ) { update_option( self::OPT_EVER_SIGNED, '1', true ); } } public static function ever_signed() { return '1' === (string) get_option( self::OPT_EVER_SIGNED, '' ); } const OPT_DOWNGRADED_AT = 'aieo_entitlement_downgraded_at'; const DOWNGRADE_GRACE = 259200; public static function is_downgraded() { if ( ! self::ever_signed() ) { return false; } $ent = get_option( AIEO_Entitlement_Binding::OPT_ENTITLEMENT ); if ( ! is_array( $ent ) ) { return false; } if ( ! empty( $ent['signed'] ) ) { if ( false !== get_option( self::OPT_DOWNGRADED_AT, false ) && self::may_write() ) { delete_option( self::OPT_DOWNGRADED_AT ); } return false; } $since = (int) get_option( self::OPT_DOWNGRADED_AT, 0 ); if ( $since <= 0 ) { if ( self::may_write() ) { update_option( self::OPT_DOWNGRADED_AT, time(), false ); } return false; } return ( time() - $since ) >= self::DOWNGRADE_GRACE; } private static function may_write() { return is_admin() || wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ); } private static function b64url_decode( $s ) { $s = strtr( (string) $s, '-_', '+/' ); $pad = strlen( $s ) % 4; if ( $pad ) { $s .= str_repeat( '=', 4 - $pad ); } $out = base64_decode( $s, true ); return ( false === $out ) ? '' : $out; } } }