Skip to content

Commit

Permalink
Clean up for release
Browse files Browse the repository at this point in the history
  • Loading branch information
wpscholar committed Sep 2, 2022
1 parent 1907add commit bd93daa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
18 changes: 8 additions & 10 deletions CookieManager.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
<?php

namespace wpscholar\WordPress;
namespace WP_Forge\CookieManager;

/**
* Class CookieManager
*
* @package wpscholar\WordPress
*/
class CookieManager {

/**
* Set a cookie
*
* @param string $name The cookie name.
* @param string $value The cookie value.
* @param int $expiration A Unix timestamp representing the expiration (use time() plus seconds until expiration). Defaults to 0, which will cause the cookie to expire at the end of the user's browsing session.
* @param string $name The cookie name.
* @param string $value The cookie value.
* @param int $expiration A Unix timestamp representing the expiration (use time() plus seconds until expiration). Defaults to 0, which will cause the cookie to expire at the end of the user's browsing session.
*/
public static function setCookie( $name, $value, $expiration = 0 ) {
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
Expand All @@ -35,8 +33,8 @@ public static function hasCookie( $name ) {
/**
* Get a cookie
*
* @param string $name The cookie name.
* @param mixed $default The default value to return if the cookie doesn't exist (defaults to null).
* @param string $name The cookie name.
* @param mixed $default The default value to return if the cookie doesn't exist (defaults to null).
*
* @return mixed Returns the value or the default if the cookie doesn't exist.
*/
Expand All @@ -51,10 +49,10 @@ public static function getCookie( $name, $default = null ) {
*/
public static function deleteCookie( $name ) {
if ( self::hasCookie( $name ) ) {
$value = self::getCookie( $name );
$value = self::getCookie( $name );
$expiration = time() - HOUR_IN_SECONDS;
setcookie( $name, $value, $expiration, COOKIEPATH, COOKIE_DOMAIN );
}
}

}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "wpscholar/wp-cookie-manager",
"name": "wp-forge/wp-cookie-manager",
"description": "A WordPress library to simplify cookie management.",
"type": "library",
"license": "GPL-2.0-or-later",
Expand All @@ -11,7 +11,7 @@
],
"autoload": {
"psr-4": {
"wpscholar\\WordPress\\": ""
"WP_Forge\\CookieManager\\": ""
}
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Abstracts away all the PHP cookie management and WordPress cookie constants so y
1. Add to your project via [Composer](https://getcomposer.org/):

```bash
$ composer require wpscholar/wp-cookie-management
$ composer require wp-forge/wp-cookie-management
```

2. Make sure you have added the Composer autoloader to your project:
Expand All @@ -25,7 +25,7 @@ require __DIR__ . '/vendor/autoload.php';
```php
<?php

use wpscholar\WordPress\CookieManager;
use WP_Forge\CookieManager;

// Create a cookie
$cookie = CookieManager::setCookie('mycookie', 'myvalue', time() + 86400); // Expires one day from now
Expand Down

0 comments on commit bd93daa

Please sign in to comment.