{"id":15472564,"url":"https://github.com/wberredo/nonce","last_synced_at":"2025-04-22T13:46:45.556Z","repository":{"id":62546957,"uuid":"83107368","full_name":"WBerredo/nonce","owner":"WBerredo","description":"Use wordpress nonce functions in a object oriented environment.","archived":false,"fork":false,"pushed_at":"2017-03-31T15:22:07.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-10T08:43:36.581Z","etag":null,"topics":["nonce","wordpress","wordpress-library","wordpress-plugin"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WBerredo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-25T04:55:53.000Z","updated_at":"2024-04-22T09:28:23.000Z","dependencies_parsed_at":"2022-11-02T22:02:11.688Z","dependency_job_id":null,"html_url":"https://github.com/WBerredo/nonce","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WBerredo%2Fnonce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WBerredo%2Fnonce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WBerredo%2Fnonce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WBerredo%2Fnonce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WBerredo","download_url":"https://codeload.github.com/WBerredo/nonce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250251364,"owners_count":21399805,"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":["nonce","wordpress","wordpress-library","wordpress-plugin"],"created_at":"2024-10-02T02:40:15.954Z","updated_at":"2025-04-22T13:46:45.533Z","avatar_url":"https://github.com/WBerredo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/wberredo/nonce/v/stable)](https://packagist.org/packages/wberredo/nonce)\n[![Latest Unstable Version](https://poser.pugx.org/wberredo/nonce/v/unstable)](https://packagist.org/packages/wberredo/nonce)\n[![License](https://poser.pugx.org/wberredo/nonce/license)](https://packagist.org/packages/wberredo/nonce)\n\n# nonce\nUse wordpress nonce functions in a object oriented environment.\n\n## Installation\n\nAdd this package as requirement at your composer.json file and\nthen run 'composer update'\n```json\n\"wberredo/nonce\": \"1.0.*\"\n```\n\nOr directly run\n```bash\ncomposer require wberredo/nonce\n```\n\n## Setup\n\nIf you want to change some configs before you start to generate\nnonces, you will use *Nonce_Config* class.\n```php\n// set lifetime for 4 hours\nNonce_Config::set_nonce_lifetime( 4 * HOUR_IN_SECONDS );\n\n// set message showed when showAys is called\nNonce_Config::set_error_message( \"Are you sure\" );\n```\n\n## Usage\nTo create a nonce you have to use the *Nonce_Generator* class and\nto verify a nonce already created you will need the *Nonce_Verifier*\nclass.\n\n### Nonce_Generator\nTo generate a nonce\n```php\n$nonce_gen = new Nonce_Generator( \"default-action\" );\n$nonce = $nonce_gen-\u003egenerate_nonce();\n```\n\nTo generate a URL nonce\n```php\n// you can also set parameters with set functions\n$nonce_gen = new Nonce_Generator();\n$complete_url = $nonce_gen\n                    -\u003eset_url( \"http://github.com/WBerredo\" )\n                    -\u003eset_action( \"default_action\" )\n                    -\u003egenerate_nonce_url();\n```\n\nTo retrieve a nonce field.\n```php\n$nonce_gen = new Nonce_Generator();\n$nonceField = $nonce_gen\n                    -\u003eset_action( \"default_action\" )\n                    -\u003egenerate_nonce_field( \"nonce\", \"referer\", \"do_not_echo\" );\n                    \n// to print the nonce field you have to set the last param as true\n$nonce_gen\n    -\u003egenerate_nonce_field( \"nonce\", \"referer\", \"echo\" );\n```\n\nTo  Display 'Are you sure you want to do this?' message\n(or the new message set with Nonce_Config#setErrorMessage)\nto confirm the action being taken.\n```php\nNonce_Generator::show_ays( 'action' );\n```\n### Nonce_Verifier\nTo verify a nonce\n```php\nif ( Nonce_Verifier::verify( $nonce, $defaultAction ) ) {\n// if is valid\n} else {\n// if is not valid\n}\n```\n\nTo verify a URL nonce\n```php\nif ( Nonce_Verifier::verify_url( $complete_url, $defaultAction ) ) { \n// if is valid\n} else {\n// if is not valid\n}\n```\n\nTo tests either if the current request carries a valid nonce,\nor if the current request was referred from an administration screen\n```php\nif ( Nonce_Verifier::verify_admin_referer( $defaultAction ) ) {\n// if is valid\n} else {\n// if is not valid\n}\n```\n\nTo verify the AJAX request, to prevent any processing of\nrequests which are passed in by third-party sites or systems.\n```php\nif ( Nonce_Verifier::verify_ajax_referer( $defaultAction ) ) {\n// if is valid\n} else {\n// if is not valid\n}\n```\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Tests\n\n1. **Install PHPUnit.** WordPress uses PHPUnit, the standard for unit \ntesting PHP projects. Installation instructions can be found in\n[the PHPUnit manual](https://phpunit.de/manual/current/en/installation.html) \nor on the [PHPUnit Github repository](https://github.com/sebastianbergmann/phpunit#readme).\n\n2. **Check out the test repository.** The WordPress tests live in \nthe core development repository, \nat https://develop.svn.wordpress.org/trunk/:\n  ```bash\n  svn co https://develop.svn.wordpress.org/trunk/ wordpress-develop\n  cd wordpress-develop\n  ```\n\n3. **Create an empty MySQL database.** The test suite will delete all \ndata from all tables for whichever MySQL database it is configured.\nUse a separate database.\n\n4. **Set up a config file.** Copy wp-tests-config-sample.php \nto wp-tests-config.php, and enter your database credentials.\nUse a separate database.\n\n5. **Change the path of Wordpress project** in the bootstrap.php file of the plugin\n  ```php\n  /**\n  * The path to the WordPress tests checkout.\n  */\n  define( 'WP_TESTS_DIR', '/home/berredo/Documents/repository/wordpress/wordpress-develop/tests/phpunit/' );\n  ```\n\n6. **Go to plugin's folder**\n \n  ```bash\n  cd vendor/wberredo/nonce\n  ```\n7. **Run phpunit** to test\n  \n  ```bash\n  phpunit \n  ```\n\n## Thanks to\n* [Wordpress Nonces Documentation](https://codex.wordpress.org/WordPress_Nonces)\n* [Wordpress Automated Testing Documentation](https://make.wordpress.org/core/handbook/testing/automated-testing/)\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwberredo%2Fnonce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwberredo%2Fnonce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwberredo%2Fnonce/lists"}