This commit is contained in:
Javier Casares 2026-08-18 16:26:15 +00:00
commit 8a85a4d9af
17 changed files with 3258 additions and 0 deletions

72
CHANGELOG.md Normal file
View file

@ -0,0 +1,72 @@
# Changelog
## [0.2.0] - 2026-08-18
### Highlights
* Settings screen and uninstall behavior (data preserved by default), Manager (by ROBOTSTXT) dependency notices, and lowered requirements to WordPress 6.2 / PHP 7.4
### Added
* Settings screen with the "Delete all telemetry logs and plugin options on uninstall" checkbox (unchecked by default).
* Manager (by ROBOTSTXT) dependency notice: dismissible on the plugins list screen, permanent on the plugin Settings screen.
* `uninstall.php` routine honoring the delete-data option, Multisite aware (per-site tables), using WordPress database APIs.
* `bin/deploy.sh` script that builds a distributable ZIP in the plugin's parent directory, reading the version from the plugin headers.
* `languages/robotstxt-telemetry.pot` translation template.
### Changed
* Minimum requirements lowered to WordPress 6.2 and PHP 7.4 (previously 6.7 / 8.2).
* Plugin URI and Update URI set to https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Author URI set to https://www.robotstxt.software/
* Contributors ordered as robotstxt, javiercasares.
### Fixed
* Query parameters were not stored because the `wp_parse_args()` return value was discarded.
* Invalid UTF-8 no longer discards whole payloads; values are truncated first and then scrubbed.
### Security
* Query strings are redacted before the URL is stored; credentials embedded in URLs are stripped.
* Log detail view prefers the already-redacted stored parameters over re-parsing the raw URL.
* Removed the bundled self-updater (`robotstxt-updater.php`, `update.json`); updates are now handled by the Manager (by ROBOTSTXT) plugin.
### Removed
* Bundled updater files `robotstxt-updater.php` and `update.json`.
### Compatibility
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
### Tests
* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8
* PHP Coding Standards: 3.13.6
* WordPress Coding Standards: 3.4.1
* PHPCompatibilityWP (PHP 7.4-8.5): 9.3.5
* wp-since (WordPress 6.2+): 1.5.0
## [0.1.0] - 2026-08-18
### Highlights
* Initial release: outbound HTTP request logging with an admin Logs screen
### Added
* Outbound HTTP capture through `http_request_args` storing method, URL, host, path, query parameters, body parameters/raw body, sanitized headers, user agent, and caller backtrace.
* Custom database table `{$wpdb->prefix}robotstxt_telemetry_logs` created with `dbDelta()` on activation, with lazy per-site schema upgrades on Multisite.
* Logs admin screen: paginated `WP_List_Table` with method, host, and date range filters, single entry view with pretty-printed JSON, and nonce-protected delete action.
* Secret redaction for sensitive keys (authorization, password, token, secret, api_key, nonce) applied before storing.
* Payload size limits: 64 KB per JSON blob, 64 KB raw body, 16 KB caller trace.
* Dedicated analysis view for `api.wordpress.org` requests grouping environment, extensions, platform flags, and image support parameters.
### Compatibility
* WordPress: 6.7 - 6.9
* PHP: 8.2 - 8.5

674
LICENSE Normal file
View file

@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.

56
README.md Normal file
View file

