Version
Version

Helpers

Helpers are framework utility functions you can use anywhere. They are functions that run on the global scope.

td($value)

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);

tp($value)

This function prints a $value. Useful for debugging.

$value = 42;

tp($value);

themosis_theme_assets()

This function returns the URL path of the themosis-theme assets dist directory. Useful if you want to point to an asset without using the Asset class.

// http://.../wp-content/themes/themosis-theme/dist/images/favicon.ico
$iconUrl = themosis_theme_assets().'/images/favicon.ico';

The previous function themosis_assets() is now deprecated.

themosis_is_post($id)

  • param int
  • return boolean

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.
}

themosis_attachment_id_from_url($url)

  • param string
  • return int|boolean

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);

themosis_path($name)

  • param string
  • return string

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:

  • plugin: Returns the Themosis framework plugin path.
  • sys: Returns the Themosis framework plugin src/Themosis path.
  • storage: Returns the storage folder path.
  • base: Returns the theme path.
  • theme: Returns the theme resources path.
  • admin: Returns the theme resources/admin path.

themosis_set_path(array $paths)

  • param array A list of paths to register using key/value pairs.

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');

themosis_is_subpage($parent)

  • param array Parent page properties (ID, slug, post name, ...)
  • return int|bool

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

themosis_convert_path($path)

  • param string
  • return string

Replaces all '.' characters to the '/' directory seperator

// assets/images/header
$value = themosis_convert_path('assets.images.header')

themosis_plugin_directory_name()

  • return string

Returns the directory name of the core themosis framework plugin.

themosis_plugin_url()

  • return string

Retrieves the absolute URL to the core themosis framework plugin.

themosis_get_the_query()

  • return _WPQuery

Returns the current WordPress query inside the $wp_query global

themosis_use_permalink()

  • return bool

Returns whether the WordPress pretty permalink structure is used.

themosis_add_filters($tags, $function)

  • param array, function
  • return bool

Runs the add_filter() function multiple times for every given tag in the $tags array parameter using the given function in the $function argument.

themosis_is_template($name = [])

  • param array
  • return bool

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

e($value)

  • param string Raw data.
  • return string Escaped data.

Escapes HTML entities in a string. This function uses the htmlentities() PHP core function.

$escaped = e('<p>Raw input</p>');

starts_with($haystack, $needles)

  • param string, string|array
  • return bool

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

array_get($array, $key, $default)

  • param array, string, mixed
  • return mixed

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'

array_set($array, $key, $value)

  • param array $array
  • param string $key
  • param mixed $value
  • return array

Set an array item to a given value using "dot" notation. If no key is given to the method, the entire array will be replaced.

$array = array_set($array, 'items.first', 'blue');

array_except($array, $keys)

  • param array $array
  • param string $keys
  • return array

Get all of the given array except for a specified array of items (keys).

$array = array_except(['a' => 1, 'b' => 2, 'c' => 3], ['b']);

array_is_sequential($array)

  • param array $array
  • return bool

Check if an array is sequential (have keys from 0 to n) or not.

array_is_sequential(['red', 'green', 'blue']); return true
array_is_sequential([3 => 'red', 42 => 'green', 119 => 'blue']); return false

value($value)

  • param mixed $value
  • return mixed

Return the default value of the given value.

$value = value($var);

with($object)

  • param mixed $object
  • return mixed

Return the given object. Useful for chaining.

$val = with($instance)->get();

str_contains($haystack, $needles)

  • param string $haystack
  • param string | array $needles
  • return bool

Determine if a given string contains a given substring.

str_contains('This is a comment', 'comment'); // return true
str_contains('This is a comment', ['is', 'comment']); // return true
str_contains('This is a comment', 'post'); // return false

app($instance) & container($instance)

  • param string $instance

Helper function to return any instance registerd into the service container.

$config = container('config'); // return the config instance
$factory = container('view'); // return the view factory instance
$twig = container('twig'); // return the twig environment instance

view($name, $data, $mergeData)

  • param string $name
  • param array $data
  • param array $mergeData
  • return string

Helper function to build views.

$view = view('pages', ['title' => 'Custom page']);

meta($key, $id, $context, $single)

  • param string $key
  • param int $id
  • param string $context
  • param bool $single
  • return mixed|string

Helper function to get any meta data from objects.

$value = meta('_wp_page_template', $id);
$term_order = meta('order', $term_id, 'term');

Newsletter

Subscribe to our mailing list and stay notified regarding future framework releases and its related services.

Made in Belgium