{"id":20857,"date":"2026-10-05T09:26:00","date_gmt":"2026-10-05T07:26:00","guid":{"rendered":"https:\/\/www.lukaswojcik.com\/blog\/?p=20857"},"modified":"2026-11-14T23:38:47","modified_gmt":"2026-11-14T22:38:47","slug":"securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights","status":"publish","type":"post","link":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/","title":{"rendered":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights"},"content":{"rendered":"<p>A plugin can reject a forged request and still store unsafe data. It can also clean every field and still allow the wrong account to change settings. Four separate checks prevent different mistakes: permission, a request token, valid input and safe output.<\/p>\n<p>The examples use a notice with a label, an optional link, limited HTML and a row count. The code blocks are cooperating teaching examples, not a complete installable plugin: the settings screen, plugin header, translations, installation and database-error handling still belong in the surrounding plugin.<\/p>\n<h2>What each check means<\/h2>\n<table><thead><tr><th>Check<\/th><th>Concrete question<\/th><th>Example<\/th><\/tr><\/thead><tbody>\n<tr><td>Capability<\/td><td>Does this account have permission to change site settings?<\/td><td><code>current_user_can('manage_options')<\/code><\/td><\/tr>\n<tr><td>Nonce<\/td><td>Does this request carry a token valid for this action and session?<\/td><td><code>wp_verify_nonce()<\/code><\/td><\/tr>\n<tr><td>Validation<\/td><td>Is the row count a whole number from 1 to 50?<\/td><td>Reject <code>-1<\/code>, <code>1.5<\/code> and arrays.<\/td><\/tr>\n<tr><td>Sanitizing<\/td><td>Which parts of this text or HTML may remain?<\/td><td><code>sanitize_text_field()<\/code>, <code>wp_kses_post()<\/code><\/td><\/tr>\n<tr><td>Escaping<\/td><td>Can this value safely appear in this HTML position?<\/td><td><code>esc_attr()<\/code> for an attribute.<\/td><\/tr><\/tbody><\/table>\n<p>A WordPress nonce is not a one-time password and does not prove that a person intended an action or used a particular form. It helps prevent cross-site request forgery (CSRF), where a hostile page tries to trigger an action using an existing login. A token can be reused during its validity period; by default this is roughly 12 to 24 hours. Permission checks remain necessary.<\/p>\n<figure class=\"lw-diagram\"><img loading=\"lazy\" src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/diagrams\/dia-20857-review-20261026.png?v=20261114\" width=\"1120\" height=\"580\" decoding=\"async\" alt=\"Three separate groups: permission and token, valid values, and parameterized storage with context-specific output escaping.\"><figcaption>Permission, request protection and data handling need separate checks.<\/figcaption><\/figure>\n<h2>1. Types, cleaning and value rules<\/h2>\n<p>A field named <code>link<\/code> can arrive as an array, a collection of values, through <code>link[]=value<\/code>. Text-oriented functions should not receive it unchecked. The helper below accepts exactly the four expected fields as strings, ignores additional fields and returns either a cleaned array or <code>WP_Error<\/code>. It expects input that has already passed through <code>wp_unslash()<\/code> when coming from WordPress form globals.<\/p>\n<figure style=\"--cbb-digits:2\" class=\"cbb cbb--wrap cbb--numbers wp-block-code-beautifier-block-code\" data-lang=\"php\"><figcaption class=\"cbb-head\"><span class=\"cbb-lang\">PHP<\/span><span class=\"cbb-actions\"><button type=\"button\" class=\"cbb-button cbb-button--wrap\" data-cbb-action=\"wrap\" aria-pressed=\"true\" title=\"Wrap long lines\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M2 4h12M2 8h9.5a2.5 2.5 0 0 1 0 5H8m0 0 1.5-1.5M8 13l1.5 1.5M2 12h3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/><\/svg><span class=\"cbb-sr\">Wrap long lines<\/span><\/button><button type=\"button\" class=\"cbb-button cbb-button--copy\" data-cbb-action=\"copy\" aria-label=\"Copy code\" data-cbb-status-done=\"Code copied to the clipboard.\" data-cbb-status-failed=\"Copying failed. The code is selected for copying with Ctrl+C or \u2318+C.\" data-cbb-status-noselect=\"Copying failed.\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8.5\" rx=\"1.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><path d=\"M10.5 3.5V3A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v6.5A1.5 1.5 0 0 0 4 11h.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><\/svg><span class=\"cbb-button-label\">Copy<\/span><\/button><\/span><\/figcaption><pre class=\"cbb-pre\" tabindex=\"0\" role=\"region\" aria-label=\"Code example: PHP\"><code class=\"cbb-code language-php\" style=\"counter-reset:cbb-line 0;\"><span class=\"cbb-line\"><span class=\"cbb-meta\">&lt;?php<\/span>\n<\/span><span class=\"cbb-line\"><span class=\"cbb-keyword\">function<\/span> <span class=\"cbb-function\">lw_nb_review_label<\/span>( <span class=\"cbb-variable\">$raw<\/span> ) {\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">is_string<\/span>( <span class=\"cbb-variable\">$raw<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_label'<\/span>, <span class=\"cbb-string\">'Label must be text.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$label<\/span> = <span class=\"cbb-function\">sanitize_text_field<\/span>( <span class=\"cbb-variable\">$raw<\/span> );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-number\">1<\/span> !== <span class=\"cbb-function\">preg_match<\/span>( <span class=\"cbb-string\">'\/^.{1,100}$\/us'<\/span>, <span class=\"cbb-variable\">$label<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_label'<\/span>, <span class=\"cbb-string\">'Label must contain 1 to 100 characters after cleaning.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-variable\">$label<\/span>;\n<\/span><span class=\"cbb-line\">}\n<\/span><span class=\"cbb-line\">\n<\/span><span class=\"cbb-line\"><span class=\"cbb-keyword\">function<\/span> <span class=\"cbb-function\">lw_nb_review_values<\/span>( <span class=\"cbb-variable\">$input<\/span> ) {\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">is_array<\/span>( <span class=\"cbb-variable\">$input<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_input'<\/span>, <span class=\"cbb-string\">'Expected form fields.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">foreach<\/span> ( <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'label'<\/span>, <span class=\"cbb-string\">'link'<\/span>, <span class=\"cbb-string\">'message'<\/span>, <span class=\"cbb-string\">'rows'<\/span> ) <span class=\"cbb-keyword\">as<\/span> <span class=\"cbb-variable\">$key<\/span> ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-keyword\">isset<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91; <span class=\"cbb-variable\">$key<\/span> &#93; ) || ! <span class=\"cbb-function\">is_string<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91; <span class=\"cbb-variable\">$key<\/span> &#93; ) ) {\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_input'<\/span>, <span class=\"cbb-string\">'A required text field is missing or malformed.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">        }\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$label<\/span> = <span class=\"cbb-function\">lw_nb_review_label<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'label'<\/span>&#93; );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-function\">is_wp_error<\/span>( <span class=\"cbb-variable\">$label<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-variable\">$label<\/span>;\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-number\">1<\/span> !== <span class=\"cbb-function\">preg_match<\/span>( <span class=\"cbb-string\">'\/^(?:&#91;1-9&#93;|&#91;1-4&#93;&#91;0-9&#93;|50)$\/D'<\/span>, <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'rows'<\/span>&#93; ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_rows'<\/span>, <span class=\"cbb-string\">'Rows must be an integer from 1 to 50.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$link<\/span> = <span class=\"cbb-function\">sanitize_url<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'link'<\/span>&#93;, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'http'<\/span>, <span class=\"cbb-string\">'https'<\/span> ) );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$parts<\/span> = <span class=\"cbb-function\">wp_parse_url<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'link'<\/span>&#93; );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-string\">''<\/span> !== <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'link'<\/span>&#93; &amp;&amp; (\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">''<\/span> === <span class=\"cbb-variable\">$link<\/span> || <span class=\"cbb-constant\">false<\/span> === <span class=\"cbb-variable\">$parts<\/span> || <span class=\"cbb-keyword\">empty<\/span>( <span class=\"cbb-variable\">$parts<\/span>&#91;<span class=\"cbb-string\">'host'<\/span>&#93; ) ||\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">empty<\/span>( <span class=\"cbb-variable\">$parts<\/span>&#91;<span class=\"cbb-string\">'scheme'<\/span>&#93; ) ||\n<\/span><span class=\"cbb-line\">        ! <span class=\"cbb-function\">in_array<\/span>( <span class=\"cbb-function\">strtolower<\/span>( <span class=\"cbb-variable\">$parts<\/span>&#91;<span class=\"cbb-string\">'scheme'<\/span>&#93; ), <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'http'<\/span>, <span class=\"cbb-string\">'https'<\/span> ), <span class=\"cbb-constant\">true<\/span> )\n<\/span><span class=\"cbb-line\">    ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">new<\/span> <span class=\"cbb-type\">WP_Error<\/span>( <span class=\"cbb-string\">'invalid_link'<\/span>, <span class=\"cbb-string\">'Link must be empty or an absolute HTTP(S) URL.'<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'status'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-keyword\">array<\/span>(\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'label'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-variable\">$label<\/span>,\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'link'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-variable\">$link<\/span>,\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'message'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-function\">wp_kses_post<\/span>( <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'message'<\/span>&#93; ),\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'rows'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-type\">(int)<\/span> <span class=\"cbb-variable\">$input<\/span>&#91;<span class=\"cbb-string\">'rows'<\/span>&#93;,\n<\/span><span class=\"cbb-line\">    );\n<\/span><span class=\"cbb-line\">}<\/span><\/code><\/pre><span class=\"cbb-status\" role=\"status\"><\/span><\/figure>\n<p><code>wp_unslash()<\/code> removes the extra slashes WordPress adds to form input. It is not a security check. REST parameters do not need this form-specific step. <code>absint()<\/code> also is not validation: it can turn <code>-5<\/code> into <code>5<\/code> and truncate fractional values. The row-count pattern instead rejects values outside the chosen format.<\/p>\n<p>The label is checked after cleaning too. For example, <code>&lt;b&gt;&lt;\/b&gt;<\/code> has characters before cleaning but becomes empty afterwards. The helper rejects it. The 100-character limit counts Unicode code points, not necessarily 100 visible symbols; a letter plus a combining accent can use two code points. The URL rule allows an empty value or an absolute HTTP(S) URL with a host. It does not establish that a destination is trustworthy or safe for a server-side fetch.<\/p>\n<h2>2. Protection inside the save handler<\/h2>\n<p>Restricting the settings menu does not protect a separate <code>admin_post_...<\/code> handler. The handler must check permission again. The form uses <code>method=\"post\"<\/code>, targets <code>admin_url('admin-post.php')<\/code> escaped with <code>esc_url()<\/code>, includes the hidden action <code>lw_nb_review_save<\/code> and outputs <code>wp_nonce_field('lw_nb_review_save', 'lw_nb_nonce')<\/code>. The following handler checks the method, capability and token before saving:<\/p>\n<figure style=\"--cbb-digits:2\" class=\"cbb cbb--wrap cbb--numbers wp-block-code-beautifier-block-code\" data-lang=\"php\"><figcaption class=\"cbb-head\"><span class=\"cbb-lang\">PHP<\/span><span class=\"cbb-actions\"><button type=\"button\" class=\"cbb-button cbb-button--wrap\" data-cbb-action=\"wrap\" aria-pressed=\"true\" title=\"Wrap long lines\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M2 4h12M2 8h9.5a2.5 2.5 0 0 1 0 5H8m0 0 1.5-1.5M8 13l1.5 1.5M2 12h3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/><\/svg><span class=\"cbb-sr\">Wrap long lines<\/span><\/button><button type=\"button\" class=\"cbb-button cbb-button--copy\" data-cbb-action=\"copy\" aria-label=\"Copy code\" data-cbb-status-done=\"Code copied to the clipboard.\" data-cbb-status-failed=\"Copying failed. The code is selected for copying with Ctrl+C or \u2318+C.\" data-cbb-status-noselect=\"Copying failed.\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8.5\" rx=\"1.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><path d=\"M10.5 3.5V3A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v6.5A1.5 1.5 0 0 0 4 11h.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><\/svg><span class=\"cbb-button-label\">Copy<\/span><\/button><\/span><\/figcaption><pre class=\"cbb-pre\" tabindex=\"0\" role=\"region\" aria-label=\"Code example: PHP\"><code class=\"cbb-code language-php\" style=\"counter-reset:cbb-line 0;\"><span class=\"cbb-line\"><span class=\"cbb-meta\">&lt;?php<\/span>\n<\/span><span class=\"cbb-line\"><span class=\"cbb-function\">add_action<\/span>( <span class=\"cbb-string\">'admin_post_lw_nb_review_save'<\/span>, <span class=\"cbb-string\">'lw_nb_review_save'<\/span> );\n<\/span><span class=\"cbb-line\">\n<\/span><span class=\"cbb-line\"><span class=\"cbb-keyword\">function<\/span> <span class=\"cbb-function\">lw_nb_review_save<\/span>() {\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-string\">'POST'<\/span> !== ( <span class=\"cbb-variable\">$_SERVER<\/span>&#91;<span class=\"cbb-string\">'REQUEST_METHOD'<\/span>&#93; ?? <span class=\"cbb-string\">''<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-function\">wp_die<\/span>( <span class=\"cbb-string\">'POST required.'<\/span>, <span class=\"cbb-string\">''<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'response'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">405<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">current_user_can<\/span>( <span class=\"cbb-string\">'manage_options'<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-function\">wp_die<\/span>( <span class=\"cbb-string\">'Permission denied.'<\/span>, <span class=\"cbb-string\">''<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'response'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">403<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$nonce<\/span> = <span class=\"cbb-keyword\">isset<\/span>( <span class=\"cbb-variable\">$_POST<\/span>&#91;<span class=\"cbb-string\">'lw_nb_nonce'<\/span>&#93; ) &amp;&amp; <span class=\"cbb-function\">is_string<\/span>( <span class=\"cbb-variable\">$_POST<\/span>&#91;<span class=\"cbb-string\">'lw_nb_nonce'<\/span>&#93; )\n<\/span><span class=\"cbb-line\">        ? <span class=\"cbb-function\">sanitize_text_field<\/span>( <span class=\"cbb-function\">wp_unslash<\/span>( <span class=\"cbb-variable\">$_POST<\/span>&#91;<span class=\"cbb-string\">'lw_nb_nonce'<\/span>&#93; ) )\n<\/span><span class=\"cbb-line\">        : <span class=\"cbb-string\">''<\/span>;\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">wp_verify_nonce<\/span>( <span class=\"cbb-variable\">$nonce<\/span>, <span class=\"cbb-string\">'lw_nb_review_save'<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-function\">wp_die<\/span>( <span class=\"cbb-string\">'Invalid request token.'<\/span>, <span class=\"cbb-string\">''<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'response'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">403<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$values<\/span> = <span class=\"cbb-function\">lw_nb_review_values<\/span>( <span class=\"cbb-function\">wp_unslash<\/span>( <span class=\"cbb-variable\">$_POST<\/span> ) );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-function\">is_wp_error<\/span>( <span class=\"cbb-variable\">$values<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-function\">wp_die<\/span>( <span class=\"cbb-function\">esc_html<\/span>( <span class=\"cbb-variable\">$values<\/span><span class=\"cbb-operator\">-&gt;<\/span><span class=\"cbb-function\">get_error_message<\/span>() ), <span class=\"cbb-string\">''<\/span>, <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'response'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">400<\/span> ) );\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-function\">update_option<\/span>( <span class=\"cbb-string\">'lw_nb_review_notice'<\/span>, <span class=\"cbb-variable\">$values<\/span> );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-function\">wp_safe_redirect<\/span>( <span class=\"cbb-function\">admin_url<\/span>( <span class=\"cbb-string\">'options-general.php'<\/span> ) );\n<\/span><span class=\"cbb-line\">    exit;\n<\/span><span class=\"cbb-line\">}<\/span><\/code><\/pre><span class=\"cbb-status\" role=\"status\"><\/span><\/figure>\n<p>The capability identifies a permission rather than a role name. For editing a particular post, an object-aware check such as <code>current_user_can('edit_post', $post_id)<\/code> is more appropriate. A subscriber&#8217;s own valid token does not grant <code>manage_options<\/code>. A leaked token from another account is not automatically valid for the subscriber&#8217;s session either.<\/p>\n\n\n<!-- lw-flux-illu 20857-a3 -->\n<figure class=\"lw-illu\"><img src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/illustrationen\/flux-20857-a3.webp\" width=\"1120\" height=\"630\" loading=\"lazy\" decoding=\"async\" alt=\"A rain jacket is zipped tight at the front, but a forgotten vent under the arm lets water in. Likewise, the function that saves the data needs its own check as well.\"><figcaption>A rain jacket is zipped tight at the front, but a forgotten vent under the arm lets water in. Likewise, the function that saves the data needs its own check as well.<\/figcaption><\/figure>\n\n\n<h2>3. Escaping at the final HTML output<\/h2>\n<p>Saved data remains untrusted: an import, older plugin version or another write path may have changed it. Escaping belongs where HTML is finally built, including a string returned by a shortcode. The function depends on the output position:<\/p>\n<table><thead><tr><th>Position<\/th><th>Function<\/th><\/tr><\/thead><tbody>\n<tr><td>Text between tags<\/td><td><code>esc_html()<\/code><\/td><\/tr>\n<tr><td>Quoted attribute value<\/td><td><code>esc_attr()<\/code><\/td><\/tr>\n<tr><td>URL in href, src or action<\/td><td><code>esc_url()<\/code><\/td><\/tr>\n<tr><td>Textarea contents<\/td><td><code>esc_textarea()<\/code><\/td><\/tr>\n<tr><td>Limited post-style HTML<\/td><td><code>wp_kses_post()<\/code><\/td><\/tr><\/tbody><\/table>\n<p>For example, <code>esc_html($label)<\/code> displays a label as text, while <code>wp_kses_post($message)<\/code> allows the permitted HTML in a message. These operations are not interchangeable. <code>sanitize_url()<\/code> cleans a URL for storage; it does not replace <code>esc_url()<\/code> at HTML output. A JSON response is a different output format: HTML escaping should happen where a client later inserts a value into HTML.<\/p>\n<h2>4. SQL needs placeholders and allowed names<\/h2>\n<p>Cleaning text does not make string concatenation safe in SQL. The example below assumes an existing custom log table. It permits only three sort columns and limits the number of returned rows. The variables come from validated values rather than raw query parameters.<\/p>\n<figure style=\"--cbb-digits:2\" class=\"cbb cbb--wrap cbb--numbers wp-block-code-beautifier-block-code\" data-lang=\"php\"><figcaption class=\"cbb-head\"><span class=\"cbb-lang\">PHP<\/span><span class=\"cbb-actions\"><button type=\"button\" class=\"cbb-button cbb-button--wrap\" data-cbb-action=\"wrap\" aria-pressed=\"true\" title=\"Wrap long lines\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M2 4h12M2 8h9.5a2.5 2.5 0 0 1 0 5H8m0 0 1.5-1.5M8 13l1.5 1.5M2 12h3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/><\/svg><span class=\"cbb-sr\">Wrap long lines<\/span><\/button><button type=\"button\" class=\"cbb-button cbb-button--copy\" data-cbb-action=\"copy\" aria-label=\"Copy code\" data-cbb-status-done=\"Code copied to the clipboard.\" data-cbb-status-failed=\"Copying failed. The code is selected for copying with Ctrl+C or \u2318+C.\" data-cbb-status-noselect=\"Copying failed.\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8.5\" rx=\"1.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><path d=\"M10.5 3.5V3A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v6.5A1.5 1.5 0 0 0 4 11h.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><\/svg><span class=\"cbb-button-label\">Copy<\/span><\/button><\/span><\/figcaption><pre class=\"cbb-pre\" tabindex=\"0\" role=\"region\" aria-label=\"Code example: PHP\"><code class=\"cbb-code language-php\" style=\"counter-reset:cbb-line 0;\"><span class=\"cbb-line\"><span class=\"cbb-meta\">&lt;?php<\/span>\n<\/span><span class=\"cbb-line\"><span class=\"cbb-keyword\">function<\/span> <span class=\"cbb-function\">lw_nb_review_get_log<\/span>( <span class=\"cbb-variable\">$orderby<\/span>, <span class=\"cbb-variable\">$limit<\/span> ) {\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">global<\/span> <span class=\"cbb-variable\">$wpdb<\/span>;\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-variable\">$allowed<\/span> = <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'saved_at'<\/span>, <span class=\"cbb-string\">'label'<\/span>, <span class=\"cbb-string\">'user_id'<\/span> );\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">is_string<\/span>( <span class=\"cbb-variable\">$orderby<\/span> ) || ! <span class=\"cbb-function\">in_array<\/span>( <span class=\"cbb-variable\">$orderby<\/span>, <span class=\"cbb-variable\">$allowed<\/span>, <span class=\"cbb-constant\">true<\/span> ) ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-variable\">$orderby<\/span> = <span class=\"cbb-string\">'saved_at'<\/span>;\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">if<\/span> ( ! <span class=\"cbb-function\">is_int<\/span>( <span class=\"cbb-variable\">$limit<\/span> ) || <span class=\"cbb-variable\">$limit<\/span> &lt; <span class=\"cbb-number\">1<\/span> || <span class=\"cbb-variable\">$limit<\/span> &gt; <span class=\"cbb-number\">50<\/span> ) {\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-variable\">$limit<\/span> = <span class=\"cbb-number\">10<\/span>;\n<\/span><span class=\"cbb-line\">    }\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-variable\">$wpdb<\/span><span class=\"cbb-operator\">-&gt;<\/span><span class=\"cbb-function\">get_results<\/span>(\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-variable\">$wpdb<\/span><span class=\"cbb-operator\">-&gt;<\/span><span class=\"cbb-function\">prepare<\/span>(\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-string\">'SELECT user_id, label, saved_at FROM %i ORDER BY %i DESC LIMIT %d'<\/span>,\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$wpdb<\/span><span class=\"cbb-operator\">-&gt;<\/span>prefix . <span class=\"cbb-string\">'lw_nb_log'<\/span>,\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$orderby<\/span>,\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$limit<\/span>\n<\/span><span class=\"cbb-line\">        )\n<\/span><span class=\"cbb-line\">    );\n<\/span><span class=\"cbb-line\">}<\/span><\/code><\/pre><span class=\"cbb-status\" role=\"status\"><\/span><\/figure>\n<p><code>%i<\/code> quotes a table or column identifier and requires WordPress 6.2 or later. The allowlist decides which identifier is permitted; the placeholder alone does not make that decision. Values use placeholders such as <code>%s<\/code> and <code>%d<\/code>, or a format list with <code>$wpdb-&gt;insert()<\/code>. An added database column does not automatically belong in the sorting allowlist.<\/p>\n\n\n<!-- lw-flux-illu 20857-a5 -->\n<figure class=\"lw-illu\"><img src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/illustrationen\/flux-20857-a5.webp\" width=\"1120\" height=\"630\" loading=\"lazy\" decoding=\"async\" alt=\"In the organiser each bead sits in its own hollow, while loose beads roll into one another. Likewise, placeholders keep entered values neatly apart from the actual SQL database command.\"><figcaption>In the organiser each bead sits in its own hollow, while loose beads roll into one another. Likewise, placeholders keep entered values neatly apart from the actual SQL database command.<\/figcaption><\/figure>\n\n\n<h2>5. REST permission and cleaned-value checks<\/h2>\n<p>A REST route is an address through which software requests data or changes. These routes need an explicit <code>permission_callback<\/code>. A missing callback can leave a route public despite the warning issued by WordPress. For intentionally public data, <code>__return_true<\/code> makes that choice visible. The write route below permits only accounts with <code>manage_options<\/code> and exposes POST only.<\/p>\n<figure style=\"--cbb-digits:2\" class=\"cbb cbb--wrap cbb--numbers wp-block-code-beautifier-block-code\" data-lang=\"php\"><figcaption class=\"cbb-head\"><span class=\"cbb-lang\">PHP<\/span><span class=\"cbb-actions\"><button type=\"button\" class=\"cbb-button cbb-button--wrap\" data-cbb-action=\"wrap\" aria-pressed=\"true\" title=\"Wrap long lines\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M2 4h12M2 8h9.5a2.5 2.5 0 0 1 0 5H8m0 0 1.5-1.5M8 13l1.5 1.5M2 12h3\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"\/><\/svg><span class=\"cbb-sr\">Wrap long lines<\/span><\/button><button type=\"button\" class=\"cbb-button cbb-button--copy\" data-cbb-action=\"copy\" aria-label=\"Copy code\" data-cbb-status-done=\"Code copied to the clipboard.\" data-cbb-status-failed=\"Copying failed. The code is selected for copying with Ctrl+C or \u2318+C.\" data-cbb-status-noselect=\"Copying failed.\"><svg aria-hidden=\"true\" focusable=\"false\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8.5\" rx=\"1.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><path d=\"M10.5 3.5V3A1.5 1.5 0 0 0 9 1.5H4A1.5 1.5 0 0 0 2.5 3v6.5A1.5 1.5 0 0 0 4 11h.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\"\/><\/svg><span class=\"cbb-button-label\">Copy<\/span><\/button><\/span><\/figcaption><pre class=\"cbb-pre\" tabindex=\"0\" role=\"region\" aria-label=\"Code example: PHP\"><code class=\"cbb-code language-php\" style=\"counter-reset:cbb-line 0;\"><span class=\"cbb-line\"><span class=\"cbb-meta\">&lt;?php<\/span>\n<\/span><span class=\"cbb-line\"><span class=\"cbb-function\">add_action<\/span>( <span class=\"cbb-string\">'rest_api_init'<\/span>, <span class=\"cbb-keyword\">function<\/span> () {\n<\/span><span class=\"cbb-line\">    <span class=\"cbb-function\">register_rest_route<\/span>( <span class=\"cbb-string\">'lw-nb-review\/v1'<\/span>, <span class=\"cbb-string\">'\/notice'<\/span>, <span class=\"cbb-keyword\">array<\/span>(\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'methods'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-type\">WP_REST_Server<\/span><span class=\"cbb-operator\">::<\/span><span class=\"cbb-constant\">CREATABLE<\/span>,\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'permission_callback'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-keyword\">function<\/span> () {\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-function\">current_user_can<\/span>( <span class=\"cbb-string\">'manage_options'<\/span> );\n<\/span><span class=\"cbb-line\">        },\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'args'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-keyword\">array<\/span>(\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-string\">'label'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-keyword\">array<\/span>(\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'type'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-string\">'string'<\/span>,\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'required'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-constant\">true<\/span>,\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'minLength'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">1<\/span>,\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'maxLength'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-number\">100<\/span>,\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'validate_callback'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-string\">'rest_validate_request_arg'<\/span>,\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-string\">'sanitize_callback'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-string\">'lw_nb_review_label'<\/span>,\n<\/span><span class=\"cbb-line\">            ),\n<\/span><span class=\"cbb-line\">        ),\n<\/span><span class=\"cbb-line\">        <span class=\"cbb-string\">'callback'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-keyword\">function<\/span> ( WP_REST_Request <span class=\"cbb-variable\">$request<\/span> ) {\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$label<\/span> = <span class=\"cbb-function\">lw_nb_review_label<\/span>( <span class=\"cbb-variable\">$request<\/span><span class=\"cbb-operator\">-&gt;<\/span><span class=\"cbb-function\">get_param<\/span>( <span class=\"cbb-string\">'label'<\/span> ) );\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-keyword\">if<\/span> ( <span class=\"cbb-function\">is_wp_error<\/span>( <span class=\"cbb-variable\">$label<\/span> ) ) {\n<\/span><span class=\"cbb-line\">                <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-variable\">$label<\/span>;\n<\/span><span class=\"cbb-line\">            }\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$stored<\/span> = <span class=\"cbb-function\">get_option<\/span>( <span class=\"cbb-string\">'lw_nb_review_notice'<\/span>, <span class=\"cbb-keyword\">array<\/span>() );\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$stored<\/span> = <span class=\"cbb-function\">is_array<\/span>( <span class=\"cbb-variable\">$stored<\/span> ) ? <span class=\"cbb-variable\">$stored<\/span> : <span class=\"cbb-keyword\">array<\/span>();\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-variable\">$stored<\/span>&#91;<span class=\"cbb-string\">'label'<\/span>&#93; = <span class=\"cbb-variable\">$label<\/span>;\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-function\">update_option<\/span>( <span class=\"cbb-string\">'lw_nb_review_notice'<\/span>, <span class=\"cbb-variable\">$stored<\/span> );\n<\/span><span class=\"cbb-line\">            <span class=\"cbb-keyword\">return<\/span> <span class=\"cbb-function\">rest_ensure_response<\/span>( <span class=\"cbb-keyword\">array<\/span>( <span class=\"cbb-string\">'label'<\/span> <span class=\"cbb-operator\">=&gt;<\/span> <span class=\"cbb-variable\">$label<\/span> ) );\n<\/span><span class=\"cbb-line\">        },\n<\/span><span class=\"cbb-line\">    ) );\n<\/span><span class=\"cbb-line\">} );<\/span><\/code><\/pre><span class=\"cbb-status\" role=\"status\"><\/span><\/figure>\n<p>The explicit schema validation checks the incoming type and length. The custom sanitizer also checks the cleaned label, closing the empty-after-cleaning case. With cookie authentication, core checks a <code>wp_rest<\/code> nonce supplied through <code>X-WP-Nonce<\/code> or <code>_wpnonce<\/code>. Without that nonce, cookie-authenticated REST requests are treated as unauthenticated. Other authentication methods, such as application passwords, have their own authentication flow; the capability check still applies.<\/p>\n<h2>What the checks prove<\/h2>\n<p>The helper functions passed 41 isolated cases using WordPress 7.1.3 and PHP 8.4.27: arrays, missing fields, negative and fractional row counts, empty cleaned labels, URL protocols and allowed HTML. PHP syntax checks also passed for the helper, form-handler and REST snippets. The save handler and REST route were not executed against live settings. These results do not claim a full plugin audit or a clean Plugin Check report.<\/p>\n<p>A complete integration also needs tests with an authorized account, a lower-privileged account and no login; missing or stale tokens; database failures; and escaped output in the browser. Plugin Check findings are useful clues, but an empty report cannot prove that every operation has the right permission check.<\/p>\n<div class=\"lw-faq\"><h2>Questions and answers<\/h2>\n<h3>Does a read-only sort parameter need a nonce?<\/h3><p>Changing display order does not itself modify stored data. The parameter still needs type checking and an allowlist, and access to private results still needs authorization. A nonce is not a substitute for either.<\/p>\n<h3>Does a nonce stop repeated submissions?<\/h3><p>No. WordPress tokens can be reused during their validity period. Payments or other actions that must occur once need a separate duplicate-prevention mechanism.<\/p>\n<h3>Is sanitizing once enough?<\/h3><p>No. Input rules, permission checks, parameterized SQL and context-specific output protection have different jobs. A cleaned label can still contain a quotation mark that needs escaping in an HTML attribute.<\/p><\/div>\n<div class=\"lw-quellen\"><h2>Sources<\/h2><ul><li><a href=\"https:\/\/developer.wordpress.org\/apis\/security\/nonces\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: nonces and their limits<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/apis\/security\/sanitizing\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: cleaning input<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/apis\/security\/escaping\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: escaping output<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/current_user_can\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: checking capabilities<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wpdb\/prepare\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: SQL placeholders<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/rest-api\/extending-the-rest-api\/adding-custom-endpoints\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: custom REST endpoints<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/rest-api\/using-the-rest-api\/authentication\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: REST authentication<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/reference\/classes\/wp_rest_request\/sanitize_params\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: REST argument sanitizing<\/a><\/li><li><a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/register_rest_route\/\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress: route registration<\/a><\/li><\/ul><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Permission, nonces, input rules and output escaping solve different problems. Tested validators show array checks, strict row counts and labels that must remain nonempty after cleaning.<\/p>\n","protected":false},"author":1,"featured_media":31419,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[91093,91115,91096],"class_list":["post-20857","post","type-post","status-publish","format-standard","hentry","category-wordpress-plugins-tricks","tag-php","tag-web-security","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik<\/title>\n<meta name=\"description\" content=\"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb-&gt;prepare and REST.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik\" \/>\n<meta property=\"og:description\" content=\"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb-&gt;prepare and REST.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukas Wojcik - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-05T07:26:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-14T22:38:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Lukas Wojcik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lukas Wojcik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/\"},\"author\":{\"name\":\"Lukas Wojcik\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"headline\":\"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights\",\"datePublished\":\"2026-10-05T07:26:00+00:00\",\"dateModified\":\"2026-11-14T22:38:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/\"},\"wordCount\":1156,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/klarheit-20261111-20857.png\",\"keywords\":[\"PHP\",\"Web Security\",\"WordPress\"],\"articleSection\":[\"WordPress Plugins &amp; Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/\",\"name\":\"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/klarheit-20261111-20857.png\",\"datePublished\":\"2026-10-05T07:26:00+00:00\",\"dateModified\":\"2026-11-14T22:38:47+00:00\",\"description\":\"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb->prepare and REST.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/klarheit-20261111-20857.png\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/klarheit-20261111-20857.png\",\"width\":1200,\"height\":630,\"caption\":\"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/wordpress-plugins-tricks\\\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/de\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\",\"name\":\"Lukas Wojcik - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\",\"name\":\"Lukas Wojcik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"width\":424,\"height\":636,\"caption\":\"Lukas Wojcik\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik","description":"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb->prepare and REST.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/","og_locale":"en_US","og_type":"article","og_title":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik","og_description":"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb->prepare and REST.","og_url":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/","og_site_name":"Lukas Wojcik - Blog","article_published_time":"2026-10-05T07:26:00+00:00","article_modified_time":"2026-11-14T22:38:47+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png","type":"image\/png"}],"author":"Lukas Wojcik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Lukas Wojcik","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#article","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/"},"author":{"name":"Lukas Wojcik","@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"headline":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights","datePublished":"2026-10-05T07:26:00+00:00","dateModified":"2026-11-14T22:38:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/"},"wordCount":1156,"commentCount":0,"publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png","keywords":["PHP","Web Security","WordPress"],"articleSection":["WordPress Plugins &amp; Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/","url":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/","name":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights | Lukas Wojcik","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#primaryimage"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png","datePublished":"2026-10-05T07:26:00+00:00","dateModified":"2026-11-14T22:38:47+00:00","description":"Sanitize early, escape late, always validate: faulty and fixed code for input, output, nonces, capabilities, $wpdb->prepare and REST.","breadcrumb":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#primaryimage","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/klarheit-20261111-20857.png","width":1200,"height":630,"caption":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights"},{"@type":"BreadcrumbList","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/wordpress-plugins-tricks\/securing-wordpress-plugins-checking-inputs-outputs-requests-and-access-rights\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lukaswojcik.com\/blog\/de\/"},{"@type":"ListItem","position":2,"name":"Securing WordPress Plugins: Checking Inputs, Outputs, Requests and Access Rights"}]},{"@type":"WebSite","@id":"https:\/\/www.lukaswojcik.com\/blog\/#website","url":"https:\/\/www.lukaswojcik.com\/blog\/","name":"Lukas Wojcik - Blog","description":"","publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lukaswojcik.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9","name":"Lukas Wojcik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","width":424,"height":636,"caption":"Lukas Wojcik"},"logo":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg"},"sameAs":["https:\/\/www.lukaswojcik.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/20857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/comments?post=20857"}],"version-history":[{"count":3,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/20857\/revisions"}],"predecessor-version":[{"id":26301,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/20857\/revisions\/26301"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media\/31419"}],"wp:attachment":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media?parent=20857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/categories?post=20857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/tags?post=20857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}