@ -0,0 +1,56 @@
# Telemetry (by ROBOTSTXT)
Logs outbound HTTP requests made by WordPress for inspection. Every external call performed through the WordPress HTTP API is recorded — with sensitive values redacted — in a custom database table, and can be browsed from a dedicated admin panel with filters, detail views, and safe deletion.
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Author: [ROBOTSTXT](https://www.robotstxt.software/)
* License: GPL-3.0-or-later
## Features
* Captures GET, POST, HEAD, PUT, PATCH, and DELETE requests made via the WP HTTP API.
* Stores method, URL, host, path, query parameters, body parameters (or truncated raw body), sanitized headers, user agent, and caller backtrace.
* Redacts secrets (authorization, passwords, tokens, API keys, nonces) and strips URL credentials before anything is written to the database.
* Size-limited storage: 64 KB per JSON blob, 64 KB raw body, 16 KB caller trace.
* Logs admin screen with pagination, method/host/date filters, single-entry detail view, and nonce-protected deletion.
* Dedicated analysis view for `api.wordpress.org` calls (environment, extensions, platform flags, image support).
* Multisite compatible (`Network: true`), per-site tables.
## Compatibility
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
## Updates
Updates are delivered through the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin. If it is not installed and active, this plugin shows a dismissible reminder in the plugins list and a permanent notice on its Settings screen.
## Dependencies
* Runtime: none.
* Development only (not shipped): Composer with PHPCS, WordPress Coding Standards, PHPCompatibility, and wp-since for QA. See `composer.json`.
## Documentation
* User documentation: `readme.txt`
* Full changelog: `changelog.txt` and `CHANGELOG.md`
* Internal design notes: `docs/`
## Development QA
```bash
composer install
vendor/bin/phpcs --standard=WordPress --ignore=vendor .
vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 7.4- --ignore=vendor .
```
## Deployment
Builds are always executed manually:
```bash
./bin/deploy.sh
```
The script reads the version from the plugin headers and generates `robotstxt-telemetry-<version>.zip` in the parent directory of the plugin folder, excluding development files.

59
bin/deploy.sh Normal file
View file

@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# Build a distributable ZIP of the plugin.
#
# Reads the version from the plugin header and writes the artifact to the
# parent directory of the plugin folder. Deploys are always executed manually.
#
# Usage: ./bin/deploy.sh
set -euo pipefail
PLUGIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PLUGIN_SLUG="$(basename "$PLUGIN_DIR")"
MAIN_FILE="$PLUGIN_DIR/$PLUGIN_SLUG.php"
if [[ ! -f "$MAIN_FILE" ]]; then
echo "Error: $MAIN_FILE not found." >&2
exit 1
fi
VERSION="$(awk -F': ' '/Version:/{gsub(/[[:space:]]/, "", $2); print $2; exit}' "$MAIN_FILE")"
if [[ -z "$VERSION" ]]; then
echo "Error: unable to read the plugin version from $MAIN_FILE." >&2
exit 1
fi
ARTIFACT="$PLUGIN_DIR/../$PLUGIN_SLUG-$VERSION.zip"
STAGING="$(mktemp -d)"
trap 'rm -rf "$STAGING"' EXIT
rsync -a \
--exclude '.git/' \
--exclude '.github/' \
--exclude '.claude/' \
--exclude '.codex/' \
--exclude 'vendor/' \
--exclude 'node_modules/' \
--exclude 'tests/' \
--exclude 'phpunit.xml*' \
--exclude 'phpstan.neon*' \
--exclude 'composer.json' \
--exclude 'composer.lock' \
--exclude 'package.json' \
--exclude 'package-lock.json' \
--exclude '.gitignore' \
--exclude '.wporg' \
--exclude 'AGENTS.md' \
--exclude 'CLAUDE.md' \
--exclude 'CHANGELOG-*.md' \
--exclude 'docs/' \
"$PLUGIN_DIR/" "$STAGING/$PLUGIN_SLUG/"
rm -f "$ARTIFACT"
(cd "$STAGING" && zip -r -q "$ARTIFACT" "$PLUGIN_SLUG")
echo "Built $ARTIFACT (version $VERSION)."

80
changelog.txt Normal file
View file

@ -0,0 +1,80 @@
== Changelog ==
= 0.2.0 =
_Release date: 2026-08-18_
**Highlights**
* Settings screen and uninstall behavior (data preserved by default), Manager (by ROBOTSTXT) dependency notices, and lowered requirements to WordPress 6.2 / PHP 7.4
**Added**
* Settings screen with the "Delete all telemetry logs and plugin options on uninstall" checkbox (unchecked by default)
* Manager (by ROBOTSTXT) dependency notice: dismissible on the plugins list screen, permanent on the plugin Settings screen
* `uninstall.php` routine honoring the delete-data option, Multisite aware (per-site tables), using WordPress database APIs
* `bin/deploy.sh` script that builds a distributable ZIP in the plugin's parent directory, reading the version from the plugin headers
* `languages/robotstxt-telemetry.pot` translation template
**Changed**
* Minimum requirements lowered to WordPress 6.2 and PHP 7.4 (previously 6.7 / 8.2)
* Plugin URI and Update URI set to https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Author URI set to https://www.robotstxt.software/
* Contributors ordered as robotstxt, javiercasares
**Fixed**
* Query parameters were not stored because the `wp_parse_args()` return value was discarded
* Invalid UTF-8 no longer discards whole payloads; values are truncated first and then scrubbed
**Security**
* Query strings are redacted before the URL is stored; credentials embedded in URLs are stripped
* Log detail view prefers the already-redacted stored parameters over re-parsing the raw URL
* Removed the bundled self-updater (`robotstxt-updater.php`, `update.json`); updates are now handled by the Manager (by ROBOTSTXT) plugin
**Removed**
* Bundled updater files `robotstxt-updater.php` and `update.json`
**Compatibility**
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible
**Tests**
* WordPress 7.2-alpha-63320, PHP 8.5.9, MariaDB 11.8.8
* PHP Coding Standards: 3.13.6
* WordPress Coding Standards: 3.4.1
* PHPCompatibilityWP (PHP 7.4-8.5): 9.3.5
* wp-since (WordPress 6.2+): 1.5.0
= 0.1.0 =
_Release date: 2026-08-18_
**Highlights**
* Initial release: outbound HTTP request logging with an admin Logs screen
**Added**
* Outbound HTTP capture through `http_request_args` storing method, URL, host, path, query parameters, body parameters/raw body, sanitized headers, user agent, and caller backtrace
* Custom database table `{$wpdb->prefix}robotstxt_telemetry_logs` created with `dbDelta()` on activation, with lazy per-site schema upgrades on Multisite
* Logs admin screen: paginated `WP_List_Table` with method, host, and date range filters, single entry view with pretty-printed JSON, and nonce-protected delete action
* Secret redaction for sensitive keys (authorization, password, token, secret, api_key, nonce) applied before storing
* Payload size limits: 64 KB per JSON blob, 64 KB raw body, 16 KB caller trace
* Dedicated analysis view for `api.wordpress.org` requests grouping environment, extensions, platform flags, and image support parameters
**Compatibility**
* WordPress: 6.7 - 6.9
* PHP: 8.2 - 8.5
**Tests**
* WordPress 6.9, PHP 8.2-8.5

View file

@ -0,0 +1,329 @@
<?php
/**
* Admin UI handler.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Admin' ) ) {
/**
* Class Robotstxt_Telemetry_Admin
*/
class Robotstxt_Telemetry_Admin {
/**
* Register hooks.
*/
public function register(): void {
add_action( 'admin_menu', array( $this, 'register_menu' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_init', array( $this, 'handle_actions' ) );
add_action( 'admin_notices', array( $this, 'render_saved_notice' ) );
}
/**
* Register admin menus.
*/
public function register_menu(): void {
add_menu_page(
__( 'Telemetry', 'robotstxt-telemetry' ),
__( 'Telemetry', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry',
array( $this, 'render_settings_page' ),
'dashicons-admin-generic'
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Settings', 'robotstxt-telemetry' ),
__( 'Settings', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry',
array( $this, 'render_settings_page' )
);
add_submenu_page(
'robotstxt-telemetry',
__( 'Logs', 'robotstxt-telemetry' ),
__( 'Logs', 'robotstxt-telemetry' ),
'manage_options',
'robotstxt-telemetry-logs',
array( $this, 'render_logs_page' )
);
}
/**
* Register the uninstall behavior setting.
*/
public function register_settings(): void {
register_setting(
'robotstxt_telemetry_settings',
'robotstxt_telemetry_delete_on_uninstall',
array(
'type' => 'boolean',
'default' => false,
'sanitize_callback' => array( $this, 'sanitize_checkbox' ),
'show_in_rest' => false,
)
);
}
/**
* Sanitize a checkbox value.
*
* @param mixed $value Raw input value.
* @return bool
*/
public function sanitize_checkbox( $value ): bool {
return (bool) $value;
}
/**
* Handle admin actions.
*/
public function handle_actions(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- State change is protected by check_admin_referer() below.
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
$action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
if ( 'robotstxt-telemetry-logs' !== $page || 'delete' !== $action ) {
return;
}
$log_id = isset( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
// phpcs:enable
if ( 0 === $log_id ) {
return;
}
check_admin_referer( 'robotstxt_telemetry_delete_log_' . $log_id );
Robotstxt_Telemetry_DB::delete_log( $log_id );
wp_safe_redirect(
add_query_arg(
array(
'page' => 'robotstxt-telemetry-logs',
'deleted' => 1,
),
admin_url( 'admin.php' )
)
);
exit;
}
/**
* Render the settings saved notice.
*/
public function render_saved_notice(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
$settings_updated = isset( $_GET['settings-updated'] ) ? sanitize_key( wp_unslash( $_GET['settings-updated'] ) ) : '';
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
// phpcs:enable
if ( 'true' !== $settings_updated || 'robotstxt-telemetry' !== $page ) {
return;
}
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Settings saved.', 'robotstxt-telemetry' ) . '</p></div>';
}
/**
* Render settings page.
*/
public function render_settings_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
echo '<div class="wrap">';
echo '<h1>' . esc_html__( 'Telemetry Settings', 'robotstxt-telemetry' ) . '</h1>';
$manager_notice = new Robotstxt_Telemetry_Manager_Notice();
$manager_notice->render_settings_notice();
echo '<form method="post" action="options.php">';
settings_fields( 'robotstxt_telemetry_settings' );
echo '<table class="form-table" role="presentation">';
echo '<tbody><tr>';
echo '<th scope="row">' . esc_html__( 'Uninstall behavior', 'robotstxt-telemetry' ) . '</th>';
echo '<td>';
echo '<label for="robotstxt-telemetry-delete-on-uninstall">';
echo '<input type="checkbox" id="robotstxt-telemetry-delete-on-uninstall" name="robotstxt_telemetry_delete_on_uninstall" value="1" ' . checked( (bool) get_option( 'robotstxt_telemetry_delete_on_uninstall', false ), true, false ) . '/>';
echo '<span>' . esc_html__( 'Delete all telemetry logs and plugin options on uninstall', 'robotstxt-telemetry' ) . '</span>';
echo '</label>';
echo '<p class="description">' . esc_html__( 'By default, all telemetry logs are preserved when the plugin is uninstalled.', 'robotstxt-telemetry' ) . '</p>';
echo '</td>';
echo '</tr></tbody>';
echo '</table>';
submit_button();
echo '</form>';
echo '</div>';
}
/**
* Render logs page.
*/
public function render_logs_page(): void {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-logs-table.php';
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only rendering of an admin screen.
$view_action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
$log_id = isset( $_GET['log'] ) ? absint( wp_unslash( $_GET['log'] ) ) : 0;
echo '<div class="wrap">';
echo '<h1>' . esc_html__( 'Telemetry Logs', 'robotstxt-telemetry' ) . '</h1>';
if ( 'view' === $view_action && $log_id > 0 ) {
$this->render_single_log( $log_id );
echo '</div>';
return;
}
$deleted_notice = isset( $_GET['deleted'] ) ? absint( wp_unslash( $_GET['deleted'] ) ) : 0;
// phpcs:enable
if ( $deleted_notice > 0 ) {
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Log entry deleted.', 'robotstxt-telemetry' ) . '</p></div>';
}
$table = new Robotstxt_Telemetry_Logs_Table();
$table->prepare_items();
echo '<form method="get">';
echo '<input type="hidden" name="page" value="robotstxt-telemetry-logs" />';
$table->display();
echo '</form>';
echo '</div>';
}
/**
* Render a single log entry.
*
* @param int $log_id Log ID.
*/
private function render_single_log( int $log_id ): void {
$log = Robotstxt_Telemetry_DB::get_log( $log_id );
if ( empty( $log ) ) {
echo '<p>' . esc_html__( 'Log entry not found.', 'robotstxt-telemetry' ) . '</p>';
return;
}
echo '<p><a href="' . esc_url( admin_url( 'admin.php?page=robotstxt-telemetry-logs' ) ) . '">' . esc_html__( 'Back to logs', 'robotstxt-telemetry' ) . '</a></p>';
echo '<table class="widefat striped">';
echo '<tbody>';
$this->render_log_row( __( 'Date', 'robotstxt-telemetry' ), $log['created_at'] );
$this->render_log_row( __( 'Method', 'robotstxt-telemetry' ), $log['method'] );
$this->render_log_row( __( 'URL', 'robotstxt-telemetry' ), $log['url'] );
$this->render_log_row( __( 'Host', 'robotstxt-telemetry' ), $log['host'] );
$this->render_log_row( __( 'Path', 'robotstxt-telemetry' ), $log['path'] );
$this->render_log_row( __( 'Body Params', 'robotstxt-telemetry' ), $this->format_params_field( $log, 'body' ) );
$this->render_log_row( __( 'Headers', 'robotstxt-telemetry' ), $this->format_json_field( $log['headers_json'] ) );
$this->render_log_row( __( 'User Agent', 'robotstxt-telemetry' ), $log['user_agent'] );
$this->render_log_row( __( 'Raw Body', 'robotstxt-telemetry' ), $log['raw_body'] );
$this->render_log_row( __( 'Caller', 'robotstxt-telemetry' ), $log['caller'] );
echo '</tbody>';
echo '</table>';
$this->render_telemetry_analysis( $log );
}
/**
* Render telemetry analysis section.
*
* @param array $log Log data.
*/
private function render_telemetry_analysis( array $log ): void {
$sections = Robotstxt_Telemetry_Analysis::build_sections( $log );
if ( empty( $sections ) ) {
return;
}
echo '<h2>' . esc_html__( 'Telemetry Analysis', 'robotstxt-telemetry' ) . '</h2>';
echo '<table class="widefat striped">';
echo '<tbody>';
foreach ( $sections as $label => $value ) {
$this->render_log_row( $label, $value );
}
echo '</tbody>';
echo '</table>';
}
/**
* Render a table row.
*
* @param string $label Label.
* @param string $value Value.
*/
private function render_log_row( string $label, $value ): void {
echo '<tr>';
echo '<th scope="row" style="width: 180px; vertical-align: top;">' . esc_html( $label ) . '</th>';
echo '<td><pre style="white-space: pre-wrap; margin: 0;">' . esc_html( (string) $value ) . '</pre></td>';
echo '</tr>';
}
/**
* Format JSON fields for display.
*
* @param string|null $value JSON string.
* @return string
*/
private function format_json_field( ?string $value ): string {
if ( empty( $value ) ) {
return '';
}
$decoded = json_decode( $value, true );
if ( null !== $decoded && JSON_ERROR_NONE === json_last_error() ) {
return (string) wp_json_encode( $decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
}
return $value;
}
/**
* Format query/body params as line-per-parameter output.
*
* @param array $log Log data.
* @param string $type Param source.
* @return string
*/
private function format_params_field( array $log, string $type ): string {
$params = array();
if ( 'body' === $type ) {
$params = Robotstxt_Telemetry_Analysis::extract_body_params( $log );
}
if ( empty( $params ) ) {
return '';
}
return Robotstxt_Telemetry_Analysis::format_params_lines( $params );
}
}
}

View file

@ -0,0 +1,158 @@
<?php
/**
* Telemetry analysis for api.wordpress.org.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Analysis_Api_WordPress_Org' ) ) {
/**
* Class Robotstxt_Telemetry_Analysis_Api_WordPress_Org
*/
class Robotstxt_Telemetry_Analysis_Api_WordPress_Org {
/**
* Build analysis sections for api.wordpress.org.
*
* @param array $log Log data.
* @return array
*/
public static function build_sections( array $log ): array {
$sections = array();
$query_params = Robotstxt_Telemetry_Analysis::extract_query_params( $log );
if ( ! empty( $query_params ) ) {
$sections = array_merge( $sections, self::group_query_params( $query_params ) );
}
$body_params = Robotstxt_Telemetry_Analysis::extract_body_params( $log );
if ( ! empty( $body_params ) ) {
$sections = array_merge( $sections, self::group_body_params( $body_params ) );
}
return $sections;
}
/**
* Group query parameters.
*
* @param array $params Query parameters.
* @return array
*/
private static function group_query_params( array $params ): array {
$sections = array();
$core_keys = array(
'version',
'php',
'locale',
'mysql',
'local_package',
'blogs',
'users',
'multisite_enabled',
'initial_db_version',
);
$core = array();
foreach ( $core_keys as $key ) {
if ( array_key_exists( $key, $params ) ) {
$core[ $key ] = $params[ $key ];
unset( $params[ $key ] );
}
}
$extensions = self::pluck_bracketed( $params, 'extensions' );
$platform = self::pluck_bracketed( $params, 'platform_flags' );
$images = self::pluck_bracketed( $params, 'image_support' );
if ( ! empty( $core ) ) {
$sections[ __( 'Environment', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $core );
}
if ( ! empty( $extensions ) ) {
$sections[ __( 'Extensions', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $extensions );
}
if ( ! empty( $platform ) ) {
$sections[ __( 'Platform Flags', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $platform );
}
if ( ! empty( $images ) ) {
$sections[ __( 'Image Support', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $images );
}
if ( ! empty( $params ) ) {
$sections[ __( 'Other URL Parameters', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $params );
}
return $sections;
}
/**
* Group body parameters.
*
* @param array $params Body parameters.
* @return array
*/
private static function group_body_params( array $params ): array {
$sections = array();
if ( isset( $params['translations'] ) ) {
$translations = $params['translations'];
unset( $params['translations'] );
if ( is_string( $translations ) ) {
$decoded = json_decode( $translations, true );
if ( is_array( $decoded ) ) {
$translations = $decoded;
}
}
if ( is_array( $translations ) ) {
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $translations );
} else {
$sections[ __( 'Translations', 'robotstxt-telemetry' ) ] = (string) $translations;
}
}
if ( ! empty( $params ) ) {
$sections[ __( 'Other Body Parameters', 'robotstxt-telemetry' ) ] = Robotstxt_Telemetry_Analysis::format_params_lines( $params );
}
return $sections;
}
/**
* Extract bracketed parameters into a nested array.
*
* @param array $params Parameters (will be mutated).
* @param string $prefix Prefix name.
* @return array
*/
private static function pluck_bracketed( array &$params, string $prefix ): array {
$result = array();
foreach ( $params as $key => $value ) {
if ( 0 !== strpos( $key, $prefix . '[' ) ) {
continue;
}
$inner_key = substr( $key, strlen( $prefix ) + 1 );
$inner_key = rtrim( $inner_key, ']' );
if ( '' === $inner_key ) {
continue;
}
$result[ $inner_key ] = $value;
unset( $params[ $key ] );
}
return $result;
}
}
}

View file

@ -0,0 +1,195 @@
<?php
/**
* Telemetry analysis helpers.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Analysis' ) ) {
/**
* Class Robotstxt_Telemetry_Analysis
*/
class Robotstxt_Telemetry_Analysis {
/**
* Build analysis sections for a log entry.
*
* @param array $log Log data.
* @return array
*/
public static function build_sections( array $log ): array {
$host = isset( $log['host'] ) ? strtolower( (string) $log['host'] ) : '';
if ( 'api.wordpress.org' === $host ) {
return Robotstxt_Telemetry_Analysis_Api_WordPress_Org::build_sections( $log );
}
return self::build_generic_sections( $log );
}
/**
* Build generic analysis sections.
*
* @param array $log Log data.
* @return array
*/
private static function build_generic_sections( array $log ): array {
$sections = array();
$query_params = self::extract_query_params( $log );
if ( ! empty( $query_params ) ) {
$sections[ __( 'URL Parameters', 'robotstxt-telemetry' ) ] = self::format_params_lines( $query_params );
}
$body_params = self::extract_body_params( $log );
if ( ! empty( $body_params ) ) {
$sections[ __( 'Body Parameters', 'robotstxt-telemetry' ) ] = self::format_params_lines( $body_params );
}
return $sections;
}
/**
* Extract parameters from the URL query string.
*
* Prefers the redacted query_json column over re-parsing the raw URL.
*
* @param array $log Log data.
* @return array
*/
public static function extract_query_params( array $log ): array {
if ( empty( $log['url'] ) && empty( $log['query_json'] ) ) {
return array();
}
if ( ! empty( $log['query_json'] ) ) {
$decoded = json_decode( $log['query_json'], true );
if ( is_array( $decoded ) && ! empty( $decoded ) ) {
return $decoded;
}
}
$parts = explode( '?', (string) $log['url'], 2 );
$query = isset( $parts[1] ) ? $parts[1] : '';
if ( '' === $query ) {
return array();
}
return self::parse_query_string_flat( $query );
}
/**
* Extract parameters from the body.
*
* @param array $log Log data.
* @return array
*/
public static function extract_body_params( array $log ): array {
if ( ! empty( $log['body_json'] ) ) {
$decoded = json_decode( $log['body_json'], true );
if ( is_array( $decoded ) ) {
return $decoded;
}
if ( is_string( $decoded ) ) {
return self::parse_query_string_flat( $decoded );
}
}
if ( ! empty( $log['raw_body'] ) ) {
return self::parse_query_string_flat( $log['raw_body'] );
}
return array();
}
/**
* Parse a query string into a flat key/value array.
*
* @param string $query Query string.
* @return array
*/
public static function parse_query_string_flat( string $query ): array {
$params = array();
$pairs = explode( '&', $query );
foreach ( $pairs as $pair ) {
if ( '' === $pair ) {
continue;
}
$parts = explode( '=', $pair, 2 );
$key = rawurldecode( $parts[0] );
$value = isset( $parts[1] ) ? rawurldecode( $parts[1] ) : '';
if ( '' === $key ) {
continue;
}
if ( isset( $params[ $key ] ) ) {
if ( ! is_array( $params[ $key ] ) ) {
$params[ $key ] = array( $params[ $key ] );
}
$params[ $key ][] = $value;
continue;
}
$params[ $key ] = $value;
}
return $params;
}
/**
* Format parameters as line-per-entry output.
*
* @param array $params Parameters.
* @return string
*/
public static function format_params_lines( array $params ): string {
$lines = array();
$flatten = self::flatten_params( $params );
foreach ( $flatten as $key => $value ) {
if ( is_array( $value ) ) {
$value = wp_json_encode( $value );
}
$lines[] = sprintf( '%s=%s', $key, $value );
}
return implode( "\n", $lines );
}
/**
* Flatten nested parameters into bracketed keys.
*
* @param array $params Parameters to flatten.
* @param string|null $prefix Current prefix.
* @return array
*/
public static function flatten_params( array $params, ?string $prefix = null ): array {
$flat = array();
foreach ( $params as $key => $value ) {
$key_string = is_int( $key ) ? (string) $key : $key;
$full_key = null === $prefix ? $key_string : $prefix . '[' . $key_string . ']';
if ( is_array( $value ) ) {
$flat = array_merge( $flat, self::flatten_params( $value, $full_key ) );
continue;
}
$flat[ $full_key ] = $value;
}
return $flat;
}
}
}

View file

@ -0,0 +1,170 @@
<?php
/**
* Database handler.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_DB' ) ) {
/**
* Class Robotstxt_Telemetry_DB
*/
class Robotstxt_Telemetry_DB {
/**
* Whether the schema was checked in this request.
*
* @var bool
*/
private static bool $did_check = false;
/**
* Get the table name.
*
* @return string
*/
public static function get_table_name(): string {
global $wpdb;
return $wpdb->prefix . 'robotstxt_telemetry_logs';
}
/**
* Activation hook.
*/
public static function activate(): void {
self::create_table();
update_option( 'robotstxt_telemetry_db_version', ROBOTSTXT_TELEMETRY_DB_VERSION );
}
/**
* Ensure the database schema is up to date.
*/
public static function maybe_upgrade(): void {
if ( self::$did_check ) {
return;
}
self::$did_check = true;
$installed_version = get_option( 'robotstxt_telemetry_db_version' );
if ( ROBOTSTXT_TELEMETRY_DB_VERSION !== $installed_version ) {
self::create_table();
update_option( 'robotstxt_telemetry_db_version', ROBOTSTXT_TELEMETRY_DB_VERSION );
}
}
/**
* Create or update the logs table.
*/
public static function create_table(): void {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$table_name = self::get_table_name();
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$table_name} (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
created_at DATETIME NOT NULL,
method VARCHAR(10) NOT NULL,
url TEXT NOT NULL,
host VARCHAR(255) NULL,
path TEXT NULL,
query_json LONGTEXT NULL,
body_json LONGTEXT NULL,
headers_json LONGTEXT NULL,
user_agent TEXT NULL,
raw_body LONGTEXT NULL,
caller TEXT NULL,
redacted TINYINT(1) NOT NULL DEFAULT 1,
response_code SMALLINT UNSIGNED NULL,
response_time_ms FLOAT NULL,
PRIMARY KEY (id),
KEY created_at (created_at),
KEY host (host),
KEY method_host (method, host)
) {$charset_collate};";
dbDelta( $sql );
}
/**
* Insert a log row.
*
* @param array $data Log data.
*/
public static function insert_log( array $data ): void {
global $wpdb;
$wpdb->insert( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Insert into the plugin's custom table via the wpdb API.
self::get_table_name(),
$data,
array(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%s',
'%d',
)
);
}
/**
* Fetch a single log row.
*
* @param int $log_id Log ID.
* @return array|null
*/
public static function get_log( int $log_id ): ?array {
global $wpdb;
$table_name = self::get_table_name();
$log = $wpdb->get_row( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; single-row view is never cached.
$wpdb->prepare(
'SELECT * FROM %i WHERE id = %d',
$table_name,
$log_id
),
ARRAY_A
);
if ( empty( $log ) ) {
return null;
}
return $log;
}
/**
* Delete a log row.
*
* @param int $log_id Log ID.
* @return bool
*/
public static function delete_log( int $log_id ): bool {
global $wpdb;
$deleted = $wpdb->delete( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Delete from the plugin's custom table via the wpdb API.
self::get_table_name(),
array( 'id' => $log_id ),
array( '%d' )
);
return false !== $deleted;
}
}
}

View file

@ -0,0 +1,411 @@
<?php
/**
* Request logger.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Logger' ) ) {
/**
* Class Robotstxt_Telemetry_Logger
*/
class Robotstxt_Telemetry_Logger {
/**
* Maximum JSON size to store.
*
* @var int
*/
private int $max_json_bytes = 65535;
/**
* Maximum raw body size to store.
*
* @var int
*/
private int $max_raw_body_bytes = 65535;
/**
* Maximum caller summary size.
*
* @var int
*/
private int $max_caller_bytes = 16000;
/**
* Register hooks.
*/
public function register(): void {
add_filter( 'http_request_args', array( $this, 'capture_request' ), 10, 2 );
}
/**
* Capture outbound request arguments.
*
* @param array $args HTTP request arguments.
* @param string $url Request URL.
* @return array
*/
public function capture_request( $args, $url ): array {
if ( empty( $url ) || ! is_array( $args ) ) {
return $args;
}
try {
Robotstxt_Telemetry_DB::maybe_upgrade();
$log_data = $this->prepare_log_data( $args, $url );
if ( ! empty( $log_data ) ) {
Robotstxt_Telemetry_DB::insert_log( $log_data );
}
} catch ( Throwable $exception ) {
// Never interrupt outbound requests if logging fails.
do_action( 'robotstxt_telemetry_logging_failed', $exception, $args, $url );
}
return $args;
}
/**
* Prepare log data for storage.
*
* @param array $args Request args.
* @param string $url Request URL.
* @return array
*/
private function prepare_log_data( array $args, string $url ): array {
$method = isset( $args['method'] ) ? strtoupper( sanitize_text_field( (string) $args['method'] ) ) : 'GET';
$url = esc_url_raw( $url );
$parsed_url = wp_parse_url( $url );
$host = isset( $parsed_url['host'] ) ? sanitize_text_field( $parsed_url['host'] ) : '';
$path = isset( $parsed_url['path'] ) ? sanitize_text_field( $parsed_url['path'] ) : '';
$query_params = array();
if ( ! empty( $parsed_url['query'] ) ) {
$query_params = wp_parse_args( $parsed_url['query'] );
}
$query_params = $this->redact_array( $query_params );
// Rebuild the URL with redacted query parameters and without credentials.
if ( ! empty( $parsed_url['query'] ) ) {
$redacted_url = $this->build_redacted_url( $parsed_url, http_build_query( $query_params ) );
if ( '' !== $redacted_url ) {
$url = $redacted_url;
}
}
$query_json = $this->encode_json_limited( $query_params, $this->max_json_bytes );
if ( empty( $query_json ) && ! empty( $query_params ) ) {
$query_json = http_build_query( $query_params );
}
$body_json = null;
$raw_body = null;
if ( isset( $args['body'] ) ) {
$body_data = $args['body'];
if ( is_array( $body_data ) ) {
$redacted_body = $this->redact_array( $body_data );
$body_json = $this->encode_json_limited( $redacted_body, $this->max_json_bytes );
if ( empty( $body_json ) ) {
$body_json = http_build_query( $redacted_body );
$raw_body = $this->truncate_string(
http_build_query( $redacted_body ),
$this->max_raw_body_bytes
);
}
} elseif ( is_string( $body_data ) ) {
$parsed_body = $this->parse_body_string( $body_data );
if ( null !== $parsed_body ) {
$redacted_body = $this->redact_array( $parsed_body );
$body_json = $this->encode_json_limited( $redacted_body, $this->max_json_bytes );
if ( empty( $body_json ) ) {
$body_json = http_build_query( $redacted_body );
$raw_body = $this->truncate_string(
http_build_query( $redacted_body ),
$this->max_raw_body_bytes
);
}
} else {
$raw_body = $this->truncate_string( $body_data, $this->max_raw_body_bytes );
}
}
}
$headers = $this->normalize_headers( $args['headers'] ?? array() );
$headers = $this->redact_array( $headers );
$headers_json = $this->encode_json_limited( $headers, $this->max_json_bytes );
$user_agent = $this->extract_user_agent( $args );
// phpcs:ignore WordPress.PHP.DevelopmentFunctions -- Needed for caller context logging.
$caller = wp_debug_backtrace_summary( null, 0, false );
if ( is_array( $caller ) || is_object( $caller ) ) {
$caller = wp_json_encode( $caller );
}
$caller = $this->truncate_string( (string) $caller, $this->max_caller_bytes );
return array(
'created_at' => current_time( 'mysql', true ),
'method' => $method,
'url' => $url,
'host' => $host,
'path' => $path,
'query_json' => $query_json,
'body_json' => $body_json,
'headers_json' => $headers_json,
'user_agent' => $user_agent,
'raw_body' => $raw_body,
'caller' => $caller,
'redacted' => 1,
);
}
/**
* Rebuild a URL with a redacted query string and without credentials.
*
* @param array $parts URL parts from wp_parse_url().
* @param string $query Redacted query string.
* @return string
*/
private function build_redacted_url( array $parts, string $query ): string {
$url = '';
if ( ! empty( $parts['scheme'] ) && ! empty( $parts['host'] ) ) {
$url = $parts['scheme'] . '://' . $parts['host'];
} else {
return '';
}
if ( ! empty( $parts['port'] ) ) {
$url .= ':' . (int) $parts['port'];
}
$url .= $parts['path'] ?? '';
if ( '' !== $query ) {
$url .= '?' . $query;
}
if ( ! empty( $parts['fragment'] ) ) {
$url .= '#' . $parts['fragment'];
}
return $url;
}
/**
* Normalize request headers into a simple array.
*
* @param mixed $headers Headers value.
* @return array
*/
private function normalize_headers( $headers ): array {
if ( is_object( $headers ) && method_exists( $headers, 'getAll' ) ) {
$headers = $headers->getAll();
}
if ( ! is_array( $headers ) ) {
return array();
}
$normalized = array();
foreach ( $headers as $key => $value ) {
$sanitized_key = sanitize_text_field( (string) $key );
$normalized[ $sanitized_key ] = $this->normalize_value( $value );
}
return $normalized;
}
/**
* Extract the user agent from request args.
*
* @param array $args Request args.
* @return string|null
*/
private function extract_user_agent( array $args ): ?string {
$user_agent = '';
if ( isset( $args['user-agent'] ) ) {
$user_agent = (string) $args['user-agent'];
} elseif ( isset( $args['user_agent'] ) ) {
$user_agent = (string) $args['user_agent'];
} elseif ( isset( $args['headers']['user-agent'] ) ) {
$user_agent = (string) $args['headers']['user-agent'];
} elseif ( isset( $args['headers']['User-Agent'] ) ) {
$user_agent = (string) $args['headers']['User-Agent'];
}
if ( '' === $user_agent ) {
return null;
}
return sanitize_text_field( $this->truncate_string( $user_agent, 512 ) );
}
/**
* Parse body strings into arrays when possible.
*
* @param string $body Raw body.
* @return array|null
*/
private function parse_body_string( string $body ): ?array {
$decoded = json_decode( $body, true );
if ( is_array( $decoded ) ) {
return $decoded;
}
$parsed = wp_parse_args( $body );
if ( ! empty( $parsed ) ) {
return $parsed;
}
return null;
}
/**
* Redact sensitive keys in arrays.
*
* @param array $data Data to sanitize.
* @return array
*/
private function redact_array( array $data ): array {
$redacted = array();
foreach ( $data as $key => $value ) {
$normalized_key = is_string( $key ) ? strtolower( $key ) : (string) $key;
if ( $this->is_sensitive_key( $normalized_key ) ) {
$redacted[ $key ] = '[redacted]';
continue;
}
if ( is_array( $value ) ) {
$redacted[ $key ] = $this->redact_array( $value );
continue;
}
$redacted[ $key ] = $this->normalize_value( $value );
}
return $redacted;
}
/**
* Check if a key should be redacted.
*
* @param string $key Key name.
* @return bool
*/
private function is_sensitive_key( string $key ): bool {
$sensitive_keys = array(
'authorization',
'password',
'pass',
'token',
'secret',
'api_key',
'apikey',
'nonce',
);
foreach ( $sensitive_keys as $sensitive_key ) {
if ( false !== strpos( $key, $sensitive_key ) ) {
return true;
}
}
return false;
}
/**
* Normalize values to safe strings or scalars.
*
* @param mixed $value Value to normalize.
* @return mixed
*/
private function normalize_value( $value ) {
if ( is_scalar( $value ) || null === $value ) {
if ( is_string( $value ) ) {
return sanitize_text_field( $value );
}
return $value;
}
return sanitize_text_field( wp_json_encode( $value ) );
}
/**
* Encode JSON with size limits.
*
* @param array $data Data to encode.
* @param int $limit Max size in bytes.
* @return string|null
*/
private function encode_json_limited( array $data, int $limit ): ?string {
$encoded = wp_json_encode( $this->truncate_array_values( $data, 2048 ) );
if ( false === $encoded ) {
return null;
}
if ( strlen( $encoded ) > $limit ) {
return $this->truncate_string( $encoded, $limit );
}
return $encoded;
}
/**
* Truncate array values to keep payloads manageable.
*
* @param array $data Data to trim.
* @param int $max_len Max length per string value.
* @return array
*/
private function truncate_array_values( array $data, int $max_len ): array {
$trimmed = array();
foreach ( $data as $key => $value ) {
if ( is_array( $value ) ) {
$trimmed[ $key ] = $this->truncate_array_values( $value, $max_len );
continue;
}
if ( is_string( $value ) ) {
$trimmed[ $key ] = $this->truncate_string( $value, $max_len );
continue;
}
$trimmed[ $key ] = $value;
}
return $trimmed;
}
/**
* Truncate a string safely.
*
* @param string $value String to truncate.
* @param int $limit Max length in bytes.
* @return string
*/
private function truncate_string( string $value, int $limit ): string {
if ( strlen( $value ) > $limit ) {
$value = substr( $value, 0, $limit );
}
return wp_check_invalid_utf8( $value, true );
}
}
}

View file

@ -0,0 +1,385 @@
<?php
/**
* Logs list table.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
if ( ! class_exists( 'Robotstxt_Telemetry_Logs_Table' ) ) {
/**
* Class Robotstxt_Telemetry_Logs_Table
*/
class Robotstxt_Telemetry_Logs_Table extends WP_List_Table {
/**
* Number of items per page.
*
* @var int
*/
private int $per_page = 20;
/**
* Constructor.
*/
public function __construct() {
parent::__construct(
array(
'singular' => 'telemetry_log',
'plural' => 'telemetry_logs',
'ajax' => false,
)
);
}
/**
* Get columns.
*
* @return array
*/
public function get_columns(): array {
return array(
'created_at' => __( 'Date', 'robotstxt-telemetry' ),
'method' => __( 'Method', 'robotstxt-telemetry' ),
'host' => __( 'Host', 'robotstxt-telemetry' ),
'path' => __( 'Path', 'robotstxt-telemetry' ),
);
}
/**
* Prepare items for display.
*/
public function prepare_items(): void {
global $wpdb;
$table_name = Robotstxt_Telemetry_DB::get_table_name();
$paged = max( 1, $this->get_pagenum() );
$offset = ( $paged - 1 ) * $this->per_page;
$columns = $this->get_columns();
$this->_column_headers = array( $columns, array(), array() );
$method = strtoupper( $this->get_filter_value( 'method' ) );
$host = $this->get_filter_value( 'host' );
$date_from = $this->sanitize_date_filter( $this->get_filter_value( 'date_from' ) );
$date_from_value = ! empty( $date_from ) ? $date_from . ' 00:00:00' : '';
$date_to = $this->sanitize_date_filter( $this->get_filter_value( 'date_to' ) );
$date_to_value = ! empty( $date_to ) ? $date_to . ' 23:59:59' : '';
$this->items = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; list output is never cached.
$wpdb->prepare(
'SELECT * FROM %i
WHERE ( %s = \'\' OR method = %s )
AND ( %s = \'\' OR host = %s )
AND ( %s = \'\' OR created_at >= %s )
AND ( %s = \'\' OR created_at <= %s )
ORDER BY created_at DESC
LIMIT %d OFFSET %d',
$table_name,
$method,
$method,
$host,
$host,
$date_from_value,
$date_from_value,
$date_to_value,
$date_to_value,
$this->per_page,
$offset
),
ARRAY_A
);
$total = (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery -- Custom table read via the wpdb API; pagination count is never cached.
$wpdb->prepare(
'SELECT COUNT(*) FROM %i
WHERE ( %s = \'\' OR method = %s )
AND ( %s = \'\' OR host = %s )
AND ( %s = \'\' OR created_at >= %s )
AND ( %s = \'\' OR created_at <= %s )',
$table_name,
$method,
$method,
$host,
$host,
$date_from_value,
$date_from_value,
$date_to_value,
$date_to_value
)
);
$this->set_pagination_args(
array(
'total_items' => $total,
'per_page' => $this->per_page,
)
);
}
/**
* Render default column output.
*
* @param array $item Column data.
* @param string $column_name Column name.
* @return string
*/
public function column_default( $item, $column_name ): string {
switch ( $column_name ) {
case 'created_at':
return esc_html( $item[ $column_name ] ?? '' );
case 'method':
case 'host':
case 'path':
return esc_html( $item[ $column_name ] ?? '' );
default:
return '';
}
}
/**
* Add row actions.
*
* @param array $item Item data.
* @return string
*/
public function column_created_at( $item ): string {
$log_id = (int) $item['id'];
$view_url = add_query_arg(
array(
'page' => 'robotstxt-telemetry-logs',
'action' => 'view',
'log' => $log_id,
),
admin_url( 'admin.php' )
);
$delete_url = wp_nonce_url(
add_query_arg(
array(
'page' => 'robotstxt-telemetry-logs',
'action' => 'delete',
'log' => $log_id,
),
admin_url( 'admin.php' )
),
'robotstxt_telemetry_delete_log_' . $log_id
);
$actions = array(
'view' => '<a href="' . esc_url( $view_url ) . '">' . esc_html__( 'View', 'robotstxt-telemetry' ) . '</a>',
'delete' => '<a href="' . esc_url( $delete_url ) . '">' . esc_html__( 'Delete', 'robotstxt-telemetry' ) . '</a>',
);
return esc_html( $item['created_at'] ) . $this->row_actions( $actions );
}
/**
* Render the URL column without query parameters.
*
* @param array $item Item data.
* @return string
*/
public function column_url( $item ): string {
if ( empty( $item['url'] ) ) {
return '';
}
$parsed_url = wp_parse_url( $item['url'] );
if ( empty( $parsed_url ) || empty( $parsed_url['host'] ) ) {
return esc_html( $item['url'] );
}
$scheme = $parsed_url['scheme'] ?? 'https';
$path = $parsed_url['path'] ?? '';
$port = isset( $parsed_url['port'] ) ? ':' . (int) $parsed_url['port'] : '';
$base = sprintf( '%s://%s%s%s', $scheme, $parsed_url['host'], $port, $path );
return esc_html( $base );
}
/**
* Format parameters column output.
*
* @param array $item Item data.
* @return string
*/
private function format_params_column( array $item ): string {
$params = array();
if ( ! empty( $item['url'] ) ) {
$parsed_url = wp_parse_url( $item['url'] );
if ( ! empty( $parsed_url['query'] ) ) {
$fallback_query = wp_parse_args( $parsed_url['query'] );
$params = array_merge( $params, $fallback_query );
}
}
$query_params = $this->decode_json_params( $item['query_json'] ?? '' );
if ( ! empty( $query_params ) ) {
$params = array_merge( $params, $query_params );
}
$body_params = $this->decode_json_params( $item['body_json'] ?? '' );
if ( ! empty( $body_params ) ) {
$params = array_merge( $params, $body_params );
}
if ( empty( $body_params ) && ! empty( $item['raw_body'] ) ) {
$fallback_body = wp_parse_args( $item['raw_body'] );
if ( ! empty( $fallback_body ) ) {
$params = array_merge( $params, $fallback_body );
}
}
if ( empty( $params ) ) {
return '';
}
$lines = array();
foreach ( $params as $key => $value ) {
if ( is_array( $value ) ) {
$value = wp_json_encode( $value );
}
$lines[] = sprintf( '%s=%s', $key, $value );
}
return '<pre style="white-space: pre-wrap; margin: 0;">' . esc_html( implode( "\n", $lines ) ) . '</pre>';
}
/**
* Decode JSON parameters into arrays.
*
* @param string $value JSON string.
* @return array
*/
private function decode_json_params( string $value ): array {
if ( empty( $value ) ) {
return array();
}
$decoded = json_decode( $value, true );
if ( is_array( $decoded ) ) {
return $decoded;
}
if ( is_string( $decoded ) ) {
$parsed = wp_parse_args( $decoded );
if ( ! empty( $parsed ) ) {
return $parsed;
}
}
$parsed = wp_parse_args( $value );
if ( ! empty( $parsed ) ) {
return $parsed;
}
return array();
}
/**
* Extra controls for filtering.
*
* @param string $which Top or bottom.
*/
public function extra_tablenav( $which ): void {
if ( 'top' !== $which ) {
return;
}
$method = strtoupper( $this->get_filter_value( 'method' ) );
$host = $this->get_filter_value( 'host' );
$date_from = $this->get_filter_value( 'date_from' );
$date_to = $this->get_filter_value( 'date_to' );
echo '<div class="alignleft actions">';
echo '<label class="screen-reader-text" for="robotstxt-telemetry-method-filter">' . esc_html__( 'Filter by method', 'robotstxt-telemetry' ) . '</label>';
echo '<select name="method" id="robotstxt-telemetry-method-filter">';
echo '<option value="">' . esc_html__( 'All methods', 'robotstxt-telemetry' ) . '</option>';
$methods = array( 'GET', 'POST', 'HEAD', 'PUT', 'PATCH', 'DELETE' );
foreach ( $methods as $option ) {
printf(
'<option value="%s" %s>%s</option>',
esc_attr( $option ),
selected( strtoupper( (string) $method ), $option, false ),
esc_html( $option )
);
}
echo '</select>';
echo '<label class="screen-reader-text" for="robotstxt-telemetry-host-filter">' . esc_html__( 'Filter by host', 'robotstxt-telemetry' ) . '</label>';
printf(
'<input type="text" name="host" id="robotstxt-telemetry-host-filter" value="%s" placeholder="%s" />',
esc_attr( (string) $host ),
esc_attr__( 'Host', 'robotstxt-telemetry' )
);
echo '<label class="screen-reader-text" for="robotstxt-telemetry-date-from">' . esc_html__( 'From date', 'robotstxt-telemetry' ) . '</label>';
printf(
'<input type="date" name="date_from" id="robotstxt-telemetry-date-from" value="%s" />',
esc_attr( (string) $date_from )
);
echo '<label class="screen-reader-text" for="robotstxt-telemetry-date-to">' . esc_html__( 'To date', 'robotstxt-telemetry' ) . '</label>';
printf(
'<input type="date" name="date_to" id="robotstxt-telemetry-date-to" value="%s" />',
esc_attr( (string) $date_to )
);
submit_button( __( 'Filter', 'robotstxt-telemetry' ), '', 'filter_action', false );
echo '</div>';
}
/**
* Get a sanitized filter value from the request.
*
* Values are only used to build read-only list filters.
*
* @param string $key Filter key.
* @return string
*/
private function get_filter_value( string $key ): string {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only list filters.
if ( ! isset( $_GET[ $key ] ) ) {
return '';
}
return sanitize_text_field( wp_unslash( $_GET[ $key ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
}
/**
* Sanitize date inputs.
*
* @param string|null $value Date string.
* @return string|null
*/
private function sanitize_date_filter( ?string $value ): ?string {
if ( empty( $value ) ) {
return null;
}
$date = DateTime::createFromFormat( 'Y-m-d', $value );
if ( false === $date ) {
return null;
}
return $date->format( 'Y-m-d' );
}
}
}

View file

@ -0,0 +1,171 @@
<?php
/**
* Manager plugin dependency notice.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry_Manager_Notice' ) ) {
/**
* Class Robotstxt_Telemetry_Manager_Notice
*
* Detects the Manager (by ROBOTSTXT) plugin and reminds admins to install
* it when it is missing, so this plugin keeps receiving updates.
*/
class Robotstxt_Telemetry_Manager_Notice {
/**
* Manager plugin basename.
*
* @var string
*/
const MANAGER_PLUGIN_BASENAME = 'robotstxt-manager/robotstxt-manager.php';
/**
* User meta key storing the dismissal state.
*
* @var string
*/
const DISMISS_META_KEY = 'robotstxt_telemetry_manager_notice_dismissed';
/**
* Register hooks.
*/
public function register(): void {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_notices', array( $this, 'render_plugins_page_notice' ) );
add_action( 'network_admin_notices', array( $this, 'render_plugins_page_notice' ) );
add_action( 'wp_ajax_robotstxt_telemetry_dismiss_manager_notice', array( $this, 'handle_dismiss' ) );
}
/**
* Whether the Manager (by ROBOTSTXT) plugin is active.
*
* @return bool
*/
public static function is_manager_active(): bool {
if ( ! function_exists( 'is_plugin_active' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
return is_plugin_active( self::MANAGER_PLUGIN_BASENAME )
|| is_plugin_active_for_network( self::MANAGER_PLUGIN_BASENAME );
}
/**
* Enqueue the inline dismissal script on the plugins list screen.
*/
public function enqueue_scripts(): void {
if ( ! $this->should_show_notice() ) {
return;
}
wp_enqueue_script( 'common' );
wp_add_inline_script(
'common',
'(function () {
document.addEventListener(
\'click\',
function ( event ) {
var notice = document.getElementById( \'robotstxt-telemetry-manager-notice\' );
if ( ! notice || ! event.target.closest( \'#robotstxt-telemetry-manager-notice .notice-dismiss\' ) ) {
return;
}
var data = new FormData();
data.append( \'action\', \'robotstxt_telemetry_dismiss_manager_notice\' );
data.append( \'nonce\', \'' . esc_js( wp_create_nonce( 'robotstxt_telemetry_manager_notice' ) ) . '\' );
fetch( window.ajaxurl, { method: \'POST\', credentials: \'same-origin\', body: data } );
}
);
})();',
'after'
);
}
/**
* Render the dismissible notice on the plugins list screen.
*/
public function render_plugins_page_notice(): void {
if ( ! $this->should_show_notice() ) {
return;
}
$this->render_notice( 'notice-warning is-dismissible', 'robotstxt-telemetry-manager-notice' );
}
/**
* Render a permanent notice for the settings screen.
*/
public function render_settings_notice(): void {
$this->render_notice( 'notice-info', '' );
}
/**
* Render the Manager (by ROBOTSTXT) notice markup.
*
* @param string $classes Extra CSS classes.
* @param string $id Optional DOM id for the notice container.
*/
private function render_notice( string $classes, string $id ): void {
if ( self::is_manager_active() ) {
return;
}
printf(
'<div class="notice %s"%s><p>%s</p></div>',
esc_attr( $classes ),
$id ? sprintf( ' id="%s"', esc_attr( $id ) ) : '',
wp_kses_post(
sprintf(
/* translators: 1: Manager plugin URL, 2: link text. */
__( 'To receive updates for Telemetry (by ROBOTSTXT), the <a href="%1$s">%2$s</a> plugin must be installed and active.', 'robotstxt-telemetry' ),
'https://www.robotstxt.software/plugins/robotstxt-manager/',
__( 'Manager (by ROBOTSTXT)', 'robotstxt-telemetry' )
)
)
);
}
/**
* Whether the plugins page notice should be displayed.
*
* @return bool
*/
private function should_show_notice(): bool {
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;
if ( ! $screen || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
return false;
}
if ( self::is_manager_active() ) {
return false;
}
return ! get_user_meta( get_current_user_id(), self::DISMISS_META_KEY, true );
}
/**
* Persist the notice dismissal for the current user.
*/
public function handle_dismiss(): void {
check_ajax_referer( 'robotstxt_telemetry_manager_notice' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to perform this action.', 'robotstxt-telemetry' ) );
}
update_user_meta( get_current_user_id(), self::DISMISS_META_KEY, 1 );
wp_send_json_success();
}
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* Main plugin bootstrap.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Robotstxt_Telemetry' ) ) {
/**
* Class Robotstxt_Telemetry
*/
class Robotstxt_Telemetry {
/**
* Initialize the plugin.
*/
public static function init(): void {
$instance = new self();
$instance->register_hooks();
}
/**
* Register hooks.
*/
private function register_hooks(): void {
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
add_action( 'init', array( 'Robotstxt_Telemetry_DB', 'maybe_upgrade' ) );
$logger = new Robotstxt_Telemetry_Logger();
$logger->register();
if ( is_admin() ) {
$notice = new Robotstxt_Telemetry_Manager_Notice();
$notice->register();
$admin = new Robotstxt_Telemetry_Admin();
$admin->register();
}
}
/**
* Load plugin translations.
*/
public function load_textdomain(): void {
load_plugin_textdomain(
'robotstxt-telemetry',
false,
dirname( plugin_basename( ROBOTSTXT_TELEMETRY_PLUGIN_FILE ) ) . '/languages'
);
}
}
}

View file

@ -0,0 +1,223 @@
# Copyright (C) 2026 ROBOTSTXT
# This file is distributed under the GPL v3 or later.
msgid ""
msgstr ""
"Project-Id-Version: Telemetry (by ROBOTSTXT) 0.2.0\n"
"Report-Msgid-Bugs-To: https://www.robotstxt.software/plugins/robotstxt-telemetry/\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2026-08-18T13:23:28+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: robotstxt-telemetry\n"
#. Plugin Name of the plugin
#: robotstxt-telemetry.php
msgid "Telemetry (by ROBOTSTXT)"
msgstr ""
#. Plugin URI of the plugin
#: robotstxt-telemetry.php
msgid "https://www.robotstxt.software/plugins/robotstxt-telemetry/"
msgstr ""
#. Description of the plugin
#: robotstxt-telemetry.php
msgid "Logs outbound HTTP requests made by WordPress for inspection."
msgstr ""
#. Author of the plugin
#: robotstxt-telemetry.php
msgid "ROBOTSTXT"
msgstr ""
#. Author URI of the plugin
#: robotstxt-telemetry.php
msgid "https://www.robotstxt.software/"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:33
#: includes/class-robotstxt-telemetry-admin.php:34
msgid "Telemetry"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:43
#: includes/class-robotstxt-telemetry-admin.php:44
msgid "Settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:52
#: includes/class-robotstxt-telemetry-admin.php:53
msgid "Logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:141
msgid "Settings saved."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:153
msgid "Telemetry Settings"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:163
msgid "Uninstall behavior"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:167
msgid "Delete all telemetry logs and plugin options on uninstall"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:169
msgid "By default, all telemetry logs are preserved when the plugin is uninstalled."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:194
msgid "Telemetry Logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:205
msgid "Log entry deleted."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:227
msgid "Log entry not found."
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:231
msgid "Back to logs"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:235
#: includes/class-robotstxt-telemetry-logs-table.php:49
msgid "Date"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:236
#: includes/class-robotstxt-telemetry-logs-table.php:50
msgid "Method"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:237
msgid "URL"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:238
#: includes/class-robotstxt-telemetry-logs-table.php:51
#: includes/class-robotstxt-telemetry-logs-table.php:330
msgid "Host"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:239
#: includes/class-robotstxt-telemetry-logs-table.php:52
msgid "Path"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:240
msgid "Body Params"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:241
msgid "Headers"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:242
msgid "User Agent"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:243
msgid "Raw Body"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:244
msgid "Caller"
msgstr ""
#: includes/class-robotstxt-telemetry-admin.php:264
msgid "Telemetry Analysis"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:74
msgid "Environment"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:78
msgid "Extensions"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:82
msgid "Platform Flags"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:86
msgid "Image Support"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:90
msgid "Other URL Parameters"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:117
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:119
msgid "Translations"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php:124
msgid "Other Body Parameters"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis.php:45
msgid "URL Parameters"
msgstr ""
#: includes/class-robotstxt-telemetry-analysis.php:50
msgid "Body Parameters"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:182
msgid "View"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:183
msgid "Delete"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:310
msgid "Filter by method"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:312
msgid "All methods"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:326
msgid "Filter by host"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:333
msgid "From date"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:339
msgid "To date"
msgstr ""
#: includes/class-robotstxt-telemetry-logs-table.php:345
msgid "Filter"
msgstr ""
#. translators: 1: Manager plugin URL, 2: link text.
#: includes/class-robotstxt-telemetry-manager-notice.php:126
#, php-format
msgid "To receive updates for Telemetry (by ROBOTSTXT), the <a href=\"%1$s\">%2$s</a> plugin must be installed and active."
msgstr ""
#: includes/class-robotstxt-telemetry-manager-notice.php:128
msgid "Manager (by ROBOTSTXT)"
msgstr ""
#: includes/class-robotstxt-telemetry-manager-notice.php:163
msgid "You do not have sufficient permissions to perform this action."
msgstr ""

114
readme.txt Normal file
View file

@ -0,0 +1,114 @@
=== Telemetry (by ROBOTSTXT) ===
Contributors: robotstxt, javiercasares
Tags: telemetry, http, logging, debug, requests
Requires at least: 6.2
Tested up to: 7.1
Stable tag: 0.2.0
Requires PHP: 7.4
Version: 0.2.0
License: GPL-3.0-or-later
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
Logs outbound HTTP requests made by WordPress for inspection.
== Description ==
Telemetry (by ROBOTSTXT) records the external HTTP requests that WordPress (and its plugins and themes) performs through the WordPress HTTP API, so they can be inspected from the administration panel.
For every outbound call, the plugin stores the request method, full URL, host and path, query parameters, body parameters or raw body, sanitized request headers, user agent, and the caller backtrace summary. Sensitive values (authorization headers, passwords, tokens, API keys, secrets, nonces) are automatically redacted before storing, and all payloads are size-limited to keep the database lean.
The Logs screen provides a paginated list with filters by method, host, and date range, a detailed single-entry view, and nonce-protected delete actions. Entries pointing to `api.wordpress.org` get a dedicated analysis view that groups environment, extensions, platform, and image support parameters.
Updates for this plugin are delivered through the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin. If the Manager is not active, the plugin shows a dismissible reminder in the plugins list and a permanent notice on its Settings screen.
= Privacy by default =
* Sensitive keys (`authorization`, `password`, `pass`, `token`, `secret`, `api_key`, `apikey`, `nonce`) are redacted before anything is written to the database.
* Credentials embedded in URLs are stripped, and query strings are stored redacted.
* Payloads are truncated (64 KB per JSON blob, 64 KB raw body, 16 KB caller trace).
* Logs are only accessible to administrators (`manage_options`).
* No data ever leaves the site; logs are stored in the site's own database.
== Using the plugin ==
= Logs =
Navigate to **Telemetry → Logs**. Use the method, host, and date filters to narrow the list, then click **View** on any entry to see its full details, or **Delete** to remove it.
= Settings =
Navigate to **Telemetry → Settings**. The "Delete all telemetry logs and plugin options on uninstall" checkbox controls the uninstall behavior: unchecked by default, so all telemetry data is preserved when the plugin is removed. When the Manager (by ROBOTSTXT) plugin is not active, a permanent notice about updates is shown on this screen.
== Extra Configurations ==
This plugin does not require any `define()` in `wp-config.php`.
== Installation ==
= Automatic download =
Visit the plugin section in your WordPress, search for "Telemetry (by ROBOTSTXT)"; download and install the plugin.
= Manual download =
Extract the contents of the ZIP and upload the contents to the `/wp-content/plugins/robotstxt-telemetry/` directory. Once uploaded, it will appear in your plugin list.
== Frequently Asked Questions ==
= Does the plugin send any data anywhere? =
No. The plugin only records outbound HTTP requests in the site's own database for local inspection. Nothing is transmitted to third parties.
= Where is the data stored? =
In a custom database table (`{$wpdb->prefix}robotstxt_telemetry_logs`) created on activation, using the WordPress database API.
= What happens to my logs when I uninstall the plugin? =
By default all logs are preserved. If you want a full cleanup, enable "Delete all telemetry logs and plugin options on uninstall" in **Telemetry → Settings** before uninstalling.
= How do I get updates? =
Install and activate the [Manager (by ROBOTSTXT)](https://www.robotstxt.software/plugins/robotstxt-manager/) plugin, which handles updates for ROBOTSTXT plugins.
== Compatibility ==
* WordPress: 6.2 - 7.1
* PHP: 7.4 - 8.5
* MariaDB: 10.6+
* Multisite: compatible (`Network: true`)
== Changelog ==
Only the 3 last versions. The full changelog will be at changelog.txt
= 0.2.0 =
* Added: Settings screen with uninstall behavior option (data preserved by default)
* Added: Manager (by ROBOTSTXT) dependency notice, dismissible in the plugins list and permanent in Settings
* Added: `uninstall.php` routine honoring the delete-data option, Multisite aware
* Added: `bin/deploy.sh` distributable packaging script
* Changed: minimum requirements lowered to WordPress 6.2 and PHP 7.4
* Changed: Plugin, author, and update URLs moved to robotstxt.software
* Removed: bundled self-updater (`robotstxt-updater.php`, `update.json`) in favor of the Manager plugin
* Security: query strings and credentials in URLs are redacted before storing
* Fixed: query parameters were not stored due to a discarded `wp_parse_args()` return value
* Fixed: UTF-8 scrubbing no longer discards whole payloads
= 0.1.0 =
* Initial release: outbound HTTP logging with custom table, Logs admin screen with filters, pagination, view and delete actions, and secret redaction
= Previous versions =
If you want to see the full changelog, visit the [changelog.txt](https://www.robotstxt.software/plugins/robotstxt-telemetry/) page.
== Compliance ==
This plugin adheres to the following security measures and review protocols for each version:
* [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
* [WordPress Plugin Security](https://developer.wordpress.org/plugins/wordpress-org/plugin-security/)
* [WordPress APIs Security](https://developer.wordpress.org/apis/security/)
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
* [Plugin Check (PCP)](https://wordpress.org/plugins/plugin-check/)

41
robotstxt-telemetry.php Normal file
View file

@ -0,0 +1,41 @@
<?php
/**
* Plugin Name: Telemetry (by ROBOTSTXT)
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Update URI: https://www.robotstxt.software/plugins/robotstxt-telemetry/
* Description: Logs outbound HTTP requests made by WordPress for inspection.
* Version: 0.2.0
* Author: ROBOTSTXT
* Author URI: https://www.robotstxt.software/
* Text Domain: robotstxt-telemetry
* Domain Path: /languages
* Requires at least: 6.2
* Requires PHP: 7.4
* Tested up to: 7.1
* Network: true
* License: GPL v3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'ROBOTSTXT_TELEMETRY_VERSION', '0.2.0' );
define( 'ROBOTSTXT_TELEMETRY_DB_VERSION', '1.1.0' );
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_FILE', __FILE__ );
define( 'ROBOTSTXT_TELEMETRY_PLUGIN_DIR', __DIR__ );
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-db.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-logger.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-admin.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-manager-notice.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-analysis.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry-analysis-api-wordpress-org.php';
require_once ROBOTSTXT_TELEMETRY_PLUGIN_DIR . '/includes/class-robotstxt-telemetry.php';
register_activation_hook( __FILE__, array( 'Robotstxt_Telemetry_DB', 'activate' ) );
Robotstxt_Telemetry::init();

64
uninstall.php Normal file
View file

@ -0,0 +1,64 @@
<?php
/**
* Uninstall handler.
*
* By default all telemetry data is preserved. When the user opts in via the
* "Delete all telemetry logs on uninstall" setting, the logs table and plugin
* options are removed.
*
* @package RobotstxtTelemetry
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
$robotstxt_telemetry_delete_data = (bool) get_option( 'robotstxt_telemetry_delete_on_uninstall', false );
// Remove per-user manager notice dismissals (user meta is global).
delete_metadata( 'user', 0, 'robotstxt_telemetry_manager_notice_dismissed', '', true );
if ( ! $robotstxt_telemetry_delete_data ) {
// Keep all log data. Only remove the plugin options.
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_option( 'robotstxt_telemetry_db_version' );
return;
}
/**
* Delete telemetry data for the current site.
*
* @return void
*/
function robotstxt_telemetry_uninstall_site(): void {
global $wpdb;
$table_name = $wpdb->prefix . 'robotstxt_telemetry_logs';
$wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table_name ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.DirectDatabaseQuery.NoCaching
delete_option( 'robotstxt_telemetry_delete_on_uninstall' );
delete_option( 'robotstxt_telemetry_db_version' );
}
if ( is_multisite() ) {
$robotstxt_telemetry_site_ids = get_sites(
array(
'fields' => 'ids',
'number' => 0,
'update_site_cache' => false,
'update_archived_cache' => false,
)
);
foreach ( $robotstxt_telemetry_site_ids as $robotstxt_telemetry_site_id ) {
switch_to_blog( $robotstxt_telemetry_site_id );
robotstxt_telemetry_uninstall_site();
restore_current_blog();
}
} else {
robotstxt_telemetry_uninstall_site();
}
// Remove per-user manager notice dismissals (user meta is global).
delete_metadata( 'user', 0, 'robotstxt_telemetry_manager_notice_dismissed', '', true );