we develop communication with weLaika Advertising

New Wordless helpers

Tags: wordless, wordpress, helpers, php
Filippo Gangi Dino -

We use WordPress and we love Wordless, our framework. Here is a summary of a new set of Wordless helpers, that you’ll find in the new version.

1
is_subpage($id)

Implements WordPress Conditional Tags.

Checks if the current page is a subpage and returns the parent post ID if true. if you pass a page ID as a parameter it can check if it is a subpage of a specific parent page.

1
is_valid_url($url)

Checks if the string $url is a valid URL

1
resize_image($src, $width, $height)

Resizes the specified image to the specified dimensions.

The crop will be centered relatively to the image.

If the file does not exist, it will be created and saved into the tmp folder.

After the first creation, the cached file will be served when calling this function.

$src: The path of the image to be resized.

$width: The width at which the image will be cropped.

$height: The height at which the image will be cropped.

return string: The valid URL to the resized image.

1
get_post_attachments($post_id)

Gets the attached files in a post ($post_id)

1
get_current_attachment()

Gets the attached files in current post

1
detect_user_agent()

This function includes a PHP class (Mobile Detect - Version 2.5.2 - commit b5b8992dbe) to detect mobile devices and user agent details. To use it, simply call the function detect_user_agent() in your view and then call one of the avaible methods.

Example: $detect->isMobile() More details here https://github.com/serbanghita/Mobile-Detect

1
truncate($text, $options = array()) //UPDATE

Truncates the text to the specified length.

$text: The text to be truncated.

$options (optional): An array with options to be passed to the function.

Available options:

  • length (default 30): the length at which truncate the text
  • omission (default ’...’): the suffix string to be added to the truncate text
  • word_count (default FALSE): if it’s TRUE the length is counted in words, if it’s FALSE it’s counted in characters
  • separator (default FALSE): the separator string used to trim the argument
  • html (default FALSE): sets if you want to preserve html in the string. If it’s set to false remove ALL HTML tags.
  • allowed_tags (default array('b', 'i', 'em', 'strong')): if html is TRUE it preserves the allowed tags. If this parameter is set to ’all’, the function will leave untouched the string.

Return: The truncated text.

Good work!

welaika