Confetti Bits

CB_Ajax_Component extends CB_Component
in package

A component that helps organize our AJAX endpoints.

Use this to include files that house API handlers for each component. The naming convention for our endpoints is: /cb-ajax/{{version}}/{{component}}/{{action}}

Tags
see
CB_Component
since
2.3.0

Table of Contents

Properties

$admin_menu  : array<string|int, mixed>
WordPress Toolbar links.
$current_id  : string
The current ID of the queried object.
$global_tables  : array<string|int, mixed>
Global tables for the component (if applicable).
$has_directory  : bool
Does the component need a top-level directory?
$id  : string
Unique ID for the component.
$meta_tables  : array<string|int, mixed>
Metadata tables for the component (if applicable).
$name  : string
Translatable name for the component.
$notification_callback  : callable
Callback for formatting notifications.
$path  : string
The path to the component's files.
$query  : WP_Query
The WP_Query loop for this component.
$root_slug  : string
Root slug for the component.
$search_query_arg  : string
Query argument for component search URLs.
$search_string  : string
Placeholder text for component directory search box.
$slug  : string
Unique slug for the component, for use in query strings and URLs.

Methods

__construct()  : mixed
Bring out the dancing wizard.
add_permastructs()  : mixed
Add any permalink structures.
add_rewrite_rules()  : mixed
Add any additional rewrite rules.
add_rewrite_tags()  : mixed
Add any additional rewrite tags.
enqueue_scripts()  : mixed
Enqueues all of our scripts in a clean fashion.
generate_rewrite_rules()  : mixed
Generate any additional rewrite rules.
includes()  : mixed
Include files for the AJAX component.
late_includes()  : mixed
Late includes method.
parse_query()  : mixed
Allow components to parse the main query.
register_api_endpoints()  : mixed
Sets up REST endpoints for the component.
register_global_tables()  : mixed
Register global tables for the component, so that it may use WordPress's database API.
register_meta_tables()  : mixed
Register component metadata tables.
register_post_types()  : mixed
Set up the component post types.
register_scripts()  : mixed
register_taxonomies()  : mixed
Register component-specific taxonomies.
setup_actions()  : mixed
Set up the actions.
setup_admin_bar()  : mixed
Set up the component entries in the WordPress Admin Bar.
setup_cache_groups()  : mixed
Setup component-specific cache groups.
setup_canonical_stack()  : mixed
Set up the canonical URL stack for this component.
setup_filters()  : mixed
Sets up filters for redirect shenanigans.
setup_globals()  : mixed
Setup component globals for the AJAX component.
setup_nav()  : mixed
Set up component navigation.
setup_title()  : mixed
Set up the component title.
start()  : mixed
Component loader.

Properties

$admin_menu

WordPress Toolbar links.

public array<string|int, mixed> $admin_menu = ''
Tags
since
1.0.0

$current_id

The current ID of the queried object.

public string $current_id = ''
Tags
since
1.0.0

$global_tables

Global tables for the component (if applicable).

public array<string|int, mixed> $global_tables = array()
Tags
since
1.0.0

$has_directory

Does the component need a top-level directory?

public bool $has_directory = \false
Tags
since
1.0.0

$meta_tables

Metadata tables for the component (if applicable).

public array<string|int, mixed> $meta_tables = array()
Tags
since
1.0.0

$notification_callback

Callback for formatting notifications.

public callable $notification_callback = ''
Tags
since
1.0.0

$path

The path to the component's files.

public string $path = ''
Tags
since
1.0.0

$query

The WP_Query loop for this component.

public WP_Query $query = \false
Tags
since
1.0.0

$root_slug

Root slug for the component.

public string $root_slug = ''
Tags
since
1.0.0

$search_query_arg

Query argument for component search URLs.

public string $search_query_arg = 's'
Tags
since
1.0.0

$search_string

Placeholder text for component directory search box.

public string $search_string = ''
Tags
since
1.0.0

$slug

Unique slug for the component, for use in query strings and URLs.

public string $slug = ''
Tags
since
1.0.0

Methods

add_permastructs()

Add any permalink structures.

public add_permastructs() : mixed
Tags
since
1.0.0

add_rewrite_rules()

Add any additional rewrite rules.

public add_rewrite_rules() : mixed
Tags
since
1.0.0

add_rewrite_tags()

Add any additional rewrite tags.

public add_rewrite_tags() : mixed
Tags
since
1.0.0

enqueue_scripts()

Enqueues all of our scripts in a clean fashion.

public enqueue_scripts([mixed $components = [] ]) : mixed

From each according to their capability, to each according to their need. Scripts are enqueued and localized using the following nested array structure: [ $unique_name_for_script => [ $name_of_api_component_to_use => [ $http_method1, $http_method2, ... ], 'dependencies' => [ $dependency1, $dependency2, ... ] ] ] This structure is then picked apart to dynamically enqueue and localize scripts. This gives us granular control over who gets access to what API endpoints, and can perform which actions, based on capability.

The scripts will be enqueued as: "cb_{$unique_name_for_script}", and will load a corresponding file, with the underscores replaced with dashes, like so: "cb-{$unique-name-for-script}.js". This will also load any dependencies found in the 'dependencies' array.

Scripts will then be localized using the same "cb_{$unique_name_for_script}" identifier, which will become the global name that is usable within the file. All API endpoints are localized as: "{$endpoint}_{$name_of_api_component}".

So, for example: - "cb_participation.get_participation" will return the API endpoint for getting participation entries ONLY when used within the cb-participation.js file. - "cb_core_admin.new_transactions" will return the API endpoint for creating a new transaction ONLY when used within the cb-core-admin.js file.

To access the API key, use "{$unique_name_for_script}.api_key" in the {$unique-name-for-script}.js file.

