pfeifferNet

Add_Ratings extends Tool
in package

Bulk add ratings to recipes.

  • Handle AJAX interaction.
  • Use WPRM methods to add or update ratings.
Tags
since
5.8.0
5.11.0

Deprecated global singleton.

6.0.0

Refactor for newUI.

6.1.0

Extend pNet admin tool class.

6.6.0

Add a user dropdown to limit user_id to a maximum value, not a user, and not rated before.

6.6.0

Add a rating dropdown to limit rating value to between 1 and 5.

uses
HTTP_Handler
Tool

Table of Contents

Constants

ACTION  : string = 'pnet_add_ratings'
The wp_ajax hook action properties.
CAPABILITY  : string = 'edit_others_posts'
The user capability required to run this tool.
FORM_NAME  : string = 'add_ratings'
The name attribute of the form.
HANDLER  : string = 'addRatings'
The name of the javascript handler for the form.
MAX_USER_ID  : int = 1024
The maximum value to use for user_id in rating.
MIN_USER_ID  : int = 4
The minimum value to use for user_id in rating.
NONCE_NAME  : string = 'token'
The nonce name for the form.
TARGET_TAB  : string = 'cookbook'
Target tools page tab for this tool.
TOOL_CONTAINER  : string = 'form-add-ratings.php'
Tools container partial.

Properties

$form_vars  : array<string|int, mixed>
The variables used to render the form.
$http_handler  : HTTP_Handler
The instance of the HTTP_Handler class.
$instances  : array<string|int, object>
The array of instances of this class and sub-classes.
$tool_container  : string
Fully qualified path to the tool container partial.

Methods

get_action()  : string
Return the action name.
get_instance()  : object
Creates and/or returns the instance of this class.
handle_ajax_request()  : void
The AJAX call handler.
render()  : void
Render the tool.
set_tab()  : array<string|int, mixed>
Create the target tab on the tools page if it doesn't exist.
__construct()  : void
Initialise the class.
add_ratings()  : int
Update the user ratings.
get_available_user_ids()  : array<string|int, mixed>
Get a limited array of available user ids.
get_rater_ids()  : array<string|int, mixed>
Get the array of user ids that have already rated recipes.
get_rating_select_options()  : string
Populate the select options for the rating dropdown.
get_tab_name()  : string
Return the tab name.
get_user_select_options()  : string
Populate the select options for the user id dropdown.
init_tool()  : void
Initialise the tool form with required values and assets.

Constants

ACTION

The wp_ajax hook action properties.

protected string ACTION = 'pnet_add_ratings'
Tags
since
5.8.0

CAPABILITY

The user capability required to run this tool.

protected string CAPABILITY = 'edit_others_posts'
Tags
since
5.10.0

FORM_NAME

The name attribute of the form.

protected string FORM_NAME = 'add_ratings'
Tags
since
6.0.0

HANDLER

The name of the javascript handler for the form.

protected string HANDLER = 'addRatings'
Tags
since
6.0.0

MAX_USER_ID

The maximum value to use for user_id in rating.

protected int MAX_USER_ID = 1024
Tags
since
6.6.0

MIN_USER_ID

The minimum value to use for user_id in rating.

protected int MIN_USER_ID = 4
Tags
since
6.6.0

NONCE_NAME

The nonce name for the form.

protected string NONCE_NAME = 'token'
Tags
since
6.1.0

TARGET_TAB

Target tools page tab for this tool.

protected string TARGET_TAB = 'cookbook'

This will be created if it doesn't exist.

Tags
since
5.11.0

TOOL_CONTAINER

Tools container partial.

protected string TOOL_CONTAINER = 'form-add-ratings.php'
Tags
since
5.8.0

Properties

$form_vars

The variables used to render the form.

protected array<string|int, mixed> $form_vars = array('title' => '', 'description' => '')
  • Each tool may have its own set of variables other than these.

{ Array of variables used to render the form. @type string $title The title of the form. @type string $description The description for the form. }

Tags
since
6.1.0

$instances

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

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

$tool_container

Fully qualified path to the tool container partial.

protected string $tool_container = ''
Tags
since
6.1.0

Methods

get_instance()

Creates and/or returns the instance of this class.

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

The instance of this class.

render()

Render the tool.

public render([string $tab = '' ]) : void
  • The priority set on this hook will determine the tool sequence down the page.
Parameters
$tab : string = ''

The slug of the active tab on tools page.

Tags
since
6.1.0
see
Tools::render()

set_tab()

Create the target tab on the tools page if it doesn't exist.

public set_tab([array<string|int, mixed> $tabs = array() ]) : array<string|int, mixed>
  • The priority set on this hook will determine the tab sequence across the page.
Parameters
$tabs : array<string|int, mixed> = array()

A set of key/value pairs for the admin tools page.

Tags
since
6.1.0
see
Tools::render()
Return values
array<string|int, mixed>

The (maybe) modified tabs array.

add_ratings()

Update the user ratings.

protected add_ratings(int $user_id, int $rating) : int
Parameters
$user_id : int

The user ID to assign to rating.

$rating : int

The rating value to apply.

Tags
since
5.8.0
uses
WPRM_Rating_Database::add_or_update_rating()
Return values
int

The number of ratings added or updated.

get_available_user_ids()

Get a limited array of available user ids.

protected get_available_user_ids([int $num_ids = 8 ]) : array<string|int, mixed>
Parameters
$num_ids : int = 8

Optional. The number of ids to return. Defaults to 8.

Tags
since
6.6.0
Return values
array<string|int, mixed>

The array of available user ids, limited to the specified number.

get_rater_ids()

Get the array of user ids that have already rated recipes.

protected get_rater_ids() : array<string|int, mixed>
Tags
since
6.6.0
Return values
array<string|int, mixed>

The array of user ids that have already rated recipes.

get_rating_select_options()

Populate the select options for the rating dropdown.

protected get_rating_select_options() : string
Tags
since
6.6.0
Return values
string

The select options for the rating dropdown.

get_tab_name()

Return the tab name.

protected get_tab_name() : string
Tags
since
6.1.0
Return values
string

The display name of the tab for this tool.

get_user_select_options()

Populate the select options for the user id dropdown.

protected get_user_select_options() : string
Tags
since
6.6.0
Return values
string

The select options for the user id dropdown.

init_tool()

Initialise the tool form with required values and assets.

protected init_tool() : void
Tags
since
6.1.0

        
On this page

Search results