This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(function() { | |
| /** | |
| * Get the closest element of a given element by class | |
| * | |
| * Take an element (the firt param), and traverse the DOM upward from it | |
| * untill it hits the element with a given class name (second parameter). | |
| * This mimics jquery's `.closest()`. | |
| * | |
| * @param {element} el The element to start from | |
| * @param {string} clazz The class name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| define(function() { | |
| return { | |
| /** | |
| * Adds a class name to an element | |
| * @param {element} el The target element | |
| * @param {string} clazz The class names wanted to add | |
| */ | |
| add: function addClass(el, clazz) { | |
| var cn = el.className; | |
| // Test for existance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Gets a slug of a custom posty | |
| * @param string $post_type The post type wanted | |
| * @return string Slug for the post type | |
| */ | |
| function slugger($post_type) | |
| { | |
| if ($post_type) { | |
| $post_type_data = get_post_type_object($post_type); | |
| $post_type_slug = $post_type_data->rewrite['slug']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Returns a URL to the page where user was before this page | |
| * @param string $domain The sites domain name | |
| * @param string $exeption_path The path to go to if not referer is not your site | |
| * @return string URL string | |
| */ | |
| function pps_back_href($domain, $exeption_path) | |
| { | |
| // Get the referer, aka where user comes | |
| $referer = htmlspecialchars($_SERVER['HTTP_REFERER']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Strips http:// and https:// and www. and the trailing slash / from URL | |
| * @param string $url The URL to be processed | |
| * @return string Modified URL | |
| */ | |
| function strip_crap_from_url($url) | |
| { | |
| return preg_replace('/https?:\/\/|www.|\/$/', '', $url); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Cut string to lenght and add prefix | |
| * @param string $string The string to truncate | |
| * @param int $length The amount of characters wanted | |
| * @param string $prefix The prefix, default ... | |
| * @return string The modified string | |
| */ | |
| function str_truncater($string, $length, $prefix = '...') | |
| { | |
| return strlen($string) > $length ? substr($string, 0, $length).$prefix : $string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Gets an attachement image as lazy loaded img based on ID | |
| * @param string $size Thumbnail, medium, large, original, or {custom size} | |
| * @param string $class CSS class name for the img tag | |
| * @param integer $attachment_id ID of the attachment | |
| * @param string $attachment_id The custom src atrribute to use, default to data-echo | |
| * @return string Lazyload friendly HTML img tag | |
| */ | |
| function get_attachemt_lazy($size, $class, $attachment_id = "", $src_attr = "data-echo") | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get SVG file as raw SVG, not img tag | |
| * @param string $path Path to images direcotry | |
| * @param string $file The filename, file extension (.svg) can be omitted | |
| * @return string The contents of the wanted SVG file | |
| */ | |
| function cm_svg_get($path = 'images', $file = '') | |
| { | |
| // $file = $file.".svg"; | |
| $svg = ".svg"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Prints out array in human readable form, just a helper function | |
| * @param array $arr The wanted array to be printed | |
| * @return array The array in human readable form | |
| */ | |
| function printr_func($arr) | |
| { | |
| echo "<pre class='printr'><code>"; | |
| print_r($arr); | |
| echo "</code></pre>"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Adds a custom class to excerpt `p` tah | |
| * @param string $class The wanted new class | |
| * @return string `p` tag with a class and the content of the excerpt | |
| */ | |
| function cm_excerpt($class) | |
| { | |
| $excerpt = strip_tags(get_the_excerpt()); | |
| echo '<p class="' . $class . '">' . $excerpt . '</p>'; | |
| } |