{"id":23387244,"url":"https://github.com/wp-forge/wp-cookie-manager","last_synced_at":"2026-01-11T10:48:44.418Z","repository":{"id":57082384,"uuid":"119090225","full_name":"wp-forge/wp-cookie-manager","owner":"wp-forge","description":"A WordPress library to simplify cookie management.","archived":false,"fork":false,"pushed_at":"2023-01-16T17:20:30.000Z","size":9,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T05:09:12.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wp-forge.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-26T18:50:20.000Z","updated_at":"2025-01-07T02:12:36.000Z","dependencies_parsed_at":"2023-02-10T05:15:37.250Z","dependency_job_id":null,"html_url":"https://github.com/wp-forge/wp-cookie-manager","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-cookie-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-cookie-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-cookie-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Fwp-cookie-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-forge","download_url":"https://codeload.github.com/wp-forge/wp-cookie-manager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345266,"owners_count":21088244,"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":[],"created_at":"2024-12-22T01:15:23.623Z","updated_at":"2026-01-11T10:48:44.409Z","avatar_url":"https://github.com/wp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WordPress Cookie Manager\n\nA WordPress library to simplify cookie management.\n\n## What It Does\n\nAbstracts away all the PHP cookie management and WordPress cookie constants so you can just get and set cookies.\n\n## How to Use It\n\n1. Add to your project via [Composer](https://getcomposer.org/):\n\n```bash\n$ composer require wp-forge/wp-cookie-manager\n```\n\n2. Make sure you have added the Composer autoloader to your project:\n\n```php\n\u003c?php\n\nrequire __DIR__ . '/vendor/autoload.php';\n```\n\n3. Start managing cookies\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n// Set a cookie\nCookieManager::get()-\u003ecookie('myCookieName')-\u003eset('myCookieValue', time() + 86400);  // Expires one day from now\n\n// Check if cookie exists\nCookieManager::get()-\u003ecookie('myCookieName')-\u003eexists();\n\n// Get cookie value, or default value if it doesn't exist\nCookieManager::get()-\u003ecookie('myCookieName')-\u003evalue('myDefaultValue');\n\n// Delete cookie\nCookieManager::get()-\u003ecookie('myCookieName')-\u003edelete();\n```\n\n## Using the Underlying Cookie Class\n\nThe `CookieManager` provides you with a global way to configure and manage working with cookies. However, if you need to\nwork with a cookie that needs a very different configuration, you can use the `Cookie` class directly.\n\nNote that using the `Cookie` class directly will not use the smart defaults provided by the `CookieManager`.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\Cookie;\n\n// Create a cookie instance\n$cookie = Cookie::make('myCookieName')\n  -\u003esetDomain(COOKIE_DOMAIN)\n  -\u003esetPath(COOKIEPATH)\n  -\u003esetSecure(is_ssl())\n  -\u003esetHttpOnly(true);\n  \n// Set a cookie\n$cookie-\u003eset('myCookieValue', time() + 86400) // Expires one day from now\n\n// Check if cookie exists\n$cookie-\u003eexists();\n\n// Get cookie value\n$cookie-\u003evalue();\n\n// Get cookie value, or default value if the cookie doesn't exist\n$cookie-\u003evalue('myDefaultValue');\n\n// Delete cookie\n$cookie-\u003edelete();\n```\n\n## Advanced Usage\n\nBy default, the `CookieManager` will use smart, WordPress-specific defaults. These defaults can be overridden and \nthe steps to do so are outlined below.\n\n### Customizable properties\n\n#### Name Prefix\n\nBy default, all cookie names are prefixed with `wp-`. This can be changed by setting the `$namePrefix` property.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003enamePrefix = 'my-prefix-'; // Set to an empty string to disable the prefix\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n\n#### Name Suffix\n\nBy default, all cookie names are suffixed with a `-` followed by the WordPress `COOKIEHASH` constant. This can be\nchanged by setting the`$nameSuffix` property.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003enameSuffix = '-my-suffix'; // Set to an empty string to disable the suffix\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n\n#### Path\n\nBy default, the cookie path is set to the WordPress `COOKIEPATH` constant. This can be changed by setting the`$path`\nproperty.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003epath = '/my/path';\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n\n#### Domain\n\nBy default, the cookie domain is set to the WordPress `COOKIE_DOMAIN` constant. If the `COOKIE_DOMAIN` is empty, it\nfalls back to the `$_SERVER['HTTP_HOST']` value (i.e. the current domain). This can be overwritten by setting\nthe`$domain` property.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003edomain = '.example.com';\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n\n#### Secure\n\nBy default, the `$secure` property is set to the value returned by the `is_ssl()` WordPress function. Setting the value\nto `true` will ensure that the cookie is only sent over an HTTPS connection. Setting the value to `false` will ensure\nthat the cookie is always sent, regardless of whether the connection is encrypted.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003esecure = false;\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n\n#### HTTP Only\n\nBy default, the `$httpOnly` property is set to `false`, which means that the cookie will be available in all contexts.\nSetting the value to `true` will ensure that the cookie is only accessible in PHP, not JavaScript. This can be useful to\nhelp prevent identify theft via XSS attacks.\n\n```php\n\u003c?php\n\nuse WP_Forge\\CookieManager\\CookieManager;\n\n$cookieManager = CookieManager::get();\n$cookieManager-\u003ehttpOnly = true;\n\n$cookieManager-\u003ecookie('myCookieName')-\u003eexists();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fwp-cookie-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-forge%2Fwp-cookie-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Fwp-cookie-manager/lists"}