pfeifferNet

User_Favourites extends Collection
in package

Provides post or recipe ids for favourite recipes by user.

  • A user is someone who has login credentials.
  • This class does NOT use transients, unlike the other Collection sub-classes. This is done to provide immediate response to users updating favourites.
  • User favourites are stored in user-meta.
  • Provide functionality to add and manage these favourites.
Tags
since
5.5.0
since
5.7.0

Inherit Collection class.

since
6.0.0

Change user favourites to use user-meta.

uses
Collection

Table of Contents

Constants

ACTION_ADD  = 'add_favourite'
The AJAX action to add a favourite.
ACTION_DEL  = 'del_favourite'
The AJAX action to delete a favourite.
AJAX_VARS  = array('action' => '', 'recipe' => '', 'token' => '', 'user' => '')
The AJAX post vars defaults.
FAV_BUTTON_CONTAINER  = 'button-favourite.php'
The favourite button partial filename.
FAVOURITES_KEY  = 'pfic_favourites'
The user meta key for the favourites.
TRANSIENT_EXPIRATION_DEBUG  = MINUTE_IN_SECONDS * 5
The transient expiration for debugging.
TRANSIENT_EXPIRATION_PRODUCTION  = WEEK_IN_SECONDS
The transient expiration for production
TRANSIENT_KEY  = ''
Collection members transient key.

Properties

$fav_button_container  : string
The fully qualified path to the add favourite button container.
$instances  : array<string|int, object>
The array of instances of this class and sub-classes.
$recipe  : Recipe
The instance of the recipe class.
$transient_expiration  : int
The transient expiration.

Methods

get_instance()  : object
Creates and/or returns the instance of this class.
get_post_ids()  : array<string|int, int>
Return the array of user favourite post ids.
get_recipe_ids()  : array<string|int, int>
Return the array of user favourite recipe ids.
handle_ajax_request()  : void
The AJAX handler for the favourite action.
rebuild_collection()  : array<string|int, int>|bool
Rebuild the array of collection post ids and set as transient.
render_buttons()  : void
Render the favourite buttons.
__construct()  : void
Initialise the class and set its properties.
add()  : int
Add a favurite to user meta.
delete()  : int
Delete a favourite from user meta.

Constants

ACTION_ADD

The AJAX action to add a favourite.

protected string ACTION_ADD = 'add_favourite'
Tags
since
6.0.0

ACTION_DEL

The AJAX action to delete a favourite.

protected string ACTION_DEL = 'del_favourite'
Tags
since
6.0.0

AJAX_VARS

The AJAX post vars defaults.

protected array<string|int, string> AJAX_VARS = array('action' => '', 'recipe' => '', 'token' => '', 'user' => '')

{ The fields returned by the AJAX favourites request. @type string $action The AJAX action. @type string $recipe The recipe id. @type string $token The AJAX token. @type string $user The user id. }

Tags
since
6.0.0

FAV_BUTTON_CONTAINER

The favourite button partial filename.

protected string FAV_BUTTON_CONTAINER = 'button-favourite.php'
Tags
since
5.1.0

FAVOURITES_KEY

The user meta key for the favourites.

protected string FAVOURITES_KEY = 'pfic_favourites'
Tags
since
6.0.0

TRANSIENT_EXPIRATION_DEBUG

The transient expiration for debugging.

protected int TRANSIENT_EXPIRATION_DEBUG = MINUTE_IN_SECONDS * 5
Tags
since
6.0.0

TRANSIENT_EXPIRATION_PRODUCTION

The transient expiration for production

protected int TRANSIENT_EXPIRATION_PRODUCTION = WEEK_IN_SECONDS
Tags
since
6.0.0

TRANSIENT_KEY

Collection members transient key.

protected string TRANSIENT_KEY = ''
  • MUST override this in sub-classes.
Tags
since
6.0.0

Properties

$fav_button_container

The fully qualified path to the add favourite button container.

protected string $fav_button_container
Tags
since
5.1.0

$instances

The array of instances of this class and sub-classes.

protected static array<string|int, object> $instances = array()
Tags
since
6.0.0

$transient_expiration

The transient expiration.

protected int $transient_expiration
Tags
since
6.0.0

Methods

get_instance()

Creates and/or returns the instance of this class.

public static get_instance() : object
Tags
since
6.0.0
Return values
object

The instance of this class.

get_recipe_ids()

Return the array of user favourite recipe ids.

public get_recipe_ids() : array<string|int, int>
Tags
since
1.0.0
since
6.0.0

Refactor to use user-meta favourites entry..

Return values
array<string|int, int>

Array of recipe ids.

rebuild_collection()

Rebuild the array of collection post ids and set as transient.

public rebuild_collection() : array<string|int, int>|bool
  • MUST override this in child classes.
  • Return the array of post_ids.
Tags
since
6.0.0
since
6.7.0

Make method public to allow execution from cron job..

Return values
array<string|int, int>|bool

Array of post ids or false if no data

__construct()

Initialise the class and set its properties.

protected __construct() : void
Tags
since
6.0.0

add()

Add a favurite to user meta.

protected add(int $recipe_id, int $user_id) : int
Parameters
$recipe_id : int

The recipe id.

$user_id : int

The user id.

Tags
since
6.0.0
Return values
int

The result of the update_user_meta() call. 0 on no update.

delete()

Delete a favourite from user meta.

protected delete(int $recipe_id, int $user_id) : int
Parameters
$recipe_id : int

The recipe id.

$user_id : int

The user id.

Tags
since
6.0.0
Return values
int

The result of the update_user_meta() call. 0 on no update.


        
On this page

Search results