id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
46,000
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.getTopLevelPages
protected function getTopLevelPages() { $topLevelQuery = new \WP_Query(array( 'post_parent' => 0, 'post_type' => 'page', 'post_status' => $this->postStatuses, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ) )); $this->topLevelPages = $topLevelQuery->posts; return $this->topLevelPages; }
php
protected function getTopLevelPages() { $topLevelQuery = new \WP_Query(array( 'post_parent' => 0, 'post_type' => 'page', 'post_status' => $this->postStatuses, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ) )); $this->topLevelPages = $topLevelQuery->posts; return $this->topLevelPages; }
[ "protected", "function", "getTopLevelPages", "(", ")", "{", "$", "topLevelQuery", "=", "new", "\\", "WP_Query", "(", "array", "(", "'post_parent'", "=>", "0", ",", "'post_type'", "=>", "'page'", ",", "'post_status'", "=>", "$", "this", "->", "postStatuses", ...
Gets top level pages @return void
[ "Gets", "top", "level", "pages" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L130-L158
46,001
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.getSecondLevelPages
protected function getSecondLevelPages() { $secondLevel = array(); foreach ($this->topLevelPages as $topLevelPage) { $pages = get_posts(array( 'post_parent' => $topLevelPage->ID, 'post_type' => 'page', 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1 )); $secondLevel[$topLevelPage->ID] = $pages; } $this->secondLevelPages = $secondLevel; return $secondLevel; }
php
protected function getSecondLevelPages() { $secondLevel = array(); foreach ($this->topLevelPages as $topLevelPage) { $pages = get_posts(array( 'post_parent' => $topLevelPage->ID, 'post_type' => 'page', 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1 )); $secondLevel[$topLevelPage->ID] = $pages; } $this->secondLevelPages = $secondLevel; return $secondLevel; }
[ "protected", "function", "getSecondLevelPages", "(", ")", "{", "$", "secondLevel", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "topLevelPages", "as", "$", "topLevelPage", ")", "{", "$", "pages", "=", "get_posts", "(", "array", "(", "'...
Gets second level pages @return array
[ "Gets", "second", "level", "pages" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L164-L182
46,002
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.walk
protected function walk($pages, $depth = 1, $classes = null) { $this->currentDepth = $depth; if ($this->args['sublevel']) { $this->startWrapper($classes, $depth === 1); } if (!is_array($pages)) { return; } foreach ($pages as $page) { $pageId = $this->getPageId($page); $attributes = array(); $attributes['class'] = array(); $output = true; if (is_numeric($page)) { $page = get_post($page); } if ($this->isAncestors($pageId)) { $attributes['class'][] = 'current-node current-menu-ancestor'; if (count($this->getChildren($pageId)) > 0) { $attributes['class'][] = 'is-expanded'; } } if ($this->getPageId($this->currentPage) == $pageId) { $attributes['class'][] = 'current current-menu-item'; if (count($this->getChildren($this->currentPage->ID)) > 0 && $depth != $this->args['depth']) { $attributes['class'][] = 'is-expanded'; } } if (($this->isAjaxParent && $depth === 1) || $depth < $this->args['start_depth']) { $output = false; } $this->item($page, $depth, $attributes, $output); } if ($this->args['sublevel']) { $this->endWrapper($depth === 1); } }
php
protected function walk($pages, $depth = 1, $classes = null) { $this->currentDepth = $depth; if ($this->args['sublevel']) { $this->startWrapper($classes, $depth === 1); } if (!is_array($pages)) { return; } foreach ($pages as $page) { $pageId = $this->getPageId($page); $attributes = array(); $attributes['class'] = array(); $output = true; if (is_numeric($page)) { $page = get_post($page); } if ($this->isAncestors($pageId)) { $attributes['class'][] = 'current-node current-menu-ancestor'; if (count($this->getChildren($pageId)) > 0) { $attributes['class'][] = 'is-expanded'; } } if ($this->getPageId($this->currentPage) == $pageId) { $attributes['class'][] = 'current current-menu-item'; if (count($this->getChildren($this->currentPage->ID)) > 0 && $depth != $this->args['depth']) { $attributes['class'][] = 'is-expanded'; } } if (($this->isAjaxParent && $depth === 1) || $depth < $this->args['start_depth']) { $output = false; } $this->item($page, $depth, $attributes, $output); } if ($this->args['sublevel']) { $this->endWrapper($depth === 1); } }
[ "protected", "function", "walk", "(", "$", "pages", ",", "$", "depth", "=", "1", ",", "$", "classes", "=", "null", ")", "{", "$", "this", "->", "currentDepth", "=", "$", "depth", ";", "if", "(", "$", "this", "->", "args", "[", "'sublevel'", "]", ...
Walks pages in the menu @param array $pages Pages to walk @return void
[ "Walks", "pages", "in", "the", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L189-L236
46,003
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.getCurrentPage
protected function getCurrentPage() { if (is_post_type_archive()) { $pageForPostType = get_option('page_for_' . get_post_type()); return get_post($pageForPostType); } global $post; if (!is_object($post)) { return get_queried_object(); } return $post; }
php
protected function getCurrentPage() { if (is_post_type_archive()) { $pageForPostType = get_option('page_for_' . get_post_type()); return get_post($pageForPostType); } global $post; if (!is_object($post)) { return get_queried_object(); } return $post; }
[ "protected", "function", "getCurrentPage", "(", ")", "{", "if", "(", "is_post_type_archive", "(", ")", ")", "{", "$", "pageForPostType", "=", "get_option", "(", "'page_for_'", ".", "get_post_type", "(", ")", ")", ";", "return", "get_post", "(", "$", "pageFor...
Gets the current page object @return object
[ "Gets", "the", "current", "page", "object" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L281-L295
46,004
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.getChildren
protected function getChildren($parent) { $key = array_search($parent, $this->getPageForPostTypeIds()); if ($key && is_post_type_hierarchical($key)) { $inMenu = false; foreach (get_field('avabile_dynamic_post_types', 'options') as $type) { if (sanitize_title(substr($type['post_type_name'], 0, 19)) !== $key) { continue; } $inMenu = $type['show_posts_in_sidebar_menu']; } if ($inMenu) { return get_posts(array( 'post_type' => $key, 'post_status' => $this->postStatuses, 'post_parent' => 0, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ), 'OBJECT'); } return array(); } return get_posts(array( 'post_parent' => $parent, 'post_type' => get_post_type($parent), 'post_status' => $this->postStatuses, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ) ), 'OBJECT'); }
php
protected function getChildren($parent) { $key = array_search($parent, $this->getPageForPostTypeIds()); if ($key && is_post_type_hierarchical($key)) { $inMenu = false; foreach (get_field('avabile_dynamic_post_types', 'options') as $type) { if (sanitize_title(substr($type['post_type_name'], 0, 19)) !== $key) { continue; } $inMenu = $type['show_posts_in_sidebar_menu']; } if ($inMenu) { return get_posts(array( 'post_type' => $key, 'post_status' => $this->postStatuses, 'post_parent' => 0, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ), 'OBJECT'); } return array(); } return get_posts(array( 'post_parent' => $parent, 'post_type' => get_post_type($parent), 'post_status' => $this->postStatuses, 'orderby' => 'menu_order post_title', 'order' => 'asc', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'relation' => 'OR', array( 'key' => 'hide_in_menu', 'compare' => 'NOT EXISTS' ), array( 'key' => 'hide_in_menu', 'value' => '0', 'compare' => '=' ) ) ) ), 'OBJECT'); }
[ "protected", "function", "getChildren", "(", "$", "parent", ")", "{", "$", "key", "=", "array_search", "(", "$", "parent", ",", "$", "this", "->", "getPageForPostTypeIds", "(", ")", ")", ";", "if", "(", "$", "key", "&&", "is_post_type_hierarchical", "(", ...
Get page children @param integer $parent The parent page ID @return object Page objects for children
[ "Get", "page", "children" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L302-L366
46,005
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.isAncestors
protected function isAncestors($id) { $ancestors = $this->ancestors; $baseParent = $this->getAncestors($this->currentPage); if (is_array($baseParent) && !empty($baseParent)) { $ancestors = array_merge($ancestors, $baseParent); } return in_array($id, $ancestors); }
php
protected function isAncestors($id) { $ancestors = $this->ancestors; $baseParent = $this->getAncestors($this->currentPage); if (is_array($baseParent) && !empty($baseParent)) { $ancestors = array_merge($ancestors, $baseParent); } return in_array($id, $ancestors); }
[ "protected", "function", "isAncestors", "(", "$", "id", ")", "{", "$", "ancestors", "=", "$", "this", "->", "ancestors", ";", "$", "baseParent", "=", "$", "this", "->", "getAncestors", "(", "$", "this", "->", "currentPage", ")", ";", "if", "(", "is_arr...
Checks if a specific id is in the ancestors array @param integer $id @return boolean
[ "Checks", "if", "a", "specific", "id", "is", "in", "the", "ancestors", "array" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L413-L422
46,006
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.startItem
protected function startItem($item, $attributes = array(), $hasChildren = false) { if (!$this->shouldBeIncluded($item) || !is_object($item)) { return; } $this->itemCount++; $outputSubmenuToggle = false; $attributes['class'][] = 'page-' . $item->ID; if ($hasChildren && ($this->args['depth'] === -1 || $this->currentDepth < $this->args['depth'] + 1)) { $outputSubmenuToggle = true; if (array_search('has-children', $attributes['class']) > -1) { unset($attributes['class'][array_search('has-children', $attributes['class'])]); } } $title = isset($item->post_title) ? $item->post_title : ''; $objId = $this->getPageId($item); if (isset($item->post_type) && $item->post_type == 'nav_menu_item') { $title = $item->title; } if (!empty(get_field('custom_menu_title', $objId))) { $title = get_field('custom_menu_title', $objId); } $href = get_permalink($objId); if (isset($item->type) && $item->type == 'custom') { $href = $item->url; } if ($outputSubmenuToggle) { $this->addOutput(sprintf( '<li%1$s><a href="%2$s">%3$s</a>', $this->attributes($attributes), $href, $title )); $this->addOutput('<button data-load-submenu="' . $objId . '"><span class="sr-only">' . __('Show submenu', 'municipio') . '</span><span class="icon"></span></button>'); } else { $this->addOutput(sprintf( '<li%1$s><a href="%2$s">%3$s</a>', $this->attributes($attributes), $href, $title )); } }
php
protected function startItem($item, $attributes = array(), $hasChildren = false) { if (!$this->shouldBeIncluded($item) || !is_object($item)) { return; } $this->itemCount++; $outputSubmenuToggle = false; $attributes['class'][] = 'page-' . $item->ID; if ($hasChildren && ($this->args['depth'] === -1 || $this->currentDepth < $this->args['depth'] + 1)) { $outputSubmenuToggle = true; if (array_search('has-children', $attributes['class']) > -1) { unset($attributes['class'][array_search('has-children', $attributes['class'])]); } } $title = isset($item->post_title) ? $item->post_title : ''; $objId = $this->getPageId($item); if (isset($item->post_type) && $item->post_type == 'nav_menu_item') { $title = $item->title; } if (!empty(get_field('custom_menu_title', $objId))) { $title = get_field('custom_menu_title', $objId); } $href = get_permalink($objId); if (isset($item->type) && $item->type == 'custom') { $href = $item->url; } if ($outputSubmenuToggle) { $this->addOutput(sprintf( '<li%1$s><a href="%2$s">%3$s</a>', $this->attributes($attributes), $href, $title )); $this->addOutput('<button data-load-submenu="' . $objId . '"><span class="sr-only">' . __('Show submenu', 'municipio') . '</span><span class="icon"></span></button>'); } else { $this->addOutput(sprintf( '<li%1$s><a href="%2$s">%3$s</a>', $this->attributes($attributes), $href, $title )); } }
[ "protected", "function", "startItem", "(", "$", "item", ",", "$", "attributes", "=", "array", "(", ")", ",", "$", "hasChildren", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "shouldBeIncluded", "(", "$", "item", ")", "||", "!", "is_obje...
Opens a menu item @param object $item The menu item @param array $classes Classes @return void
[ "Opens", "a", "menu", "item" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L444-L497
46,007
helsingborg-stad/Municipio
library/Helper/NavigationTree.php
NavigationTree.shouldBeIncluded
public function shouldBeIncluded($item) { if (!is_object($item)) { return false; } $pageId = $this->getPageId($item); $showInMenu = get_field('hide_in_menu', $pageId) ? !get_field('hide_in_menu', $pageId) : true; $isNotTopLevelItem = !($item->post_type === 'page' && isset($item->post_parent) && $item->post_parent === 0); $showTopLevel = $this->args['include_top_level']; return ($showTopLevel || $isNotTopLevelItem) && $showInMenu; }
php
public function shouldBeIncluded($item) { if (!is_object($item)) { return false; } $pageId = $this->getPageId($item); $showInMenu = get_field('hide_in_menu', $pageId) ? !get_field('hide_in_menu', $pageId) : true; $isNotTopLevelItem = !($item->post_type === 'page' && isset($item->post_parent) && $item->post_parent === 0); $showTopLevel = $this->args['include_top_level']; return ($showTopLevel || $isNotTopLevelItem) && $showInMenu; }
[ "public", "function", "shouldBeIncluded", "(", "$", "item", ")", "{", "if", "(", "!", "is_object", "(", "$", "item", ")", ")", "{", "return", "false", ";", "}", "$", "pageId", "=", "$", "this", "->", "getPageId", "(", "$", "item", ")", ";", "$", ...
Datermines if page should be included in the menu or not @param object $item The menu item @return boolean
[ "Datermines", "if", "page", "should", "be", "included", "in", "the", "menu", "or", "not" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L592-L604
46,008
helsingborg-stad/Municipio
library/Helper/ReCaptcha.php
ReCaptcha.controlReCaptcha
public static function controlReCaptcha($response) : bool { $g_recaptcha_secret = defined('G_RECAPTCHA_SECRET') ? G_RECAPTCHA_SECRET : ''; // Make a GET request to the Google reCAPTCHA server $request = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $g_recaptcha_secret . '&response=' . $response . '&remoteip=' . $_SERVER["REMOTE_ADDR"]); // Get the request response body $response_body = wp_remote_retrieve_body($request); $result = json_decode($response_body, true); return $result['success']; }
php
public static function controlReCaptcha($response) : bool { $g_recaptcha_secret = defined('G_RECAPTCHA_SECRET') ? G_RECAPTCHA_SECRET : ''; // Make a GET request to the Google reCAPTCHA server $request = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $g_recaptcha_secret . '&response=' . $response . '&remoteip=' . $_SERVER["REMOTE_ADDR"]); // Get the request response body $response_body = wp_remote_retrieve_body($request); $result = json_decode($response_body, true); return $result['success']; }
[ "public", "static", "function", "controlReCaptcha", "(", "$", "response", ")", ":", "bool", "{", "$", "g_recaptcha_secret", "=", "defined", "(", "'G_RECAPTCHA_SECRET'", ")", "?", "G_RECAPTCHA_SECRET", ":", "''", ";", "// Make a GET request to the Google reCAPTCHA server...
Check if Google reCaptcha request is valid @param string $response Google reCaptcha response @return bool If valid or not
[ "Check", "if", "Google", "reCaptcha", "request", "is", "valid" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/ReCaptcha.php#L12-L24
46,009
helsingborg-stad/Municipio
library/Helper/PostType.php
PostType.getPublic
public static function getPublic($filter = array()) { $postTypes = array(); foreach (get_post_types() as $key => $postType) { $args = get_post_type_object($postType); if (!$args->public || $args->name === 'page') { continue; } $postTypes[$postType] = $args; } if (!empty($filter)) { $postTypes = array_filter($postTypes, function ($item) use ($filter) { if (substr($item, 0, 4) === 'mod-') { return false; } return !in_array($item, $filter); }); } return $postTypes; }
php
public static function getPublic($filter = array()) { $postTypes = array(); foreach (get_post_types() as $key => $postType) { $args = get_post_type_object($postType); if (!$args->public || $args->name === 'page') { continue; } $postTypes[$postType] = $args; } if (!empty($filter)) { $postTypes = array_filter($postTypes, function ($item) use ($filter) { if (substr($item, 0, 4) === 'mod-') { return false; } return !in_array($item, $filter); }); } return $postTypes; }
[ "public", "static", "function", "getPublic", "(", "$", "filter", "=", "array", "(", ")", ")", "{", "$", "postTypes", "=", "array", "(", ")", ";", "foreach", "(", "get_post_types", "(", ")", "as", "$", "key", "=>", "$", "postType", ")", "{", "$", "a...
Get public post types @param array $filter Don't get these @return array
[ "Get", "public", "post", "types" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/PostType.php#L12-L37
46,010
helsingborg-stad/Municipio
library/Helper/PostType.php
PostType.postTypeRestUrl
public static function postTypeRestUrl($postType = null) { $restUrl = null; $postType = !$postType ? get_post_type() : $postType; $postTypeObj = get_post_type_object($postType); if ($postTypeObj && !empty($postTypeObj->show_in_rest) && !empty($postTypeObj->rest_base)) { $restUrl = esc_url_raw(get_rest_url() . 'wp/v2/' . $postTypeObj->rest_base); } return $restUrl; }
php
public static function postTypeRestUrl($postType = null) { $restUrl = null; $postType = !$postType ? get_post_type() : $postType; $postTypeObj = get_post_type_object($postType); if ($postTypeObj && !empty($postTypeObj->show_in_rest) && !empty($postTypeObj->rest_base)) { $restUrl = esc_url_raw(get_rest_url() . 'wp/v2/' . $postTypeObj->rest_base); } return $restUrl; }
[ "public", "static", "function", "postTypeRestUrl", "(", "$", "postType", "=", "null", ")", "{", "$", "restUrl", "=", "null", ";", "$", "postType", "=", "!", "$", "postType", "?", "get_post_type", "(", ")", ":", "$", "postType", ";", "$", "postTypeObj", ...
Get post type REST URL @param string|null $postType Post type slug @return string Post types REST URL
[ "Get", "post", "type", "REST", "URL" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/PostType.php#L44-L55
46,011
helsingborg-stad/Municipio
library/Search/Algolia.php
Algolia.excludeFromSearchCheckbox
public function excludeFromSearchCheckbox() { global $post; //Only show if not set to not index if (!$this->shouldIndexPost(true, $post, false)) { return false; } if (is_object($post) && isset($post->ID)) { $checked = checked(true, get_post_meta($post->ID, 'exclude_from_search', true), false); echo ' <div class="misc-pub-section"> <label><input type="checkbox" name="algolia-exclude-from-search" value="true" ' . $checked . '> ' . __('Exclude from search', 'municipio') . '</label> </div> '; } }
php
public function excludeFromSearchCheckbox() { global $post; //Only show if not set to not index if (!$this->shouldIndexPost(true, $post, false)) { return false; } if (is_object($post) && isset($post->ID)) { $checked = checked(true, get_post_meta($post->ID, 'exclude_from_search', true), false); echo ' <div class="misc-pub-section"> <label><input type="checkbox" name="algolia-exclude-from-search" value="true" ' . $checked . '> ' . __('Exclude from search', 'municipio') . '</label> </div> '; } }
[ "public", "function", "excludeFromSearchCheckbox", "(", ")", "{", "global", "$", "post", ";", "//Only show if not set to not index", "if", "(", "!", "$", "this", "->", "shouldIndexPost", "(", "true", ",", "$", "post", ",", "false", ")", ")", "{", "return", "...
Adds form field for exclude from search @return void
[ "Adds", "form", "field", "for", "exclude", "from", "search" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Algolia.php#L35-L52
46,012
helsingborg-stad/Municipio
library/Search/Algolia.php
Algolia.saveExcludeFromSearch
public function saveExcludeFromSearch($postId) { if (!isset($_POST['algolia-exclude-from-search']) || $_POST['algolia-exclude-from-search'] != 'true') { delete_post_meta($postId, 'exclude_from_search'); return; } update_post_meta($postId, 'exclude_from_search', true); }
php
public function saveExcludeFromSearch($postId) { if (!isset($_POST['algolia-exclude-from-search']) || $_POST['algolia-exclude-from-search'] != 'true') { delete_post_meta($postId, 'exclude_from_search'); return; } update_post_meta($postId, 'exclude_from_search', true); }
[ "public", "function", "saveExcludeFromSearch", "(", "$", "postId", ")", "{", "if", "(", "!", "isset", "(", "$", "_POST", "[", "'algolia-exclude-from-search'", "]", ")", "||", "$", "_POST", "[", "'algolia-exclude-from-search'", "]", "!=", "'true'", ")", "{", ...
Saves the "exclude from search" value @param int $postId The post id @return void
[ "Saves", "the", "exclude", "from", "search", "value" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Algolia.php#L60-L67
46,013
helsingborg-stad/Municipio
library/Search/Google.php
Google.search
public function search($keyword = null, $startingIndex = 1) { // Handle if keyword is null or empty string if ($keyword === null || $keyword === '') { return false; } $url = 'https://www.googleapis.com/customsearch/v1?key=' . $this->apiKey . '&cx=' . $this->apiCx . '&q=' . urlencode($keyword) . '&hl=sv&siteSearchFilter=i&alt=json&start=' . $startingIndex; $results = $this->request($url); return $results; }
php
public function search($keyword = null, $startingIndex = 1) { // Handle if keyword is null or empty string if ($keyword === null || $keyword === '') { return false; } $url = 'https://www.googleapis.com/customsearch/v1?key=' . $this->apiKey . '&cx=' . $this->apiCx . '&q=' . urlencode($keyword) . '&hl=sv&siteSearchFilter=i&alt=json&start=' . $startingIndex; $results = $this->request($url); return $results; }
[ "public", "function", "search", "(", "$", "keyword", "=", "null", ",", "$", "startingIndex", "=", "1", ")", "{", "// Handle if keyword is null or empty string", "if", "(", "$", "keyword", "===", "null", "||", "$", "keyword", "===", "''", ")", "{", "return", ...
Perform a search with the Google Custom Search API @param string $keyword The search query/keyword @param integer $start Starting search result index (used for pagination) @return object The search results
[ "Perform", "a", "search", "with", "the", "Google", "Custom", "Search", "API" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L35-L49
46,014
helsingborg-stad/Municipio
library/Search/Google.php
Google.request
public function request($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($ch); curl_close($ch); return json_decode($result); }
php
public function request($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($ch); curl_close($ch); return json_decode($result); }
[ "public", "function", "request", "(", "$", "url", ")", "{", "$", "ch", "=", "curl_init", "(", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_SSL_VERIFYHOST", ",", "...
Curl the Google API to get the search results @param string $url The url to curl @return object The result
[ "Curl", "the", "Google", "API", "to", "get", "the", "search", "results" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L56-L70
46,015
helsingborg-stad/Municipio
library/Search/Google.php
Google.getModifiedDate
public function getModifiedDate($item) { if (!isset($item->pagemap)) { return null; } $meta = $item->pagemap->metatags[0]; $dateMod = null; if (isset($meta->moddate)) { $dateMod = $meta->moddate; } elseif (isset($meta->pubdate)) { $dateMod = $meta->pubdate; } elseif (isset($meta->{'last-modified'})) { $dateMod = $meta->{'last-modified'}; } $dateMod = $this->convertDate($dateMod); return $dateMod; }
php
public function getModifiedDate($item) { if (!isset($item->pagemap)) { return null; } $meta = $item->pagemap->metatags[0]; $dateMod = null; if (isset($meta->moddate)) { $dateMod = $meta->moddate; } elseif (isset($meta->pubdate)) { $dateMod = $meta->pubdate; } elseif (isset($meta->{'last-modified'})) { $dateMod = $meta->{'last-modified'}; } $dateMod = $this->convertDate($dateMod); return $dateMod; }
[ "public", "function", "getModifiedDate", "(", "$", "item", ")", "{", "if", "(", "!", "isset", "(", "$", "item", "->", "pagemap", ")", ")", "{", "return", "null", ";", "}", "$", "meta", "=", "$", "item", "->", "pagemap", "->", "metatags", "[", "0", ...
Gets the modified date for an item @param object $item The item @return string The modified date
[ "Gets", "the", "modified", "date", "for", "an", "item" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L99-L119
46,016
helsingborg-stad/Municipio
library/Helper/Cache.php
Cache.start
public function start() { if (!$this->isActive()) { return true; } if (!$this->hasCache()) { ob_start(); return true; } $this->getCache(true); return false; }
php
public function start() { if (!$this->isActive()) { return true; } if (!$this->hasCache()) { ob_start(); return true; } $this->getCache(true); return false; }
[ "public", "function", "start", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isActive", "(", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "$", "this", "->", "hasCache", "(", ")", ")", "{", "ob_start", "(", ")", ";", "return",...
Starts the "cache engine" @return boolean Returns true if engine started or inactivated, returns false if previous cache is loaded
[ "Starts", "the", "cache", "engine" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L94-L107
46,017
helsingborg-stad/Municipio
library/Helper/Cache.php
Cache.stop
public function stop() { if (!$this->isActive() || $this->hasCache()) { return false; } // Get output buffer and save to cache $return_data = ob_get_clean(); if (!empty($return_data)) { $cacheArray = (array) wp_cache_get($this->postId, self::getKeyGroup()); $cacheArray[$this->hash] = $return_data.$this->fragmentTag(); wp_cache_delete($this->postId, self::getKeyGroup()); wp_cache_add($this->postId, array_filter($cacheArray), self::getKeyGroup(), $this->ttl); } echo $return_data; return true; }
php
public function stop() { if (!$this->isActive() || $this->hasCache()) { return false; } // Get output buffer and save to cache $return_data = ob_get_clean(); if (!empty($return_data)) { $cacheArray = (array) wp_cache_get($this->postId, self::getKeyGroup()); $cacheArray[$this->hash] = $return_data.$this->fragmentTag(); wp_cache_delete($this->postId, self::getKeyGroup()); wp_cache_add($this->postId, array_filter($cacheArray), self::getKeyGroup(), $this->ttl); } echo $return_data; return true; }
[ "public", "function", "stop", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isActive", "(", ")", "||", "$", "this", "->", "hasCache", "(", ")", ")", "{", "return", "false", ";", "}", "// Get output buffer and save to cache", "$", "return_data", "=",...
Stops the cache engine and saves the output buffer to the cache @return boolean
[ "Stops", "the", "cache", "engine", "and", "saves", "the", "output", "buffer", "to", "the", "cache" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L113-L134
46,018
helsingborg-stad/Municipio
library/Helper/Cache.php
Cache.createShortHash
private function createShortHash($input, $keysOnly = false) { if ($keysOnly === true && (is_array($input) || is_object($input))) { $input = array_keys($input); } if (is_array($input) || is_object($input)) { $input = substr(base_convert(md5(serialize($input)), 16, 32), 0, 12); return $input; } $input = substr(base_convert(md5($input), 16, 32), 0, 12); return $input; }
php
private function createShortHash($input, $keysOnly = false) { if ($keysOnly === true && (is_array($input) || is_object($input))) { $input = array_keys($input); } if (is_array($input) || is_object($input)) { $input = substr(base_convert(md5(serialize($input)), 16, 32), 0, 12); return $input; } $input = substr(base_convert(md5($input), 16, 32), 0, 12); return $input; }
[ "private", "function", "createShortHash", "(", "$", "input", ",", "$", "keysOnly", "=", "false", ")", "{", "if", "(", "$", "keysOnly", "===", "true", "&&", "(", "is_array", "(", "$", "input", ")", "||", "is_object", "(", "$", "input", ")", ")", ")", ...
Create a short hash from a value @param string $input Key @param boolean $keysOnly Set to true for keys only @return string Hash
[ "Create", "a", "short", "hash", "from", "a", "value" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L197-L210
46,019
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.getPostType
public function getPostType() { global $wp_query; // If taxonomy or category page and post type not isset then it's the "post" post type if (is_home() || ((is_tax() || is_category() || is_tag()) && is_a(get_queried_object(), 'WP_Term') && !get_post_type())) { return 'post'; } $postType = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : false; if (!$postType && isset($wp_query->query['category_name']) && !empty($wp_query->query['category_name'])) { $postType = 'post'; } if (is_array($postType)) { $postType = end($postType); } return $postType; }
php
public function getPostType() { global $wp_query; // If taxonomy or category page and post type not isset then it's the "post" post type if (is_home() || ((is_tax() || is_category() || is_tag()) && is_a(get_queried_object(), 'WP_Term') && !get_post_type())) { return 'post'; } $postType = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : false; if (!$postType && isset($wp_query->query['category_name']) && !empty($wp_query->query['category_name'])) { $postType = 'post'; } if (is_array($postType)) { $postType = end($postType); } return $postType; }
[ "public", "function", "getPostType", "(", ")", "{", "global", "$", "wp_query", ";", "// If taxonomy or category page and post type not isset then it's the \"post\" post type", "if", "(", "is_home", "(", ")", "||", "(", "(", "is_tax", "(", ")", "||", "is_category", "("...
Get post type @return string
[ "Get", "post", "type" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L26-L46
46,020
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.initFilters
public function initFilters() { //Only run on frontend if (is_admin()) { return; } global $wp_query; if ((is_category() || is_tax() || is_tag()) && !get_post_type()) { $postType = 'post'; } $postType = get_post_type(); if (!$postType && isset($wp_query->query['post_type'])) { $postType = $wp_query->query['post_type']; } if (!$postType) { return; } $queriedObject = get_queried_object(); $objectId = null; if (isset($queriedObject->ID)) { $objectId = $queriedObject->ID; } $pageForPosts = get_option('page_for_' . get_post_type()); if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) { return; } add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) { //Get current post type enabledTaxonomyFilters if (!isset($data['postType']) || !$data['postType']) { $data['postType'] = $postType; } //Get header filters if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) { $data['enabledHeaderFilters'] = $enabledHeaderFilters; } else { $data['enabledHeaderFilters'] = array(); } //Get taxonomy filters if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) { $data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters; } else { $data['enabledTaxonomyFilters'] = array(); } //Is query string present? $data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false; //The archive url $data['archiveUrl'] = $this->getArchiveSlug($postType); $data['searchQuery'] = $this->getSearchQuery(); return $data; }); }
php
public function initFilters() { //Only run on frontend if (is_admin()) { return; } global $wp_query; if ((is_category() || is_tax() || is_tag()) && !get_post_type()) { $postType = 'post'; } $postType = get_post_type(); if (!$postType && isset($wp_query->query['post_type'])) { $postType = $wp_query->query['post_type']; } if (!$postType) { return; } $queriedObject = get_queried_object(); $objectId = null; if (isset($queriedObject->ID)) { $objectId = $queriedObject->ID; } $pageForPosts = get_option('page_for_' . get_post_type()); if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) { return; } add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) { //Get current post type enabledTaxonomyFilters if (!isset($data['postType']) || !$data['postType']) { $data['postType'] = $postType; } //Get header filters if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) { $data['enabledHeaderFilters'] = $enabledHeaderFilters; } else { $data['enabledHeaderFilters'] = array(); } //Get taxonomy filters if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) { $data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters; } else { $data['enabledTaxonomyFilters'] = array(); } //Is query string present? $data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false; //The archive url $data['archiveUrl'] = $this->getArchiveSlug($postType); $data['searchQuery'] = $this->getSearchQuery(); return $data; }); }
[ "public", "function", "initFilters", "(", ")", "{", "//Only run on frontend", "if", "(", "is_admin", "(", ")", ")", "{", "return", ";", "}", "global", "$", "wp_query", ";", "if", "(", "(", "is_category", "(", ")", "||", "is_tax", "(", ")", "||", "is_ta...
Initialize the post filter UI @return void
[ "Initialize", "the", "post", "filter", "UI" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L52-L119
46,021
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.getSearchQuery
public function getSearchQuery() { $searchQuery = ''; if (!empty(get_search_query())) { $searchQuery = get_search_query(); } elseif (!empty($_GET['s'])) { $searchQuery = esc_attr($_GET['s']); } return $searchQuery; }
php
public function getSearchQuery() { $searchQuery = ''; if (!empty(get_search_query())) { $searchQuery = get_search_query(); } elseif (!empty($_GET['s'])) { $searchQuery = esc_attr($_GET['s']); } return $searchQuery; }
[ "public", "function", "getSearchQuery", "(", ")", "{", "$", "searchQuery", "=", "''", ";", "if", "(", "!", "empty", "(", "get_search_query", "(", ")", ")", ")", "{", "$", "searchQuery", "=", "get_search_query", "(", ")", ";", "}", "elseif", "(", "!", ...
Returns escaped search query @return string Search query
[ "Returns", "escaped", "search", "query" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L125-L135
46,022
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.sortTerms
public static function sortTerms($terms) { $sort_terms = array(); foreach ($terms as $term) { $sort_terms[$term->name] = $term; } uksort($sort_terms, 'strnatcmp'); return $sort_terms; }
php
public static function sortTerms($terms) { $sort_terms = array(); foreach ($terms as $term) { $sort_terms[$term->name] = $term; } uksort($sort_terms, 'strnatcmp'); return $sort_terms; }
[ "public", "static", "function", "sortTerms", "(", "$", "terms", ")", "{", "$", "sort_terms", "=", "array", "(", ")", ";", "foreach", "(", "$", "terms", "as", "$", "term", ")", "{", "$", "sort_terms", "[", "$", "term", "->", "name", "]", "=", "$", ...
Trying to sort terms natural @param $terms @return array
[ "Trying", "to", "sort", "terms", "natural" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L157-L166
46,023
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.enablePostTypeArchiveSearch
public function enablePostTypeArchiveSearch($template) { $template = \Municipio\Helper\Template::locateTemplate($template); if ((is_post_type_archive() || is_category() || is_date() || is_tax() || is_tag()) && is_search()) { $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive-' . get_post_type() . '.blade.php'); if (!$archiveTemplate) { $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive.blade.php'); } $template = $archiveTemplate; } return $template; }
php
public function enablePostTypeArchiveSearch($template) { $template = \Municipio\Helper\Template::locateTemplate($template); if ((is_post_type_archive() || is_category() || is_date() || is_tax() || is_tag()) && is_search()) { $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive-' . get_post_type() . '.blade.php'); if (!$archiveTemplate) { $archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive.blade.php'); } $template = $archiveTemplate; } return $template; }
[ "public", "function", "enablePostTypeArchiveSearch", "(", "$", "template", ")", "{", "$", "template", "=", "\\", "Municipio", "\\", "Helper", "\\", "Template", "::", "locateTemplate", "(", "$", "template", ")", ";", "if", "(", "(", "is_post_type_archive", "(",...
Use correct template when filtering a post type archive @param string $template Template path @return string Template path
[ "Use", "correct", "template", "when", "filtering", "a", "post", "type", "archive" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L327-L342
46,024
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.doPostTaxonomyFiltering
public function doPostTaxonomyFiltering($query) { // Do not execute this in admin view if (is_admin() || !(is_archive() || is_home() || is_category() || is_tax() || is_tag()) || !$query->is_main_query()) { return $query; } $postType = $this->getPostType(); $filterable = $this->getEnabledTaxonomies($postType, false); if (empty($filterable)) { return $query; } $taxQuery = array('relation' => 'AND'); foreach ($filterable as $key => $value) { if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') { continue; } $terms = (array)$_GET['filter'][$key]; $taxQuery[] = array( 'taxonomy' => $key, 'field' => 'slug', 'terms' => $terms, 'operator' => 'IN' ); } if (is_tax() || is_category() || is_tag()) { $taxQuery = array( 'relation' => 'AND', array( 'relation' => 'AND', array( 'taxonomy' => get_queried_object()->taxonomy, 'field' => 'slug', 'terms' => (array)get_queried_object()->slug, 'operator' => 'IN' ) ), $taxQuery ); } $taxQuery = apply_filters('Municipio/archive/tax_query', $taxQuery, $query); $query->set('tax_query', $taxQuery); return $query; }
php
public function doPostTaxonomyFiltering($query) { // Do not execute this in admin view if (is_admin() || !(is_archive() || is_home() || is_category() || is_tax() || is_tag()) || !$query->is_main_query()) { return $query; } $postType = $this->getPostType(); $filterable = $this->getEnabledTaxonomies($postType, false); if (empty($filterable)) { return $query; } $taxQuery = array('relation' => 'AND'); foreach ($filterable as $key => $value) { if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') { continue; } $terms = (array)$_GET['filter'][$key]; $taxQuery[] = array( 'taxonomy' => $key, 'field' => 'slug', 'terms' => $terms, 'operator' => 'IN' ); } if (is_tax() || is_category() || is_tag()) { $taxQuery = array( 'relation' => 'AND', array( 'relation' => 'AND', array( 'taxonomy' => get_queried_object()->taxonomy, 'field' => 'slug', 'terms' => (array)get_queried_object()->slug, 'operator' => 'IN' ) ), $taxQuery ); } $taxQuery = apply_filters('Municipio/archive/tax_query', $taxQuery, $query); $query->set('tax_query', $taxQuery); return $query; }
[ "public", "function", "doPostTaxonomyFiltering", "(", "$", "query", ")", "{", "// Do not execute this in admin view", "if", "(", "is_admin", "(", ")", "||", "!", "(", "is_archive", "(", ")", "||", "is_home", "(", ")", "||", "is_category", "(", ")", "||", "is...
Do taxonomy fitering @param object $query Query object @return object Modified query
[ "Do", "taxonomy", "fitering" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L349-L400
46,025
helsingborg-stad/Municipio
library/Content/PostFilters.php
PostFilters.doPostOrdering
public function doPostOrdering($query) { // Do not execute this in admin view if (is_admin() || !(is_archive() || is_home()) || !$query->is_main_query()) { return $query; } $isMetaQuery = false; $posttype = $query->get('post_type'); if (empty($posttype)) { $posttype = 'post'; } // Get orderby key, default to post_date $orderby = (isset($_GET['orderby']) && !empty($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : get_field('archive_' . sanitize_title($posttype) . '_sort_key', 'option'); if (empty($orderby)) { $orderby = 'post_date'; } if (in_array($orderby, array('post_date', 'post_modified', 'post_title'))) { $orderby = str_replace('post_', '', $orderby); } else { $isMetaQuery = true; } // Get orderby order, default to desc $order = (isset($_GET['order']) && !empty($_GET['order'])) ? sanitize_text_field($_GET['order']) : get_field('archive_' . sanitize_title($posttype) . '_sort_order', 'option'); if (empty($order) || !in_array(strtolower($order), array('asc', 'desc'))) { $order = 'desc'; } $query->set('order', $order); // Return if not meta query if (!$isMetaQuery) { $query->set('orderby', $orderby); return $query; } if (isset($_GET['orderby']) && $_GET['orderby'] == 'meta_key' && isset($_GET['meta_key']) && !empty($_GET['meta_key'])) { $orderby = sanitize_text_field($_GET['meta_key']); } // Continue if meta query $query->set('meta_key', $orderby); $query->set('orderby', 'meta_value'); return $query; }
php
public function doPostOrdering($query) { // Do not execute this in admin view if (is_admin() || !(is_archive() || is_home()) || !$query->is_main_query()) { return $query; } $isMetaQuery = false; $posttype = $query->get('post_type'); if (empty($posttype)) { $posttype = 'post'; } // Get orderby key, default to post_date $orderby = (isset($_GET['orderby']) && !empty($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : get_field('archive_' . sanitize_title($posttype) . '_sort_key', 'option'); if (empty($orderby)) { $orderby = 'post_date'; } if (in_array($orderby, array('post_date', 'post_modified', 'post_title'))) { $orderby = str_replace('post_', '', $orderby); } else { $isMetaQuery = true; } // Get orderby order, default to desc $order = (isset($_GET['order']) && !empty($_GET['order'])) ? sanitize_text_field($_GET['order']) : get_field('archive_' . sanitize_title($posttype) . '_sort_order', 'option'); if (empty($order) || !in_array(strtolower($order), array('asc', 'desc'))) { $order = 'desc'; } $query->set('order', $order); // Return if not meta query if (!$isMetaQuery) { $query->set('orderby', $orderby); return $query; } if (isset($_GET['orderby']) && $_GET['orderby'] == 'meta_key' && isset($_GET['meta_key']) && !empty($_GET['meta_key'])) { $orderby = sanitize_text_field($_GET['meta_key']); } // Continue if meta query $query->set('meta_key', $orderby); $query->set('orderby', 'meta_value'); return $query; }
[ "public", "function", "doPostOrdering", "(", "$", "query", ")", "{", "// Do not execute this in admin view", "if", "(", "is_admin", "(", ")", "||", "!", "(", "is_archive", "(", ")", "||", "is_home", "(", ")", ")", "||", "!", "$", "query", "->", "is_main_qu...
Do post ordering for archives @param object $query Query @return object Modified query
[ "Do", "post", "ordering", "for", "archives" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L446-L497
46,026
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.sidebarMenu
public function sidebarMenu() { if (get_field('nav_sub_enable', 'option') === false) { return ''; } if (get_field('nav_primary_type', 'option') == 'wp' && in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp'))) { return $this->sidebarMenuWP(); } else { return $this->sidebarMenuAuto(); } return ''; }
php
public function sidebarMenu() { if (get_field('nav_sub_enable', 'option') === false) { return ''; } if (get_field('nav_primary_type', 'option') == 'wp' && in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp'))) { return $this->sidebarMenuWP(); } else { return $this->sidebarMenuAuto(); } return ''; }
[ "public", "function", "sidebarMenu", "(", ")", "{", "if", "(", "get_field", "(", "'nav_sub_enable'", ",", "'option'", ")", "===", "false", ")", "{", "return", "''", ";", "}", "if", "(", "get_field", "(", "'nav_primary_type'", ",", "'option'", ")", "==", ...
Finds out which type of menu to use for the sidebar menu @return mixed
[ "Finds", "out", "which", "type", "of", "menu", "to", "use", "for", "the", "sidebar", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L32-L45
46,027
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.mobileMenu
public function mobileMenu() { if (get_field('nav_mobile_enable', 'option') === false) { return ''; } if (get_field('nav_primary_enable', 'option') === false && get_field('nav_sub_enable', 'option') === false) { return ''; } if (get_field('nav_primary_type', 'option') == 'wp' && (!get_field('nav_sub_type', 'option') || in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp')))) { return $this->mobileMenuWP(); } else { return $this->mobileMenuAuto(); } }
php
public function mobileMenu() { if (get_field('nav_mobile_enable', 'option') === false) { return ''; } if (get_field('nav_primary_enable', 'option') === false && get_field('nav_sub_enable', 'option') === false) { return ''; } if (get_field('nav_primary_type', 'option') == 'wp' && (!get_field('nav_sub_type', 'option') || in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp')))) { return $this->mobileMenuWP(); } else { return $this->mobileMenuAuto(); } }
[ "public", "function", "mobileMenu", "(", ")", "{", "if", "(", "get_field", "(", "'nav_mobile_enable'", ",", "'option'", ")", "===", "false", ")", "{", "return", "''", ";", "}", "if", "(", "get_field", "(", "'nav_primary_enable'", ",", "'option'", ")", "===...
Get the mobile menu @return string Mobile menu html
[ "Get", "the", "mobile", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L51-L66
46,028
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.mainMenuWP
public function mainMenuWP() { $classes = array('nav'); if (!empty(get_field('nav_primary_align', 'option'))) { $classes[] = 'nav-' . get_field('nav_primary_align', 'option'); } $args = array( 'echo' => false, 'depth' => 1, 'theme_location' => 'main-menu', 'container' => false, 'container_class' => 'menu-{menu-slug}-container', 'container_id' => '', 'menu_id' => 'main-menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false' ); if (get_field('nav_primariy_second_level', 'option')) { $classes[] = 'nav-multilevel'; $args['depth'] = 2; $args['walker'] = new \Municipio\Walker\MainMenuSecondary(); $args['items_section_wrap'] = $args['items_wrap']; $args['items_wrap'] = '%3$s'; } $args['menu_class'] = implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm'); return wp_nav_menu($args); }
php
public function mainMenuWP() { $classes = array('nav'); if (!empty(get_field('nav_primary_align', 'option'))) { $classes[] = 'nav-' . get_field('nav_primary_align', 'option'); } $args = array( 'echo' => false, 'depth' => 1, 'theme_location' => 'main-menu', 'container' => false, 'container_class' => 'menu-{menu-slug}-container', 'container_id' => '', 'menu_id' => 'main-menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false' ); if (get_field('nav_primariy_second_level', 'option')) { $classes[] = 'nav-multilevel'; $args['depth'] = 2; $args['walker'] = new \Municipio\Walker\MainMenuSecondary(); $args['items_section_wrap'] = $args['items_wrap']; $args['items_wrap'] = '%3$s'; } $args['menu_class'] = implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm'); return wp_nav_menu($args); }
[ "public", "function", "mainMenuWP", "(", ")", "{", "$", "classes", "=", "array", "(", "'nav'", ")", ";", "if", "(", "!", "empty", "(", "get_field", "(", "'nav_primary_align'", ",", "'option'", ")", ")", ")", "{", "$", "classes", "[", "]", "=", "'nav-...
Get WP main menu @return string Markuo
[ "Get", "WP", "main", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L72-L107
46,029
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.mainMenuAuto
public function mainMenuAuto() { $markup = null; $menu = false; $classes = array('nav'); if (!$menu || !is_string($menu) || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { if (!empty(get_field('nav_primary_align', 'option'))) { $classes[] = 'nav-' . get_field('nav_primary_align', 'option'); } $menu = new \Municipio\Helper\NavigationTree(array( 'theme_location' => 'main-menu', 'include_top_level' => true, 'render' => get_field('nav_primary_render', 'option'), 'depth' => 1, 'sublevel' => get_field('nav_primariy_second_level', 'option'), 'classes' => implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm') )); if (isset($menu) && $menu->itemCount() > 0) { $markup = apply_filters('Municipio/main_menu/items', $menu->render(false)); } return $markup; } return $menu; }
php
public function mainMenuAuto() { $markup = null; $menu = false; $classes = array('nav'); if (!$menu || !is_string($menu) || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { if (!empty(get_field('nav_primary_align', 'option'))) { $classes[] = 'nav-' . get_field('nav_primary_align', 'option'); } $menu = new \Municipio\Helper\NavigationTree(array( 'theme_location' => 'main-menu', 'include_top_level' => true, 'render' => get_field('nav_primary_render', 'option'), 'depth' => 1, 'sublevel' => get_field('nav_primariy_second_level', 'option'), 'classes' => implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm') )); if (isset($menu) && $menu->itemCount() > 0) { $markup = apply_filters('Municipio/main_menu/items', $menu->render(false)); } return $markup; } return $menu; }
[ "public", "function", "mainMenuAuto", "(", ")", "{", "$", "markup", "=", "null", ";", "$", "menu", "=", "false", ";", "$", "classes", "=", "array", "(", "'nav'", ")", ";", "if", "(", "!", "$", "menu", "||", "!", "is_string", "(", "$", "menu", ")"...
Get navigation tree main menu @return string Markup
[ "Get", "navigation", "tree", "main", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L113-L142
46,030
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.mobileMenuAuto
public function mobileMenuAuto() { //Create common hash for 404 & search if(is_search()) { $transientHash = "is_search"; $cacheTtl = 60*60*168; //Cache for a week } elseif(is_404()) { $transientHash = "is_404"; $cacheTtl = 60*60*168; //Cache for a week } else { $transientHash = \Municipio\Helper\Hash::short(\Municipio\Helper\Url::getCurrent()); $cacheTtl = 60*30; //Cache for an hour } //Toggle between logged out / logged in $transientType = ''; if (is_user_logged_in()) { $transientType = '_loggedin'; } //Get menu cached value $menu = wp_cache_get($transientHash, 'municipioMenuCache' . $transientType); if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { $mobileMenuArgs = array( 'include_top_level' => true ); if (get_field('nav_primary_type', 'option') == 'wp') { $mobileMenuArgs['top_level_type'] = 'mobile'; } //Render menu $menu = new \Municipio\Helper\NavigationTree($mobileMenuArgs); //Add to cache wp_cache_add($transientHash, $menu, 'municipioMenuCache' . $transientType, $cacheTtl); } if ($menu->itemCount === 0) { return ''; } return '<ul class="nav-mobile">' . apply_filters( 'Municipio/Helper/Navigation/MobileMenuAutoItems', $menu->render(false) ) . '</ul>'; }
php
public function mobileMenuAuto() { //Create common hash for 404 & search if(is_search()) { $transientHash = "is_search"; $cacheTtl = 60*60*168; //Cache for a week } elseif(is_404()) { $transientHash = "is_404"; $cacheTtl = 60*60*168; //Cache for a week } else { $transientHash = \Municipio\Helper\Hash::short(\Municipio\Helper\Url::getCurrent()); $cacheTtl = 60*30; //Cache for an hour } //Toggle between logged out / logged in $transientType = ''; if (is_user_logged_in()) { $transientType = '_loggedin'; } //Get menu cached value $menu = wp_cache_get($transientHash, 'municipioMenuCache' . $transientType); if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { $mobileMenuArgs = array( 'include_top_level' => true ); if (get_field('nav_primary_type', 'option') == 'wp') { $mobileMenuArgs['top_level_type'] = 'mobile'; } //Render menu $menu = new \Municipio\Helper\NavigationTree($mobileMenuArgs); //Add to cache wp_cache_add($transientHash, $menu, 'municipioMenuCache' . $transientType, $cacheTtl); } if ($menu->itemCount === 0) { return ''; } return '<ul class="nav-mobile">' . apply_filters( 'Municipio/Helper/Navigation/MobileMenuAutoItems', $menu->render(false) ) . '</ul>'; }
[ "public", "function", "mobileMenuAuto", "(", ")", "{", "//Create common hash for 404 & search", "if", "(", "is_search", "(", ")", ")", "{", "$", "transientHash", "=", "\"is_search\"", ";", "$", "cacheTtl", "=", "60", "*", "60", "*", "168", ";", "//Cache for a ...
Get navigation tree mobile menu @return [type] [description]
[ "Get", "navigation", "tree", "mobile", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L148-L193
46,031
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.sidebarMenuWP
public function sidebarMenuWP() { if (get_field('nav_sub_type', 'option') == 'sub') { return wp_nav_menu(array( 'theme_location' => 'main-menu', 'container' => 'nav', 'container_class' => 'sidebar-menu', 'container_id' => 'sidebar-menu', 'menu_class' => 'nav-aside hidden-xs hidden-sm', 'menu_id' => '', 'echo' => false, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false', 'walker' => new \Municipio\Walker\SidebarMenu(), 'child_menu' => true )); } return wp_nav_menu(array( 'theme_location' => 'sidebar-menu', 'container' => 'nav', 'container_class' => 'sidebar-menu', 'container_id' => 'sidebar-menu', 'menu_class' => 'nav-aside hidden-xs hidden-sm', 'menu_id' => '', 'echo' => false, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false' )); }
php
public function sidebarMenuWP() { if (get_field('nav_sub_type', 'option') == 'sub') { return wp_nav_menu(array( 'theme_location' => 'main-menu', 'container' => 'nav', 'container_class' => 'sidebar-menu', 'container_id' => 'sidebar-menu', 'menu_class' => 'nav-aside hidden-xs hidden-sm', 'menu_id' => '', 'echo' => false, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false', 'walker' => new \Municipio\Walker\SidebarMenu(), 'child_menu' => true )); } return wp_nav_menu(array( 'theme_location' => 'sidebar-menu', 'container' => 'nav', 'container_class' => 'sidebar-menu', 'container_id' => 'sidebar-menu', 'menu_class' => 'nav-aside hidden-xs hidden-sm', 'menu_id' => '', 'echo' => false, 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'fallback_cb' => '__return_false' )); }
[ "public", "function", "sidebarMenuWP", "(", ")", "{", "if", "(", "get_field", "(", "'nav_sub_type'", ",", "'option'", ")", "==", "'sub'", ")", "{", "return", "wp_nav_menu", "(", "array", "(", "'theme_location'", "=>", "'main-menu'", ",", "'container'", "=>", ...
Get WP or sub sidebar menu @return string Markuo
[ "Get", "WP", "or", "sub", "sidebar", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L223-L260
46,032
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.sidebarMenuAuto
public function sidebarMenuAuto() { $menu = false; if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { $menu = new \Municipio\Helper\NavigationTree(array( 'include_top_level' => !empty(get_field('nav_sub_include_top_level', 'option')) ? get_field('nav_sub_include_top_level', 'option') : false, 'render' => get_field('nav_sub_render', 'option'), 'depth' => get_field('nav_sub_depth', 'option') ? get_field('nav_sub_depth', 'option') : -1, 'start_depth' => get_field('nav_primariy_second_level', 'option') ? 3 : 1, 'classes' => 'nav-aside hidden-xs hidden-sm', 'sidebar' => true )); } if ($menu->itemCount === 0) { return ''; } return '<nav id="sidebar-menu"> ' . $menu->render(false) . ' </nav>'; }
php
public function sidebarMenuAuto() { $menu = false; if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) { $menu = new \Municipio\Helper\NavigationTree(array( 'include_top_level' => !empty(get_field('nav_sub_include_top_level', 'option')) ? get_field('nav_sub_include_top_level', 'option') : false, 'render' => get_field('nav_sub_render', 'option'), 'depth' => get_field('nav_sub_depth', 'option') ? get_field('nav_sub_depth', 'option') : -1, 'start_depth' => get_field('nav_primariy_second_level', 'option') ? 3 : 1, 'classes' => 'nav-aside hidden-xs hidden-sm', 'sidebar' => true )); } if ($menu->itemCount === 0) { return ''; } return '<nav id="sidebar-menu"> ' . $menu->render(false) . ' </nav>'; }
[ "public", "function", "sidebarMenuAuto", "(", ")", "{", "$", "menu", "=", "false", ";", "if", "(", "!", "$", "menu", "||", "(", "isset", "(", "$", "_GET", "[", "'menu_cache'", "]", ")", "&&", "$", "_GET", "[", "'menu_cache'", "]", "==", "'false'", ...
Get navigation tree sidebar menu @return string Menu markup
[ "Get", "navigation", "tree", "sidebar", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L266-L288
46,033
helsingborg-stad/Municipio
library/Helper/Navigation.php
Navigation.getMenuNameByLocation
public static function getMenuNameByLocation($location) { if(!has_nav_menu($location)) return false; $menus = get_nav_menu_locations(); $menuTitle = wp_get_nav_menu_object($menus[$location])->name; return $menuTitle; }
php
public static function getMenuNameByLocation($location) { if(!has_nav_menu($location)) return false; $menus = get_nav_menu_locations(); $menuTitle = wp_get_nav_menu_object($menus[$location])->name; return $menuTitle; }
[ "public", "static", "function", "getMenuNameByLocation", "(", "$", "location", ")", "{", "if", "(", "!", "has_nav_menu", "(", "$", "location", ")", ")", "return", "false", ";", "$", "menus", "=", "get_nav_menu_locations", "(", ")", ";", "$", "menuTitle", "...
Get menu name by menu location @param mixed $location slug or ID of registered menu @return string menu name
[ "Get", "menu", "name", "by", "menu", "location" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L295-L301
46,034
helsingborg-stad/Municipio
library/Admin/Roles/General.php
General.addMissingRoles
public function addMissingRoles() { if (!get_role('author')) { add_role( 'author', 'Author', array( 'upload_files' => true, 'edit_posts' => true, 'edit_published_posts' => true, 'publish_posts' => true, 'read' => true, 'level_2' => true, 'level_1' => true, 'level_0' => true, 'delete_posts' => true, 'delete_published_posts' => true ) ); delete_option('_author_role_bkp'); } }
php
public function addMissingRoles() { if (!get_role('author')) { add_role( 'author', 'Author', array( 'upload_files' => true, 'edit_posts' => true, 'edit_published_posts' => true, 'publish_posts' => true, 'read' => true, 'level_2' => true, 'level_1' => true, 'level_0' => true, 'delete_posts' => true, 'delete_published_posts' => true ) ); delete_option('_author_role_bkp'); } }
[ "public", "function", "addMissingRoles", "(", ")", "{", "if", "(", "!", "get_role", "(", "'author'", ")", ")", "{", "add_role", "(", "'author'", ",", "'Author'", ",", "array", "(", "'upload_files'", "=>", "true", ",", "'edit_posts'", "=>", "true", ",", "...
Adds back missing author role
[ "Adds", "back", "missing", "author", "role" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/Roles/General.php#L27-L49
46,035
helsingborg-stad/Municipio
library/Admin/Roles/General.php
General.removeUnusedRoles
public function removeUnusedRoles() { $removeRoles = array( 'contributor' ); foreach ($removeRoles as $role) { if (!get_role($role)) { continue; } update_option('_' . $role . '_role_bkp', get_role('author')); remove_role($role); } }
php
public function removeUnusedRoles() { $removeRoles = array( 'contributor' ); foreach ($removeRoles as $role) { if (!get_role($role)) { continue; } update_option('_' . $role . '_role_bkp', get_role('author')); remove_role($role); } }
[ "public", "function", "removeUnusedRoles", "(", ")", "{", "$", "removeRoles", "=", "array", "(", "'contributor'", ")", ";", "foreach", "(", "$", "removeRoles", "as", "$", "role", ")", "{", "if", "(", "!", "get_role", "(", "$", "role", ")", ")", "{", ...
Remove unwanted roles @return void
[ "Remove", "unwanted", "roles" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/Roles/General.php#L55-L69
46,036
helsingborg-stad/Municipio
library/Theme/Sidebars.php
Sidebars.moduleClasses
public function moduleClasses($classes, $moduleType, $sidebarArgs) { // Box panel in content area and content area bottom if (in_array($sidebarArgs['id'], array('content-area', 'content-area-bottom')) && in_array('box-panel', $classes) && !is_front_page()) { $classes[] = 'box-panel-secondary'; } // Inline box panels if (is_numeric($sidebarArgs['id']) && in_array('box-panel', $classes)) { $classes[] = 'box-panel-secondary'; } // Sidebar box-panel (should be filled) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-panel', $classes)) { unset($classes[array_search('box-panel', $classes)]); $classes[] = 'box-filled'; } // Sidebar box-index (should be filled) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-index', $classes)) { unset($classes[array_search('box-index', $classes)]); $classes[] = 'box-filled'; } // Sidebar box-news-horizontal (should be only box-news in sidebar) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-news-horizontal', $classes)) { unset($classes[array_search('box-news-horizontal', $classes)]); } return $classes; }
php
public function moduleClasses($classes, $moduleType, $sidebarArgs) { // Box panel in content area and content area bottom if (in_array($sidebarArgs['id'], array('content-area', 'content-area-bottom')) && in_array('box-panel', $classes) && !is_front_page()) { $classes[] = 'box-panel-secondary'; } // Inline box panels if (is_numeric($sidebarArgs['id']) && in_array('box-panel', $classes)) { $classes[] = 'box-panel-secondary'; } // Sidebar box-panel (should be filled) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-panel', $classes)) { unset($classes[array_search('box-panel', $classes)]); $classes[] = 'box-filled'; } // Sidebar box-index (should be filled) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-index', $classes)) { unset($classes[array_search('box-index', $classes)]); $classes[] = 'box-filled'; } // Sidebar box-news-horizontal (should be only box-news in sidebar) if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-news-horizontal', $classes)) { unset($classes[array_search('box-news-horizontal', $classes)]); } return $classes; }
[ "public", "function", "moduleClasses", "(", "$", "classes", ",", "$", "moduleType", ",", "$", "sidebarArgs", ")", "{", "// Box panel in content area and content area bottom", "if", "(", "in_array", "(", "$", "sidebarArgs", "[", "'id'", "]", ",", "array", "(", "'...
Modify module classes in different areas @param array $classes Default classes @param string $moduleType Module type @param array $sidebarArgs Sidebar arguments @return array Modified list of classes
[ "Modify", "module", "classes", "in", "different", "areas" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L44-L74
46,037
helsingborg-stad/Municipio
library/Theme/Sidebars.php
Sidebars.moduleSidebarIncompability
public function moduleSidebarIncompability($moduleSpecification, $modulePostType) : array { switch ($modulePostType) { case "mod-section-featured": case "mod-section-full": case "mod-section-split": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "content-area-bottom", "content-area", "content-area-top", "footer-area"); break; case "mod-slider": case "mod-video": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area"); break; case "mod-table": case "mod-gallery": case "mod-guide": case "mod-alarms": case "mod-interactive-map": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "slider-area", "bottom-sidebar", "top-sidebar"); break; case "mod-posts": case "mod-location": case "mod-social": case "mod-dictionary": case "mod-contacts": case "mod-fileslist": case "mod-g-calendar": case "mod-index": case "mod-inlaylist": $moduleSpecification['sidebar_incompability'] = array("footer-area", "slider-area", "bottom-sidebar", "top-sidebar"); break; case "mod-rss": case "mod-script": case "mod-notice": case "mod-iframe": case "mod-event": case "mod-form": case "mod-location": case "mod-text": $moduleSpecification['sidebar_incompability'] = array("slider-area", "bottom-sidebar", "top-sidebar"); break; } return $moduleSpecification; }
php
public function moduleSidebarIncompability($moduleSpecification, $modulePostType) : array { switch ($modulePostType) { case "mod-section-featured": case "mod-section-full": case "mod-section-split": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "content-area-bottom", "content-area", "content-area-top", "footer-area"); break; case "mod-slider": case "mod-video": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area"); break; case "mod-table": case "mod-gallery": case "mod-guide": case "mod-alarms": case "mod-interactive-map": $moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "slider-area", "bottom-sidebar", "top-sidebar"); break; case "mod-posts": case "mod-location": case "mod-social": case "mod-dictionary": case "mod-contacts": case "mod-fileslist": case "mod-g-calendar": case "mod-index": case "mod-inlaylist": $moduleSpecification['sidebar_incompability'] = array("footer-area", "slider-area", "bottom-sidebar", "top-sidebar"); break; case "mod-rss": case "mod-script": case "mod-notice": case "mod-iframe": case "mod-event": case "mod-form": case "mod-location": case "mod-text": $moduleSpecification['sidebar_incompability'] = array("slider-area", "bottom-sidebar", "top-sidebar"); break; } return $moduleSpecification; }
[ "public", "function", "moduleSidebarIncompability", "(", "$", "moduleSpecification", ",", "$", "modulePostType", ")", ":", "array", "{", "switch", "(", "$", "modulePostType", ")", "{", "case", "\"mod-section-featured\"", ":", "case", "\"mod-section-full\"", ":", "ca...
Appends compability support @param array $moduleSpecification Original module settings @return array
[ "Appends", "compability", "support" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L209-L253
46,038
helsingborg-stad/Municipio
library/Theme/Sidebars.php
Sidebars.registerModulesWithContainerSupport
public function registerModulesWithContainerSupport($modules) { $modules[] = "mod-posts"; $modules[] = "mod-location"; $modules[] = "mod-social"; $modules[] = "mod-contacts"; $modules[] = "mod-fileslist"; $modules[] = "mod-index"; $modules[] = "mod-inlaylist"; $modules[] = "mod-form"; $modules[] = "mod-text"; $modules[] = "mod-guide"; $modules[] = "mod-table"; $modules[] = "mod-gallery"; $modules[] = "mod-video"; $modules[] = "mod-notice"; $modules[] = "mod-g-calendar"; return $modules; }
php
public function registerModulesWithContainerSupport($modules) { $modules[] = "mod-posts"; $modules[] = "mod-location"; $modules[] = "mod-social"; $modules[] = "mod-contacts"; $modules[] = "mod-fileslist"; $modules[] = "mod-index"; $modules[] = "mod-inlaylist"; $modules[] = "mod-form"; $modules[] = "mod-text"; $modules[] = "mod-guide"; $modules[] = "mod-table"; $modules[] = "mod-gallery"; $modules[] = "mod-video"; $modules[] = "mod-notice"; $modules[] = "mod-g-calendar"; return $modules; }
[ "public", "function", "registerModulesWithContainerSupport", "(", "$", "modules", ")", "{", "$", "modules", "[", "]", "=", "\"mod-posts\"", ";", "$", "modules", "[", "]", "=", "\"mod-location\"", ";", "$", "modules", "[", "]", "=", "\"mod-social\"", ";", "$"...
Add container grid to some modules placed in full-width widget areas @return array
[ "Add", "container", "grid", "to", "some", "modules", "placed", "in", "full", "-", "width", "widget", "areas" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L272-L291
46,039
helsingborg-stad/Municipio
library/Admin/UI/Editor.php
Editor.allowedHtmlTags
public function allowedHtmlTags($init) { $extend = 'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]'; if (isset($init['extended_valid_elements']) && !empty($init['extended_valid_elements'])) { $init['extended_valid_elements'] .= ', ' . $extend; } else { $init['extended_valid_elements'] = $extend; } return $init; }
php
public function allowedHtmlTags($init) { $extend = 'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]'; if (isset($init['extended_valid_elements']) && !empty($init['extended_valid_elements'])) { $init['extended_valid_elements'] .= ', ' . $extend; } else { $init['extended_valid_elements'] = $extend; } return $init; }
[ "public", "function", "allowedHtmlTags", "(", "$", "init", ")", "{", "$", "extend", "=", "'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]'", ";", "if", "(", "isset", "(", "$", "init", "[", "'extended_valid_elements'", "]", ")...
Extend valid html-elements for wp editor @param array $init @return array
[ "Extend", "valid", "html", "-", "elements", "for", "wp", "editor" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L30-L41
46,040
helsingborg-stad/Municipio
library/Admin/UI/Editor.php
Editor.oembed
public static function oembed($html, $url, $attr, $postId, $wrapper = true) { $provider = false; if (strpos(strtolower($url), 'youtube') !== false || strpos(strtolower($url), 'youtu.be') !== false) { $provider = 'YouTube'; } elseif (strpos(strtolower($url), 'vimeo') !== false) { $provider = 'Vimeo'; } $shouldFilter = apply_filters('Municipio/oembed/should_filter_markup', true, $provider, $url, $postId); // Check if there's a oembed class for the provider if (!class_exists('\Municipio\Oembed\\' . $provider) || !$shouldFilter) { return $html; } $class = '\Municipio\Oembed\\' . $provider; $oembed = new $class($url, $html, $wrapper); return $oembed->output(); }
php
public static function oembed($html, $url, $attr, $postId, $wrapper = true) { $provider = false; if (strpos(strtolower($url), 'youtube') !== false || strpos(strtolower($url), 'youtu.be') !== false) { $provider = 'YouTube'; } elseif (strpos(strtolower($url), 'vimeo') !== false) { $provider = 'Vimeo'; } $shouldFilter = apply_filters('Municipio/oembed/should_filter_markup', true, $provider, $url, $postId); // Check if there's a oembed class for the provider if (!class_exists('\Municipio\Oembed\\' . $provider) || !$shouldFilter) { return $html; } $class = '\Municipio\Oembed\\' . $provider; $oembed = new $class($url, $html, $wrapper); return $oembed->output(); }
[ "public", "static", "function", "oembed", "(", "$", "html", ",", "$", "url", ",", "$", "attr", ",", "$", "postId", ",", "$", "wrapper", "=", "true", ")", "{", "$", "provider", "=", "false", ";", "if", "(", "strpos", "(", "strtolower", "(", "$", "...
Filters oembed output @param string $data Markup @param string $url Embedded url @param array $args Args @return string Markup
[ "Filters", "oembed", "output" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L70-L91
46,041
helsingborg-stad/Municipio
library/Admin/UI/Editor.php
Editor.styleFormat
public function styleFormat($settings) { // Set color scheme class on mce body $color = get_field('color_scheme', 'option'); if ($color) { $settings['body_class'] .= ' theme-' . $color; } // Get style formats $styleFormats = self::getEnabledStyleFormats(); if (empty($styleFormats)) { return $settings; } $settings['style_formats'] = json_encode($styleFormats); return $settings; }
php
public function styleFormat($settings) { // Set color scheme class on mce body $color = get_field('color_scheme', 'option'); if ($color) { $settings['body_class'] .= ' theme-' . $color; } // Get style formats $styleFormats = self::getEnabledStyleFormats(); if (empty($styleFormats)) { return $settings; } $settings['style_formats'] = json_encode($styleFormats); return $settings; }
[ "public", "function", "styleFormat", "(", "$", "settings", ")", "{", "// Set color scheme class on mce body", "$", "color", "=", "get_field", "(", "'color_scheme'", ",", "'option'", ")", ";", "if", "(", "$", "color", ")", "{", "$", "settings", "[", "'body_clas...
Add style format options @param array $settings Options array @return array Modified options array
[ "Add", "style", "format", "options" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L98-L116
46,042
helsingborg-stad/Municipio
library/Admin/UI/Editor.php
Editor.getEnabledStyleFormats
public static function getEnabledStyleFormats() { $returnFormats = array(); $formats = self::getAvailableStyleFormats(); $enabled = get_field('content_editor_formats', 'options'); if (is_array($enabled) && !empty($enabled) && is_array($formats) && !empty($formats)) { foreach ($formats as $key => &$format) { $format = array_filter($format, function ($key) use ($enabled) { return in_array($key, $enabled); }, ARRAY_FILTER_USE_KEY); } foreach ($formats as $key => $items) { if (!is_array($items) || count($items) === 0) { continue; } $returnFormats[] = array( 'title' => $key, 'items' => $items ); } } return $returnFormats; }
php
public static function getEnabledStyleFormats() { $returnFormats = array(); $formats = self::getAvailableStyleFormats(); $enabled = get_field('content_editor_formats', 'options'); if (is_array($enabled) && !empty($enabled) && is_array($formats) && !empty($formats)) { foreach ($formats as $key => &$format) { $format = array_filter($format, function ($key) use ($enabled) { return in_array($key, $enabled); }, ARRAY_FILTER_USE_KEY); } foreach ($formats as $key => $items) { if (!is_array($items) || count($items) === 0) { continue; } $returnFormats[] = array( 'title' => $key, 'items' => $items ); } } return $returnFormats; }
[ "public", "static", "function", "getEnabledStyleFormats", "(", ")", "{", "$", "returnFormats", "=", "array", "(", ")", ";", "$", "formats", "=", "self", "::", "getAvailableStyleFormats", "(", ")", ";", "$", "enabled", "=", "get_field", "(", "'content_editor_fo...
Get enabled style formats from options @return array
[ "Get", "enabled", "style", "formats", "from", "options" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L122-L149
46,043
helsingborg-stad/Municipio
library/Admin/UI/Editor.php
Editor.pricons
public function pricons() { add_filter('mce_external_plugins', function ($plugins) { global $pagenow; if (!current_user_can('edit_posts') || !current_user_can('edit_pages') || $pagenow != 'post.php') { return $plugins; } $plugins['pricons'] = get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/mce-pricons.js'); return $plugins; }); add_filter('mce_buttons_2', function ($buttons) { global $pagenow; if (!current_user_can('edit_posts') || !current_user_can('edit_pages') || $pagenow != 'post.php') { return $buttons; } $buttons[] = 'pricons'; return $buttons; }); }
php
public function pricons() { add_filter('mce_external_plugins', function ($plugins) { global $pagenow; if (!current_user_can('edit_posts') || !current_user_can('edit_pages') || $pagenow != 'post.php') { return $plugins; } $plugins['pricons'] = get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/mce-pricons.js'); return $plugins; }); add_filter('mce_buttons_2', function ($buttons) { global $pagenow; if (!current_user_can('edit_posts') || !current_user_can('edit_pages') || $pagenow != 'post.php') { return $buttons; } $buttons[] = 'pricons'; return $buttons; }); }
[ "public", "function", "pricons", "(", ")", "{", "add_filter", "(", "'mce_external_plugins'", ",", "function", "(", "$", "plugins", ")", "{", "global", "$", "pagenow", ";", "if", "(", "!", "current_user_can", "(", "'edit_posts'", ")", "||", "!", "current_user...
Add pricons button to editor @return void
[ "Add", "pricons", "button", "to", "editor" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L331-L354
46,044
helsingborg-stad/Municipio
library/Helper/Svg.php
Svg.extract
public static function extract($symbol, $classes = '') { $symbol = file_get_contents($symbol); //Get by dom method if (class_exists('DOMDocument')) { $doc = new \DOMDocument(); if ($doc->loadXML($symbol) === true) { try { $doc->getElementsByTagName('svg'); $svg = $doc->getElementsByTagName('svg'); if ($svg->item(0)->C14N() !== null) { $symbol = $svg->item(0)->C14N(); } } catch (exception $e) { error_log("Error loading SVG file to header or footer."); } } } //Filter tags & comments (if above not applicated) $symbol = preg_replace('/<\?xml.*?\/>/im', '', $symbol); //Remove XML $symbol = preg_replace('/<!--(.*)-->/Uis', '', $symbol); //Remove comments & javascript if (strlen($classes) > 0) { $symbol = str_replace('<svg', '<svg class="' . $classes . '"', $symbol); } return $symbol; }
php
public static function extract($symbol, $classes = '') { $symbol = file_get_contents($symbol); //Get by dom method if (class_exists('DOMDocument')) { $doc = new \DOMDocument(); if ($doc->loadXML($symbol) === true) { try { $doc->getElementsByTagName('svg'); $svg = $doc->getElementsByTagName('svg'); if ($svg->item(0)->C14N() !== null) { $symbol = $svg->item(0)->C14N(); } } catch (exception $e) { error_log("Error loading SVG file to header or footer."); } } } //Filter tags & comments (if above not applicated) $symbol = preg_replace('/<\?xml.*?\/>/im', '', $symbol); //Remove XML $symbol = preg_replace('/<!--(.*)-->/Uis', '', $symbol); //Remove comments & javascript if (strlen($classes) > 0) { $symbol = str_replace('<svg', '<svg class="' . $classes . '"', $symbol); } return $symbol; }
[ "public", "static", "function", "extract", "(", "$", "symbol", ",", "$", "classes", "=", "''", ")", "{", "$", "symbol", "=", "file_get_contents", "(", "$", "symbol", ")", ";", "//Get by dom method", "if", "(", "class_exists", "(", "'DOMDocument'", ")", ")"...
Extracts svg-code from svg-file @param string $symbol Path to symbol (.svg) @param string $classes Classes to add to svg-element @return string Svg element markup
[ "Extracts", "svg", "-", "code", "from", "svg", "-", "file" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Svg.php#L13-L43
46,045
helsingborg-stad/Municipio
library/Theme/FileUploads.php
FileUploads.santitizeFileNames
public function santitizeFileNames($file) { $path = pathinfo($file['name']); $new_filename = preg_replace('/.' . $path['extension'] . '$/', '', $file['name']); $file['name'] = $this->localLetterSanitize(sanitize_title($new_filename)) . '.' . $path['extension']; return $file; }
php
public function santitizeFileNames($file) { $path = pathinfo($file['name']); $new_filename = preg_replace('/.' . $path['extension'] . '$/', '', $file['name']); $file['name'] = $this->localLetterSanitize(sanitize_title($new_filename)) . '.' . $path['extension']; return $file; }
[ "public", "function", "santitizeFileNames", "(", "$", "file", ")", "{", "$", "path", "=", "pathinfo", "(", "$", "file", "[", "'name'", "]", ")", ";", "$", "new_filename", "=", "preg_replace", "(", "'/.'", ".", "$", "path", "[", "'extension'", "]", ".",...
Santitize file names @param array $file with parameters for uploaded file @return string Array with file specifications
[ "Santitize", "file", "names" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/FileUploads.php#L19-L25
46,046
helsingborg-stad/Municipio
library/Theme/FileUploads.php
FileUploads.mimeTypes
public function mimeTypes($mimes) { // Archives $mimes['zip'] = 'application/zip'; $mimes['gz'] = 'application/x-gzip'; // Images $mimes['ico'] = 'image/x-icon'; // Video $mimes['webm'] = 'video/webm'; $mimes['mp4'] = 'video/mp4'; $mimes['ogg'] = 'video/ogg'; // MS Office $mimes['doc'] = 'application/msword'; $mimes['pot|pps|ppt'] = 'application/vnd.ms-powerpoint'; $mimes['wri'] = 'application/vnd.ms-write'; $mimes['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel'; $mimes['mdb'] = 'application/vnd.ms-access'; $mimes['mpp'] = 'application/vnd.ms-project'; $mimes['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; $mimes['docm'] = 'application/vnd.ms-word.document.macroEnabled.12'; $mimes['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; $mimes['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12'; $mimes['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $mimes['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12'; $mimes['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'; $mimes['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; $mimes['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12'; $mimes['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12'; $mimes['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; $mimes['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'; $mimes['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; $mimes['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'; $mimes['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template'; $mimes['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12'; $mimes['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'; $mimes['sldx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slide'; $mimes['sldm'] = 'application/vnd.ms-powerpoint.slide.macroEnabled.12'; $mimes['onetoc|onetoc2|onetmp|onepkg'] = 'application/onenote'; // Drawings $mimes['dwg'] = 'application/dwg'; return $mimes; }
php
public function mimeTypes($mimes) { // Archives $mimes['zip'] = 'application/zip'; $mimes['gz'] = 'application/x-gzip'; // Images $mimes['ico'] = 'image/x-icon'; // Video $mimes['webm'] = 'video/webm'; $mimes['mp4'] = 'video/mp4'; $mimes['ogg'] = 'video/ogg'; // MS Office $mimes['doc'] = 'application/msword'; $mimes['pot|pps|ppt'] = 'application/vnd.ms-powerpoint'; $mimes['wri'] = 'application/vnd.ms-write'; $mimes['xla|xls|xlt|xlw'] = 'application/vnd.ms-excel'; $mimes['mdb'] = 'application/vnd.ms-access'; $mimes['mpp'] = 'application/vnd.ms-project'; $mimes['docx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; $mimes['docm'] = 'application/vnd.ms-word.document.macroEnabled.12'; $mimes['dotx'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; $mimes['dotm'] = 'application/vnd.ms-word.template.macroEnabled.12'; $mimes['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; $mimes['xlsm'] = 'application/vnd.ms-excel.sheet.macroEnabled.12'; $mimes['xlsb'] = 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'; $mimes['xltx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; $mimes['xltm'] = 'application/vnd.ms-excel.template.macroEnabled.12'; $mimes['xlam'] = 'application/vnd.ms-excel.addin.macroEnabled.12'; $mimes['pptx'] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; $mimes['pptm'] = 'application/vnd.ms-powerpoint.presentation.macroEnabled.12'; $mimes['ppsx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; $mimes['ppsm'] = 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'; $mimes['potx'] = 'application/vnd.openxmlformats-officedocument.presentationml.template'; $mimes['potm'] = 'application/vnd.ms-powerpoint.template.macroEnabled.12'; $mimes['ppam'] = 'application/vnd.ms-powerpoint.addin.macroEnabled.12'; $mimes['sldx'] = 'application/vnd.openxmlformats-officedocument.presentationml.slide'; $mimes['sldm'] = 'application/vnd.ms-powerpoint.slide.macroEnabled.12'; $mimes['onetoc|onetoc2|onetmp|onepkg'] = 'application/onenote'; // Drawings $mimes['dwg'] = 'application/dwg'; return $mimes; }
[ "public", "function", "mimeTypes", "(", "$", "mimes", ")", "{", "// Archives", "$", "mimes", "[", "'zip'", "]", "=", "'application/zip'", ";", "$", "mimes", "[", "'gz'", "]", "=", "'application/x-gzip'", ";", "// Images", "$", "mimes", "[", "'ico'", "]", ...
Add allowed mime types @param array $mimes Mime types @return array Modified mime types
[ "Add", "allowed", "mime", "types" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/FileUploads.php#L45-L91
46,047
helsingborg-stad/Municipio
library/Theme/Navigation.php
Navigation.pageForPostTypeNavigation
public function pageForPostTypeNavigation($posts) { if (is_main_query() && is_single() && isset($posts[0])) { $postType = $posts[0]->post_type; $parent = get_option("page_for_{$postType}"); if ($parent) { $posts[0]->post_parent = $parent; } } return $posts; }
php
public function pageForPostTypeNavigation($posts) { if (is_main_query() && is_single() && isset($posts[0])) { $postType = $posts[0]->post_type; $parent = get_option("page_for_{$postType}"); if ($parent) { $posts[0]->post_parent = $parent; } } return $posts; }
[ "public", "function", "pageForPostTypeNavigation", "(", "$", "posts", ")", "{", "if", "(", "is_main_query", "(", ")", "&&", "is_single", "(", ")", "&&", "isset", "(", "$", "posts", "[", "0", "]", ")", ")", "{", "$", "postType", "=", "$", "posts", "["...
Fix sidebar nav if "page for post type" is same as the curretn post's post type @param array $posts @return array
[ "Fix", "sidebar", "nav", "if", "page", "for", "post", "type", "is", "same", "as", "the", "curretn", "post", "s", "post", "type" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Navigation.php#L53-L65
46,048
helsingborg-stad/Municipio
library/Theme/Navigation.php
Navigation.purgeTreeMenuTransientForAncestors
public function purgeTreeMenuTransientForAncestors($postId) { // Get page ancestors $ancestors = get_post_ancestors($postId); $ancestors[] = $postId; // Remove front page from ancestors array $ancestors = array_reverse($ancestors); if ($ancestors[0] == get_option('page_on_front')) { unset($ancestors[0]); } $ancestors = array_values($ancestors); // Delete transient for page ancestors foreach ($ancestors as $postId) { $children = get_children(array( 'post_parent' => $postId, 'numberofposts' => -1, 'post_type' => 'page', )); foreach ($children as $child) { delete_transient('main_menu_' . $child->ID); delete_transient('mobile_menu_' . $child->ID); delete_transient('sidebar_menu_' . $child->ID); delete_transient('main_menu_' . $child->ID . '_loggedin'); delete_transient('mobile_menu_' . $child->ID . '_loggedin'); delete_transient('sidebar_menu_' . $child->ID . '_loggedin'); } } }
php
public function purgeTreeMenuTransientForAncestors($postId) { // Get page ancestors $ancestors = get_post_ancestors($postId); $ancestors[] = $postId; // Remove front page from ancestors array $ancestors = array_reverse($ancestors); if ($ancestors[0] == get_option('page_on_front')) { unset($ancestors[0]); } $ancestors = array_values($ancestors); // Delete transient for page ancestors foreach ($ancestors as $postId) { $children = get_children(array( 'post_parent' => $postId, 'numberofposts' => -1, 'post_type' => 'page', )); foreach ($children as $child) { delete_transient('main_menu_' . $child->ID); delete_transient('mobile_menu_' . $child->ID); delete_transient('sidebar_menu_' . $child->ID); delete_transient('main_menu_' . $child->ID . '_loggedin'); delete_transient('mobile_menu_' . $child->ID . '_loggedin'); delete_transient('sidebar_menu_' . $child->ID . '_loggedin'); } } }
[ "public", "function", "purgeTreeMenuTransientForAncestors", "(", "$", "postId", ")", "{", "// Get page ancestors", "$", "ancestors", "=", "get_post_ancestors", "(", "$", "postId", ")", ";", "$", "ancestors", "[", "]", "=", "$", "postId", ";", "// Remove front page...
Delete tree menu transient for ancestors of post id. @param int $postId The post id @return void
[ "Delete", "tree", "menu", "transient", "for", "ancestors", "of", "post", "id", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Navigation.php#L81-L114
46,049
helsingborg-stad/Municipio
library/Theme/Navigation.php
Navigation.outputDropdownLinksMenu
public static function outputDropdownLinksMenu() { if (!\Municipio\Helper\Navigation::getMenuNameByLocation('dropdown-links-menu')) { return; } $args = array( 'menu' => \Municipio\Helper\Navigation::getMenuNameByLocation('dropdown-links-menu'), 'container' => false, 'menu_class' => 'o-dropdown-links', 'echo' => false ); return wp_nav_menu($args); }
php
public static function outputDropdownLinksMenu() { if (!\Municipio\Helper\Navigation::getMenuNameByLocation('dropdown-links-menu')) { return; } $args = array( 'menu' => \Municipio\Helper\Navigation::getMenuNameByLocation('dropdown-links-menu'), 'container' => false, 'menu_class' => 'o-dropdown-links', 'echo' => false ); return wp_nav_menu($args); }
[ "public", "static", "function", "outputDropdownLinksMenu", "(", ")", "{", "if", "(", "!", "\\", "Municipio", "\\", "Helper", "\\", "Navigation", "::", "getMenuNameByLocation", "(", "'dropdown-links-menu'", ")", ")", "{", "return", ";", "}", "$", "args", "=", ...
Output dropdown links menu markup @return string menu markup
[ "Output", "dropdown", "links", "menu", "markup" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Navigation.php#L149-L163
46,050
helsingborg-stad/Municipio
library/Theme/Navigation.php
Navigation.addTranslate
public function addTranslate($items, $args = null) { if (!is_object($args)) { $args = (object)$args; } if ($args && $args->theme_location != get_field('google_translate_menu', 'option')) { return $items; } //Not in child (if inherited from main) if ($args && (isset($args->child_menu) && $args->child_menu == true) && $args->theme_location == "main-menu") { return $items; } $label = 'Translate'; if (get_field('google_translate_show_as', 'option') == 'icon') { $label = '<span data-tooltip="Translate"><i class="pricon pricon-globe"></i></span>'; } elseif (get_field('google_translate_show_as', 'option') == 'combined') { $label = '<i class="pricon pricon-globe"></i> Translate'; } $translate = '<li class="menu-item-translate"><a href="#translate" class="translate-icon-btn" aria-label="translate">' . $label . '</a></li>'; if (isset($args->include_top_level)) { $items = $translate . $items; } else { $items .= $translate; } return $items; }
php
public function addTranslate($items, $args = null) { if (!is_object($args)) { $args = (object)$args; } if ($args && $args->theme_location != get_field('google_translate_menu', 'option')) { return $items; } //Not in child (if inherited from main) if ($args && (isset($args->child_menu) && $args->child_menu == true) && $args->theme_location == "main-menu") { return $items; } $label = 'Translate'; if (get_field('google_translate_show_as', 'option') == 'icon') { $label = '<span data-tooltip="Translate"><i class="pricon pricon-globe"></i></span>'; } elseif (get_field('google_translate_show_as', 'option') == 'combined') { $label = '<i class="pricon pricon-globe"></i> Translate'; } $translate = '<li class="menu-item-translate"><a href="#translate" class="translate-icon-btn" aria-label="translate">' . $label . '</a></li>'; if (isset($args->include_top_level)) { $items = $translate . $items; } else { $items .= $translate; } return $items; }
[ "public", "function", "addTranslate", "(", "$", "items", ",", "$", "args", "=", "null", ")", "{", "if", "(", "!", "is_object", "(", "$", "args", ")", ")", "{", "$", "args", "=", "(", "object", ")", "$", "args", ";", "}", "if", "(", "$", "args",...
Appends translate icon to menu @param string $items Items html @param array $args Menu args @return string Items html
[ "Appends", "translate", "icon", "to", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Navigation.php#L171-L202
46,051
helsingborg-stad/Municipio
library/Theme/Navigation.php
Navigation.addSearchMagnifier
public function addSearchMagnifier($items, $args = null) { if (!is_object($args)) { $args = (object)$args; } if ($args && $args->theme_location != apply_filters('Municipio/main_menu_theme_location', 'main-menu')) { return $items; } //Not in child (if inherited from main) if ($args && (isset($args->child_menu) && $args->child_menu == true) && $args->theme_location == "main-menu") { return $items; } $search = '<li class="menu-item-search"><a href="#search" class="search-icon-btn toggle-search-top" aria-label="' . __('Search', 'municipio') . '"><span data-tooltip="' . __('Search', 'municipio') . '"><i class="pricon pricon-search"></i></span></a></li>'; if (isset($args->include_top_level)) { $items = $search . $items; } else { $items .= $search; } return $items; }
php
public function addSearchMagnifier($items, $args = null) { if (!is_object($args)) { $args = (object)$args; } if ($args && $args->theme_location != apply_filters('Municipio/main_menu_theme_location', 'main-menu')) { return $items; } //Not in child (if inherited from main) if ($args && (isset($args->child_menu) && $args->child_menu == true) && $args->theme_location == "main-menu") { return $items; } $search = '<li class="menu-item-search"><a href="#search" class="search-icon-btn toggle-search-top" aria-label="' . __('Search', 'municipio') . '"><span data-tooltip="' . __('Search', 'municipio') . '"><i class="pricon pricon-search"></i></span></a></li>'; if (isset($args->include_top_level)) { $items = $search . $items; } else { $items .= $search; } return $items; }
[ "public", "function", "addSearchMagnifier", "(", "$", "items", ",", "$", "args", "=", "null", ")", "{", "if", "(", "!", "is_object", "(", "$", "args", ")", ")", "{", "$", "args", "=", "(", "object", ")", "$", "args", ";", "}", "if", "(", "$", "...
Adds a search icon to the main menu @param string $items Menu items html markup @param object $args Menu args
[ "Adds", "a", "search", "icon", "to", "the", "main", "menu" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Navigation.php#L209-L233
46,052
helsingborg-stad/Municipio
library/Content/ShortCode.php
ShortCode.displayMetaValue
public function displayMetaValue($atts, $content = "") { //Default value extract(shortcode_atts(array( 'key' => '' ), $atts)); //Get field with formatting if exits if (function_exists('get_field')) { return (string) get_field($key); } else { global $post; return (string) get_post_meta($post->ID, $key); } }
php
public function displayMetaValue($atts, $content = "") { //Default value extract(shortcode_atts(array( 'key' => '' ), $atts)); //Get field with formatting if exits if (function_exists('get_field')) { return (string) get_field($key); } else { global $post; return (string) get_post_meta($post->ID, $key); } }
[ "public", "function", "displayMetaValue", "(", "$", "atts", ",", "$", "content", "=", "\"\"", ")", "{", "//Default value", "extract", "(", "shortcode_atts", "(", "array", "(", "'key'", "=>", "''", ")", ",", "$", "atts", ")", ")", ";", "//Get field with for...
Shortcode function for "meta" @param array $atts Attributes @param string $content The content of the shortcode @return mixed
[ "Shortcode", "function", "for", "meta" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/ShortCode.php#L62-L76
46,053
helsingborg-stad/Municipio
library/Helper/AcfImportCleaner.php
AcfImportCleaner.acfLoadClean
public function acfLoadClean($paths) { $paths = array_unique($paths); foreach ($paths as $path) { foreach (@glob($path . '/*.json') as $file) { $json = json_decode(file_get_contents($file)); if (!is_array($json)) { continue; } $content = file($file); if (trim($content[0]) == '[') { array_shift($content); array_pop($content); } file_put_contents($file, $content); } } return $paths; }
php
public function acfLoadClean($paths) { $paths = array_unique($paths); foreach ($paths as $path) { foreach (@glob($path . '/*.json') as $file) { $json = json_decode(file_get_contents($file)); if (!is_array($json)) { continue; } $content = file($file); if (trim($content[0]) == '[') { array_shift($content); array_pop($content); } file_put_contents($file, $content); } } return $paths; }
[ "public", "function", "acfLoadClean", "(", "$", "paths", ")", "{", "$", "paths", "=", "array_unique", "(", "$", "paths", ")", ";", "foreach", "(", "$", "paths", "as", "$", "path", ")", "{", "foreach", "(", "@", "glob", "(", "$", "path", ".", "'/*.j...
Checks and cleans the formatting of the acf export files @param array $paths @return array
[ "Checks", "and", "cleans", "the", "formatting", "of", "the", "acf", "export", "files" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/AcfImportCleaner.php#L24-L48
46,054
helsingborg-stad/Municipio
library/Helper/Template.php
Template.locateTemplate
public static function locateTemplate($template, $additionalPaths = array()) { $defaultPaths = array( get_stylesheet_directory() . '/views', get_stylesheet_directory(), get_template_directory() . '/views', get_template_directory() ); $searchPaths = array_merge($defaultPaths, $additionalPaths); $searchPaths = apply_filters('Municipio/blade/view_paths', $searchPaths); if (isset($searchPaths) && is_array($searchPaths) && !empty($searchPaths)) { foreach ($searchPaths as $path) { $file = $path . '/' . str_replace('.blade.php', '', basename($template)) . '.blade.php'; if (!file_exists($file)) { continue; } return $file; } } else { error_log("Muncipio error: No template search paths defined in " . __DIR__ . __FILE__); } return false; }
php
public static function locateTemplate($template, $additionalPaths = array()) { $defaultPaths = array( get_stylesheet_directory() . '/views', get_stylesheet_directory(), get_template_directory() . '/views', get_template_directory() ); $searchPaths = array_merge($defaultPaths, $additionalPaths); $searchPaths = apply_filters('Municipio/blade/view_paths', $searchPaths); if (isset($searchPaths) && is_array($searchPaths) && !empty($searchPaths)) { foreach ($searchPaths as $path) { $file = $path . '/' . str_replace('.blade.php', '', basename($template)) . '.blade.php'; if (!file_exists($file)) { continue; } return $file; } } else { error_log("Muncipio error: No template search paths defined in " . __DIR__ . __FILE__); } return false; }
[ "public", "static", "function", "locateTemplate", "(", "$", "template", ",", "$", "additionalPaths", "=", "array", "(", ")", ")", "{", "$", "defaultPaths", "=", "array", "(", "get_stylesheet_directory", "(", ")", ".", "'/views'", ",", "get_stylesheet_directory",...
Check if and where template exists @param string $template Template file name @param array $additionalPaths Additional search paths @return bool False if not found else path to template file
[ "Check", "if", "and", "where", "template", "exists" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Template.php#L46-L74
46,055
helsingborg-stad/Municipio
library/Helper/Url.php
Url.queryStringExclude
public static function queryStringExclude($queryString, $excludeParams, $suffix = null) { $queryString = explode('&', $queryString); $query = array(); foreach ($queryString as $value) { $parts = explode('=', $value); $query[$parts[0]] = isset($parts[1]) ? $parts[1] : ''; } $queryString = $query; if (is_string($excludeParams)) { $excludeParams = array($excludeParams); } foreach ($excludeParams as $exclude) { unset($queryString[$exclude]); } $queryString = array_filter($queryString); $queryString = http_build_query($queryString); if (strlen($queryString) > 0) { $queryString .= $suffix; } return $queryString; }
php
public static function queryStringExclude($queryString, $excludeParams, $suffix = null) { $queryString = explode('&', $queryString); $query = array(); foreach ($queryString as $value) { $parts = explode('=', $value); $query[$parts[0]] = isset($parts[1]) ? $parts[1] : ''; } $queryString = $query; if (is_string($excludeParams)) { $excludeParams = array($excludeParams); } foreach ($excludeParams as $exclude) { unset($queryString[$exclude]); } $queryString = array_filter($queryString); $queryString = http_build_query($queryString); if (strlen($queryString) > 0) { $queryString .= $suffix; } return $queryString; }
[ "public", "static", "function", "queryStringExclude", "(", "$", "queryString", ",", "$", "excludeParams", ",", "$", "suffix", "=", "null", ")", "{", "$", "queryString", "=", "explode", "(", "'&'", ",", "$", "queryString", ")", ";", "$", "query", "=", "ar...
Exclude specified params from a querystring @param string $queryString The querystring @param array|string $excludeParams Paramters to exclude (remove) @param string $suffix Optional suffix to add last in the querystring @return string The new querystring
[ "Exclude", "specified", "params", "from", "a", "querystring" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Url.php#L30-L58
46,056
helsingborg-stad/Municipio
library/Helper/Url.php
Url.getQueryString
public static function getQueryString() { $querystringsDefault = explode('&', $_SERVER['QUERY_STRING']); $querystrings = array(); foreach ($querystringsDefault as $querystring) { $querystring = explode('=', $querystring); $querystrings[$querystring[0]] = isset($querystring[1]) ? $querystring[1] : null; } return $querystrings; }
php
public static function getQueryString() { $querystringsDefault = explode('&', $_SERVER['QUERY_STRING']); $querystrings = array(); foreach ($querystringsDefault as $querystring) { $querystring = explode('=', $querystring); $querystrings[$querystring[0]] = isset($querystring[1]) ? $querystring[1] : null; } return $querystrings; }
[ "public", "static", "function", "getQueryString", "(", ")", "{", "$", "querystringsDefault", "=", "explode", "(", "'&'", ",", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ")", ";", "$", "querystrings", "=", "array", "(", ")", ";", "foreach", "(", "$", "qu...
Get array with querystring params and values in current url @return array
[ "Get", "array", "with", "querystring", "params", "and", "values", "in", "current", "url" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Url.php#L64-L75
46,057
helsingborg-stad/Municipio
library/Helper/Css.php
Css.grid
public static function grid($columnSize = 'all', $screen = 'all') { if (!is_array(self::breakpoints()) || empty(self::breakpoints())) { return; } $breakpoints = self::breakpoints(); $columns = apply_filters('Municipio/Helper/Css/Grid/Columns', 12, $columnSize, $screen); $pattern = apply_filters('Municipio/Helper/Css/Grid/Pattern', 'grid-%s-%d', $columnSize, $screen); //Convert $screen to array $screen = (is_string($screen) && $screen != 'all') ? array($screen) : $screen; //Set breakpoints if ($screen != 'all') { foreach ($breakpoints as $i => $breakpoint) { if (!in_array($breakpoint, $screen)) { unset($breakpoints[$i]); } } } //Convert $columnSize to array $columnSize = (!is_array($columnSize) && $columnSize != 'all') ? array($columnSize) : $columnSize; //Create grid classes $grid = array(); foreach ($breakpoints as $breakpoint) { if ($columnSize == 'all') { for ($i = 1; $i <= $columns; $i++) { $grid[] = sprintf($pattern, $breakpoint, $i); } } else { foreach ($columnSize as $column) { if ($column <= $columns) { $grid[] = sprintf($pattern, $breakpoint, $column); } } } } //Convert to string if grid only has 1 item $grid = (count($grid) == 1) ? $grid[0] : $grid; if (!empty($grid) && is_array($grid) || !empty($grid) && is_string($grid)) { return $grid; } return false; }
php
public static function grid($columnSize = 'all', $screen = 'all') { if (!is_array(self::breakpoints()) || empty(self::breakpoints())) { return; } $breakpoints = self::breakpoints(); $columns = apply_filters('Municipio/Helper/Css/Grid/Columns', 12, $columnSize, $screen); $pattern = apply_filters('Municipio/Helper/Css/Grid/Pattern', 'grid-%s-%d', $columnSize, $screen); //Convert $screen to array $screen = (is_string($screen) && $screen != 'all') ? array($screen) : $screen; //Set breakpoints if ($screen != 'all') { foreach ($breakpoints as $i => $breakpoint) { if (!in_array($breakpoint, $screen)) { unset($breakpoints[$i]); } } } //Convert $columnSize to array $columnSize = (!is_array($columnSize) && $columnSize != 'all') ? array($columnSize) : $columnSize; //Create grid classes $grid = array(); foreach ($breakpoints as $breakpoint) { if ($columnSize == 'all') { for ($i = 1; $i <= $columns; $i++) { $grid[] = sprintf($pattern, $breakpoint, $i); } } else { foreach ($columnSize as $column) { if ($column <= $columns) { $grid[] = sprintf($pattern, $breakpoint, $column); } } } } //Convert to string if grid only has 1 item $grid = (count($grid) == 1) ? $grid[0] : $grid; if (!empty($grid) && is_array($grid) || !empty($grid) && is_string($grid)) { return $grid; } return false; }
[ "public", "static", "function", "grid", "(", "$", "columnSize", "=", "'all'", ",", "$", "screen", "=", "'all'", ")", "{", "if", "(", "!", "is_array", "(", "self", "::", "breakpoints", "(", ")", ")", "||", "empty", "(", "self", "::", "breakpoints", "(...
Generates grid classes @param mixed (int/string/array) $columnSize Column size (defaults to 'all') @param mixed (string/array) $screen Breakpoints (defaults to 'all') @return mixed (string/array) CSS grid classes
[ "Generates", "grid", "classes" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Css.php#L29-L79
46,058
helsingborg-stad/Municipio
library/Theme/Icons.php
Icons.getPricons
public static function getPricons() { if (!defined('MUNICIPIO_STYLEGUIDE_URI')) { $styleGuideUrl = '//helsingborg-stad.github.io/styleguide-web/dist/'; } else { $styleGuideUrl = MUNICIPIO_STYLEGUIDE_URI; } $transientKey = apply_filters('Municipio/Theme/Icons/Pricons/TransientKey', 'hbg_pricons'); if (get_site_transient($transientKey)) { return get_site_transient($transientKey); } $url = apply_filters('Municipio/Theme/Icons/Pricons/Url', 'https:' . $styleGuideUrl . 'pricons.json'); $json = \Municipio\Helper\Data::getRemoteJson($url); if ($json && is_array($json) && !empty($json)) { $pricons = array(); //Convert values to array foreach ($json as $icon) { $pricons[$icon->name] = get_object_vars($icon); } set_site_transient($transientKey, $pricons, 10); return get_site_transient($transientKey); } return false; }
php
public static function getPricons() { if (!defined('MUNICIPIO_STYLEGUIDE_URI')) { $styleGuideUrl = '//helsingborg-stad.github.io/styleguide-web/dist/'; } else { $styleGuideUrl = MUNICIPIO_STYLEGUIDE_URI; } $transientKey = apply_filters('Municipio/Theme/Icons/Pricons/TransientKey', 'hbg_pricons'); if (get_site_transient($transientKey)) { return get_site_transient($transientKey); } $url = apply_filters('Municipio/Theme/Icons/Pricons/Url', 'https:' . $styleGuideUrl . 'pricons.json'); $json = \Municipio\Helper\Data::getRemoteJson($url); if ($json && is_array($json) && !empty($json)) { $pricons = array(); //Convert values to array foreach ($json as $icon) { $pricons[$icon->name] = get_object_vars($icon); } set_site_transient($transientKey, $pricons, 10); return get_site_transient($transientKey); } return false; }
[ "public", "static", "function", "getPricons", "(", ")", "{", "if", "(", "!", "defined", "(", "'MUNICIPIO_STYLEGUIDE_URI'", ")", ")", "{", "$", "styleGuideUrl", "=", "'//helsingborg-stad.github.io/styleguide-web/dist/'", ";", "}", "else", "{", "$", "styleGuideUrl", ...
Get list of pricons from remote Json @return array List of pricons and values
[ "Get", "list", "of", "pricons", "from", "remote", "Json" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Icons.php#L12-L43
46,059
helsingborg-stad/Municipio
library/Controller/Single.php
Single.likeButton
public static function likeButton($id) { if (! is_user_logged_in()) { return; } $likes = get_comment_meta($id, '_likes', true); if (empty($likes) || is_array($likes) == false) { $count = 0; } else { $count = count($likes); } $classes = array('like-button'); if (is_array($likes) == true && in_array(get_current_user_id(), $likes)) { $classes[] = 'active'; } $output = '<a class="' . implode(' ', $classes) . '" href="javascript:void(0)" data-comment-id="' . $id . '">'; $output .= '<span id="like-count">' . $count . '</span>'; $output .= '</a>'; return $output; }
php
public static function likeButton($id) { if (! is_user_logged_in()) { return; } $likes = get_comment_meta($id, '_likes', true); if (empty($likes) || is_array($likes) == false) { $count = 0; } else { $count = count($likes); } $classes = array('like-button'); if (is_array($likes) == true && in_array(get_current_user_id(), $likes)) { $classes[] = 'active'; } $output = '<a class="' . implode(' ', $classes) . '" href="javascript:void(0)" data-comment-id="' . $id . '">'; $output .= '<span id="like-count">' . $count . '</span>'; $output .= '</a>'; return $output; }
[ "public", "static", "function", "likeButton", "(", "$", "id", ")", "{", "if", "(", "!", "is_user_logged_in", "(", ")", ")", "{", "return", ";", "}", "$", "likes", "=", "get_comment_meta", "(", "$", "id", ",", "'_likes'", ",", "true", ")", ";", "if", ...
Display comment like button @param int $id Comment ID @return string Markup to display button
[ "Display", "comment", "like", "button" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/Single.php#L36-L61
46,060
helsingborg-stad/Municipio
library/Theme/General.php
General.bemItClassDefinition
public function bemItClassDefinition() { //Classes $classes = array(); //Theme specific class $themeObject = wp_get_theme(); $classes[] = "t-" . sanitize_title($themeObject->get("Name")); //Child theme specific class if (is_child_theme()) { $childThemeObject = wp_get_theme(get_template()); $classes[] = "t-" . sanitize_title($childThemeObject->get("Name")); } //Define const for later use define("MUNICIPIO_BEM_THEME_NAME", implode(" ", $classes)); }
php
public function bemItClassDefinition() { //Classes $classes = array(); //Theme specific class $themeObject = wp_get_theme(); $classes[] = "t-" . sanitize_title($themeObject->get("Name")); //Child theme specific class if (is_child_theme()) { $childThemeObject = wp_get_theme(get_template()); $classes[] = "t-" . sanitize_title($childThemeObject->get("Name")); } //Define const for later use define("MUNICIPIO_BEM_THEME_NAME", implode(" ", $classes)); }
[ "public", "function", "bemItClassDefinition", "(", ")", "{", "//Classes", "$", "classes", "=", "array", "(", ")", ";", "//Theme specific class", "$", "themeObject", "=", "wp_get_theme", "(", ")", ";", "$", "classes", "[", "]", "=", "\"t-\"", ".", "sanitize_t...
Defines global BEM class for theme @return void
[ "Defines", "global", "BEM", "class", "for", "theme" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/General.php#L34-L51
46,061
helsingborg-stad/Municipio
library/Theme/General.php
General.sitesGridImage
public function sitesGridImage($image, $site) { switch_to_blog($site->blog_id); $image = null; if ($frontpage = get_option('page_on_front') && get_the_post_thumbnail_url(get_option('page_on_front'))) { $src = get_the_post_thumbnail_url($frontpage); if ($src) { $image = '<div style="background-image:url(' . $src . ');" class="box-image"> <img alt="' . $site->blogname . '" src="' . $src . '"> </div>'; } } if (!$image && $logo = get_field('logotype_negative', 'option')) { $image = '<div class="box-image"> ' . \Municipio\Helper\Svg::extract($logo['url']) . ' </div>'; } restore_current_blog(); return $image; }
php
public function sitesGridImage($image, $site) { switch_to_blog($site->blog_id); $image = null; if ($frontpage = get_option('page_on_front') && get_the_post_thumbnail_url(get_option('page_on_front'))) { $src = get_the_post_thumbnail_url($frontpage); if ($src) { $image = '<div style="background-image:url(' . $src . ');" class="box-image"> <img alt="' . $site->blogname . '" src="' . $src . '"> </div>'; } } if (!$image && $logo = get_field('logotype_negative', 'option')) { $image = '<div class="box-image"> ' . \Municipio\Helper\Svg::extract($logo['url']) . ' </div>'; } restore_current_blog(); return $image; }
[ "public", "function", "sitesGridImage", "(", "$", "image", ",", "$", "site", ")", "{", "switch_to_blog", "(", "$", "site", "->", "blog_id", ")", ";", "$", "image", "=", "null", ";", "if", "(", "$", "frontpage", "=", "get_option", "(", "'page_on_front'", ...
Returns image for module site grid @param string $image String containing previous image @param object $site The site object @return string
[ "Returns", "image", "for", "module", "site", "grid" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/General.php#L77-L102
46,062
helsingborg-stad/Municipio
library/Theme/General.php
General.fixFieldgroupLocationPath
public function fixFieldgroupLocationPath($fieldgroup) { if (!isset($fieldgroup['location'])) { return $fieldgroup; } foreach ($fieldgroup['location'] as &$locations) { foreach ($locations as &$location) { if ($location['param'] !== 'page_template') { return $fieldgroup; } $location['value'] = basename($location['value']); } } return $fieldgroup; }
php
public function fixFieldgroupLocationPath($fieldgroup) { if (!isset($fieldgroup['location'])) { return $fieldgroup; } foreach ($fieldgroup['location'] as &$locations) { foreach ($locations as &$location) { if ($location['param'] !== 'page_template') { return $fieldgroup; } $location['value'] = basename($location['value']); } } return $fieldgroup; }
[ "public", "function", "fixFieldgroupLocationPath", "(", "$", "fieldgroup", ")", "{", "if", "(", "!", "isset", "(", "$", "fieldgroup", "[", "'location'", "]", ")", ")", "{", "return", "$", "fieldgroup", ";", "}", "foreach", "(", "$", "fieldgroup", "[", "'...
Fixes fieldgroups page-template path @param array $fieldgroup Fieldgroup @return array
[ "Fixes", "fieldgroups", "page", "-", "template", "path" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/General.php#L111-L128
46,063
helsingborg-stad/Municipio
library/Theme/General.php
General.removeEmptyPTag
public function removeEmptyPTag($content) { $content = force_balance_tags($content); $content = preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content); $content = preg_replace('~\s?<p>(\s|&nbsp;)+</p>\s?~', '', $content); return $content; }
php
public function removeEmptyPTag($content) { $content = force_balance_tags($content); $content = preg_replace('#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content); $content = preg_replace('~\s?<p>(\s|&nbsp;)+</p>\s?~', '', $content); return $content; }
[ "public", "function", "removeEmptyPTag", "(", "$", "content", ")", "{", "$", "content", "=", "force_balance_tags", "(", "$", "content", ")", ";", "$", "content", "=", "preg_replace", "(", "'#<p>\\s*+(<br\\s*/*>)?\\s*</p>#i'", ",", "''", ",", "$", "content", ")...
Removes empty p-tags @param string $content Text @return string Markup
[ "Removes", "empty", "p", "-", "tags" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/General.php#L161-L168
46,064
helsingborg-stad/Municipio
library/Controller/Search.php
Search.algoliaCustomSearch
public function algoliaCustomSearch() { $this->data['results'] = queryAlgoliaSearch(get_search_query()); $this->data['keyword'] = get_search_query(); //Get count per index $this->data['resultIndexCount'] = $this->algoliaCustomSearchResultCount($this->data['results']); $this->data['resultIndexCountUrl'] = implode("-", $this->data['resultIndexCount']); //Total count if(isset($_GET['count_data'])) { $this->data['resultCount'] = array_sum(explode("-", $_GET['count_data'])); } else { if(is_array($this->data['results'])) { $this->data['resultCount'] = count($this->data['results']); } else { $this->data['resultCount'] = 0; } } //Pagination if(is_array($this->data['results'])) { $this->data['paginatedResults'] = array_chunk($this->data['results'], 30); } else { $this->data['paginatedResults'] = array(); } $this->data['pg'] = isset($_GET['pg']) && is_numeric($_GET['pg']) ? $_GET['pg'] : 0; }
php
public function algoliaCustomSearch() { $this->data['results'] = queryAlgoliaSearch(get_search_query()); $this->data['keyword'] = get_search_query(); //Get count per index $this->data['resultIndexCount'] = $this->algoliaCustomSearchResultCount($this->data['results']); $this->data['resultIndexCountUrl'] = implode("-", $this->data['resultIndexCount']); //Total count if(isset($_GET['count_data'])) { $this->data['resultCount'] = array_sum(explode("-", $_GET['count_data'])); } else { if(is_array($this->data['results'])) { $this->data['resultCount'] = count($this->data['results']); } else { $this->data['resultCount'] = 0; } } //Pagination if(is_array($this->data['results'])) { $this->data['paginatedResults'] = array_chunk($this->data['results'], 30); } else { $this->data['paginatedResults'] = array(); } $this->data['pg'] = isset($_GET['pg']) && is_numeric($_GET['pg']) ? $_GET['pg'] : 0; }
[ "public", "function", "algoliaCustomSearch", "(", ")", "{", "$", "this", "->", "data", "[", "'results'", "]", "=", "queryAlgoliaSearch", "(", "get_search_query", "(", ")", ")", ";", "$", "this", "->", "data", "[", "'keyword'", "]", "=", "get_search_query", ...
Algolia custom search @return void
[ "Algolia", "custom", "search" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/Search.php#L85-L114
46,065
helsingborg-stad/Municipio
library/Controller/Search.php
Search.googleSearch
public function googleSearch() { $search = new \Municipio\Search\Google(get_search_query(), $this->getIndex()); $this->data['search'] = $search; $this->data['results'] = $search->results; }
php
public function googleSearch() { $search = new \Municipio\Search\Google(get_search_query(), $this->getIndex()); $this->data['search'] = $search; $this->data['results'] = $search->results; }
[ "public", "function", "googleSearch", "(", ")", "{", "$", "search", "=", "new", "\\", "Municipio", "\\", "Search", "\\", "Google", "(", "get_search_query", "(", ")", ",", "$", "this", "->", "getIndex", "(", ")", ")", ";", "$", "this", "->", "data", "...
Google Site Search init @return void
[ "Google", "Site", "Search", "init" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/Search.php#L146-L151
46,066
helsingborg-stad/Municipio
library/Theme/Share.php
Share.redirectFromShortlink
public function redirectFromShortlink() { //Check if is admin if(is_admin()) { return; } //Get the post id $postId = get_query_var('socialShareId', null); //Do redirect if(!is_null($postId) && is_numeric($postId)) { wp_safe_redirect(get_permalink($postId), 301); exit; } }
php
public function redirectFromShortlink() { //Check if is admin if(is_admin()) { return; } //Get the post id $postId = get_query_var('socialShareId', null); //Do redirect if(!is_null($postId) && is_numeric($postId)) { wp_safe_redirect(get_permalink($postId), 301); exit; } }
[ "public", "function", "redirectFromShortlink", "(", ")", "{", "//Check if is admin", "if", "(", "is_admin", "(", ")", ")", "{", "return", ";", "}", "//Get the post id", "$", "postId", "=", "get_query_var", "(", "'socialShareId'", ",", "null", ")", ";", "//Do r...
Make a redirect to the actiual page @return void
[ "Make", "a", "redirect", "to", "the", "actiual", "page" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Share.php#L38-L54
46,067
helsingborg-stad/Municipio
library/Widget/Source/BaseWidget.php
BaseWidget.widget
public function widget($args, $instance) { $this->data['args'] = $args; $this->data['instance'] = $instance; if (method_exists($this, 'beforeViewController')) { $this->beforeViewController(); } $this->viewController($args, $instance); if (method_exists($this, 'afterViewController')) { $this->afterViewController(); } $blade = new Blade($this->viewPath, $this->cachePath); echo $blade->view()->make('widget.' . str_replace(array('widget.', '.blade.php'), '', $this->template), $this->data)->render(); }
php
public function widget($args, $instance) { $this->data['args'] = $args; $this->data['instance'] = $instance; if (method_exists($this, 'beforeViewController')) { $this->beforeViewController(); } $this->viewController($args, $instance); if (method_exists($this, 'afterViewController')) { $this->afterViewController(); } $blade = new Blade($this->viewPath, $this->cachePath); echo $blade->view()->make('widget.' . str_replace(array('widget.', '.blade.php'), '', $this->template), $this->data)->render(); }
[ "public", "function", "widget", "(", "$", "args", ",", "$", "instance", ")", "{", "$", "this", "->", "data", "[", "'args'", "]", "=", "$", "args", ";", "$", "this", "->", "data", "[", "'instance'", "]", "=", "$", "instance", ";", "if", "(", "meth...
Front-end of the widget. Instantiates the viewController method and renders blade view. @param array $args Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'. @param array $instance The settings for the particular instance of the widget. @return void
[ "Front", "-", "end", "of", "the", "widget", ".", "Instantiates", "the", "viewController", "method", "and", "renders", "blade", "view", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/BaseWidget.php#L86-L103
46,068
helsingborg-stad/Municipio
library/Widget/Source/BaseWidget.php
BaseWidget.update
public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = (! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; return $instance; }
php
public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = (! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; return $instance; }
[ "public", "function", "update", "(", "$", "new_instance", ",", "$", "old_instance", ")", "{", "$", "instance", "=", "array", "(", ")", ";", "$", "instance", "[", "'title'", "]", "=", "(", "!", "empty", "(", "$", "new_instance", "[", "'title'", "]", "...
Updates a particular instance of a widget. This function should check that `$new_instance` is set correctly. The newly-calculated value of `$instance` should be returned. If false is returned, the instance won't be saved/updated. @param array $new_instance New settings for this instance as input by the user via WP_Widget::form(). @param array $old_instance Old settings for this instance. @return array Settings to save or bool false to cancel saving.
[ "Updates", "a", "particular", "instance", "of", "a", "widget", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/BaseWidget.php#L137-L142
46,069
helsingborg-stad/Municipio
library/Theme/FixedActionBar.php
FixedActionBar.populateSelectField
public function populateSelectField($field) { $menus = \Municipio\Helper\Navigation::getMenuList(); $field['choices'] = array(); foreach ($menus as $menu) { $field['choices'][$menu->term_id] = $menu->name . ' (ID: ' . $menu->term_id . ')'; } return $field; }
php
public function populateSelectField($field) { $menus = \Municipio\Helper\Navigation::getMenuList(); $field['choices'] = array(); foreach ($menus as $menu) { $field['choices'][$menu->term_id] = $menu->name . ' (ID: ' . $menu->term_id . ')'; } return $field; }
[ "public", "function", "populateSelectField", "(", "$", "field", ")", "{", "$", "menus", "=", "\\", "Municipio", "\\", "Helper", "\\", "Navigation", "::", "getMenuList", "(", ")", ";", "$", "field", "[", "'choices'", "]", "=", "array", "(", ")", ";", "f...
Populate select field with WP menus @param array $field ACF fields @return array
[ "Populate", "select", "field", "with", "WP", "menus" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/FixedActionBar.php#L17-L27
46,070
helsingborg-stad/Municipio
library/Theme/FixedActionBar.php
FixedActionBar.getFab
public static function getFab() { if (!get_field('fab_settings', 'options') || get_field('fab_settings', 'options') == 'disabled') { return false; } $fab = array(); if (get_field('fab_settings', 'options') == 'wp' && get_field('fab_wp_menu', 'options')) { $fab['menu'] = self::wpMenu(get_field('fab_wp_menu', 'options')); } if (self::generateClasses() && isset($fab['menu'])) { $fab['classes'] = self::generateClasses(); } if (isset($fab['menu'])) { return $fab; } return false; }
php
public static function getFab() { if (!get_field('fab_settings', 'options') || get_field('fab_settings', 'options') == 'disabled') { return false; } $fab = array(); if (get_field('fab_settings', 'options') == 'wp' && get_field('fab_wp_menu', 'options')) { $fab['menu'] = self::wpMenu(get_field('fab_wp_menu', 'options')); } if (self::generateClasses() && isset($fab['menu'])) { $fab['classes'] = self::generateClasses(); } if (isset($fab['menu'])) { return $fab; } return false; }
[ "public", "static", "function", "getFab", "(", ")", "{", "if", "(", "!", "get_field", "(", "'fab_settings'", ",", "'options'", ")", "||", "get_field", "(", "'fab_settings'", ",", "'options'", ")", "==", "'disabled'", ")", "{", "return", "false", ";", "}", ...
Get fixed action bar @return array/boolean
[ "Get", "fixed", "action", "bar" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/FixedActionBar.php#L33-L54
46,071
helsingborg-stad/Municipio
library/Theme/FixedActionBar.php
FixedActionBar.generateClasses
public static function generateClasses() { $classes = array(); $classes[] = 'fab--right'; if (get_field('fab_visabllity', 'options') && is_array(get_field('fab_visabllity', 'options')) && !empty(get_field('fab_visabllity', 'options'))) { $classes = array_merge($classes, get_field('fab_visabllity', 'options')); } if (!empty($classes)) { return implode(' ', $classes); } return false; }
php
public static function generateClasses() { $classes = array(); $classes[] = 'fab--right'; if (get_field('fab_visabllity', 'options') && is_array(get_field('fab_visabllity', 'options')) && !empty(get_field('fab_visabllity', 'options'))) { $classes = array_merge($classes, get_field('fab_visabllity', 'options')); } if (!empty($classes)) { return implode(' ', $classes); } return false; }
[ "public", "static", "function", "generateClasses", "(", ")", "{", "$", "classes", "=", "array", "(", ")", ";", "$", "classes", "[", "]", "=", "'fab--right'", ";", "if", "(", "get_field", "(", "'fab_visabllity'", ",", "'options'", ")", "&&", "is_array", "...
Generate fab style classes @return string/boolean
[ "Generate", "fab", "style", "classes" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/FixedActionBar.php#L60-L74
46,072
helsingborg-stad/Municipio
library/Helper/User.php
User.hasRole
public static function hasRole($roles) { $user = wp_get_current_user(); if (is_string($roles)) { $roles = array($roles); } if (!array_intersect($roles, $user->roles)) { return false; } return true; }
php
public static function hasRole($roles) { $user = wp_get_current_user(); if (is_string($roles)) { $roles = array($roles); } if (!array_intersect($roles, $user->roles)) { return false; } return true; }
[ "public", "static", "function", "hasRole", "(", "$", "roles", ")", "{", "$", "user", "=", "wp_get_current_user", "(", ")", ";", "if", "(", "is_string", "(", "$", "roles", ")", ")", "{", "$", "roles", "=", "array", "(", "$", "roles", ")", ";", "}", ...
Check if current user has a specific role Can also check multiple roles, returns true if any of exists for the user @param string|array $roles Role or roles to check @return boolean
[ "Check", "if", "current", "user", "has", "a", "specific", "role", "Can", "also", "check", "multiple", "roles", "returns", "true", "if", "any", "of", "exists", "for", "the", "user" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/User.php#L13-L26
46,073
helsingborg-stad/Municipio
library/Comment/CommentsActions.php
CommentsActions.updateComment
public function updateComment() { $newComment = $_POST['comment'] ?? null; $commentId = $_POST['commentId'] ?? null; if (!$newComment || !$commentId || !$comment = get_comment($commentId)) { wp_send_json_error('Missing variables'); } if (!current_user_can('edit_comment', $comment->comment_ID) && !($comment->user_id == get_current_user_id())) { wp_send_json_error('Missing authorization'); } // Validate nonce if (!check_ajax_referer("update-comment_$comment->comment_ID", 'nonce', false)) { wp_send_json_error('Nonce failed'); } $comment->comment_content = $newComment; if (wp_update_comment((array) $comment)) { wp_send_json_success('Update was successful'); } wp_send_json(); }
php
public function updateComment() { $newComment = $_POST['comment'] ?? null; $commentId = $_POST['commentId'] ?? null; if (!$newComment || !$commentId || !$comment = get_comment($commentId)) { wp_send_json_error('Missing variables'); } if (!current_user_can('edit_comment', $comment->comment_ID) && !($comment->user_id == get_current_user_id())) { wp_send_json_error('Missing authorization'); } // Validate nonce if (!check_ajax_referer("update-comment_$comment->comment_ID", 'nonce', false)) { wp_send_json_error('Nonce failed'); } $comment->comment_content = $newComment; if (wp_update_comment((array) $comment)) { wp_send_json_success('Update was successful'); } wp_send_json(); }
[ "public", "function", "updateComment", "(", ")", "{", "$", "newComment", "=", "$", "_POST", "[", "'comment'", "]", "??", "null", ";", "$", "commentId", "=", "$", "_POST", "[", "'commentId'", "]", "??", "null", ";", "if", "(", "!", "$", "newComment", ...
Update a comment front end @return void
[ "Update", "a", "comment", "front", "end" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsActions.php#L18-L42
46,074
helsingborg-stad/Municipio
library/Comment/CommentsActions.php
CommentsActions.getCommentForm
public function getCommentForm() { $postId = $_POST['postId'] ?? null; $commentId = $_POST['commentId'] ?? null; if (!$commentId || !$postId || !$comment = get_comment($commentId)) { wp_send_json_error('Missing variables'); } if (!$comment = get_comment($commentId)) { wp_send_json_error('Comment is missing'); } $args = array( 'id_form' => 'commentupdate', 'class_submit' => 'btn btn-sm btn-primary', 'title_reply' => '', 'title_reply_before' => '', 'title_reply_after' => '', 'label_submit' => __('Update', 'municipio'), 'logged_in_as' => '', 'comment_field' => '<textarea id="update-comment" name="comment" cols="45" rows="8" aria-required="true">' . $comment->comment_content . '</textarea>', 'comment_notes_after' => '<input type="hidden" name="commentId" value="' . $commentId . '"> <input type="hidden" name="nonce" value="' . wp_create_nonce("update-comment_$commentId") . '">', 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" /> <a href="#" class="cancel-update-comment gutter gutter-left gutter-sm"><small>' . __('Cancel', 'municipio') . '</small></a>' ); ob_start(); comment_form($args, $postId); $form = ob_get_clean(); $form = str_replace('class="comment-respond"', 'class="comment-respond comment-respond-new comment-update"', $form); $form = str_replace('id="respond"', 'id="respond-edit"', $form); wp_send_json_success($form); }
php
public function getCommentForm() { $postId = $_POST['postId'] ?? null; $commentId = $_POST['commentId'] ?? null; if (!$commentId || !$postId || !$comment = get_comment($commentId)) { wp_send_json_error('Missing variables'); } if (!$comment = get_comment($commentId)) { wp_send_json_error('Comment is missing'); } $args = array( 'id_form' => 'commentupdate', 'class_submit' => 'btn btn-sm btn-primary', 'title_reply' => '', 'title_reply_before' => '', 'title_reply_after' => '', 'label_submit' => __('Update', 'municipio'), 'logged_in_as' => '', 'comment_field' => '<textarea id="update-comment" name="comment" cols="45" rows="8" aria-required="true">' . $comment->comment_content . '</textarea>', 'comment_notes_after' => '<input type="hidden" name="commentId" value="' . $commentId . '"> <input type="hidden" name="nonce" value="' . wp_create_nonce("update-comment_$commentId") . '">', 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" /> <a href="#" class="cancel-update-comment gutter gutter-left gutter-sm"><small>' . __('Cancel', 'municipio') . '</small></a>' ); ob_start(); comment_form($args, $postId); $form = ob_get_clean(); $form = str_replace('class="comment-respond"', 'class="comment-respond comment-respond-new comment-update"', $form); $form = str_replace('id="respond"', 'id="respond-edit"', $form); wp_send_json_success($form); }
[ "public", "function", "getCommentForm", "(", ")", "{", "$", "postId", "=", "$", "_POST", "[", "'postId'", "]", "??", "null", ";", "$", "commentId", "=", "$", "_POST", "[", "'commentId'", "]", "??", "null", ";", "if", "(", "!", "$", "commentId", "||",...
Returns markup for the edit comment form @return void
[ "Returns", "markup", "for", "the", "edit", "comment", "form" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsActions.php#L48-L82
46,075
helsingborg-stad/Municipio
library/Comment/CommentsActions.php
CommentsActions.removeComment
public function removeComment() { $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; if (!$comment = get_comment($id)) { wp_send_json_error('Comment is missing'); } if (!current_user_can('edit_comment', $comment->comment_ID) && !($comment->user_id == get_current_user_id())) { wp_send_json_error('Missing authorization'); } // Validate nonce if (!check_ajax_referer("delete-comment_$id", 'nonce', false)) { wp_send_json_error('Nonce failed'); } $trashed = wp_trash_comment($comment); if ($trashed) { wp_send_json_success('Deletion was successful'); } wp_send_json(); }
php
public function removeComment() { $id = isset($_POST['id']) ? (int) $_POST['id'] : 0; if (!$comment = get_comment($id)) { wp_send_json_error('Comment is missing'); } if (!current_user_can('edit_comment', $comment->comment_ID) && !($comment->user_id == get_current_user_id())) { wp_send_json_error('Missing authorization'); } // Validate nonce if (!check_ajax_referer("delete-comment_$id", 'nonce', false)) { wp_send_json_error('Nonce failed'); } $trashed = wp_trash_comment($comment); if ($trashed) { wp_send_json_success('Deletion was successful'); } wp_send_json(); }
[ "public", "function", "removeComment", "(", ")", "{", "$", "id", "=", "isset", "(", "$", "_POST", "[", "'id'", "]", ")", "?", "(", "int", ")", "$", "_POST", "[", "'id'", "]", ":", "0", ";", "if", "(", "!", "$", "comment", "=", "get_comment", "(...
Delete comment. Works similar as 'wp_ajax_delete_comment', but this allows all user roles to delete their own comments. @return void
[ "Delete", "comment", ".", "Works", "similar", "as", "wp_ajax_delete_comment", "but", "this", "allows", "all", "user", "roles", "to", "delete", "their", "own", "comments", "." ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsActions.php#L89-L112
46,076
helsingborg-stad/Municipio
library/Content/CustomPostType.php
CustomPostType.setPageTemplate
public function setPageTemplate($template_path) { // Exclude post types $excludedPostTypes = array(); if (has_filter('Municipio/CustomPostType/ExcludedPostTypes')) { $excludedPostTypes = apply_filters('Municipio/CustomPostType/ExcludedPostTypes', $excludedPostTypes); } if ($post_type = get_post_type()) { $post_type_object = get_post_type_object($post_type); if (is_object($post_type_object) && $post_type_object->hierarchical == true && $post_type_object->_builtin == false && !in_array($post_type_object->name, $excludedPostTypes)) { $template_path = \Municipio\Helper\Template::locateTemplate('page'); } } return($template_path); }
php
public function setPageTemplate($template_path) { // Exclude post types $excludedPostTypes = array(); if (has_filter('Municipio/CustomPostType/ExcludedPostTypes')) { $excludedPostTypes = apply_filters('Municipio/CustomPostType/ExcludedPostTypes', $excludedPostTypes); } if ($post_type = get_post_type()) { $post_type_object = get_post_type_object($post_type); if (is_object($post_type_object) && $post_type_object->hierarchical == true && $post_type_object->_builtin == false && !in_array($post_type_object->name, $excludedPostTypes)) { $template_path = \Municipio\Helper\Template::locateTemplate('page'); } } return($template_path); }
[ "public", "function", "setPageTemplate", "(", "$", "template_path", ")", "{", "// Exclude post types", "$", "excludedPostTypes", "=", "array", "(", ")", ";", "if", "(", "has_filter", "(", "'Municipio/CustomPostType/ExcludedPostTypes'", ")", ")", "{", "$", "excludedP...
Use page template for hierarchical custom post types @param string $template_path Path to post type template @return string
[ "Use", "page", "template", "for", "hierarchical", "custom", "post", "types" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/CustomPostType.php#L115-L132
46,077
helsingborg-stad/Municipio
library/Comment/LikeButton.php
LikeButton.ajaxLikeMethod
public function ajaxLikeMethod() { if (! defined('DOING_AJAX') && ! DOING_AJAX) { return false; } if (! wp_verify_nonce($_POST['nonce'], 'likeNonce')) { die('Busted!'); } ignore_user_abort(true); $commentId = $_REQUEST['comment_id']; $commentObj = get_comment($commentId); $like = array(); $create = true; if (is_array(get_comment_meta($commentId, '_likes', true)) == true) { $like = array_merge($like, get_comment_meta($commentId, '_likes', true)); } if (in_array(get_current_user_id(), $like)) { $create = false; $index = array_search(get_current_user_id(), $like); unset($like[$index]); } else { $like[] = get_current_user_id(); } do_action('Municipio/comment/save_like', $commentObj, get_current_user_id(), $create); update_comment_meta($commentId, '_likes', $like); return true; }
php
public function ajaxLikeMethod() { if (! defined('DOING_AJAX') && ! DOING_AJAX) { return false; } if (! wp_verify_nonce($_POST['nonce'], 'likeNonce')) { die('Busted!'); } ignore_user_abort(true); $commentId = $_REQUEST['comment_id']; $commentObj = get_comment($commentId); $like = array(); $create = true; if (is_array(get_comment_meta($commentId, '_likes', true)) == true) { $like = array_merge($like, get_comment_meta($commentId, '_likes', true)); } if (in_array(get_current_user_id(), $like)) { $create = false; $index = array_search(get_current_user_id(), $like); unset($like[$index]); } else { $like[] = get_current_user_id(); } do_action('Municipio/comment/save_like', $commentObj, get_current_user_id(), $create); update_comment_meta($commentId, '_likes', $like); return true; }
[ "public", "function", "ajaxLikeMethod", "(", ")", "{", "if", "(", "!", "defined", "(", "'DOING_AJAX'", ")", "&&", "!", "DOING_AJAX", ")", "{", "return", "false", ";", "}", "if", "(", "!", "wp_verify_nonce", "(", "$", "_POST", "[", "'nonce'", "]", ",", ...
Ajax method to add comment likes @return boolean
[ "Ajax", "method", "to", "add", "comment", "likes" ]
923ca84eafa775237b97221e73a9b381fa6ddcba
https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/LikeButton.php#L24-L56
46,078
wp-cli/role-command
src/Capabilities_Command.php
Capabilities_Command.list_
public function list_( $args, $assoc_args ) { $role_obj = self::get_role( $args[0] ); $show_grant = ! empty( $assoc_args['show-grant'] ); if ( $show_grant ) { array_push( $this->fields, 'grant' ); $capabilities = $role_obj->capabilities; } else { $capabilities = array_filter( $role_obj->capabilities ); } $output_caps = array(); foreach ( $capabilities as $cap => $grant ) { $output_cap = new stdClass(); $output_cap->name = $cap; $output_cap->grant = $grant ? 'true' : 'false'; $output_caps[] = $output_cap; } if ( 'list' === $assoc_args['format'] ) { foreach ( $output_caps as $cap ) { if ( $show_grant ) { WP_CLI::line( implode( ',', array( $cap->name, $cap->grant ) ) ); } else { WP_CLI::line( $cap->name ); } } } else { $formatter = new Formatter( $assoc_args, $this->fields ); $formatter->display_items( $output_caps ); } }
php
public function list_( $args, $assoc_args ) { $role_obj = self::get_role( $args[0] ); $show_grant = ! empty( $assoc_args['show-grant'] ); if ( $show_grant ) { array_push( $this->fields, 'grant' ); $capabilities = $role_obj->capabilities; } else { $capabilities = array_filter( $role_obj->capabilities ); } $output_caps = array(); foreach ( $capabilities as $cap => $grant ) { $output_cap = new stdClass(); $output_cap->name = $cap; $output_cap->grant = $grant ? 'true' : 'false'; $output_caps[] = $output_cap; } if ( 'list' === $assoc_args['format'] ) { foreach ( $output_caps as $cap ) { if ( $show_grant ) { WP_CLI::line( implode( ',', array( $cap->name, $cap->grant ) ) ); } else { WP_CLI::line( $cap->name ); } } } else { $formatter = new Formatter( $assoc_args, $this->fields ); $formatter->display_items( $output_caps ); } }
[ "public", "function", "list_", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "$", "role_obj", "=", "self", "::", "get_role", "(", "$", "args", "[", "0", "]", ")", ";", "$", "show_grant", "=", "!", "empty", "(", "$", "assoc_args", "[", "'show-...
Lists capabilities for a given role. ## OPTIONS <role> : Key for the role. [--format=<format>] : Render output in a particular format. --- default: list options: - list - table - csv - json - count - yaml --- [--show-grant] : Display all capabilities defined for a role including grant. --- default: false --- ## EXAMPLES # Display alphabetical list of Contributor capabilities. $ wp cap list 'contributor' | sort delete_posts edit_posts level_0 level_1 read @subcommand list
[ "Lists", "capabilities", "for", "a", "given", "role", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Capabilities_Command.php#L72-L106
46,079
wp-cli/role-command
src/Capabilities_Command.php
Capabilities_Command.add
public function add( $args, $assoc_args ) { self::persistence_check(); $role = array_shift( $args ); $role_obj = self::get_role( $role ); $grant = ! isset( $assoc_args['grant'] ) || ! empty( $assoc_args['grant'] ); $count = 0; foreach ( $args as $cap ) { if ( true === $grant && $role_obj->has_cap( $cap ) ) { continue; } if ( false === $grant && isset( $role_obj->capabilities[ $cap ] ) && false === $role_obj->capabilities[ $cap ] ) { continue; } $role_obj->add_cap( $cap, $grant ); $count++; } $capability = WP_CLI\Utils\pluralize( 'capability', $count ); $grant_qualification = $grant ? '' : ' as false'; WP_CLI::success( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." ); }
php
public function add( $args, $assoc_args ) { self::persistence_check(); $role = array_shift( $args ); $role_obj = self::get_role( $role ); $grant = ! isset( $assoc_args['grant'] ) || ! empty( $assoc_args['grant'] ); $count = 0; foreach ( $args as $cap ) { if ( true === $grant && $role_obj->has_cap( $cap ) ) { continue; } if ( false === $grant && isset( $role_obj->capabilities[ $cap ] ) && false === $role_obj->capabilities[ $cap ] ) { continue; } $role_obj->add_cap( $cap, $grant ); $count++; } $capability = WP_CLI\Utils\pluralize( 'capability', $count ); $grant_qualification = $grant ? '' : ' as false'; WP_CLI::success( "Added {$count} {$capability} to '{$role}' role{$grant_qualification}." ); }
[ "public", "function", "add", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "self", "::", "persistence_check", "(", ")", ";", "$", "role", "=", "array_shift", "(", "$", "args", ")", ";", "$", "role_obj", "=", "self", "::", "get_role", "(", "$", ...
Adds capabilities to a given role. ## OPTIONS <role> : Key for the role. <cap>... : One or more capabilities to add. [--grant] : Adds the capability as an explicit boolean value, instead of implicitly defaulting to `true`. --- default: true options: - true - false --- ## EXAMPLES # Add 'spectate' capability to 'author' role. $ wp cap add author spectate Success: Added 1 capability to 'author' role.
[ "Adds", "capabilities", "to", "a", "given", "role", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Capabilities_Command.php#L134-L163
46,080
wp-cli/role-command
src/Capabilities_Command.php
Capabilities_Command.remove
public function remove( $args ) { self::persistence_check(); $role = array_shift( $args ); $role_obj = self::get_role( $role ); $count = 0; foreach ( $args as $cap ) { if ( ! isset( $role_obj->capabilities[ $cap ] ) ) { continue; } $role_obj->remove_cap( $cap ); $count++; } $capability = WP_CLI\Utils\pluralize( 'capability', $count ); WP_CLI::success( "Removed {$count} {$capability} from '{$role}' role." ); }
php
public function remove( $args ) { self::persistence_check(); $role = array_shift( $args ); $role_obj = self::get_role( $role ); $count = 0; foreach ( $args as $cap ) { if ( ! isset( $role_obj->capabilities[ $cap ] ) ) { continue; } $role_obj->remove_cap( $cap ); $count++; } $capability = WP_CLI\Utils\pluralize( 'capability', $count ); WP_CLI::success( "Removed {$count} {$capability} from '{$role}' role." ); }
[ "public", "function", "remove", "(", "$", "args", ")", "{", "self", "::", "persistence_check", "(", ")", ";", "$", "role", "=", "array_shift", "(", "$", "args", ")", ";", "$", "role_obj", "=", "self", "::", "get_role", "(", "$", "role", ")", ";", "...
Removes capabilities from a given role. ## OPTIONS <role> : Key for the role. <cap>... : One or more capabilities to remove. ## EXAMPLES # Remove 'spectate' capability from 'author' role. $ wp cap remove author spectate Success: Removed 1 capability from 'author' role.
[ "Removes", "capabilities", "from", "a", "given", "role", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Capabilities_Command.php#L182-L204
46,081
wp-cli/role-command
src/Capabilities_Command.php
Capabilities_Command.get_role
private static function get_role( $role ) { global $wp_roles; $role_obj = $wp_roles->get_role( $role ); if ( ! $role_obj ) { WP_CLI::error( "'{$role}' role not found." ); } return $role_obj; }
php
private static function get_role( $role ) { global $wp_roles; $role_obj = $wp_roles->get_role( $role ); if ( ! $role_obj ) { WP_CLI::error( "'{$role}' role not found." ); } return $role_obj; }
[ "private", "static", "function", "get_role", "(", "$", "role", ")", "{", "global", "$", "wp_roles", ";", "$", "role_obj", "=", "$", "wp_roles", "->", "get_role", "(", "$", "role", ")", ";", "if", "(", "!", "$", "role_obj", ")", "{", "WP_CLI", "::", ...
Retrieve a specific role from the system. @param string $role Role to retrieve. @return WP_Role Requested role. @throws \WP_CLI\ExitException If the role could not be found.
[ "Retrieve", "a", "specific", "role", "from", "the", "system", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Capabilities_Command.php#L213-L223
46,082
wp-cli/role-command
src/Role_Command.php
Role_Command.list_
public function list_( $args, $assoc_args ) { global $wp_roles; $output_roles = array(); foreach ( $wp_roles->roles as $key => $role ) { $output_role = new stdClass(); $output_role->name = $role['name']; $output_role->role = $key; $output_roles[] = $output_role; } $formatter = new Formatter( $assoc_args, $this->fields ); $formatter->display_items( $output_roles ); }
php
public function list_( $args, $assoc_args ) { global $wp_roles; $output_roles = array(); foreach ( $wp_roles->roles as $key => $role ) { $output_role = new stdClass(); $output_role->name = $role['name']; $output_role->role = $key; $output_roles[] = $output_role; } $formatter = new Formatter( $assoc_args, $this->fields ); $formatter->display_items( $output_roles ); }
[ "public", "function", "list_", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "global", "$", "wp_roles", ";", "$", "output_roles", "=", "array", "(", ")", ";", "foreach", "(", "$", "wp_roles", "->", "roles", "as", "$", "key", "=>", "$", "role", ...
Lists all roles. ## OPTIONS [--fields=<fields>] : Limit the output to specific object fields. [--field=<field>] : Prints the value of a single field. [--format=<format>] : Render output in a particular format. --- default: table options: - table - csv - json - count - yaml --- ## AVAILABLE FIELDS These fields will be displayed by default for each role: * name * role There are no optional fields. ## EXAMPLES # List roles. $ wp role list --fields=role --format=csv role administrator editor author contributor subscriber @subcommand list
[ "Lists", "all", "roles", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Role_Command.php#L101-L116
46,083
wp-cli/role-command
src/Role_Command.php
Role_Command.exists
public function exists( $args ) { global $wp_roles; if ( ! in_array( $args[0], array_keys( $wp_roles->roles ), true ) ) { WP_CLI::error( "Role with ID '{$args[0]}' does not exist." ); } WP_CLI::success( "Role with ID '{$args[0]}' exists." ); }
php
public function exists( $args ) { global $wp_roles; if ( ! in_array( $args[0], array_keys( $wp_roles->roles ), true ) ) { WP_CLI::error( "Role with ID '{$args[0]}' does not exist." ); } WP_CLI::success( "Role with ID '{$args[0]}' exists." ); }
[ "public", "function", "exists", "(", "$", "args", ")", "{", "global", "$", "wp_roles", ";", "if", "(", "!", "in_array", "(", "$", "args", "[", "0", "]", ",", "array_keys", "(", "$", "wp_roles", "->", "roles", ")", ",", "true", ")", ")", "{", "WP_...
Checks if a role exists. Exits with return code 0 if the role exists, 1 if it does not. ## OPTIONS <role-key> : The internal name of the role. ## EXAMPLES # Check if a role exists. $ wp role exists editor Success: Role with ID 'editor' exists.
[ "Checks", "if", "a", "role", "exists", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Role_Command.php#L134-L142
46,084
wp-cli/role-command
src/Role_Command.php
Role_Command.create
public function create( $args, $assoc_args ) { global $wp_roles; self::persistence_check(); $role_key = array_shift( $args ); $role_name = array_shift( $args ); if ( empty( $role_key ) || empty( $role_name ) ) { WP_CLI::error( "Can't create role, insufficient information provided." ); } $capabilities = false; if ( ! empty( $assoc_args['clone'] ) ) { $role_obj = $wp_roles->get_role( $assoc_args['clone'] ); if ( ! $role_obj ) { WP_CLI::error( "'{$assoc_args['clone']}' role not found." ); } $capabilities = array_keys( $role_obj->capabilities ); } if ( add_role( $role_key, $role_name ) ) { if ( ! empty( $capabilities ) ) { $role_obj = $wp_roles->get_role( $role_key ); foreach ( $capabilities as $cap ) { $role_obj->add_cap( $cap ); } WP_CLI::success( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." ); } else { WP_CLI::success( "Role with key '{$role_key}' created." ); } } else { WP_CLI::error( "Role couldn't be created." ); } }
php
public function create( $args, $assoc_args ) { global $wp_roles; self::persistence_check(); $role_key = array_shift( $args ); $role_name = array_shift( $args ); if ( empty( $role_key ) || empty( $role_name ) ) { WP_CLI::error( "Can't create role, insufficient information provided." ); } $capabilities = false; if ( ! empty( $assoc_args['clone'] ) ) { $role_obj = $wp_roles->get_role( $assoc_args['clone'] ); if ( ! $role_obj ) { WP_CLI::error( "'{$assoc_args['clone']}' role not found." ); } $capabilities = array_keys( $role_obj->capabilities ); } if ( add_role( $role_key, $role_name ) ) { if ( ! empty( $capabilities ) ) { $role_obj = $wp_roles->get_role( $role_key ); foreach ( $capabilities as $cap ) { $role_obj->add_cap( $cap ); } WP_CLI::success( "Role with key '{$role_key}' created. Cloned capabilities from '{$assoc_args['clone']}'." ); } else { WP_CLI::success( "Role with key '{$role_key}' created." ); } } else { WP_CLI::error( "Role couldn't be created." ); } }
[ "public", "function", "create", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "global", "$", "wp_roles", ";", "self", "::", "persistence_check", "(", ")", ";", "$", "role_key", "=", "array_shift", "(", "$", "args", ")", ";", "$", "role_name", "="...
Creates a new role. ## OPTIONS <role-key> : The internal name of the role. <role-name> : The publicly visible name of the role. [--clone=<role>] : Clone capabilities from an existing role. ## EXAMPLES # Create role for Approver. $ wp role create approver Approver Success: Role with key 'approver' created. # Create role for Product Administrator. $ wp role create productadmin "Product Administrator" Success: Role with key 'productadmin' created.
[ "Creates", "a", "new", "role", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Role_Command.php#L168-L202
46,085
wp-cli/role-command
src/Role_Command.php
Role_Command.delete
public function delete( $args ) { global $wp_roles; self::persistence_check(); $role_key = array_shift( $args ); if ( empty( $role_key ) || ! isset( $wp_roles->roles[ $role_key ] ) ) { WP_CLI::error( 'Role key not provided, or is invalid.' ); } remove_role( $role_key ); // Note: remove_role() doesn't indicate success or otherwise, so we have to // check ourselves if ( ! isset( $wp_roles->roles[ $role_key ] ) ) { WP_CLI::success( "Role with key '{$role_key}' deleted." ); } else { WP_CLI::error( "Role with key '{$role_key}' could not be deleted." ); } }
php
public function delete( $args ) { global $wp_roles; self::persistence_check(); $role_key = array_shift( $args ); if ( empty( $role_key ) || ! isset( $wp_roles->roles[ $role_key ] ) ) { WP_CLI::error( 'Role key not provided, or is invalid.' ); } remove_role( $role_key ); // Note: remove_role() doesn't indicate success or otherwise, so we have to // check ourselves if ( ! isset( $wp_roles->roles[ $role_key ] ) ) { WP_CLI::success( "Role with key '{$role_key}' deleted." ); } else { WP_CLI::error( "Role with key '{$role_key}' could not be deleted." ); } }
[ "public", "function", "delete", "(", "$", "args", ")", "{", "global", "$", "wp_roles", ";", "self", "::", "persistence_check", "(", ")", ";", "$", "role_key", "=", "array_shift", "(", "$", "args", ")", ";", "if", "(", "empty", "(", "$", "role_key", "...
Deletes an existing role. ## OPTIONS <role-key> : The internal name of the role. ## EXAMPLES # Delete approver role. $ wp role delete approver Success: Role with key 'approver' deleted. # Delete productadmin role. wp role delete productadmin Success: Role with key 'productadmin' deleted.
[ "Deletes", "an", "existing", "role", "." ]
c6071d06d64c165588734b0d1c96f5c3dfa75736
https://github.com/wp-cli/role-command/blob/c6071d06d64c165588734b0d1c96f5c3dfa75736/src/Role_Command.php#L222-L243
46,086
swoft-cloud/swoft-task
src/TaskExecutor.php
TaskExecutor.beforeTask
private function beforeTask( string $logid, int $spanid, string $name, string $method, string $type, string $taskClass ) { $event = new BeforeTaskEvent(TaskEvent::BEFORE_TASK, $logid, $spanid, $name, $method, $type, $taskClass); App::trigger($event); }
php
private function beforeTask( string $logid, int $spanid, string $name, string $method, string $type, string $taskClass ) { $event = new BeforeTaskEvent(TaskEvent::BEFORE_TASK, $logid, $spanid, $name, $method, $type, $taskClass); App::trigger($event); }
[ "private", "function", "beforeTask", "(", "string", "$", "logid", ",", "int", "$", "spanid", ",", "string", "$", "name", ",", "string", "$", "method", ",", "string", "$", "type", ",", "string", "$", "taskClass", ")", "{", "$", "event", "=", "new", "B...
Trigger before_task event.
[ "Trigger", "before_task", "event", "." ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/TaskExecutor.php#L100-L110
46,087
swoft-cloud/swoft-task
src/TaskExecutor.php
TaskExecutor.afterTask
private function afterTask( string $logid, int $spanid, string $name, string $method, string $type, string $taskClass ) { // Release system resources. App::trigger(AppEvent::RESOURCE_RELEASE); // Trigger after task event. $event = new AfterTaskEvent(TaskEvent::AFTER_TASK, $logid, $spanid, $name, $method, $type, $taskClass); App::trigger($event); }
php
private function afterTask( string $logid, int $spanid, string $name, string $method, string $type, string $taskClass ) { // Release system resources. App::trigger(AppEvent::RESOURCE_RELEASE); // Trigger after task event. $event = new AfterTaskEvent(TaskEvent::AFTER_TASK, $logid, $spanid, $name, $method, $type, $taskClass); App::trigger($event); }
[ "private", "function", "afterTask", "(", "string", "$", "logid", ",", "int", "$", "spanid", ",", "string", "$", "name", ",", "string", "$", "method", ",", "string", "$", "type", ",", "string", "$", "taskClass", ")", "{", "// Release system resources.", "Ap...
Trigger resource_release and after_task events.
[ "Trigger", "resource_release", "and", "after_task", "events", "." ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/TaskExecutor.php#L115-L129
46,088
swoft-cloud/swoft-task
src/Task.php
Task.deliver
public static function deliver( string $taskName, string $methodName, array $params = [], string $type = self::TYPE_CO, int $timeout = 3 ) { if (! in_array($type, [static::TYPE_CO, static::TYPE_ASYNC], false)) { throw new TaskException('Invalid task type.'); } $data = TaskHelper::pack($taskName, $methodName, $params, $type); if (! App::isWorkerStatus() && ! App::isCoContext()) { return static::deliverByQueue($data); } if (! App::isWorkerStatus() && App::isCoContext()) { throw new TaskException('Deliver in non-worker environment, please deliver the task via HTTP request.'); } $server = App::$server->getServer(); switch ($type) { case static::TYPE_CO: $tasks[0] = $data; $profileKey = 'task' . '.' . $taskName . '.' . $methodName; App::profileStart($profileKey); $result = $server->taskCo($tasks, $timeout); App::profileEnd($profileKey); return $result; break; case static::TYPE_ASYNC: default: // Deliver async task return $server->task($data); break; } }
php
public static function deliver( string $taskName, string $methodName, array $params = [], string $type = self::TYPE_CO, int $timeout = 3 ) { if (! in_array($type, [static::TYPE_CO, static::TYPE_ASYNC], false)) { throw new TaskException('Invalid task type.'); } $data = TaskHelper::pack($taskName, $methodName, $params, $type); if (! App::isWorkerStatus() && ! App::isCoContext()) { return static::deliverByQueue($data); } if (! App::isWorkerStatus() && App::isCoContext()) { throw new TaskException('Deliver in non-worker environment, please deliver the task via HTTP request.'); } $server = App::$server->getServer(); switch ($type) { case static::TYPE_CO: $tasks[0] = $data; $profileKey = 'task' . '.' . $taskName . '.' . $methodName; App::profileStart($profileKey); $result = $server->taskCo($tasks, $timeout); App::profileEnd($profileKey); return $result; break; case static::TYPE_ASYNC: default: // Deliver async task return $server->task($data); break; } }
[ "public", "static", "function", "deliver", "(", "string", "$", "taskName", ",", "string", "$", "methodName", ",", "array", "$", "params", "=", "[", "]", ",", "string", "$", "type", "=", "self", "::", "TYPE_CO", ",", "int", "$", "timeout", "=", "3", "...
Deliver a coroutine or async task @return bool|array|int @throws TaskException
[ "Deliver", "a", "coroutine", "or", "async", "task" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Task.php#L32-L67
46,089
swoft-cloud/swoft-task
src/Task.php
Task.deliverByProcess
public static function deliverByProcess( string $taskName, string $methodName, array $params = [], int $timeout = 3, int $workerId = 0, string $type = self::TYPE_ASYNC ): bool { /* @var PipeMessageInterface $pipeMessage */ $pipeMessage = bean(PipeMessage::class); $message = $pipeMessage->pack(PipeMessage::MESSAGE_TYPE_TASK, [ 'name' => $taskName, 'method' => $methodName, 'params' => $params, 'timeout' => $timeout, 'type' => $type, ]); return App::$server->getServer()->sendMessage($message, $workerId); }
php
public static function deliverByProcess( string $taskName, string $methodName, array $params = [], int $timeout = 3, int $workerId = 0, string $type = self::TYPE_ASYNC ): bool { /* @var PipeMessageInterface $pipeMessage */ $pipeMessage = bean(PipeMessage::class); $message = $pipeMessage->pack(PipeMessage::MESSAGE_TYPE_TASK, [ 'name' => $taskName, 'method' => $methodName, 'params' => $params, 'timeout' => $timeout, 'type' => $type, ]); return App::$server->getServer()->sendMessage($message, $workerId); }
[ "public", "static", "function", "deliverByProcess", "(", "string", "$", "taskName", ",", "string", "$", "methodName", ",", "array", "$", "params", "=", "[", "]", ",", "int", "$", "timeout", "=", "3", ",", "int", "$", "workerId", "=", "0", ",", "string"...
Deliver task by process
[ "Deliver", "task", "by", "process" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Task.php#L78-L96
46,090
swoft-cloud/swoft-task
src/Task.php
Task.async
public static function async(array $tasks): array { $server = App::$server->getServer(); $result = []; foreach ($tasks as $task) { if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) { App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]')); continue; } if ($task['type'] !== static::TYPE_ASYNC) { App::error(sprintf('Task %s is not a asynchronous task.', $task['name'])); continue; } $data = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']); $result[] = $server->task($data); } return $result; }
php
public static function async(array $tasks): array { $server = App::$server->getServer(); $result = []; foreach ($tasks as $task) { if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) { App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]')); continue; } if ($task['type'] !== static::TYPE_ASYNC) { App::error(sprintf('Task %s is not a asynchronous task.', $task['name'])); continue; } $data = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']); $result[] = $server->task($data); } return $result; }
[ "public", "static", "function", "async", "(", "array", "$", "tasks", ")", ":", "array", "{", "$", "server", "=", "App", "::", "$", "server", "->", "getServer", "(", ")", ";", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "tasks", "as", ...
Deliver multiple asynchronous tasks @param array $tasks <pre> $task = [ 'name' => $taskName, 'method' => $methodName, 'params' => $params, 'type' => $type ]; </pre>
[ "Deliver", "multiple", "asynchronous", "tasks" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Task.php#L111-L132
46,091
swoft-cloud/swoft-task
src/Task.php
Task.co
public static function co(array $tasks): array { $taskCos = []; foreach ($tasks as $task) { if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) { App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]')); continue; } $type = $task['type']; if ($type !== static::TYPE_CO) { App::error(sprintf('Task %s is not a coroutine task.', $task['name'])); continue; } $taskCos[] = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']); } $result = []; if (! empty($taskCos)) { $result = App::$server->getServer()->taskCo($tasks); } return $result; }
php
public static function co(array $tasks): array { $taskCos = []; foreach ($tasks as $task) { if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) { App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]')); continue; } $type = $task['type']; if ($type !== static::TYPE_CO) { App::error(sprintf('Task %s is not a coroutine task.', $task['name'])); continue; } $taskCos[] = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']); } $result = []; if (! empty($taskCos)) { $result = App::$server->getServer()->taskCo($tasks); } return $result; }
[ "public", "static", "function", "co", "(", "array", "$", "tasks", ")", ":", "array", "{", "$", "taskCos", "=", "[", "]", ";", "foreach", "(", "$", "tasks", "as", "$", "task", ")", "{", "if", "(", "!", "isset", "(", "$", "task", "[", "'type'", "...
Deliver multiple coroutine tasks @param array $tasks <pre> $tasks = [ 'name' => $taskName, 'method' => $methodName, 'params' => $params, 'type' => $type ]; </pre>
[ "Deliver", "multiple", "coroutine", "tasks" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Task.php#L155-L179
46,092
swoft-cloud/swoft-task
src/Bootstrap/Listeners/BeforeStartListener.php
BeforeStartListener.initCrontabMemoryTable
private function initCrontabMemoryTable() { /** @var array[] $settings */ $settings = App::getAppProperties()->get('server'); $settings = $settings['crontab']; $taskCount = isset($settings['task_count']) && $settings['task_count'] > 0 ? $settings['task_count'] : null; $taskQueue = isset($settings['task_queue']) && $settings['task_queue'] > 0 ? $settings['task_queue'] : null; TableCrontab::init($taskCount, $taskQueue); }
php
private function initCrontabMemoryTable() { /** @var array[] $settings */ $settings = App::getAppProperties()->get('server'); $settings = $settings['crontab']; $taskCount = isset($settings['task_count']) && $settings['task_count'] > 0 ? $settings['task_count'] : null; $taskQueue = isset($settings['task_queue']) && $settings['task_queue'] > 0 ? $settings['task_queue'] : null; TableCrontab::init($taskCount, $taskQueue); }
[ "private", "function", "initCrontabMemoryTable", "(", ")", "{", "/** @var array[] $settings */", "$", "settings", "=", "App", "::", "getAppProperties", "(", ")", "->", "get", "(", "'server'", ")", ";", "$", "settings", "=", "$", "settings", "[", "'crontab'", "...
init table of crontab
[ "init", "table", "of", "crontab" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Bootstrap/Listeners/BeforeStartListener.php#L35-L45
46,093
swoft-cloud/swoft-task
src/Bean/Collector/TaskCollector.php
TaskCollector.collectTask
private static function collectTask(string $className, Task $objectAnnotation) { $name = $objectAnnotation->getName(); $beanName = empty($name) ? $className : $name; $coroutine = $objectAnnotation->isCoroutine(); self::$tasks['mapping'][$className] = $beanName; self::$tasks['task'][$beanName] = [ $className, $coroutine ]; }
php
private static function collectTask(string $className, Task $objectAnnotation) { $name = $objectAnnotation->getName(); $beanName = empty($name) ? $className : $name; $coroutine = $objectAnnotation->isCoroutine(); self::$tasks['mapping'][$className] = $beanName; self::$tasks['task'][$beanName] = [ $className, $coroutine ]; }
[ "private", "static", "function", "collectTask", "(", "string", "$", "className", ",", "Task", "$", "objectAnnotation", ")", "{", "$", "name", "=", "$", "objectAnnotation", "->", "getName", "(", ")", ";", "$", "beanName", "=", "empty", "(", "$", "name", "...
collect the annotation of task @param string $className @param Task $objectAnnotation
[ "collect", "the", "annotation", "of", "task" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Bean/Collector/TaskCollector.php#L59-L70
46,094
swoft-cloud/swoft-task
src/Bean/Collector/TaskCollector.php
TaskCollector.collectScheduled
private static function collectScheduled(string $className, Scheduled $objectAnnotation, string $methodName) { if (!isset(self::$tasks['mapping'][$className])) { return; } $cron = $objectAnnotation->getCron(); $taskName = self::$tasks['mapping'][$className]; self::$tasks['crons'][] = [ 'cron' => $cron, 'task' => $taskName, 'method' => $methodName, 'className' => $className, ]; }
php
private static function collectScheduled(string $className, Scheduled $objectAnnotation, string $methodName) { if (!isset(self::$tasks['mapping'][$className])) { return; } $cron = $objectAnnotation->getCron(); $taskName = self::$tasks['mapping'][$className]; self::$tasks['crons'][] = [ 'cron' => $cron, 'task' => $taskName, 'method' => $methodName, 'className' => $className, ]; }
[ "private", "static", "function", "collectScheduled", "(", "string", "$", "className", ",", "Scheduled", "$", "objectAnnotation", ",", "string", "$", "methodName", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "tasks", "[", "'mapping'", "]", "[...
collect the annotation of Scheduled @param string $className @param Scheduled $objectAnnotation @param string $methodName
[ "collect", "the", "annotation", "of", "Scheduled" ]
319b2b7af65caf37bbc9c2929f69e8d01f6b0d31
https://github.com/swoft-cloud/swoft-task/blob/319b2b7af65caf37bbc9c2929f69e8d01f6b0d31/src/Bean/Collector/TaskCollector.php#L79-L94
46,095
contributte/psr7-http-message
src/Nette/NetteResponseTrait.php
NetteResponseTrait.sendHeaders
public function sendHeaders(): void { if ($this->httpResponse === null) { throw new InvalidStateException(sprintf('Cannot send response without %s', Response::class)); } // Send status code $this->httpResponse->setCode($this->getStatusCode()); // Send headers foreach ($this->getHeaders() as $name => $values) { foreach ($values as $value) { $this->httpResponse->setHeader($name, $value); } } }
php
public function sendHeaders(): void { if ($this->httpResponse === null) { throw new InvalidStateException(sprintf('Cannot send response without %s', Response::class)); } // Send status code $this->httpResponse->setCode($this->getStatusCode()); // Send headers foreach ($this->getHeaders() as $name => $values) { foreach ($values as $value) { $this->httpResponse->setHeader($name, $value); } } }
[ "public", "function", "sendHeaders", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "httpResponse", "===", "null", ")", "{", "throw", "new", "InvalidStateException", "(", "sprintf", "(", "'Cannot send response without %s'", ",", "Response", "::", "c...
Send all headers and status code
[ "Send", "all", "headers", "and", "status", "code" ]
4d8cd682e50dec7fc06d0ebeb0bc2c2d7dda01bd
https://github.com/contributte/psr7-http-message/blob/4d8cd682e50dec7fc06d0ebeb0bc2c2d7dda01bd/src/Nette/NetteResponseTrait.php#L79-L94
46,096
Codeinwp/themeisle-sdk
src/Modules/Translate.php
Translate.can_load
public function can_load( $product ) { if ( $this->is_from_partner( $product ) ) { return false; } if ( ! $product->is_wordpress_available() ) { return false; } $lang = $this->get_user_locale(); if ( 'en_US' === $lang ) { return false; } $languages = $this->get_translations( $product ); if ( ! is_array( $languages ) ) { return false; } if ( ! isset( $languages['translations'] ) ) { return false; } $languages = $languages['translations']; $available = wp_list_pluck( $languages, 'language' ); if ( in_array( $lang, $available ) ) { return false; } if ( ! isset( self::$locales[ $lang ] ) ) { return false; } return apply_filters( $product->get_slug() . '_sdk_enable_translate', true ); }
php
public function can_load( $product ) { if ( $this->is_from_partner( $product ) ) { return false; } if ( ! $product->is_wordpress_available() ) { return false; } $lang = $this->get_user_locale(); if ( 'en_US' === $lang ) { return false; } $languages = $this->get_translations( $product ); if ( ! is_array( $languages ) ) { return false; } if ( ! isset( $languages['translations'] ) ) { return false; } $languages = $languages['translations']; $available = wp_list_pluck( $languages, 'language' ); if ( in_array( $lang, $available ) ) { return false; } if ( ! isset( self::$locales[ $lang ] ) ) { return false; } return apply_filters( $product->get_slug() . '_sdk_enable_translate', true ); }
[ "public", "function", "can_load", "(", "$", "product", ")", "{", "if", "(", "$", "this", "->", "is_from_partner", "(", "$", "product", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "product", "->", "is_wordpress_available", "(", ")",...
Check if we should load module for this. @param Product $product Product to check. @return bool Should load ?
[ "Check", "if", "we", "should", "load", "module", "for", "this", "." ]
7ead6c057d783ea6c827d5b5de52a25c0e72de58
https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Translate.php#L741-L778
46,097
Codeinwp/themeisle-sdk
src/Modules/Translate.php
Translate.get_user_locale
private function get_user_locale() { global $wp_version; if ( version_compare( $wp_version, '4.7.0', '>=' ) ) { return get_user_locale(); } $user = wp_get_current_user(); if ( $user ) { $locale = $user->locale; } return $locale ? $locale : get_locale(); }
php
private function get_user_locale() { global $wp_version; if ( version_compare( $wp_version, '4.7.0', '>=' ) ) { return get_user_locale(); } $user = wp_get_current_user(); if ( $user ) { $locale = $user->locale; } return $locale ? $locale : get_locale(); }
[ "private", "function", "get_user_locale", "(", ")", "{", "global", "$", "wp_version", ";", "if", "(", "version_compare", "(", "$", "wp_version", ",", "'4.7.0'", ",", "'>='", ")", ")", "{", "return", "get_user_locale", "(", ")", ";", "}", "$", "user", "="...
Get the user's locale.
[ "Get", "the", "user", "s", "locale", "." ]
7ead6c057d783ea6c827d5b5de52a25c0e72de58
https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Translate.php#L783-L794
46,098
Codeinwp/themeisle-sdk
src/Modules/Translate.php
Translate.get_translations
private function get_translations( $product ) { $cache_key = $product->get_key() . '_all_languages'; $translations = get_transient( $cache_key ); if ( false === $translations ) { require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); $translations = translations_api( $product->get_type() . 's', array( 'slug' => $product->get_slug(), 'version' => $product->get_version(), ) ); set_transient( $cache_key, $translations, WEEK_IN_SECONDS ); } return $translations; }
php
private function get_translations( $product ) { $cache_key = $product->get_key() . '_all_languages'; $translations = get_transient( $cache_key ); if ( false === $translations ) { require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); $translations = translations_api( $product->get_type() . 's', array( 'slug' => $product->get_slug(), 'version' => $product->get_version(), ) ); set_transient( $cache_key, $translations, WEEK_IN_SECONDS ); } return $translations; }
[ "private", "function", "get_translations", "(", "$", "product", ")", "{", "$", "cache_key", "=", "$", "product", "->", "get_key", "(", ")", ".", "'_all_languages'", ";", "$", "translations", "=", "get_transient", "(", "$", "cache_key", ")", ";", "if", "(",...
Fetch translations from api. @param Product $product Product to check. @return mixed Translation array.
[ "Fetch", "translations", "from", "api", "." ]
7ead6c057d783ea6c827d5b5de52a25c0e72de58
https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Translate.php#L803-L821
46,099
Codeinwp/themeisle-sdk
src/Modules/Translate.php
Translate.get_locale_paths
private function get_locale_paths( $locale ) { if ( empty( $locale ) ) { return ''; } $slug = isset( self::$locales[ $locale ] ) ? self::$locales[ $locale ]['slug'] : ''; if ( empty( $slug ) ) { return ''; } if ( strpos( $slug, '/' ) === false ) { $slug .= '/default'; } $url = 'https://translate.wordpress.org/projects/wp-' . $this->product->get_type() . 's/' . $this->product->get_slug() . '/' . ( $this->product->get_type() === 'plugin' ? 'dev/' : '' ) . $slug . '?filters%5Bstatus%5D=untranslated&sort%5Bby%5D=random'; return $url; }
php
private function get_locale_paths( $locale ) { if ( empty( $locale ) ) { return ''; } $slug = isset( self::$locales[ $locale ] ) ? self::$locales[ $locale ]['slug'] : ''; if ( empty( $slug ) ) { return ''; } if ( strpos( $slug, '/' ) === false ) { $slug .= '/default'; } $url = 'https://translate.wordpress.org/projects/wp-' . $this->product->get_type() . 's/' . $this->product->get_slug() . '/' . ( $this->product->get_type() === 'plugin' ? 'dev/' : '' ) . $slug . '?filters%5Bstatus%5D=untranslated&sort%5Bby%5D=random'; return $url; }
[ "private", "function", "get_locale_paths", "(", "$", "locale", ")", "{", "if", "(", "empty", "(", "$", "locale", ")", ")", "{", "return", "''", ";", "}", "$", "slug", "=", "isset", "(", "self", "::", "$", "locales", "[", "$", "locale", "]", ")", ...
Return the locale path. @param string $locale Locale code. @return string Locale path.
[ "Return", "the", "locale", "path", "." ]
7ead6c057d783ea6c827d5b5de52a25c0e72de58
https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Translate.php#L886-L901