Wordless
Stop writing themes like it's 1998.
|
All the helpers functions in Wordless. More...
Functions | |
AcfGutenbergBlockHelper::create_acf_block (string $block_name, array $params) | |
Creates and registers ACF Gutenberg block. More... | |
AssetTagHelper::get_asset_version_string () | |
Return the theme version, based on prederence set in Wordless config file. More... | |
AssetTagHelper::asset_version ($source) | |
Appends version information to asset source. More... | |
AssetTagHelper::audio_tag ($source, $attributes=array()) | |
Builds a valid <audio /> HTML tag. More... | |
AssetTagHelper::auto_discovery_link_tag ($model_or_url="posts", $type="rss", $additional_options=NULL) | |
Builds a valid <link /> HTML tag to a feed (rss or atom). More... | |
AssetTagHelper::favicon_link_tag ($source="favicon.ico", $attributes=NULL) | |
Builds a valid <link /> HTML tag to a favicon. More... | |
AssetTagHelper::get_feed_url ($model, $type="rss") | |
Returns a WP valid feed, depending on the type or feed requested and of the content for which the feed is created. More... | |
AssetTagHelper::image_tag ($source, $attributes=NULL) | |
Builds a valid <img /> HTML tag. More... | |
AssetTagHelper::video_tag ($sources, $attributes=NULL) | |
Builds a valid <video /> HTML tag. More... | |
AssetTagHelper::stylesheet_link_tag () | |
Returns a stylesheet link tag for the sources specified as arguments. More... | |
AssetTagHelper::javascript_include_tag () | |
Returns an HTML script tag for each of the sources provided as arguments. More... | |
ConditionalHelper::is_subpage ($id=NULL) | |
Check if the page is a subpage and return the parent post ID if true. More... | |
ConditionalHelper::is_page_wpml ( $page_title=array()) | |
Check if is a page when WPML is in use; takes in consideration all the translations. More... | |
DateHelper::distance_of_time_in_words ($from_time, $to_time, $include_seconds=false) | |
Returns a user-friendly string representation of a time distance. More... | |
DateHelper::get_the_time_ago ($granularity=1) | |
Returns a 'time ago' string based on the creation time of the current post. More... | |
DateHelper::time_tag ($date_or_time=NULL, $text=NULL, $attributes=array()) | |
Builds a valid <time /> HTML tag. More... | |
DateHelper::time_ago_in_words ($from_time, $include_seconds=false) | |
Like distance_of_time_in_words() but with fixed value of $to_time. More... | |
FakerHelper::placeholder_image ($width, $height, $options=array()) | |
Generate a placeholder image. More... | |
FakerHelper::placeholder_text ($count, $options=array()) | |
Generate placeholder text. More... | |
DebugHelper::dump ($var) | |
Prints the specified variable already formatted in <pre></pre> tags. More... | |
MediaHelper::detect_user_agent () | |
Includes a PHP class to detect mobile devices and user agent details. More... | |
MediaHelper::get_post_attachments ($post_id) | |
Get the attached files in specified post. More... | |
MediaHelper::get_current_post_attachments () | |
Get the attached files in current post. More... | |
MediaHelper::resize_image ($src, $width, $height) | |
Resizes the specified image to the specified dimensions. More... | |
ModelHelper::new_post_type ($name, $supports=array("title", "editor"), $options=array()) | |
Creates a new post type. More... | |
ModelHelper::new_taxonomy ($name, $post_types, $options=array()) | |
Create a new taxonomy. More... | |
NumberHelper::number_to_currency ($number, $options=array()) | |
Translates number to currency. More... | |
QueryHelper::latest_posts_of_type ($type, $limit=-1, $order='date', $ord='DESC') | |
Get last posts of specified type. More... | |
QueryHelper::latest_post_of_type ($type, $order='date') | |
Get the last post of the specified type. More... | |
QueryHelper::latest_posts_of_category ($category, $limit, $offset=0, $post_type='post', $taxonomy='category', $order='date', $ord='DESC') | |
Get last posts of specified category. More... | |
QueryHelper::latest_post_of_category ($category, $post_type='post', $taxonomy='category') | |
Get the last post of the specified category. More... | |
QueryHelper::is_post_type ($type) | |
Check if post type is the one specified. More... | |
QueryHelper::get_the_first_categories_except ($limit, $except) | |
Get the first categories, except one. More... | |
QueryHelper::get_page_id_by_title ($title) | |
Returns the page ID from page title. More... | |
QueryHelper::get_category_id_by_name ($cat_name, $taxonomy='category') | |
Returns the category ID from the category name. More... | |
QueryHelper::get_category_link_by_name ($cat_name, $taxonomy='category') | |
Returns a link to the specified category. More... | |
QueryHelper::get_the_filtered_content () | |
Returns the content of the current post. More... | |
QueryHelper::get_post_type_singular_name () | |
Returns the post type (always singular). More... | |
QueryHelper::get_page_title ($prefix="", $separator="") | |
Returns the page title. More... | |
TextHelper::pluralize ($string) | |
Attempts to pluralize the specified text. More... | |
TextHelper::reset_cycle ($name="default") | |
Reset the cycle pointer. More... | |
TextHelper::truncate ($text, $options=array()) | |
Truncate the text to the specified length. More... | |
TextHelper::capitalize ($text) | |
Returns a string with the first character of each word capitalized. More... | |
TextHelper::titleize ($text) | |
Capitalizes the first letter of every word. More... | |
TextHelper::is_valid_url ($url) | |
Check if the string passed as parameter is a valid URL. More... | |
ThemeHelper::get_theme_name () | |
Returns the folder theme name based on the theme path. More... | |
ThemeHelper::get_theme_path () | |
Returns the absolute path to the current theme. More... | |
ThemeHelper::get_theme_version () | |
Returns the version of the the current theme. More... | |
UrlHelper::arg ($index=NULL) | |
Returns URL arguments. More... | |
UrlHelper::asset_url ($path) | |
Returns the URL path to the spcified folder in the assets directory. More... | |
UrlHelper::image_url ($path) | |
Returns the URL path to the specified folder in the images directory. More... | |
UrlHelper::stylesheet_url ($path) | |
Returns the URL path to the specified folder in the stylesheet directory. More... | |
UrlHelper::javascript_url ($path) | |
Returns the URL path to the specified folder in the javascript directory. More... | |
UrlHelper::is_absolute_url ($url) | |
Check if an URL is absolute or not URL are considered absolute if they begin with a protocol specification (https|https in this case) or with the double slash (//) to take advantage of the protocol relative URL (http://paulirish.com/2010/the-protocol-relative-url/) More... | |
UrlHelper::is_root_relative_url ($url) | |
Check if an URL is root relative URL are considered root relative if they are not absolute but begin with a /. More... | |
UrlHelper::is_relative_url ($url) | |
Check if an URL is relative URL are considered relative if they are not absolute and don't begin with a /. More... | |
All the helpers functions in Wordless.
UrlHelper::arg | ( | $index = NULL | ) |
Returns URL arguments.
int | $index | (optional) The number (counting from zero) of the argument in the list. If is not specified all arguments will be returned as an array. |
UrlHelper::asset_url | ( | $path | ) |
Returns the URL path to the spcified folder in the assets directory.
string | $path | The path inside the {theme}/assets/ folder. |
AssetTagHelper::asset_version | ( | $source | ) |
Appends version information to asset source.
string | $source | The path to the asset source. |
AssetTagHelper::audio_tag | ( | $source, | |
$attributes = array() |
|||
) |
Builds a valid <audio /> HTML tag.
string | $source | The path to the audio source. |
array | $attributes | (optional) An array of HTML attributes to be added to the rendered tag. |
AssetTagHelper::auto_discovery_link_tag | ( | $model_or_url = "posts" , |
|
$type = "rss" , |
|||
$additional_options = NULL |
|||
) |
Builds a valid <link /> HTML tag to a feed (rss or atom).
Returns a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed. The type can either be rss (default) or atom. You can modify the LINK tag itself in $tag_options.
string | $model_or_url | (optional) The source of the feed. Can be a custom URL, posts or comments. In the latter case, the source will be returned by AssetTagHelper::get_feed_url() Defaults to posts. |
string | $type | (optional) The type of the feed. Could be rss or atom. Defaults to rss. |
array | $tag_options | (optional) An array of HTML attributes to be added to the rendered tag. |
TextHelper::capitalize | ( | $text | ) |
Returns a string with the first character of each word capitalized.
string | $text | The text to be capitalized. |
AcfGutenbergBlockHelper::create_acf_block | ( | string | $block_name, |
array | $params | ||
) |
Creates and registers ACF Gutenberg block.
string | $block_name | The name of the block. |
array | $params | The array of block specific params that will override the defaults. |
MediaHelper::detect_user_agent | ( | ) |
Includes a PHP class to detect mobile devices and user agent details.
DateHelper::distance_of_time_in_words | ( | $from_time, | |
$to_time, | |||
$include_seconds = false |
|||
) |
Returns a user-friendly string representation of a time distance.
Given 2 timestamps, return a readable representation for their distance, link "1 minute" or "about an hour", etc.
int | $from_time | The timestamp for the initial time. |
int | $to_time | (optional) The timestamp for the end time. |
boolean | $include_seconds | (optional) TRUE if you want to take in account also seconds in the time distance ( must be set if you want information about a time distance shorter than a minute ). |
DebugHelper::dump | ( | $var | ) |
Prints the specified variable already formatted in <pre></pre> tags.
string | $var | The variable to be printed |
AssetTagHelper::favicon_link_tag | ( | $source = "favicon.ico" , |
|
$attributes = NULL |
|||
) |
Builds a valid <link /> HTML tag to a favicon.
string | $source | (optional) The path to the favicon file. Must be a valid path to an .ico file. |
array | $attributes | (optional) An array of HTML attributes to be added to the rendered tag. |
|
protected |
Return the theme version, based on prederence set in Wordless config file.
QueryHelper::get_category_id_by_name | ( | $cat_name, | |
$taxonomy = 'category' |
|||
) |
Returns the category ID from the category name.
string | $cat_name | The name of the category |
string | $taxonomy | (optional) The taxonomy at which the category belongs to. |
QueryHelper::get_category_link_by_name | ( | $cat_name, | |
$taxonomy = 'category' |
|||
) |
Returns a link to the specified category.
string | $cat_name | The name of the category. |
string | $taxonomy | (optional) The taxonomy at which the category belongs to |
MediaHelper::get_current_post_attachments | ( | ) |
Get the attached files in current post.
AssetTagHelper::get_feed_url | ( | $model, | |
$type = "rss" |
|||
) |
Returns a WP valid feed, depending on the type or feed requested and of the content for which the feed is created.
Post's feeds are different from comment's feeds, this function return the correct feed (rss/atom) for the specified content.
string | $model | Return the correct feed type, depending on content type. Can be posts or comments. |
string | $type | The type of the feed. Can be rdf, rss1, rss092, rss, rss2. |
QueryHelper::get_page_id_by_title | ( | $title | ) |
Returns the page ID from page title.
string | $title |
QueryHelper::get_page_title | ( | $prefix = "" , |
|
$separator = "" |
|||
) |
Returns the page title.
string | $prefix | (optional) A string to be prefixed to the current page title. |
string | $separator | (optional) A string to separate prefix and current page title. |
MediaHelper::get_post_attachments | ( | $post_id | ) |
Get the attached files in specified post.
int | $post_id | The ID of the post of which we need to retrieve attachments. |
QueryHelper::get_post_type_singular_name | ( | ) |
Returns the post type (always singular).
QueryHelper::get_the_filtered_content | ( | ) |
Returns the content of the current post.
Must be called within The Loop.
QueryHelper::get_the_first_categories_except | ( | $limit, | |
$except | |||
) |
Get the first categories, except one.
int | $limit | The max number of categories to be retrieved. |
string | $except | The name of the category to exclude. |
DateHelper::get_the_time_ago | ( | $granularity = 1 | ) |
Returns a 'time ago' string based on the creation time of the current post.
For more details on how this function works please check the get_the_date() WordPress documentation.
int | $granularity | (optional) |
ThemeHelper::get_theme_name | ( | ) |
Returns the folder theme name based on the theme path.
The function use the whole theme path to get only the folder name of the current theme.
ThemeHelper::get_theme_path | ( | ) |
Returns the absolute path to the current theme.
Path without trailing slash.
ThemeHelper::get_theme_version | ( | ) |
Returns the version of the the current theme.
AssetTagHelper::image_tag | ( | $source, | |
$attributes = NULL |
|||
) |
Builds a valid <img /> HTML tag.
string | $source | The source path to the image. |
string | array | $attributes | (optional) A single HTML attribute or an array of HTML attributes to be added to the rendered tag. |
UrlHelper::image_url | ( | $path | ) |
Returns the URL path to the specified folder in the images directory.
string | $path | The path inside the {theme}/assets/images/ folder. |
UrlHelper::is_absolute_url | ( | $url | ) |
Check if an URL is absolute or not URL are considered absolute if they begin with a protocol specification (https|https in this case) or with the double slash (//) to take advantage of the protocol relative URL (http://paulirish.com/2010/the-protocol-relative-url/)
string | $url | The url to check. |
ConditionalHelper::is_page_wpml | ( | $page_title = array() | ) |
Check if is a page when WPML is in use; takes in consideration all the translations.
string | array | $page_title | The page title as string, or multiple page titles as an array. |
QueryHelper::is_post_type | ( | $type | ) |
Check if post type is the one specified.
string | $type | Type of the post to be compared. |
UrlHelper::is_relative_url | ( | $url | ) |
Check if an URL is relative URL are considered relative if they are not absolute and don't begin with a /.
string | $url | The url to check. |
UrlHelper::is_root_relative_url | ( | $url | ) |
Check if an URL is root relative URL are considered root relative if they are not absolute but begin with a /.
string | $url | The url to check. |
ConditionalHelper::is_subpage | ( | $id = NULL | ) |
Check if the page is a subpage and return the parent post ID if true.
int | $id | (optional) If you pass an ID to the function, will check if the current page is subpage of the specified parent page. |
TextHelper::is_valid_url | ( | $url | ) |
Check if the string passed as parameter is a valid URL.
NO SANITAZE IS PERFORMED on the URL! URL like this: http://example.com/"><script>alert(document.cookie)</script> DO PASS validation (syntactically are valid URLs).
string | $url | A URL to be validated. |
AssetTagHelper::javascript_include_tag | ( | ) |
Returns an HTML script tag for each of the sources provided as arguments.
Sources may be paths to JavaScript files. Relative paths are assumed to be relative to assets/javascripts. When passing paths, the ".js" extension is optional. If the last argument is an array, it will be used as tag attributes.
UrlHelper::javascript_url | ( | $path | ) |
Returns the URL path to the specified folder in the javascript directory.
string | $path | The path inside the {theme}/assets/javascript/ folder. |
QueryHelper::latest_post_of_category | ( | $category, | |
$post_type = 'post' , |
|||
$taxonomy = 'category' |
|||
) |
Get the last post of the specified category.
string | $category | See QueryHelper::latest_posts_of_category(). |
string | $post_type | See QueryHelper::latest_posts_of_category(). |
string | $taxonomy | (optional) See QueryHelper::latest_posts_of_category(). |
QueryHelper::latest_post_of_type | ( | $type, | |
$order = 'date' |
|||
) |
Get the last post of the specified type.
string | $type | See QueryHelper::latest_posts_of_type(). |
string | $order | (optional) See QueryHelper::latest_posts_of_type(). |
QueryHelper::latest_posts_of_category | ( | $category, | |
$limit, | |||
$offset = 0 , |
|||
$post_type = 'post' , |
|||
$taxonomy = 'category' , |
|||
$order = 'date' , |
|||
$ord = 'DESC' |
|||
) |
Get last posts of specified category.
string | $category | Name of the category used to filter posts. |
int | $limit | Maximum number of post to be retrieved. |
int | $offset | (optional) Number of post to skip while retrieveing results. |
string | $post_type | (optional) Filter results by post type. |
string | $taxonomy | (optional) Taxonomy to query to retrieve posts. |
string | $order | (optional) The order in which sort the post retrieved. See WP docs for list of available values. |
string | $ord | (optional) Can be ASC for ascending or DESC for descending. |
QueryHelper::latest_posts_of_type | ( | $type, | |
$limit = -1 , |
|||
$order = 'date' , |
|||
$ord = 'DESC' |
|||
) |
Get last posts of specified type.
string | $type | Post type used to filter result posts. |
int | $limit | (optional) Maximum number of post to be retrieved. |
string | $order | (optional) The order in which sort the post retrieved. See WP docs for list of available values. |
string | $ord | (optional) Can be ASC for ascending or DESC for descending. |
ModelHelper::new_post_type | ( | $name, | |
$supports = array("title", "editor") , |
|||
$options = array() |
|||
) |
Creates a new post type.
This function use the WP APIs and functions to register a new post type.
string | array | $name | The name of the new post type (will appear in the backend). If the name is a sting, the plural will be evaluated by the system; if is an array, must contains the singular and the plural versions of the name. Ex: $name = array(
"singular" => 'My custom post type',
"plural" => 'My custom post types'
);
|
array | $supports | (optional) Extra fields added to this post type. Default fields (the fields you can find in page/post type) are added by default. |
array | $options | (optional) An optional array to override default options passed to register_post_type(). |
ModelHelper::new_taxonomy | ( | $name, | |
$post_types, | |||
$options = array() |
|||
) |
Create a new taxonomy.
string | $name | The name of the taxonomy. |
array | string | $post_types | Name of the object type for the taxonomy object. Object-types can be built-in objects (see below) or any custom post type that may be registered. |
array | $options | (optional) An optional array to override default options passed to register_taxonomy(). |
NumberHelper::number_to_currency | ( | $number, | |
$options = array() |
|||
) |
Translates number to currency.
integer | $number | The number to translate |
array | $options | (optional) Associative array. Accepts keys: 'format' (defaults to un), 'unit'. |
FakerHelper::placeholder_image | ( | $width, | |
$height, | |||
$options = array() |
|||
) |
Generate a placeholder image.
Using the specified sevice provide a placeholder image.
Placeholder Services available are described here placeholders.
To implement your service please check the Placeholder Services.
int | $width | The width of the placeholder image. |
int | $height | The height of the placeholder image. |
array | $options | (optional) An option array to be passed to the PHP Class handling the placeholder service. See the placeholder service docs for details. |
FakerHelper::placeholder_text | ( | $count, | |
$options = array() |
|||
) |
Generate placeholder text.
Using the famous Lorem Ipsum base text, generate a dummy text based on specified options.
int | $count | The length in words of the dummy text. |
array | $options | (optional) An array of options to manage text generation. Options available are:
|
TextHelper::pluralize | ( | $string | ) |
Attempts to pluralize the specified text.
string | $string | The string to be pluralized. |
TextHelper::reset_cycle | ( | $name = "default" | ) |
Reset the cycle pointer.
string | $name | (optional) The specified name of the cycle to reset. |
MediaHelper::resize_image | ( | $src, | |
$width, | |||
$height | |||
) |
Resizes the specified image to the specified dimensions.
The crop will be centered relative to the image.
string | $src | The path to the image to be resized |
int | $width | The width at which the image will be cropped |
int | $height | The height at which the image will be cropped |
Cropped images are stored in template tmp folder.
AssetTagHelper::stylesheet_link_tag | ( | ) |
Returns a stylesheet link tag for the sources specified as arguments.
If you don’t specify an extension, ".css" will be appended automatically. Relative paths are assumed to be relative to assets/javascripts. If the last argument is an array, it will be used as tag attributes.
UrlHelper::stylesheet_url | ( | $path | ) |
Returns the URL path to the specified folder in the stylesheet directory.
string | $path | The path inside the {theme}/assets/stylesheet/ folder. |
DateHelper::time_ago_in_words | ( | $from_time, | |
$include_seconds = false |
|||
) |
Like distance_of_time_in_words() but with fixed value of $to_time.
This functions is a shorthand for distance_of_time_in_words($from_time, time(), $include_seconds).
DateHelper::time_tag | ( | $date_or_time = NULL , |
|
$text = NULL , |
|||
$attributes = array() |
|||
) |
Builds a valid <time /> HTML tag.
string | $date_or_time | (optional) A valid timestamp representing a valid date or time objects. If no timestamp is passed, use the current date with the DATE_W3C PHP predefined DateTime constant as date description. |
string | $text | (optional) The text of the time HTML tag. |
array | $attributes | (optional) An array of HTML attributes to be added to the rendered tag. |
TextHelper::titleize | ( | $text | ) |
Capitalizes the first letter of every word.
string | $text | The text to be capitalized. |
TextHelper::truncate | ( | $text, | |
$options = array() |
|||
) |
Truncate the text to the specified length.
string | $text | The text to be truncated. |
array | $options | (optional) An array with options to be passed to the function. Available options:
|
AssetTagHelper::video_tag | ( | $sources, | |
$attributes = NULL |
|||
) |
Builds a valid <video /> HTML tag.
string | array | $sources | If sources is a string, a single video tag will be returned. If sources is an array, a video tag with nested source tags for each source will be returned. |
array | $attributes | (optional) An array of HTML attributes to be added to the rendered tag. |