Parameters
$components : mixed = []
Tags
since
2.3.0

generate_rewrite_rules()

Generate any additional rewrite rules.

public generate_rewrite_rules() : mixed
Tags
since
1.0.0

includes()

Include files for the AJAX component.

public includes([mixed $includes = array() ]) : mixed
Parameters
$includes : mixed = array()

An array of file names, or file name chunks, to be parsed and then included.

Tags
see
CB_Component::includes()
since
2.3.0

late_includes()

Late includes method.

public late_includes() : mixed

Components should include files here only on specific pages using conditionals such as . Intentionally left empty.

Tags
since
1.0.0

parse_query()

Allow components to parse the main query.

public parse_query(object $query) : mixed
Parameters
$query : object

The main WP_Query.

Tags
since
1.0.0

register_api_endpoints()

Sets up REST endpoints for the component.

public register_api_endpoints([mixed $components = [] ]) : mixed

When passed a collection of strings, uses cb_ajax_register_api_endpoints() to register endpoints based on the component.

Parameters
$components : mixed = []
Tags
since
2.3.1

register_global_tables()

Register global tables for the component, so that it may use WordPress's database API.

public register_global_tables([array<string|int, mixed> $tables = array() ]) : mixed
Parameters
$tables : array<string|int, mixed> = array()

Table names to register.

Tags
since
1.0.0

register_meta_tables()

Register component metadata tables.

public register_meta_tables([array<string|int, mixed> $tables = array() ]) : mixed

Metadata tables are registered in the $wpdb global, for compatibility with the WordPress metadata API.

Parameters
$tables : array<string|int, mixed> = array()

Table names to register.

Tags
since
1.0.0

register_post_types()

Set up the component post types.

public register_post_types() : mixed
Tags
since
1.0.0

register_scripts()

public register_scripts([mixed $components = [] ]) : mixed
Parameters
$components : mixed = []

register_taxonomies()

Register component-specific taxonomies.

public register_taxonomies() : mixed
Tags
since
1.0.0

setup_actions()

Set up the actions.

public setup_actions() : mixed
Tags
since
1.0.0

setup_admin_bar()

Set up the component entries in the WordPress Admin Bar.

public setup_admin_bar([array<string|int, mixed> $wp_admin_nav = array() ]) : mixed
Parameters
$wp_admin_nav : array<string|int, mixed> = array()

An array of nav item arguments. Each item in this parameter array is passed to . See that method for a description of the required syntax for each item.

Tags
since
1.0.0
see
WP_Admin_Bar::add_menu()

for a description of the syntax required by each item in the $wp_admin_nav parameter array.

global

object $wp_admin_bar

setup_cache_groups()

Setup component-specific cache groups.

public setup_cache_groups() : mixed
Tags
since
1.0.0

setup_canonical_stack()

Set up the canonical URL stack for this component.

public setup_canonical_stack() : mixed
Tags
since
1.0.0

setup_filters()

Sets up filters for redirect shenanigans.

public setup_filters() : mixed
Tags
since
3.0.0

setup_globals()

Setup component globals for the AJAX component.

public setup_globals([mixed $args = array() ]) : mixed
Parameters
$args : mixed = array()

{ All values are optional. @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in http://example.com/members/joe/friends/. Default: the value of $this->id. @type string $root_slug The component root slug. Note that this value is generally unused if the component has a root directory (the slug will be overridden by the post_name of the directory page). Default: the slug of the directory page if one is found, otherwise an empty string. @type bool $has_directory Set to true if the component requires an associated WordPress page. @type callable $notification_callback Optional. The callable function that formats the component's notifications. @type string $search_term Optional. The placeholder text in the component directory search box. Eg, 'Search Groups...'. @type array $global_tables Optional. An array of database table names. @type array $meta_tables Optional. An array of metadata table names. }

Tags
see
CB_Copmonent::setup_globals()
since
2.3.0

setup_nav()

Set up component navigation.

public setup_nav([array<string|int, mixed> $main_nav = array() ][, array<string|int, mixed> $sub_nav = array() ]) : mixed

Maybe we'll use this someday.

Parameters
$main_nav : array<string|int, mixed> = array()

Optional. Passed directly to cb_core_new_nav_item(). See that function for a description.

$sub_nav : array<string|int, mixed> = array()

Optional. Multidimensional array, each item in which is passed to cb_core_new_subnav_item(). See that function for a description.

Tags
since
1.0.0
see
cb_core_new_nav_item()

For a description of the $main_nav parameter formatting.

see
cb_core_new_subnav_item()

For a description of how each item in the $sub_nav parameter array should be formatted.

setup_title()

Set up the component title.

public setup_title() : mixed
Tags
since
1.0.0

start()

Component loader.

public start([string $id = '' ][, string $name = '' ][, string $path = '' ][, array<string|int, mixed> $params = array() ]) : mixed
Parameters
$id : string = ''

Unique ID. Letters, numbers, and underscores only.

$name : string = ''

Unique name. This should be a translatable name, eg. __( 'Groups', 'confetti_bits' ).

$path : string = ''

The file path for the component's files. Used by .

$params : array<string|int, mixed> = array()

{ Additional parameters used by the component. @type int $adminbar_myaccount_order Set the position for our menu under the WP Toolbar's "My Account menu". @type array $features An array of feature names. This is used to load additional files from your component directory and for feature active checks. eg. array( 'awesome' ) would look for a file called "cb-{$this->id}-awesome.php" and you could use cb_is_active( $this->id, 'awesome' ) to determine if the feature is active. @type string $search_query_arg String to be used as the query argument in component search URLs. }

Tags
since
1.0.0

        
On this page

Search results