{"id":16039140,"url":"https://github.com/mehulkaklotar/wp-nonce","last_synced_at":"2026-05-01T14:32:39.062Z","repository":{"id":73703453,"uuid":"87148724","full_name":"mehulkaklotar/wp-nonce","owner":"mehulkaklotar","description":"WordPress Nonce Implementation Object Oriented Way","archived":false,"fork":false,"pushed_at":"2017-04-18T10:30:46.000Z","size":46,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T13:36:40.822Z","etag":null,"topics":["oop","wordpress","wordpress-nonce","wordpress-security"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehulkaklotar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-04T04:45:25.000Z","updated_at":"2023-03-05T02:15:54.000Z","dependencies_parsed_at":"2023-02-27T06:45:28.632Z","dependency_job_id":null,"html_url":"https://github.com/mehulkaklotar/wp-nonce","commit_stats":{"total_commits":24,"total_committers":1,"mean_commits":24.0,"dds":0.0,"last_synced_commit":"33521f2e751a6f261a5ae408f83a087632c32e5d"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehulkaklotar%2Fwp-nonce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehulkaklotar%2Fwp-nonce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehulkaklotar%2Fwp-nonce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehulkaklotar%2Fwp-nonce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehulkaklotar","download_url":"https://codeload.github.com/mehulkaklotar/wp-nonce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294463,"owners_count":20915338,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["oop","wordpress","wordpress-nonce","wordpress-security"],"created_at":"2024-10-08T23:01:37.706Z","updated_at":"2026-05-01T14:32:39.010Z","avatar_url":"https://github.com/mehulkaklotar.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/mehulkaklotar/wp-nonce.svg?branch=master)](https://travis-ci.org/mehulkaklotar/wp-nonce)\n\nWPNonce\n===================\n\nWordPress Nonce In An Object Oriented Way.\n\n## Basic Usage\n\n1. Create a demo `composer.json` file in your plugin.\n2. Run `composer install`\n3. It will load plugin dependency in a `vendor/` folder\n\n### demo `composer.json`\n\n```\n{\n    \"repositories\": [\n        {\n            \"type\": \"vcs\",\n            \"url\" : \"https://github.com/mehulkaklotar/wp-nonce\"\n        }\n    ],\n    \"require\": {\n        \"mehulkaklotar/wp-nonce\" : \"1.0.*\"\n    }\n}\n```\n\nHere I have created a demo plugin to use this system. [WP Nonce Client](https://github.com/mehulkaklotar/wp-nonce-client)\n\n### The Settings:\n\nWP Nonce need an action to find the current action which is secured by a nonce. The first parameter of the configuration defines this name. Usually forms or URLs passes the nonce. The second parameter is for request key. In this case, we would expect the nonce to be in `$_REQUEST['request_name']`.\n\n```\n$setting = new NonceSetting( \n\t'action', \n\t'request_name' \n);\n```\n\n\n### To Create a Nonce\nTo create a simple Nonce, use `NonceCreate`:\n```\n$nonce_create = new NonceCreate( $setting );\n$nonce = $nonce_create-\u003ecreate();\n```\n\nTo add a nonce to an URL, you can use\n\n```\n$nonce_create = new NonceCreateURL( $setting );\n$url = $nonce_create-\u003ecreate_url( 'http://example.com/' );\n```\nReturn URL will be:\n`http://example.com/?request_name=$nonce`\n\nTo add a form field:\n```\n$create = new NonceCreateField( $setting );\n$field = $create-\u003ecreate_field();\n```\nReturn field will be:\n`\u003cinput type=\"hidden\" name=\"request_name\" value=\"$nonce\"\u003e`\n\nReplicate `wp_nonce_field()` functionality by adding two parameters: `(bool) $referer` and `(bool) $echo`. Both are set to `false` by default. \n\nSet `$referer` to `true`, field will be appended with the URL of the current page. \nSet `$echo` to `true`, it will echo the field, before `create_url()`.\n\n### To Verify a Nonce\n\nTo verify a nonce, you can use `NonceVerify`:\n```\n$nonce_verify = new NonceVerify( $setting );\n$is_valid = $nonce_verify-\u003everify( $nonce );\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehulkaklotar%2Fwp-nonce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehulkaklotar%2Fwp-nonce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehulkaklotar%2Fwp-nonce/lists"}