This commit is contained in:
Javier Casares 2026-11-04 17:27:19 +00:00
commit 121c35737d

View file

@ -3,7 +3,7 @@
* Plugin Name: Documentation Markdown (by ROBOTSTXT)
* Plugin URI: https://www.robotstxt.software/plugins/robotstxt-documentation-markdown/
* Description: Synchronizes Markdown documentation from GitHub repositories to WordPress pages and posts automatically.
* Version: 1.2.2
* Version: 1.2.3
* Requires at least: 4.2
* Requires PHP: 8.0
* Security: robotstxt@robotstxt.es
@ -25,7 +25,7 @@ if ( ! defined( 'ABSPATH' ) ) {
}
// Define plugin constants.
define( 'ROBOTSTXT_DOCMD_VERSION', '1.2.2' );
define( 'ROBOTSTXT_DOCMD_VERSION', '1.2.3' );
define( 'ROBOTSTXT_DOCMD_PLUGIN_FILE', __FILE__ );
define( 'ROBOTSTXT_DOCMD_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'ROBOTSTXT_DOCMD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
@ -146,6 +146,13 @@ function robotstxt_docmd_register_post_types() {
* @return void
*/
function robotstxt_docmd_register_admin_menu() {
// Base64 SVG data URI (document icon). Supported by core admin menus from
// WP 4.2 through 7.2+ (rendered as a 20px background image); aligns the icon
// with core's move from the Dashicons font to SVG (see WP ticket #65089),
// without requiring the WP 7.2-only wp_get_icon() API.
// phpcs:ignore Generic.Files.LineLength.TooLong -- 264-char base64 icon string cannot be wrapped.
$icon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMCAyMCI+PHBhdGggZmlsbD0iI2MzYzRjNyIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNNSAxaDdsNCA0djE0SDVWMXptNyAxLjdWNmgzLjNMMTIgMi43ek03IDloNnYxSDdWOXptMCAzaDcuNXYxSDd2LTF6bTAgM2g3LjV2MUg3di0xeiIvPjwvc3ZnPg==';
// Main menu.
add_menu_page(
__( 'Documentation', 'robotstxt-documentation-markdown' ),
@ -153,7 +160,7 @@ function robotstxt_docmd_register_admin_menu() {
'edit_pages',
'robotstxt-docmd-mappings',
'robotstxt_docmd_render_mappings_page',
'dashicons-media-document',
$icon,
30
);
@ -735,11 +742,12 @@ function robotstxt_docmd_render_add_mapping_page() {
<?php
$post_types = get_post_types( array( 'public' => true ), 'objects' );
foreach ( $post_types as $post_type ) {
$label = $post_type->labels->singular_name;
printf(
'<option value="%s" %s>%s</option>',
esc_attr( $post_type->name ),
selected( $data['target_post_type'], $post_type->name, false ),
esc_html( $post_type->labels->singular_name )
esc_html( is_string( $label ) ? $label : $post_type->name )
);
}
?>
@ -1579,6 +1587,11 @@ function robotstxt_docmd_debug_clear_cache() {
global $wpdb;
// Type-narrow the global (PHPStan level 10: global $wpdb is mixed).
if ( ! $wpdb instanceof wpdb ) {
return;
}
$result = array(
'type' => 'error',
'message' => '',
@ -1586,16 +1599,19 @@ function robotstxt_docmd_debug_clear_cache() {
);
// Delete all plugin transients.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Direct query acceptable for cache clearing operation.
// Escaping uses the esc_sql() + esc_like() chain documented in wpdb::esc_like():
// wpdb::prepare() cannot be used here because table-name interpolation makes
// the query string non-literal (wordpress-stubs types $query as literal-string).
$transient_like = esc_sql( $wpdb->esc_like( '_transient_robotstxt_docmd_' ) ) . '%';
$timeout_like = esc_sql( $wpdb->esc_like( '_transient_timeout_robotstxt_docmd_' ) ) . '%';
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Bulk cache-clearing delete; values escaped above via esc_sql() + esc_like().
$deleted = $wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE %s
OR option_name LIKE %s",
$wpdb->esc_like( '_transient_robotstxt_docmd_' ) . '%',
$wpdb->esc_like( '_transient_timeout_robotstxt_docmd_' ) . '%'
)
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE '{$transient_like}'
OR option_name LIKE '{$timeout_like}'"
);
// phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
if ( false !== $deleted ) {
$result['type'] = 'success';