Recent

Functions class

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[];
TypeNameDescription
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;
TypeNameDescription
int|\WP_Post$snippetSnippet ID or object.

Returns: \WP_Post|stringWP_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;
TypeNameDescription
int|\WP_Post$snippetSnippet ID or object.
array$argsArguments 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;
TypeNameDescription
string$locationLocation of the snippet. Valid options are header, footer, content_before and content_after.
int$numberpostsOptional. 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[];
TypeNameDescription
int$numberpostsOptional. 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.

Retrieves an array of the latest footer snippets.

Since: 2.0.0
Line: 270

static public function get_footer_snippets( $numberposts = ... ): \WP_Post[]|int[];
TypeNameDescription
int$numberpostsOptional. 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[];
TypeNameDescription
int$numberpostsOptional. 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[];
TypeNameDescription
int$numberpostsOptional. 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;
TypeNameDescription
string$locationLocation of the snippet. Valid options are header, footer, content_before and content_after.
string$beforeText to display before the output.
string$afterText to display after the output.
int$numberpostsOptional. Number of snippets to retrieve. Default is -1.
bool$enqueue_onlyOptional. 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(  );

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;
TypeNameDescription
string$contentPost 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;
TypeNameDescription
\WP_Post$snippetSnippet 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;
TypeNameDescription
int$snippet_idSnippet ID.
string$snippet_typeSnippet type.
bool$update_metaWhether 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;
TypeNameDescription
string$outputThe output to be wrapped.
string$snippet_typeThe type of the snippet: ‘css’ or ‘js’.
int$snippet_idThe snippet ID.
bool$in_footerWhether 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;
TypeNameDescription
\WP_Post$snippetSnippet 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 );
TypeNameDescription
int$post_idPost ID.
\WP_Post$postPost object.

delete_snippet_file()

Delete snippet file on post deletion.

Line: 845

public function delete_snippet_file( $post_id );
TypeNameDescription
int$post_idPost ID.