Helpers are framework utility functions you can use anywhere. They are functions that run on the global scope.
This function prints a $value
and terminate the PHP process immediately by calling the wp_die()
function. Useful for debugging.
$value = 'A string value';
td($value);
This function prints a $value
. Useful for debugging.
$value = 42;
tp($value);
This function returns the URL path of the themosis-theme
assets directory. Useful if you want to point to an asset without using the Asset
class.
// http://.../wp-content/themes/themosis-theme/app/assets/images/favicon.ico
$iconUrl = themosis_assets().'/images/favicon.ico';
Note: In a subfolder multisite installation, this function will check if the
themosis_theme_assets()
function exists. If so, will use it in order to get the proper URL. Thethemosis_theme_assets()
function is available since release 1.2.0 inside thefunctions.php
file of your theme.
A function that checks you're on a specified admin page, post or custom post type(edit screen) in order to display a specific content.
$page = get_page_by_title('Home');
if (themosis_is_post($page->ID))
{
// You're on Home page.
// Do something for the Home page only.
}
This function returns an attachment ID
based on the URL/path given. If no attachment is found, it returns false
.
$url = 'http://www.domain.com/wp-content/uploads/2014/02/Image150x150.jpg';
// Return the media attachment ID
$id = themosis_attachment_id_from_url($url);
This function returns the real path of each part of the framework you ask for by providing the $name
parameter.
Here is the list of available values you can pass:
src/Themosis
path.resources
path.resources/admin
path.The themosis_set_path
function allows you to register paths to your project. Those paths are registered globally and are accessible by using the themosis_path
function.
// Register a new path - A custom folder inside the content directory
$paths['custom'] = WP_CONTENT_DIR.'/custom/';
themosis_set_path($paths);
You can then use your path like so:
$path = themosis_path('custom');
This function returns whether current post is a child page of the current page. By giving a string in the first index of the $parent
parameter you can give the slug of the post parent to check where the current page is a child from.
$parent = themosis_is_subpage(['existing-parent-page']) // WP_Post instance of the parent page of the current page
$parent = themosis_is_subpage(['non-existing-parent-page']) // false
Replaces all '.' characters to the '/' directory seperator
// assets/images/header
$value = themosis_convert_path('assets.images.header')
Returns the directory name of the core themosis framework plugin.
Retrieves the absolute URL to the core themosis framework plugin.
Returns the current WordPress query inside the $wp_query
global
Returns whether the WordPress pretty permalink structure is used.
Runs the add_filter()
function multiple times for every given tag in the $tags
array parameter using the given function in the $function
argument.
Checks whether the themosis template which is currently used is available in the given array of template names.
// Current page template is 'page-template'
themosis_is_template(['test', 'page-template']) // true
Escapes HTML entities in a string. This function uses the htmlentities()
PHP core function.
$escaped = e('<p>Raw input</p>');
Checks whether a given string starts with a given substring.
starts_with('foo bar', 'foo') // true
starts_with('foo bar', ['non-existing-string', 'foo']) // true
Get an item of an array using a "." notation
$array = ['items' => [
'first-item' => 'I am the first item',
'second-item' => 'I am the second Item'
]
]
$item = array_get($array, 'items.first-item', 'no key found') // 'I am the first item'
$item = array_get($array, 'items.third-item', 'No item found') // 'No item found'
Made in Belgium