Functions
Functions to perform snippet operations.
Namespace: WebberZone\Snippetz\Snippets
Since: 2.0.0
Source: includes/snippets/class-functions.php line 27
Methods
__construct()
Constructor function.
Line: 32
public function __construct( );
get_snippets() static
Retrieves an array of the latest snippets, or snippets matching the given criteria.
The defaults are as follows:
Since: 2.0.0
Line: 66
static public function get_snippets( $args = ... ): \WP_Post[]|int[];
| Type | Name | Description |
|---|---|---|
array | $args | { |
Returns: \WP_Post[]|int[] — Array of snippet objects or snippet IDs.
get_snippet() static
Retrieves the snippet data given a snippet ID or object.
Since: 2.0.0
Line: 107
static public function get_snippet( $snippet ): \WP_Post|string;
| Type | Name | Description |
|---|---|---|
int|\WP_Post | $snippet | Snippet ID or object. |
Returns: \WP_Post|string — WP_Post instance on success or error message on failure.
get_snippet_content() static
Get Snippet Content by ID.
Since: 2.1.0
Line: 135
static public function get_snippet_content( $snippet, $args = ... ): string;
| Type | Name | Description |
|---|---|---|
int|\WP_Post | $snippet | Snippet ID or object. |
array | $args | Arguments passed to the get_posts function. |
Returns: string — Snippet content.
get_snippets_by_location() static
Retrieves an array of the latest snippets based on the location specified.
Since: 2.0.0
Line: 191
static public function get_snippets_by_location( $location, $numberposts = ... ): \WP_Post[]|int[]|false;
| Type | Name | Description |
|---|---|---|
string | $location | Location of the snippet. Valid options are header, footer, content_before and content_after. |
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
Returns: \WP_Post[]|int[]|false — Array of snippet objects or snippet IDs on success or false on failure.
get_header_snippets() static
Retrieves an array of the latest header snippets.
Since: 2.0.0
Line: 256
static public function get_header_snippets( $numberposts = ... ): \WP_Post[]|int[];
| Type | Name | Description |
|---|---|---|
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
Returns: \WP_Post[]|int[] — Array of snippet objects or snippet IDs on success or false on failure.
get_footer_snippets() static
Retrieves an array of the latest footer snippets.
Since: 2.0.0
Line: 270
static public function get_footer_snippets( $numberposts = ... ): \WP_Post[]|int[];
| Type | Name | Description |
|---|---|---|
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
Returns: \WP_Post[]|int[] — Array of snippet objects or snippet IDs on success or false on failure.
get_content_before_snippets() static
Retrieves an array of the latest content_before snippets.
Since: 2.0.0
Line: 284
static public function get_content_before_snippets( $numberposts = ... ): \WP_Post[]|int[];
| Type | Name | Description |
|---|---|---|
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
Returns: \WP_Post[]|int[] — Array of snippet objects or snippet IDs on success or false on failure.
get_content_after_snippets() static
Retrieves an array of the latest content_after snippets.
Since: 2.0.0
Line: 298
static public function get_content_after_snippets( $numberposts = ... ): \WP_Post[]|int[];
| Type | Name | Description |
|---|---|---|
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
Returns: \WP_Post[]|int[] — Array of snippet objects or snippet IDs on success or false on failure.
enqueue_snippets() static
Function to enqueue snippets for the header. Filters wp_enqueue_scripts.
Since: 2.3.0
Line: 308
static public function enqueue_snippets( );
enqueue_combined_assets() static
Enqueue combined CSS/JS assets when enabled and available.
Since: 2.3.0
Line: 323
static public function enqueue_combined_assets( ): array<string,bool>;
Returns: array<string,bool> — Map of asset types to enqueue status.
get_snippets_content_by_location() static
Function to add snippets code to the header. Filters wp_head.
Since: 2.0.0
Line: 371
static public function get_snippets_content_by_location( $location, $before = ..., $after = ..., $numberposts = ..., $enqueue_only = ... ): string;
| Type | Name | Description |
|---|---|---|
string | $location | Location of the snippet. Valid options are header, footer, content_before and content_after. |
string | $before | Text to display before the output. |
string | $after | Text to display after the output. |
int | $numberposts | Optional. Number of snippets to retrieve. Default is -1. |
bool | $enqueue_only | Optional. Whether to only enqueue scripts and styles. Default false. |
Returns: string — Content of snippets for the specified location.
snippets_header() static
Function to add snippets code to the header. Filters wp_head.
Since: 2.0.0
Line: 529
static public function snippets_header( );
snippets_footer() static
Function to add snippets code to the footer. Filters wp_footer.
Since: 2.0.0
Line: 540
static public function snippets_footer( );
snippets_content() static
Function to add snippets code to the footer. Filters the_content.
Since: 2.0.0
Line: 554
static public function snippets_content( $content ): string;
| Type | Name | Description |
|---|---|---|
string | $content | Post content. |
Returns: string — Filtered post content
snippets_credit() static
Function to add snippets credit line.
Since: 2.0.0
Line: 579
static public function snippets_credit( ): string;
Returns: string — Snippets credit line.
get_snippet_type() static
Get snippet type.
Since: 2.0.0
Line: 599
static public function get_snippet_type( $snippet ): string;
| Type | Name | Description |
|---|---|---|
\WP_Post | $snippet | Snippet object. |
Returns: string — Snippet type.
get_snippet_file_url() static
Get the external file URL for a snippet if it exists.
Since: 2.3.0
Line: 616
static public function get_snippet_file_url( $snippet_id, $snippet_type, $update_meta = ... ): string;
| Type | Name | Description |
|---|---|---|
int | $snippet_id | Snippet ID. |
string | $snippet_type | Snippet type. |
bool | $update_meta | Whether to update the snippet meta when the file exists. |
Returns: string — External file URL or empty string.
wrap_output() static
Wrap output in style or script tags depending on snippet type.
Line: 652
static public function wrap_output( $output, $snippet_type, $snippet_id = ..., $in_footer = ... ): string;
| Type | Name | Description |
|---|---|---|
string | $output | The output to be wrapped. |
string | $snippet_type | The type of the snippet: ‘css’ or ‘js’. |
int | $snippet_id | The snippet ID. |
bool | $in_footer | Whether to enqueue the script in the footer. Default true. |
Returns: string — The wrapped output.
get_snippet_type_styles() static
Get snippet type styles.
Line: 713
static public function get_snippet_type_styles( $snippet ): array;
| Type | Name | Description |
|---|---|---|
\WP_Post | $snippet | Snippet object. |
Returns: array — Snippet type styles. Includes four keys: ‘type’, ‘color’, ‘background’, ‘tag’.
regenerate_snippet_files() static
Regenerate external files for all CSS/JS snippets.
Since: 2.3.0
Line: 790
static public function regenerate_snippet_files( ): int;
Returns: int — Count of updated snippets.
save_snippet_file()
Save snippet as external file if enabled.
Line: 827
public function save_snippet_file( $post_id, $post );
| Type | Name | Description |
|---|---|---|
int | $post_id | Post ID. |
\WP_Post | $post | Post object. |
delete_snippet_file()
Delete snippet file on post deletion.
Line: 845
public function delete_snippet_file( $post_id );
| Type | Name | Description |
|---|---|---|
int | $post_id | Post ID. |