--- a/page-keys/functions.php
+++ b/page-keys/functions.php
@@ -1,7 +1,11 @@
-<?php # -*- coding: utf-8 -*-
+<?php
use tfPageKeysModelsOption;
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
if ( ! function_exists( 'get_page_by_key' ) ) :
/**
--- a/page-keys/inc/Autoloader/Autoloader.php
+++ b/page-keys/inc/Autoloader/Autoloader.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfAutoloader;
--- a/page-keys/inc/Autoloader/NamespaceRule.php
+++ b/page-keys/inc/Autoloader/NamespaceRule.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfAutoloader;
--- a/page-keys/inc/Autoloader/Rule.php
+++ b/page-keys/inc/Autoloader/Rule.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfAutoloader;
--- a/page-keys/inc/Autoloader/bootstrap.php
+++ b/page-keys/inc/Autoloader/bootstrap.php
@@ -1,7 +1,11 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfAutoloader;
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+
foreach ( array( 'Autoloader', 'Rule', 'NamespaceRule' ) as $name ) {
$fqn = __NAMESPACE__ . '\' . $name;
if ( ! class_exists( $fqn ) && ! interface_exists( $fqn ) ) {
--- a/page-keys/inc/Controllers/AJAX.php
+++ b/page-keys/inc/Controllers/AJAX.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/Controllers/AdminNotice.php
+++ b/page-keys/inc/Controllers/AdminNotice.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/Controllers/Page.php
+++ b/page-keys/inc/Controllers/Page.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/Controllers/Script.php
+++ b/page-keys/inc/Controllers/Script.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/Controllers/Settings.php
+++ b/page-keys/inc/Controllers/Settings.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/Controllers/TextDomain.php
+++ b/page-keys/inc/Controllers/TextDomain.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysControllers;
--- a/page-keys/inc/ListTable.php
+++ b/page-keys/inc/ListTable.php
@@ -1,8 +1,7 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeys;
-use tfPageKeysModels;
use tfPageKeysModelsSettingsPage as PageModel;
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
@@ -139,6 +138,8 @@
/**
* Sort the items according to the values given in the $_REQUEST superglobal.
*
+ * @phpcs:disable WordPress.Security.NonceVerification.Recommended -- No nonce verification needed.
+ *
* @param array $sortable_columns Sortable columns.
*
* @return void
@@ -147,14 +148,14 @@
if (
empty( $_REQUEST[ 'orderby' ] )
- || ! array_key_exists( $_REQUEST[ 'orderby' ], $sortable_columns )
+ || ! array_key_exists( sanitize_text_field( wp_unslash( $_REQUEST[ 'orderby' ] ) ), $sortable_columns )
) {
return;
}
if (
isset( $_REQUEST[ 'order' ] )
- && strtolower( $_REQUEST[ 'order' ] ) === 'desc'
+ && strtoupper( sanitize_text_field( wp_unslash( $_REQUEST[ 'order' ] ) ) ) === 'DESC'
) {
krsort( $this->items );
} else {
@@ -170,7 +171,7 @@
private function maybe_add_item() {
if (
- filter_input( INPUT_GET, 'action' ) === 'add'
+ filter_input( INPUT_GET, 'action', FILTER_SANITIZE_SPECIAL_CHARS ) === 'add'
&& $this->page->current_user_can( 'edit' )
) {
$this->items[ ] = $this->get_empty_item();
@@ -214,7 +215,7 @@
*/
public function single_row( $item ) {
- $id = time() . mt_rand();
+ $id = time() . wp_rand();
$id = md5( $id );
$this->current_row_id = substr( $id, 0, 15 );
@@ -257,14 +258,14 @@
'<input type="text" name="%1$s[%2$s][page_key]" value="%3$s" class="page-key regular-text" data-id="%2$s">',
$this->name_prefix,
$this->current_row_id,
- $page_key
+ esc_attr( $page_key )
);
$actions = array();
if ( $this->page->current_user_can( 'edit' ) ) {
- $text = esc_html__( 'Edit' );
+ $text = esc_html__( 'Edit', 'page-keys' );
$url = get_permalink();
- $title = esc_attr__( 'Edit this item' );
+ $title = esc_attr__( 'Edit this item', 'page-keys' );
$actions[ 'edit hide-if-no-js' ] = sprintf(
'<a class="edit" title="%3$s" href="%2$s">%1$s</a>',
$text,
@@ -272,9 +273,9 @@
$title
);
- $text = esc_html__( 'Delete Permanently' );
- $url = $this->page->get_delete_page_key_url( $page_key );
- $title = esc_attr__( 'Delete this item permanently' );
+ $text = esc_html__( 'Delete Permanently', 'page-keys' );
+ $url = esc_url( $this->page->get_delete_page_key_url( $page_key ) );
+ $title = esc_attr__( 'Delete this item permanently', 'page-keys' );
$actions[ 'delete' ] = sprintf(
'<a class="submitdelete submitdelete-%4$s" title="%3$s" href="%2$s" data-id="%4$s">%1$s</a>',
$text,
@@ -307,11 +308,11 @@
return wp_dropdown_pages(
array(
- 'name' => $this->name_prefix . '[' . $this->current_row_id . '][page_id]',
- 'id' => 'page-id-' . $this->current_row_id,
+ 'name' => esc_attr( $this->name_prefix . '[' . $this->current_row_id . '][page_id]' ),
+ 'id' => esc_attr( 'page-id-' . $this->current_row_id ),
'show_option_none' => ' ',
'option_non_value' => '',
- 'selected' => $selected,
+ 'selected' => esc_attr( $selected ),
'echo' => FALSE,
)
);
--- a/page-keys/inc/Models/Nonce.php
+++ b/page-keys/inc/Models/Nonce.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
@@ -110,7 +110,8 @@
return FALSE;
}
- $nonce = $_REQUEST[ $this->name ];
+ /* phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification further down. */
+ $nonce = sanitize_key( $_REQUEST[ $this->name ] );
}
$action = $action === '' ? $this->action : $action;
--- a/page-keys/inc/Models/Option.php
+++ b/page-keys/inc/Models/Option.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
--- a/page-keys/inc/Models/Page.php
+++ b/page-keys/inc/Models/Page.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
@@ -39,7 +39,7 @@
foreach ( $pages as $page_key => $page ) {
if (
isset( $page[ 'page_id' ] )
- && $page[ 'page_id' ] == $post_id
+ && absint( $page[ 'page_id' ] ) === absint( $post_id )
) {
$pages[ $page_key ][ 'page_id' ] = '';
$update = TRUE;
--- a/page-keys/inc/Models/PageKeys.php
+++ b/page-keys/inc/Models/PageKeys.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
@@ -88,7 +88,7 @@
$data = (object) compact( 'errors' );
if ( $response ) {
- $data->id = filter_input( INPUT_POST, 'id' );
+ $data->id = filter_input( INPUT_POST, 'id', FILTER_SANITIZE_SPECIAL_CHARS );
wp_send_json_success( $data );
}
@@ -98,6 +98,8 @@
/**
* Delete the page key given in the $_REQUEST superglobal.
*
+ * @phpcs:disable WordPress.Security.NonceVerification.Recommended -- Nonce verification via Nonce::is_valid().
+ *
* @return bool
*/
private function delete() {
@@ -123,7 +125,7 @@
return FALSE;
}
- $page_key = urldecode( $_REQUEST[ 'page_key' ] );
+ $page_key = sanitize_key( $_REQUEST[ 'page_key' ] );
$pages = Option::get();
if ( array_key_exists( $page_key, $pages ) ) {
unset( $pages[ $page_key ] );
--- a/page-keys/inc/Models/Script.php
+++ b/page-keys/inc/Models/Script.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
--- a/page-keys/inc/Models/Settings.php
+++ b/page-keys/inc/Models/Settings.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
@@ -45,6 +45,7 @@
$page_key = $page[ 'page_key' ];
}
+ $page_key = sanitize_key( $page_key );
$page_id = '';
if ( isset( $page[ 'page_id' ] ) ) {
--- a/page-keys/inc/Models/SettingsErrors/DuplicatePageKey.php
+++ b/page-keys/inc/Models/SettingsErrors/DuplicatePageKey.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
@@ -21,9 +21,11 @@
$this->set_code( 'duplicate-page-key' );
+ /* translators: 1: page key, 2: page ID. */
$message = _x(
- "Cannot map page key '%s' to page ID '%d'! Page key already set.",
- 'Settings error message, %s=page key, %d=page ID', 'page-keys'
+ 'Cannot map page key "%1$s" to page ID %2$d! Page key already set.',
+ 'Settings error message',
+ 'page-keys'
);
$message = sprintf( $message, $page_key, $page_id );
$this->set_message( $message );
--- a/page-keys/inc/Models/SettingsErrors/InvalidNonce.php
+++ b/page-keys/inc/Models/SettingsErrors/InvalidNonce.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
--- a/page-keys/inc/Models/SettingsErrors/InvalidPageKey.php
+++ b/page-keys/inc/Models/SettingsErrors/InvalidPageKey.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
@@ -20,7 +20,8 @@
$this->set_code( 'invalid-page-key' );
- $message = _x( "Page key '%s' invalid!", 'Settings error message, %s=page key', 'page-keys' );
+ /* translators: 1: page key. */
+ $message = _x( 'Page key "%s" invalid!', 'Settings error message', 'page-keys' );
$message = sprintf( $message, $page_key );
$this->set_message( $message );
}
--- a/page-keys/inc/Models/SettingsErrors/MissingPageKey.php
+++ b/page-keys/inc/Models/SettingsErrors/MissingPageKey.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
--- a/page-keys/inc/Models/SettingsErrors/NoPermissionToEdit.php
+++ b/page-keys/inc/Models/SettingsErrors/NoPermissionToEdit.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
@@ -18,7 +18,7 @@
$this->set_code( 'no-permission-to-edit' );
- $message = _x( "You don't have permission to edit page keys.", 'Settings error message', 'page-keys' );
+ $message = _x( 'You don't have permission to edit page keys.', 'Settings error message', 'page-keys' );
$this->set_message( $message );
}
--- a/page-keys/inc/Models/SettingsErrors/PageKeyDeleted.php
+++ b/page-keys/inc/Models/SettingsErrors/PageKeyDeleted.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
@@ -20,7 +20,8 @@
$this->set_code( 'page-key-deleted' );
- $message = _x( "Page key '%s' permanently deleted.", 'Settings error message, %s=page key', 'page-keys' );
+ /* translators: 1: page key. */
+ $message = _x( 'Page key "%s" permanently deleted.', 'Settings error message', 'page-keys' );
$message = sprintf( $message, $page_key );
$this->set_message( $message );
--- a/page-keys/inc/Models/SettingsErrors/SettingsError.php
+++ b/page-keys/inc/Models/SettingsErrors/SettingsError.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModelsSettingsErrors;
@@ -78,7 +78,7 @@
'error',
'updated',
);
- if ( ! in_array( $type, $valid_types ) ) {
+ if ( ! in_array( $type, $valid_types, TRUE ) ) {
return FALSE;
}
--- a/page-keys/inc/Models/SettingsPage.php
+++ b/page-keys/inc/Models/SettingsPage.php
@@ -1,10 +1,7 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
-use tfPageKeysControllers;
-use tfPageKeysViews;
-
/**
* Class SettingsPage
*
@@ -121,7 +118,7 @@
'add',
'delete',
);
- if ( ! in_array( $action, $valid_actions ) ) {
+ if ( ! in_array( $action, $valid_actions, TRUE ) ) {
return '';
}
--- a/page-keys/inc/Models/TextDomain.php
+++ b/page-keys/inc/Models/TextDomain.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysModels;
@@ -37,7 +37,7 @@
*/
public function load() {
- return load_plugin_textdomain( $this->domain, FALSE, $this->path );
+ return load_plugin_textdomain( $this->domain, false, $this->path );
}
}
--- a/page-keys/inc/Plugin.php
+++ b/page-keys/inc/Plugin.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeys;
--- a/page-keys/inc/Views/AdminNotice.php
+++ b/page-keys/inc/Views/AdminNotice.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysViews;
@@ -59,8 +59,9 @@
return;
}
- $error_message = esc_html_x(
- '%sImportant:%s Not all registered page keys have a page assigned.', '%s = <strong> and </strong>',
+ /* translators: 1: <strong>, 2: </strong>. */
+ $error_message = esc_html__(
+ '%1$sImportant:%2$s Not all registered page keys have a page assigned.',
'page-keys'
);
@@ -68,7 +69,7 @@
?>
<div class="error">
<p>
- <?php printf( $error_message, '<strong>', '</strong>' ); ?>
+ <?php echo wp_kses_post( sprintf( $error_message, '<strong>', '</strong>' ) ); ?>
<a href="<?php echo esc_url( $link_url ); ?>">
<?php echo esc_html_x( 'Assign pages now.', 'Link text in admin notice', 'page-keys' ); ?>
</a>
--- a/page-keys/inc/Views/SettingsPage.php
+++ b/page-keys/inc/Views/SettingsPage.php
@@ -1,4 +1,4 @@
-<?php # -*- coding: utf-8 -*-
+<?php
namespace tfPageKeysViews;
@@ -31,8 +31,6 @@
public function __construct( Model $model ) {
$this->model = $model;
-
- $this->title = esc_html_x( 'Page Keys', 'Settings page title', 'page-keys' );
}
/**
@@ -44,9 +42,10 @@
*/
public function add() {
+ $title = esc_html_x( 'Page Keys', 'Settings page title', 'page-keys' );
$menu_title = esc_html_x( 'Page Keys', 'Menu item title', 'page-keys' );
add_pages_page(
- $this->title,
+ $title,
$menu_title,
$this->model->get_capability( 'list' ),
$this->model->get_slug(),
@@ -70,15 +69,15 @@
?>
<div class="wrap">
<h2>
- <?php echo $this->title; ?>
+ <?php echo esc_html_x( 'Page Keys', 'Settings page title', 'page-keys' ); ?>
<?php if ( $current_user_can_edit ) : ?>
- <a href="<?php echo $this->model->get_add_page_key_url(); ?>" class="add-new-h2">
- <?php esc_html_e( 'Add New' ); ?>
+ <a href="<?php echo esc_url( $this->model->get_add_page_key_url() ); ?>" class="add-new-h2">
+ <?php esc_html_e( 'Add New', 'page-keys' ); ?>
</a>
<?php endif; ?>
</h2>
<?php settings_errors(); ?>
- <form action="<?php echo admin_url( 'options.php' ); ?>" method="post" id="page-keys-form">
+ <form action="<?php echo esc_url( admin_url( 'options.php' ) ); ?>" method="post" id="page-keys-form">
<?php settings_fields( $option_name ); ?>
<?php $list_table->display(); ?>
@@ -88,9 +87,9 @@
<p>
<?php
printf(
- esc_html_x(
- '%sWarning%s: Duplicate page keys found!',
- '%s=<strong> and </strong>',
+ /* translators: 1: <strong>, 2: </strong>. */
+ esc_html__(
+ '%1$sWarning%2$s: Duplicate page keys found!',
'page-keys'
),
'<strong>',
--- a/page-keys/page-keys.php
+++ b/page-keys/page-keys.php
@@ -1,11 +1,11 @@
-<?php # -*- coding: utf-8 -*-
+<?php
/**
* Plugin Name: Page Keys
* Plugin URI: https://wordpress.org/plugins/page-keys/
- * Description: Register page keys, assign actual WordPress pages to them, and access each of these pages by its individual key.
+ * Description: Register page keys, assign WordPress pages to them, and access each of these pages by its individual key.
* Author: Thorsten Frommen
* Author URI: https://tfrommen.de
- * Version: 1.3.3
+ * Version: 1.3.4
* Text Domain: page-keys
* Domain Path: /languages
* License: GPLv3
@@ -15,8 +15,8 @@
use tfAutoloader;
-if ( ! function_exists( 'add_action' ) ) {
- return;
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
}
require_once __DIR__ . '/inc/Autoloader/bootstrap.php';