Download the PHP package radishlab/myc-getter without Composer
On this page you can find all versions of the php package radishlab/myc-getter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download radishlab/myc-getter
More information about radishlab/myc-getter
Files in radishlab/myc-getter
Package myc-getter
Short Description A library to get and escape values in WordPress + ACF environments
License GPL-2.0-or-later
Informations about the package myc-getter
MYC Getter
This class aims to facilitate the process of obtaining and sanitizing data from the post information (ID or object).
With MYC Getter, is possible to replace this:
By this:
Requirements
- PHP >= 8.0
Instalattion
Usage
The class accept two parameters:
$args- An array of arguments, listing the content you want to pull, or a preset name
- If nothing is passed, the class will use the arguments of the preset
default
$context- A string to identify where the class is being called
- If nothing is passed, the class will use
default
To overwrite the default preset, you just need to pass the keys you want to change:
If you're using the same arguments in multiples places, you can use the filter myc_getter_presets to create a new preset. Presets can also vary depend on $context:
Then, you can use this new preset when instantiate the class:
Modifying Settings After Instantiation
If you need to change the image size after creating the getter instance but before generating the image markup, you can use the setImageSize() method:
This method supports method chaining:
fields
- Format: array
Each field provides a filter to modify the returned content. The filter has three parameters: $value, $post_type and $post_id. Image and URL filters have an additional parameter: $context.
id
- Returns escaped content of
post->ID - Format: int
- Filter name:
myc_getter_get_id
slug
- Returns escaped content of
post->post_name - Format: string
- Filter name:
myc_getter_get_slug
title
- Returns escaped content of
post->post_title - Format: string
- Filter name:
myc_getter_get_title
url
- Returns escaped permalink
- Format: string
- Filter name:
myc_getter_get_url
image
- Returns image markup or image URL based on the value of
image_typeandimage_size - Format: string
- Filter name:
myc_getter_get_image
text
- Returns escaped content of
post->post_content - Format: string
- Filter name:
myc_getter_get_text
excerpt
- Returns escaped content of the function
get_the_excerpt($post) - Format: string
- Filter name:
myc_getter_get_excerpt
date
- Returns escaped dates of the post in two different format: using the global date format and using ISO 8601 (
c) date format - Format: array
- Filter name:
myc_getter_get_date
post_type
- Returns the post type slug
- Format: string
- Filter name:
myc_getter_get_post_type(to avoid redundancy, this filter has only two parameters)
image_size
- Format: string
Use one of the default WordPress image sizes (thumbnail, medium, medium_large, large, full) or a custom image size created by add_image_size() function.
image_type
- Format: string
Defines the format that the featured image will be returned: html or url.
acf
- Format: array
List of key/value where the key is the field slug and the value is the field type.
Each field type provides a filter to modify the returned content. The filter has four parameters: $value, $post_type, $post_id and $field_slug.
date
- Returns dates in two different format: using the global date format and using ISO 8601 (
c) date format orfalseif it is empty or the date is not formatted correctly - Format: array
- Filter name:
myc_getter_get_acf_date
time
- Returns time in global time format or
falseif it is empty or the time is not formatted correctly - Format: string
- Filter name:
myc_getter_get_acf_time
datetime
- Returns date and time in global date and time format or
falseif it is empty or the value is not formatted correctly - Format: string
- Filter name:
myc_getter_get_acf_datetime
url
- Returns escaped url using
esc_url()function - Format: string
- Filter name:
myc_getter_get_acf_url
link
- Returns escaped link info (
title,url,target,rel) orfalseif it is empty - Format: array
- Filter name:
myc_getter_get_acf_link
string
- Returns escaped content using
esc_html()function orfalseif it is empty - Format: string
- Filter name:
myc_getter_get_acf_string
attr
- Returns escaped content using
esc_attr()function orfalseif it is empty - Format: string
- Filter name:
myc_getter_get_acf_attr
text
- Returns escaped content using
wp_kses_post()function orfalseif it is empty - Format: string
- Filter name:
myc_getter_get_acf_text
image
- Returns the image markup or
falseif the image doesn't exists - This method also works with the Gallery field type
- Pass the image size inside the key using a pipe (e.g.
image_field|medium) - Format: string
- Filter name:
myc_getter_get_acf_image
image_url
- Returns the escaped image url or
falseif the image doesn't exists - Pass the image size inside the key using a pipe (e.g.
image_field|medium) - Format: string
- Filter name:
myc_getter_get_acf_image
int
- Returns the escaped integer value
- Format: int
- Filter name:
myc_getter_get_acf_int
- Returns the escaped email value using the function
antispambot() - Format: string
- Filter name:
myc_getter_get_acf_email
raw
- Returns the content without any treatment
- Format: string
- Filter name:
myc_getter_get_acf_raw
repeater
- For repeater fields, pass an array as the value:
taxonomies
- Format: array
List of key/value where the key is the taxonomy slug and the value is the desired returned format.
Each format provides a filter to modify the returned content. The filter has four parameters: $terms, $post_type, $post_id and $taxonomy.
all
- Returns the term object without any treatment
- Format: object
- Filter name:
myc_getter_get_terms_object
name
- Returns escaped content of
term->name - Format: string
- Filter name:
myc_getter_get_terms_name
link
- Returns escaped content of
term->nameandget_term_link()function - Format: array
- Filter name:
myc_getter_get_terms_link
slug/name
- Returns escaped content of
term->slugandterm->name - Format: array
- Filter name:
myc_getter_get_terms_slug_name
slug/id
- Returns escaped content of
term->term_idandterm->name - Format: array
- Filter name:
myc_getter_get_terms_id_name