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 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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| )+</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| )+</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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
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 | train |
Codeinwp/themeisle-sdk | src/Modules/Recommendation.php | Recommendation.get_themes | private function get_themes( $themes_list, $preferences ) {
$list = array();
foreach ( $themes_list as $slug => $nicename ) {
$theme = $this->call_theme_api( $slug );
if ( ! $theme ) {
continue;
}
$url = add_query_arg(
array(
'theme' => $theme->slug,
),
network_admin_url( 'theme-install.php' )
);
$name = empty( $nicename ) ? $theme->name : $nicename;
$theme->custom_url = $url;
$theme->custom_name = $name;
$list[] = $theme;
}
return $list;
} | php | private function get_themes( $themes_list, $preferences ) {
$list = array();
foreach ( $themes_list as $slug => $nicename ) {
$theme = $this->call_theme_api( $slug );
if ( ! $theme ) {
continue;
}
$url = add_query_arg(
array(
'theme' => $theme->slug,
),
network_admin_url( 'theme-install.php' )
);
$name = empty( $nicename ) ? $theme->name : $nicename;
$theme->custom_url = $url;
$theme->custom_name = $name;
$list[] = $theme;
}
return $list;
} | [
"private",
"function",
"get_themes",
"(",
"$",
"themes_list",
",",
"$",
"preferences",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"themes_list",
"as",
"$",
"slug",
"=>",
"$",
"nicename",
")",
"{",
"$",
"theme",
"=",
"$",... | Collect all the information for the themes list.
@param array $themes_list - list of useful themes (in slug => nicename format).
@param array $preferences - list of preferences.
@return array | [
"Collect",
"all",
"the",
"information",
"for",
"the",
"themes",
"list",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Recommendation.php#L148-L172 | train |
Codeinwp/themeisle-sdk | src/Modules/Recommendation.php | Recommendation.call_theme_api | private function call_theme_api( $slug ) {
$theme = get_transient( 'ti_theme_info_' . $slug );
if ( false !== $theme ) {
return $theme;
}
$products = wp_remote_get(
'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[theme]=' . $slug . '&request[per_page]=1'
);
$products = json_decode( wp_remote_retrieve_body( $products ) );
if ( is_object( $products ) ) {
$theme = $products->themes[0];
set_transient( 'ti_theme_info_' . $slug, $theme, 6 * HOUR_IN_SECONDS );
}
return $theme;
} | php | private function call_theme_api( $slug ) {
$theme = get_transient( 'ti_theme_info_' . $slug );
if ( false !== $theme ) {
return $theme;
}
$products = wp_remote_get(
'https://api.wordpress.org/themes/info/1.1/?action=query_themes&request[theme]=' . $slug . '&request[per_page]=1'
);
$products = json_decode( wp_remote_retrieve_body( $products ) );
if ( is_object( $products ) ) {
$theme = $products->themes[0];
set_transient( 'ti_theme_info_' . $slug, $theme, 6 * HOUR_IN_SECONDS );
}
return $theme;
} | [
"private",
"function",
"call_theme_api",
"(",
"$",
"slug",
")",
"{",
"$",
"theme",
"=",
"get_transient",
"(",
"'ti_theme_info_'",
".",
"$",
"slug",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"theme",
")",
"{",
"return",
"$",
"theme",
";",
"}",
"$",
"p... | Call theme api
@param string $slug theme slug.
@return array|mixed|object | [
"Call",
"theme",
"api"
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Recommendation.php#L181-L198 | train |
Codeinwp/themeisle-sdk | src/Modules/Recommendation.php | Recommendation.get_plugins | private function get_plugins( $plugins_list, $preferences ) {
$list = array();
foreach ( $plugins_list as $plugin => $nicename ) {
$current_plugin = $this->call_plugin_api( $plugin );
$name = empty( $nicename ) ? $current_plugin->name : $nicename;
$image = $current_plugin->banners['low'];
if ( isset( $preferences['image'] ) && 'icon' === $preferences['image'] ) {
$image = $current_plugin->icons['1x'];
}
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => $current_plugin->slug,
'TB_iframe' => true,
'width' => 800,
'height' => 800,
),
network_admin_url( 'plugin-install.php' )
);
$current_plugin->custom_url = $url;
$current_plugin->custom_name = $name;
$current_plugin->custom_image = $image;
$list[] = $current_plugin;
}
return $list;
} | php | private function get_plugins( $plugins_list, $preferences ) {
$list = array();
foreach ( $plugins_list as $plugin => $nicename ) {
$current_plugin = $this->call_plugin_api( $plugin );
$name = empty( $nicename ) ? $current_plugin->name : $nicename;
$image = $current_plugin->banners['low'];
if ( isset( $preferences['image'] ) && 'icon' === $preferences['image'] ) {
$image = $current_plugin->icons['1x'];
}
$url = add_query_arg(
array(
'tab' => 'plugin-information',
'plugin' => $current_plugin->slug,
'TB_iframe' => true,
'width' => 800,
'height' => 800,
),
network_admin_url( 'plugin-install.php' )
);
$current_plugin->custom_url = $url;
$current_plugin->custom_name = $name;
$current_plugin->custom_image = $image;
$list[] = $current_plugin;
}
return $list;
} | [
"private",
"function",
"get_plugins",
"(",
"$",
"plugins_list",
",",
"$",
"preferences",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"plugins_list",
"as",
"$",
"plugin",
"=>",
"$",
"nicename",
")",
"{",
"$",
"current_plugin",... | Collect all the information for the plugins list.
@param array $plugins_list - list of useful plugins (in slug => nicename format).
@param array $preferences - list of preferences.
@return array | [
"Collect",
"all",
"the",
"information",
"for",
"the",
"plugins",
"list",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Recommendation.php#L208-L239 | train |
Codeinwp/themeisle-sdk | src/Modules/Recommendation.php | Recommendation.call_plugin_api | private function call_plugin_api( $slug ) {
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
$call_api = get_transient( 'ti_plugin_info_' . $slug );
if ( false === $call_api ) {
$call_api = plugins_api(
'plugin_information',
array(
'slug' => $slug,
'fields' => array(
'downloaded' => false,
'rating' => false,
'description' => false,
'short_description' => true,
'donate_link' => false,
'tags' => false,
'sections' => true,
'homepage' => true,
'added' => false,
'last_updated' => false,
'compatibility' => false,
'tested' => false,
'requires' => false,
'downloadlink' => false,
'icons' => true,
'banners' => true,
),
)
);
set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
}
return $call_api;
} | php | private function call_plugin_api( $slug ) {
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
$call_api = get_transient( 'ti_plugin_info_' . $slug );
if ( false === $call_api ) {
$call_api = plugins_api(
'plugin_information',
array(
'slug' => $slug,
'fields' => array(
'downloaded' => false,
'rating' => false,
'description' => false,
'short_description' => true,
'donate_link' => false,
'tags' => false,
'sections' => true,
'homepage' => true,
'added' => false,
'last_updated' => false,
'compatibility' => false,
'tested' => false,
'requires' => false,
'downloadlink' => false,
'icons' => true,
'banners' => true,
),
)
);
set_transient( 'ti_plugin_info_' . $slug, $call_api, 30 * MINUTE_IN_SECONDS );
}
return $call_api;
} | [
"private",
"function",
"call_plugin_api",
"(",
"$",
"slug",
")",
"{",
"include_once",
"(",
"ABSPATH",
".",
"'wp-admin/includes/plugin-install.php'",
")",
";",
"$",
"call_api",
"=",
"get_transient",
"(",
"'ti_plugin_info_'",
".",
"$",
"slug",
")",
";",
"if",
"(",... | Call plugin api
@param string $slug plugin slug.
@return array|mixed|object | [
"Call",
"plugin",
"api"
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Recommendation.php#L248-L282 | train |
Codeinwp/themeisle-sdk | src/Modules/Recommendation.php | Recommendation.enqueue | public function enqueue() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) ) {
return;
}
if ( false === apply_filters( $this->product->get_key() . '_enqueue_recommend', false, $screen->id ) ) {
return;
}
?>
<style type="text/css">
.recommend-product {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.recommend-product .theme-banner {
width:200px;
margin: auto;
}
.recommend-product .plugin-banner {
width: 100px;
margin: auto;
}
.recommend-product .plugin_box .button span{
margin-top: 2px;
margin-right: 7px;
}
.recommend-product .plugin_box .button{
margin-bottom:10px;
}
.recommend-product .plugin_box {
margin-bottom: 20px;
padding-top: 5px;
display: flex;
box-shadow: 0px 0px 10px -5px rgba(0,0,0,0.55);
background: #fff;
border-radius: 5px;
flex-direction: column;
justify-content: flex-start;
width: 95%;
}
.recommend-product .title-action-wrapper {
padding: 15px 20px 5px 20px;
}
.recommend-product .plugin-name {
font-size: 18px;
display: block;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: 10px;
overflow: hidden;
line-height: normal;
}
.recommend-product .plugin-desc {
display: block;
margin-bottom: 10px;
font-size: 13px;
color: #777;
line-height: 1.6;
}
.recommend-product .button-wrap > div {
padding: 0;
margin: 0;
}
.plugin-box-footer {
display: flex;
justify-content: space-around;
vertical-align: middle;
align-items: center;
padding: 0px 10px 5px;
flex: 1;
margin-top: auto;
}
</style>
<?php
} | php | public function enqueue() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) ) {
return;
}
if ( false === apply_filters( $this->product->get_key() . '_enqueue_recommend', false, $screen->id ) ) {
return;
}
?>
<style type="text/css">
.recommend-product {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.recommend-product .theme-banner {
width:200px;
margin: auto;
}
.recommend-product .plugin-banner {
width: 100px;
margin: auto;
}
.recommend-product .plugin_box .button span{
margin-top: 2px;
margin-right: 7px;
}
.recommend-product .plugin_box .button{
margin-bottom:10px;
}
.recommend-product .plugin_box {
margin-bottom: 20px;
padding-top: 5px;
display: flex;
box-shadow: 0px 0px 10px -5px rgba(0,0,0,0.55);
background: #fff;
border-radius: 5px;
flex-direction: column;
justify-content: flex-start;
width: 95%;
}
.recommend-product .title-action-wrapper {
padding: 15px 20px 5px 20px;
}
.recommend-product .plugin-name {
font-size: 18px;
display: block;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: 10px;
overflow: hidden;
line-height: normal;
}
.recommend-product .plugin-desc {
display: block;
margin-bottom: 10px;
font-size: 13px;
color: #777;
line-height: 1.6;
}
.recommend-product .button-wrap > div {
padding: 0;
margin: 0;
}
.plugin-box-footer {
display: flex;
justify-content: space-around;
vertical-align: middle;
align-items: center;
padding: 0px 10px 5px;
flex: 1;
margin-top: auto;
}
</style>
<?php
} | [
"public",
"function",
"enqueue",
"(",
")",
"{",
"$",
"screen",
"=",
"get_current_screen",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"screen",
"->",
"id",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"false",
"===",
"apply_filters",
"(",
"$... | Load css and scripts for the plugin recommend page. | [
"Load",
"css",
"and",
"scripts",
"for",
"the",
"plugin",
"recommend",
"page",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Recommendation.php#L287-L373 | train |
Codeinwp/themeisle-sdk | src/Product.php | Product.setup_from_path | public function setup_from_path() {
$this->file = basename( $this->basefile );
$dir = dirname( $this->basefile );
$this->slug = basename( $dir );
$exts = explode( '.', $this->basefile );
$ext = $exts[ count( $exts ) - 1 ];
if ( 'css' === $ext ) {
$this->type = 'theme';
}
if ( 'php' === $ext ) {
$this->type = 'plugin';
}
$this->key = self::key_ready_name( $this->slug );
} | php | public function setup_from_path() {
$this->file = basename( $this->basefile );
$dir = dirname( $this->basefile );
$this->slug = basename( $dir );
$exts = explode( '.', $this->basefile );
$ext = $exts[ count( $exts ) - 1 ];
if ( 'css' === $ext ) {
$this->type = 'theme';
}
if ( 'php' === $ext ) {
$this->type = 'plugin';
}
$this->key = self::key_ready_name( $this->slug );
} | [
"public",
"function",
"setup_from_path",
"(",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"basename",
"(",
"$",
"this",
"->",
"basefile",
")",
";",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"this",
"->",
"basefile",
")",
";",
"$",
"this",
"->",
"slug",
"... | Setup props from path. | [
"Setup",
"props",
"from",
"path",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Product.php#L135-L148 | train |
Codeinwp/themeisle-sdk | src/Product.php | Product.setup_from_fileheaders | public function setup_from_fileheaders() {
$file_headers = array(
'Requires License' => 'Requires License',
'WordPress Available' => 'WordPress Available',
'Pro Slug' => 'Pro Slug',
'Version' => 'Version',
);
if ( 'plugin' === $this->type ) {
$file_headers['Name'] = 'Plugin Name';
$file_headers['AuthorName'] = 'Author';
$file_headers['AuthorURI'] = 'Author URI';
}
if ( 'theme' === $this->type ) {
$file_headers['Name'] = 'Theme Name';
$file_headers['AuthorName'] = 'Author';
$file_headers['AuthorURI'] = 'Author URI';
}
$file_headers = get_file_data( $this->basefile, $file_headers );
$this->name = $file_headers['Name'];
$this->store_name = $file_headers['AuthorName'];
$this->author_url = $file_headers['AuthorURI'];
$this->store_url = $file_headers['AuthorURI'];
$this->requires_license = ( 'yes' === $file_headers['Requires License'] ) ? true : false;
$this->wordpress_available = ( 'yes' === $file_headers['WordPress Available'] ) ? true : false;
$this->pro_slug = ! empty( $file_headers['Pro Slug'] ) ? $file_headers['Pro Slug'] : '';
$this->version = $file_headers['Version'];
} | php | public function setup_from_fileheaders() {
$file_headers = array(
'Requires License' => 'Requires License',
'WordPress Available' => 'WordPress Available',
'Pro Slug' => 'Pro Slug',
'Version' => 'Version',
);
if ( 'plugin' === $this->type ) {
$file_headers['Name'] = 'Plugin Name';
$file_headers['AuthorName'] = 'Author';
$file_headers['AuthorURI'] = 'Author URI';
}
if ( 'theme' === $this->type ) {
$file_headers['Name'] = 'Theme Name';
$file_headers['AuthorName'] = 'Author';
$file_headers['AuthorURI'] = 'Author URI';
}
$file_headers = get_file_data( $this->basefile, $file_headers );
$this->name = $file_headers['Name'];
$this->store_name = $file_headers['AuthorName'];
$this->author_url = $file_headers['AuthorURI'];
$this->store_url = $file_headers['AuthorURI'];
$this->requires_license = ( 'yes' === $file_headers['Requires License'] ) ? true : false;
$this->wordpress_available = ( 'yes' === $file_headers['WordPress Available'] ) ? true : false;
$this->pro_slug = ! empty( $file_headers['Pro Slug'] ) ? $file_headers['Pro Slug'] : '';
$this->version = $file_headers['Version'];
} | [
"public",
"function",
"setup_from_fileheaders",
"(",
")",
"{",
"$",
"file_headers",
"=",
"array",
"(",
"'Requires License'",
"=>",
"'Requires License'",
",",
"'WordPress Available'",
"=>",
"'WordPress Available'",
",",
"'Pro Slug'",
"=>",
"'Pro Slug'",
",",
"'Version'",... | Setup props from fileheaders. | [
"Setup",
"props",
"from",
"fileheaders",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Product.php#L164-L193 | train |
Codeinwp/themeisle-sdk | src/Product.php | Product.get_license | public function get_license() {
if ( ! $this->requires_license() && ! $this->is_wordpress_available() ) {
return 'free';
}
$license_data = get_option( $this->get_key() . '_license_data', '' );
if ( empty( $license_data ) ) {
return get_option( $this->get_key() . '_license', '' );
}
if ( ! isset( $license_data->key ) ) {
return get_option( $this->get_key() . '_license', '' );
}
return $license_data->key;
} | php | public function get_license() {
if ( ! $this->requires_license() && ! $this->is_wordpress_available() ) {
return 'free';
}
$license_data = get_option( $this->get_key() . '_license_data', '' );
if ( empty( $license_data ) ) {
return get_option( $this->get_key() . '_license', '' );
}
if ( ! isset( $license_data->key ) ) {
return get_option( $this->get_key() . '_license', '' );
}
return $license_data->key;
} | [
"public",
"function",
"get_license",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"requires_license",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"is_wordpress_available",
"(",
")",
")",
"{",
"return",
"'free'",
";",
"}",
"$",
"license_data",
"=",
"ge... | Returns current product license, if available.
@return string Return license key, if available. | [
"Returns",
"current",
"product",
"license",
"if",
"available",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Product.php#L274-L289 | train |
Codeinwp/themeisle-sdk | src/Product.php | Product.get_friendly_name | public function get_friendly_name() {
$name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
$name = rtrim( $name, '- ()' );
return $name;
} | php | public function get_friendly_name() {
$name = apply_filters( $this->get_key() . '_friendly_name', trim( str_replace( 'Lite', '', $this->get_name() ) ) );
$name = rtrim( $name, '- ()' );
return $name;
} | [
"public",
"function",
"get_friendly_name",
"(",
")",
"{",
"$",
"name",
"=",
"apply_filters",
"(",
"$",
"this",
"->",
"get_key",
"(",
")",
".",
"'_friendly_name'",
",",
"trim",
"(",
"str_replace",
"(",
"'Lite'",
",",
"''",
",",
"$",
"this",
"->",
"get_nam... | Return friendly name.
@return string Friendly name. | [
"Return",
"friendly",
"name",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Product.php#L314-L319 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.add_footer | public function add_footer() {
$screen = get_current_screen();
if ( ! isset( $screen->parent_file ) ) {
return;
}
if ( 'themes.php' !== $screen->parent_file ) {
return;
}
if ( ! $this->product->is_theme() ) {
return;
}
$version = $this->get_rollback();
if ( empty( $version ) ) {
return;
}
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
setInterval(checkTheme, 500);
function checkTheme() {
var theme = '<?php echo esc_attr( $this->product->get_slug() ); ?>-action';
if (jQuery('#' + theme).length > 0) {
if (jQuery('.theme-overlay.active').is(':visible')) {
if (jQuery('#' + theme + '-rollback').length === 0) {
jQuery('.theme-actions .active-theme').prepend('<a class="button" style="float:left" id="' + theme + '-rollback" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) ); ?>">Rollback to v<?php echo esc_attr( $version['version'] ); ?></a>')
}
}
}
}
})
</script>
<?php
} | php | public function add_footer() {
$screen = get_current_screen();
if ( ! isset( $screen->parent_file ) ) {
return;
}
if ( 'themes.php' !== $screen->parent_file ) {
return;
}
if ( ! $this->product->is_theme() ) {
return;
}
$version = $this->get_rollback();
if ( empty( $version ) ) {
return;
}
?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
setInterval(checkTheme, 500);
function checkTheme() {
var theme = '<?php echo esc_attr( $this->product->get_slug() ); ?>-action';
if (jQuery('#' + theme).length > 0) {
if (jQuery('.theme-overlay.active').is(':visible')) {
if (jQuery('#' + theme + '-rollback').length === 0) {
jQuery('.theme-actions .active-theme').prepend('<a class="button" style="float:left" id="' + theme + '-rollback" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) ); ?>">Rollback to v<?php echo esc_attr( $version['version'] ); ?></a>')
}
}
}
}
})
</script>
<?php
} | [
"public",
"function",
"add_footer",
"(",
")",
"{",
"$",
"screen",
"=",
"get_current_screen",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"screen",
"->",
"parent_file",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"'themes.php'",
"!==",
"$",
"s... | Add js scripts for themes rollback. | [
"Add",
"js",
"scripts",
"for",
"themes",
"rollback",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L30-L67 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.get_rollback | public function get_rollback() {
$rollback = array();
$versions = $this->get_api_versions();
$versions = apply_filters( $this->product->get_key() . '_rollbacks', $versions );
if ( empty( $versions ) ) {
return $rollback;
}
if ( $versions ) {
usort( $versions, array( $this, 'sort_rollback_array' ) );
foreach ( $versions as $version ) {
if ( isset( $version['version'] ) && isset( $version['url'] ) && version_compare( $this->product->get_version(), $version['version'], '>' ) ) {
$rollback = $version;
break;
}
}
}
return $rollback;
} | php | public function get_rollback() {
$rollback = array();
$versions = $this->get_api_versions();
$versions = apply_filters( $this->product->get_key() . '_rollbacks', $versions );
if ( empty( $versions ) ) {
return $rollback;
}
if ( $versions ) {
usort( $versions, array( $this, 'sort_rollback_array' ) );
foreach ( $versions as $version ) {
if ( isset( $version['version'] ) && isset( $version['url'] ) && version_compare( $this->product->get_version(), $version['version'], '>' ) ) {
$rollback = $version;
break;
}
}
}
return $rollback;
} | [
"public",
"function",
"get_rollback",
"(",
")",
"{",
"$",
"rollback",
"=",
"array",
"(",
")",
";",
"$",
"versions",
"=",
"$",
"this",
"->",
"get_api_versions",
"(",
")",
";",
"$",
"versions",
"=",
"apply_filters",
"(",
"$",
"this",
"->",
"product",
"->... | Get the last rollback for this product.
@return array The rollback version. | [
"Get",
"the",
"last",
"rollback",
"for",
"this",
"product",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L74-L92 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.get_api_versions | private function get_api_versions() {
$cache_key = $this->product->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->product->get_version() ) . 'versions';
$cache_versions = get_transient( $cache_key );
if ( false === $cache_versions ) {
$versions = $this->get_remote_versions();
set_transient( $cache_key, $versions, 5 * DAY_IN_SECONDS );
} else {
$versions = is_array( $cache_versions ) ? $cache_versions : array();
}
return $versions;
} | php | private function get_api_versions() {
$cache_key = $this->product->get_key() . '_' . preg_replace( '/[^0-9a-zA-Z ]/m', '', $this->product->get_version() ) . 'versions';
$cache_versions = get_transient( $cache_key );
if ( false === $cache_versions ) {
$versions = $this->get_remote_versions();
set_transient( $cache_key, $versions, 5 * DAY_IN_SECONDS );
} else {
$versions = is_array( $cache_versions ) ? $cache_versions : array();
}
return $versions;
} | [
"private",
"function",
"get_api_versions",
"(",
")",
"{",
"$",
"cache_key",
"=",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_'",
".",
"preg_replace",
"(",
"'/[^0-9a-zA-Z ]/m'",
",",
"''",
",",
"$",
"this",
"->",
"product",
"->",
"get... | Get versions array from wp.org
@return array Array of versions. | [
"Get",
"versions",
"array",
"from",
"wp",
".",
"org"
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L99-L111 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.get_remote_versions | private function get_remote_versions() {
$url = $this->get_versions_api_url();
if ( empty( $url ) ) {
return [];
}
$response = wp_remote_get( $url );
if ( is_wp_error( $response ) ) {
return array();
}
$response = wp_remote_retrieve_body( $response );
if ( is_serialized( $response ) ) {
$response = maybe_unserialize( $response );
} else {
$response = json_decode( $response );
}
if ( ! is_object( $response ) ) {
return array();
}
if ( ! isset( $response->versions ) ) {
return array();
}
$versions = array();
foreach ( $response->versions as $key => $value ) {
$versions[] = array(
'version' => is_object( $value ) ? $value->version : $key,
'url' => is_object( $value ) ? $value->file : $value,
);
}
return $versions;
} | php | private function get_remote_versions() {
$url = $this->get_versions_api_url();
if ( empty( $url ) ) {
return [];
}
$response = wp_remote_get( $url );
if ( is_wp_error( $response ) ) {
return array();
}
$response = wp_remote_retrieve_body( $response );
if ( is_serialized( $response ) ) {
$response = maybe_unserialize( $response );
} else {
$response = json_decode( $response );
}
if ( ! is_object( $response ) ) {
return array();
}
if ( ! isset( $response->versions ) ) {
return array();
}
$versions = array();
foreach ( $response->versions as $key => $value ) {
$versions[] = array(
'version' => is_object( $value ) ? $value->version : $key,
'url' => is_object( $value ) ? $value->file : $value,
);
}
return $versions;
} | [
"private",
"function",
"get_remote_versions",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"get_versions_api_url",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"response",
"=",
"wp_remote... | Get remote versions zips.
@return array Array of available versions. | [
"Get",
"remote",
"versions",
"zips",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L118-L151 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.get_versions_api_url | private function get_versions_api_url() {
if ( $this->product->is_wordpress_available() && $this->product->is_plugin() ) {
return sprintf( 'https://api.wordpress.org/plugins/info/1.0/%s', $this->product->get_slug() );
}
if ( $this->product->is_wordpress_available() && $this->product->is_theme() ) {
return sprintf( 'https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=%s&request[fields][versions]=true', $this->product->get_slug() );
}
$license = $this->product->get_license();
if ( $this->product->requires_license() && strlen( $license ) < 10 ) {
return '';
}
return sprintf( '%s?edd_action=get_versions&name=%s&url=%s&license=%s', $this->product->get_store_url(), urlencode( $this->product->get_name() ), urlencode( get_site_url() ), $license );
} | php | private function get_versions_api_url() {
if ( $this->product->is_wordpress_available() && $this->product->is_plugin() ) {
return sprintf( 'https://api.wordpress.org/plugins/info/1.0/%s', $this->product->get_slug() );
}
if ( $this->product->is_wordpress_available() && $this->product->is_theme() ) {
return sprintf( 'https://api.wordpress.org/themes/info/1.1/?action=theme_information&request[slug]=%s&request[fields][versions]=true', $this->product->get_slug() );
}
$license = $this->product->get_license();
if ( $this->product->requires_license() && strlen( $license ) < 10 ) {
return '';
}
return sprintf( '%s?edd_action=get_versions&name=%s&url=%s&license=%s', $this->product->get_store_url(), urlencode( $this->product->get_name() ), urlencode( get_site_url() ), $license );
} | [
"private",
"function",
"get_versions_api_url",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"product",
"->",
"is_wordpress_available",
"(",
")",
"&&",
"$",
"this",
"->",
"product",
"->",
"is_plugin",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"'https://... | Return url where to check for versions.
@return string Url where to check for versions. | [
"Return",
"url",
"where",
"to",
"check",
"for",
"versions",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L158-L171 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.add_rollback_link | public function add_rollback_link( $links ) {
$version = $this->get_rollback();
if ( empty( $version ) ) {
return $links;
}
$links[] = '<a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) . '">' . sprintf( apply_filters( $this->product->get_key() . '_rollback_label', 'Rollback to v%s' ), $version['version'] ) . '</a>';
return $links;
} | php | public function add_rollback_link( $links ) {
$version = $this->get_rollback();
if ( empty( $version ) ) {
return $links;
}
$links[] = '<a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=' . $this->product->get_key() . '_rollback' ), $this->product->get_key() . '_rollback' ) . '">' . sprintf( apply_filters( $this->product->get_key() . '_rollback_label', 'Rollback to v%s' ), $version['version'] ) . '</a>';
return $links;
} | [
"public",
"function",
"add_rollback_link",
"(",
"$",
"links",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"get_rollback",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"return",
"$",
"links",
";",
"}",
"$",
"links",
"... | Show the rollback links in the plugin page.
@param array $links Plugin links.
@return array $links Altered links. | [
"Show",
"the",
"rollback",
"links",
"in",
"the",
"plugin",
"page",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L180-L188 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.start_rollback | public function start_rollback() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) {
wp_nonce_ays( '' );
}
if ( $this->product->is_plugin() ) {
$this->start_rollback_plugin();
return;
}
if ( $this->product->is_theme() ) {
$this->start_rollback_theme();
return;
}
} | php | public function start_rollback() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], $this->product->get_key() . '_rollback' ) ) {
wp_nonce_ays( '' );
}
if ( $this->product->is_plugin() ) {
$this->start_rollback_plugin();
return;
}
if ( $this->product->is_theme() ) {
$this->start_rollback_theme();
return;
}
} | [
"public",
"function",
"start_rollback",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'_wpnonce'",
"]",
")",
"||",
"!",
"wp_verify_nonce",
"(",
"$",
"_GET",
"[",
"'_wpnonce'",
"]",
",",
"$",
"this",
"->",
"product",
"->",
"get_key",
... | Start the rollback operation. | [
"Start",
"the",
"rollback",
"operation",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L193-L208 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.start_rollback_plugin | private function start_rollback_plugin() {
$rollback = $this->get_rollback();
$plugin_transient = get_site_transient( 'update_plugins' );
$plugin_folder = $this->product->get_slug();
$plugin_file = $this->product->get_file();
$version = $rollback['version'];
$temp_array = array(
'slug' => $plugin_folder,
'new_version' => $version,
'package' => $rollback['url'],
);
$temp_object = (object) $temp_array;
$plugin_transient->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object;
set_site_transient( 'update_plugins', $plugin_transient );
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
if ( false === $transient ) {
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
$plugin = $plugin_folder . '/' . $plugin_file;
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
$upgrader_skin = new \Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
$upgrader = new \Plugin_Upgrader( $upgrader_skin );
$upgrader->upgrade( $plugin );
delete_transient( $this->product->get_key() . '_warning_rollback' );
wp_die(
'',
$title,
array(
'response' => 200,
)
);
}
} | php | private function start_rollback_plugin() {
$rollback = $this->get_rollback();
$plugin_transient = get_site_transient( 'update_plugins' );
$plugin_folder = $this->product->get_slug();
$plugin_file = $this->product->get_file();
$version = $rollback['version'];
$temp_array = array(
'slug' => $plugin_folder,
'new_version' => $version,
'package' => $rollback['url'],
);
$temp_object = (object) $temp_array;
$plugin_transient->response[ $plugin_folder . '/' . $plugin_file ] = $temp_object;
set_site_transient( 'update_plugins', $plugin_transient );
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
if ( false === $transient ) {
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
$plugin = $plugin_folder . '/' . $plugin_file;
$nonce = 'upgrade-plugin_' . $plugin;
$url = 'update.php?action=upgrade-plugin&plugin=' . urlencode( $plugin );
$upgrader_skin = new \Plugin_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'plugin' ) );
$upgrader = new \Plugin_Upgrader( $upgrader_skin );
$upgrader->upgrade( $plugin );
delete_transient( $this->product->get_key() . '_warning_rollback' );
wp_die(
'',
$title,
array(
'response' => 200,
)
);
}
} | [
"private",
"function",
"start_rollback_plugin",
"(",
")",
"{",
"$",
"rollback",
"=",
"$",
"this",
"->",
"get_rollback",
"(",
")",
";",
"$",
"plugin_transient",
"=",
"get_site_transient",
"(",
"'update_plugins'",
")",
";",
"$",
"plugin_folder",
"=",
"$",
"this"... | Start the rollback operation for the plugin. | [
"Start",
"the",
"rollback",
"operation",
"for",
"the",
"plugin",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L213-L250 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.start_rollback_theme | private function start_rollback_theme() {
add_filter( 'update_theme_complete_actions', array( $this, 'alter_links_theme_upgrade' ) );
$rollback = $this->get_rollback();
$transient = get_site_transient( 'update_themes' );
$folder = $this->product->get_slug();
$version = $rollback['version'];
$temp_array = array(
'new_version' => $version,
'package' => $rollback['url'],
);
$transient->response[ $folder . '/style.css' ] = $temp_array;
set_site_transient( 'update_themes', $transient );
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
if ( false === $transient ) {
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
$theme = $folder . '/style.css';
$nonce = 'upgrade-theme_' . $theme;
$url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
$upgrader = new \Theme_Upgrader( new \Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
$upgrader->upgrade( $theme );
delete_transient( $this->product->get_key() . '_warning_rollback' );
wp_die(
'',
$title,
array(
'response' => 200,
)
);
}
} | php | private function start_rollback_theme() {
add_filter( 'update_theme_complete_actions', array( $this, 'alter_links_theme_upgrade' ) );
$rollback = $this->get_rollback();
$transient = get_site_transient( 'update_themes' );
$folder = $this->product->get_slug();
$version = $rollback['version'];
$temp_array = array(
'new_version' => $version,
'package' => $rollback['url'],
);
$transient->response[ $folder . '/style.css' ] = $temp_array;
set_site_transient( 'update_themes', $transient );
$transient = get_transient( $this->product->get_key() . '_warning_rollback' );
if ( false === $transient ) {
set_transient( $this->product->get_key() . '_warning_rollback', 'in progress', 30 );
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
$title = sprintf( apply_filters( $this->product->get_key() . '_rollback_message', 'Rolling back %s to v%s' ), $this->product->get_name(), $version );
$theme = $folder . '/style.css';
$nonce = 'upgrade-theme_' . $theme;
$url = 'update.php?action=upgrade-theme&theme=' . urlencode( $theme );
$upgrader = new \Theme_Upgrader( new \Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
$upgrader->upgrade( $theme );
delete_transient( $this->product->get_key() . '_warning_rollback' );
wp_die(
'',
$title,
array(
'response' => 200,
)
);
}
} | [
"private",
"function",
"start_rollback_theme",
"(",
")",
"{",
"add_filter",
"(",
"'update_theme_complete_actions'",
",",
"array",
"(",
"$",
"this",
",",
"'alter_links_theme_upgrade'",
")",
")",
";",
"$",
"rollback",
"=",
"$",
"this",
"->",
"get_rollback",
"(",
"... | Start the rollback operation for the theme. | [
"Start",
"the",
"rollback",
"operation",
"for",
"the",
"theme",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L255-L290 | train |
Codeinwp/themeisle-sdk | src/Modules/Rollback.php | Rollback.can_load | public function can_load( $product ) {
if ( $this->is_from_partner( $product ) ) {
return false;
}
if ( $product->is_theme() && ! current_user_can( 'switch_themes' ) ) {
return false;
}
if ( $product->is_plugin() && ! current_user_can( 'install_plugins' ) ) {
return false;
}
return true;
} | php | public function can_load( $product ) {
if ( $this->is_from_partner( $product ) ) {
return false;
}
if ( $product->is_theme() && ! current_user_can( 'switch_themes' ) ) {
return false;
}
if ( $product->is_plugin() && ! current_user_can( 'install_plugins' ) ) {
return false;
}
return true;
} | [
"public",
"function",
"can_load",
"(",
"$",
"product",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_from_partner",
"(",
"$",
"product",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"product",
"->",
"is_theme",
"(",
")",
"&&",
"!",
"cu... | Loads product object.
@param Product $product Product object.
@return bool Should we load the module? | [
"Loads",
"product",
"object",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Rollback.php#L314-L327 | train |
Superbalist/php-pubsub-google-cloud | src/GoogleCloudPubSubAdapter.php | GoogleCloudPubSubAdapter.getTopicForChannel | protected function getTopicForChannel($channel)
{
$topic = $this->client->topic($channel);
if ($this->autoCreateTopics && !$topic->exists()) {
$topic->create();
}
return $topic;
} | php | protected function getTopicForChannel($channel)
{
$topic = $this->client->topic($channel);
if ($this->autoCreateTopics && !$topic->exists()) {
$topic->create();
}
return $topic;
} | [
"protected",
"function",
"getTopicForChannel",
"(",
"$",
"channel",
")",
"{",
"$",
"topic",
"=",
"$",
"this",
"->",
"client",
"->",
"topic",
"(",
"$",
"channel",
")",
";",
"if",
"(",
"$",
"this",
"->",
"autoCreateTopics",
"&&",
"!",
"$",
"topic",
"->",... | Return a `Topic` instance from a channel name.
If the topic doesn't exist, the topic is first created.
@param string $channel
@return \Google\Cloud\PubSub\Topic | [
"Return",
"a",
"Topic",
"instance",
"from",
"a",
"channel",
"name",
"."
] | d15d1f84d2fb1890efcd441b7831b0c0b422e3c1 | https://github.com/Superbalist/php-pubsub-google-cloud/blob/d15d1f84d2fb1890efcd441b7831b0c0b422e3c1/src/GoogleCloudPubSubAdapter.php#L321-L328 | train |
Superbalist/php-pubsub-google-cloud | src/GoogleCloudPubSubAdapter.php | GoogleCloudPubSubAdapter.getSubscriptionForChannel | protected function getSubscriptionForChannel($channel)
{
$topic = $this->getTopicForChannel($channel);
$clientIdentifier = $this->clientIdentifier ? $this->clientIdentifier : 'default';
$clientIdentifier .= '.' . $channel;
$subscription = $topic->subscription($clientIdentifier);
if ($this->autoCreateSubscriptions && !$subscription->exists()) {
$subscription->create();
}
return $subscription;
} | php | protected function getSubscriptionForChannel($channel)
{
$topic = $this->getTopicForChannel($channel);
$clientIdentifier = $this->clientIdentifier ? $this->clientIdentifier : 'default';
$clientIdentifier .= '.' . $channel;
$subscription = $topic->subscription($clientIdentifier);
if ($this->autoCreateSubscriptions && !$subscription->exists()) {
$subscription->create();
}
return $subscription;
} | [
"protected",
"function",
"getSubscriptionForChannel",
"(",
"$",
"channel",
")",
"{",
"$",
"topic",
"=",
"$",
"this",
"->",
"getTopicForChannel",
"(",
"$",
"channel",
")",
";",
"$",
"clientIdentifier",
"=",
"$",
"this",
"->",
"clientIdentifier",
"?",
"$",
"th... | Return a `Subscription` instance from a channel name.
If the subscription doesn't exist, the subscription is first created.
@param string $channel
@return \Google\Cloud\PubSub\Subscription | [
"Return",
"a",
"Subscription",
"instance",
"from",
"a",
"channel",
"name",
"."
] | d15d1f84d2fb1890efcd441b7831b0c0b422e3c1 | https://github.com/Superbalist/php-pubsub-google-cloud/blob/d15d1f84d2fb1890efcd441b7831b0c0b422e3c1/src/GoogleCloudPubSubAdapter.php#L339-L349 | train |
Codeinwp/themeisle-sdk | src/Loader.php | Loader.init | public static function init() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Loader ) ) {
self::$instance = new Loader();
$modules = array_merge( self::$available_modules, apply_filters( 'themeisle_sdk_modules', [] ) );
foreach ( $modules as $key => $module ) {
if ( ! class_exists( 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' ) ) ) {
unset( $modules[ $key ] );
}
}
self::$available_modules = $modules;
}
} | php | public static function init() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Loader ) ) {
self::$instance = new Loader();
$modules = array_merge( self::$available_modules, apply_filters( 'themeisle_sdk_modules', [] ) );
foreach ( $modules as $key => $module ) {
if ( ! class_exists( 'ThemeisleSDK\\Modules\\' . ucwords( $module, '_' ) ) ) {
unset( $modules[ $key ] );
}
}
self::$available_modules = $modules;
}
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instance",
")",
"&&",
"!",
"(",
"self",
"::",
"$",
"instance",
"instanceof",
"Loader",
")",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new"... | Initialize the sdk logic. | [
"Initialize",
"the",
"sdk",
"logic",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Loader.php#L65-L76 | train |
Codeinwp/themeisle-sdk | src/Loader.php | Loader.add_product | public static function add_product( $base_file ) {
if ( ! is_readable( $base_file ) ) {
return self::$instance;
}
$product = new Product( $base_file );
Module_Factory::attach( $product, self::get_modules() );
self::$products[ $product->get_slug() ] = $product;
return self::$instance;
} | php | public static function add_product( $base_file ) {
if ( ! is_readable( $base_file ) ) {
return self::$instance;
}
$product = new Product( $base_file );
Module_Factory::attach( $product, self::get_modules() );
self::$products[ $product->get_slug() ] = $product;
return self::$instance;
} | [
"public",
"static",
"function",
"add_product",
"(",
"$",
"base_file",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"base_file",
")",
")",
"{",
"return",
"self",
"::",
"$",
"instance",
";",
"}",
"$",
"product",
"=",
"new",
"Product",
"(",
"$",
"... | Register product into SDK.
@param string $base_file The product base file.
@return Loader The singleton object. | [
"Register",
"product",
"into",
"SDK",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Loader.php#L85-L97 | train |
Codeinwp/themeisle-sdk | src/Modules/Endpoint.php | Endpoint.checksum | function checksum( \WP_REST_Request $data ) {
$products = Loader::get_products();
if ( self::PRODUCT_SPECIFIC ) {
$params = $this->validate_params( $data, array( 'slug' ) );
foreach ( $products as $product ) {
if ( $params['slug'] === $product->get_slug() ) {
$products = array( $product );
break;
}
}
}
$response = array();
$custom_css = $this->has_custom_css();
if ( is_bool( $custom_css ) ) {
$response['custom_css'] = $custom_css;
}
$response['child_theme'] = $this->get_theme_properties();
foreach ( $products as $product ) {
$files = array();
switch ( $product->get_type() ) {
case 'plugin':
$files = array();
break;
case 'theme':
$files = array( 'style.css', 'functions.php' );
break;
}
$error = '';
// if any element in the $files array contains a '/', this would imply recursion is required.
$diff = $this->generate_diff(
$product,
$files,
array_reduce(
$files,
array(
$this,
'is_recursion_required',
),
false
)
);
if ( is_wp_error( $diff ) ) {
/**
* Error returner by the diff checker method.
*
* @var \WP_Error $diff Error returned.
*/
$error = $diff->get_error_message();
$diff = array();
}
$response['products'][] = array(
'slug' => $product->get_slug(),
'version' => $product->get_version(),
'diffs' => $diff,
'error' => $error,
);
}
return new \WP_REST_Response( array( 'checksum' => $response ) );
} | php | function checksum( \WP_REST_Request $data ) {
$products = Loader::get_products();
if ( self::PRODUCT_SPECIFIC ) {
$params = $this->validate_params( $data, array( 'slug' ) );
foreach ( $products as $product ) {
if ( $params['slug'] === $product->get_slug() ) {
$products = array( $product );
break;
}
}
}
$response = array();
$custom_css = $this->has_custom_css();
if ( is_bool( $custom_css ) ) {
$response['custom_css'] = $custom_css;
}
$response['child_theme'] = $this->get_theme_properties();
foreach ( $products as $product ) {
$files = array();
switch ( $product->get_type() ) {
case 'plugin':
$files = array();
break;
case 'theme':
$files = array( 'style.css', 'functions.php' );
break;
}
$error = '';
// if any element in the $files array contains a '/', this would imply recursion is required.
$diff = $this->generate_diff(
$product,
$files,
array_reduce(
$files,
array(
$this,
'is_recursion_required',
),
false
)
);
if ( is_wp_error( $diff ) ) {
/**
* Error returner by the diff checker method.
*
* @var \WP_Error $diff Error returned.
*/
$error = $diff->get_error_message();
$diff = array();
}
$response['products'][] = array(
'slug' => $product->get_slug(),
'version' => $product->get_version(),
'diffs' => $diff,
'error' => $error,
);
}
return new \WP_REST_Response( array( 'checksum' => $response ) );
} | [
"function",
"checksum",
"(",
"\\",
"WP_REST_Request",
"$",
"data",
")",
"{",
"$",
"products",
"=",
"Loader",
"::",
"get_products",
"(",
")",
";",
"if",
"(",
"self",
"::",
"PRODUCT_SPECIFIC",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"validate_para... | The checksum endpoint.
@param \WP_REST_Request $data the request.
@return \WP_REST_Response Response or the error | [
"The",
"checksum",
"endpoint",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Endpoint.php#L66-L130 | train |
Codeinwp/themeisle-sdk | src/Modules/Endpoint.php | Endpoint.validate_params | private function validate_params( \WP_REST_Request $data, $params ) {
$collect = array();
foreach ( $params as $param ) {
$value = sanitize_text_field( $data[ $param ] );
if ( empty( $value ) ) {
return rest_ensure_response(
new \WP_Error(
'themeisle_' . $param . '_invalid',
sprintf( 'Invalid %', $param ),
array(
'status' => 403,
)
)
);
} else {
$collect[ $param ] = $value;
}
}
return $collect;
} | php | private function validate_params( \WP_REST_Request $data, $params ) {
$collect = array();
foreach ( $params as $param ) {
$value = sanitize_text_field( $data[ $param ] );
if ( empty( $value ) ) {
return rest_ensure_response(
new \WP_Error(
'themeisle_' . $param . '_invalid',
sprintf( 'Invalid %', $param ),
array(
'status' => 403,
)
)
);
} else {
$collect[ $param ] = $value;
}
}
return $collect;
} | [
"private",
"function",
"validate_params",
"(",
"\\",
"WP_REST_Request",
"$",
"data",
",",
"$",
"params",
")",
"{",
"$",
"collect",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"value",
"=",
"sanitize_te... | Validates the parameters to the API
@param \WP_REST_Request $data the request.
@param array $params the parameters to validate.
@return array of parameter name=>value | [
"Validates",
"the",
"parameters",
"to",
"the",
"API"
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Endpoint.php#L140-L160 | train |
Codeinwp/themeisle-sdk | src/Modules/Endpoint.php | Endpoint.has_custom_css | private function has_custom_css() {
$query = new \WP_Query(
array(
'post_type' => 'custom_css',
'post_status' => 'publish',
'numberposts' => 1,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
)
);
if ( $query->have_posts() ) {
$query->the_post();
$content = get_the_content();
// if the content contains a colon, a CSS rule has been added.
return strpos( $content, ':' ) === false ? false : true;
}
return false;
} | php | private function has_custom_css() {
$query = new \WP_Query(
array(
'post_type' => 'custom_css',
'post_status' => 'publish',
'numberposts' => 1,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
)
);
if ( $query->have_posts() ) {
$query->the_post();
$content = get_the_content();
// if the content contains a colon, a CSS rule has been added.
return strpos( $content, ':' ) === false ? false : true;
}
return false;
} | [
"private",
"function",
"has_custom_css",
"(",
")",
"{",
"$",
"query",
"=",
"new",
"\\",
"WP_Query",
"(",
"array",
"(",
"'post_type'",
"=>",
"'custom_css'",
",",
"'post_status'",
"=>",
"'publish'",
",",
"'numberposts'",
"=>",
"1",
",",
"'update_post_meta_cache'",... | Check if custom css has been added to the theme.
@return bool Whether custom css has been added to the theme. | [
"Check",
"if",
"custom",
"css",
"has",
"been",
"added",
"to",
"the",
"theme",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Endpoint.php#L167-L187 | train |
Codeinwp/themeisle-sdk | src/Modules/Endpoint.php | Endpoint.get_theme_properties | function get_theme_properties() {
if ( ! is_child_theme() ) {
return false;
}
$properties = array();
$theme = wp_get_theme();
// @codingStandardsIgnoreStart
$properties['name'] = $theme->Name;
// @codingStandardsIgnoreEnd
// get the files in the child theme.
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$path = str_replace( ABSPATH, $wp_filesystem->abspath(), get_stylesheet_directory() );
$list = $wp_filesystem->dirlist( $path, false, false );
if ( $list ) {
$list = array_keys( self::flatten_dirlist( $list ) );
$properties['files'] = $list;
}
return $properties;
} | php | function get_theme_properties() {
if ( ! is_child_theme() ) {
return false;
}
$properties = array();
$theme = wp_get_theme();
// @codingStandardsIgnoreStart
$properties['name'] = $theme->Name;
// @codingStandardsIgnoreEnd
// get the files in the child theme.
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$path = str_replace( ABSPATH, $wp_filesystem->abspath(), get_stylesheet_directory() );
$list = $wp_filesystem->dirlist( $path, false, false );
if ( $list ) {
$list = array_keys( self::flatten_dirlist( $list ) );
$properties['files'] = $list;
}
return $properties;
} | [
"function",
"get_theme_properties",
"(",
")",
"{",
"if",
"(",
"!",
"is_child_theme",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"properties",
"=",
"array",
"(",
")",
";",
"$",
"theme",
"=",
"wp_get_theme",
"(",
")",
";",
"// @codingStandardsIg... | Get the current theme properties.
@return mixed Properties of the current theme. | [
"Get",
"the",
"current",
"theme",
"properties",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Endpoint.php#L194-L217 | train |
Codeinwp/themeisle-sdk | src/Modules/Endpoint.php | Endpoint.generate_diff | private function generate_diff( $product, $files, $recurse = false ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$diff = array();
$path = str_replace( ABSPATH, $wp_filesystem->abspath(), plugin_dir_path( $product->get_basefile() ) );
$list = $wp_filesystem->dirlist( $path, false, $recurse );
// nothing found.
if ( ! $list ) {
return $diff;
}
$list = array_keys( self::flatten_dirlist( $list ) );
// now let's get the valid files that actually exist.
if ( empty( $files ) ) {
$files = $list;
} else {
$files = array_intersect( $files, $list );
}
// fetch the calculated hashes.
if ( ! $wp_filesystem->is_readable( $path . '/' . self::HASH_FILE ) ) {
return new WP_Error( 'themeisle_sdk_hash_not_found', sprintf( '%s not found', self::HASH_FILE ) );
}
$hashes = json_decode( $wp_filesystem->get_contents( $path . '/' . self::HASH_FILE ), true );
ksort( $hashes );
$diff = array();
foreach ( $files as $file ) {
// file does not exist in the hashes.
if ( ! array_key_exists( $file, $hashes ) ) {
continue;
}
$new = md5( $wp_filesystem->get_contents( $path . $file ) );
$old = $hashes[ $file ];
// same hash, bail.
if ( $new === $old ) {
continue;
}
$diff[] = $file;
}
return $diff;
} | php | private function generate_diff( $product, $files, $recurse = false ) {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
WP_Filesystem();
global $wp_filesystem;
$diff = array();
$path = str_replace( ABSPATH, $wp_filesystem->abspath(), plugin_dir_path( $product->get_basefile() ) );
$list = $wp_filesystem->dirlist( $path, false, $recurse );
// nothing found.
if ( ! $list ) {
return $diff;
}
$list = array_keys( self::flatten_dirlist( $list ) );
// now let's get the valid files that actually exist.
if ( empty( $files ) ) {
$files = $list;
} else {
$files = array_intersect( $files, $list );
}
// fetch the calculated hashes.
if ( ! $wp_filesystem->is_readable( $path . '/' . self::HASH_FILE ) ) {
return new WP_Error( 'themeisle_sdk_hash_not_found', sprintf( '%s not found', self::HASH_FILE ) );
}
$hashes = json_decode( $wp_filesystem->get_contents( $path . '/' . self::HASH_FILE ), true );
ksort( $hashes );
$diff = array();
foreach ( $files as $file ) {
// file does not exist in the hashes.
if ( ! array_key_exists( $file, $hashes ) ) {
continue;
}
$new = md5( $wp_filesystem->get_contents( $path . $file ) );
$old = $hashes[ $file ];
// same hash, bail.
if ( $new === $old ) {
continue;
}
$diff[] = $file;
}
return $diff;
} | [
"private",
"function",
"generate_diff",
"(",
"$",
"product",
",",
"$",
"files",
",",
"$",
"recurse",
"=",
"false",
")",
"{",
"require_once",
"(",
"ABSPATH",
".",
"'wp-admin/includes/file.php'",
")",
";",
"WP_Filesystem",
"(",
")",
";",
"global",
"$",
"wp_fil... | Generate the diff of the files.
@param Product $product Themeisle Product.
@param array $files Array of files.
@param bool $recurse Whether to recurse or not.
@return mixed Diff data. | [
"Generate",
"the",
"diff",
"of",
"the",
"files",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Endpoint.php#L253-L299 | train |
Codeinwp/themeisle-sdk | src/Common/Abstract_module.php | Abstract_Module.is_from_partner | public function is_from_partner( $product ) {
foreach ( Module_Factory::$domains as $partner_domain ) {
if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) {
return true;
}
}
return array_key_exists( $product->get_slug(), Module_Factory::$slugs );
} | php | public function is_from_partner( $product ) {
foreach ( Module_Factory::$domains as $partner_domain ) {
if ( strpos( $product->get_store_url(), $partner_domain ) !== false ) {
return true;
}
}
return array_key_exists( $product->get_slug(), Module_Factory::$slugs );
} | [
"public",
"function",
"is_from_partner",
"(",
"$",
"product",
")",
"{",
"foreach",
"(",
"Module_Factory",
"::",
"$",
"domains",
"as",
"$",
"partner_domain",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"product",
"->",
"get_store_url",
"(",
")",
",",
"$",
"p... | Check if the product is from partner.
@param Product $product Product data.
@return bool Is product from partner. | [
"Check",
"if",
"the",
"product",
"is",
"from",
"partner",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Common/Abstract_module.php#L56-L65 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.disable_wporg_update | function disable_wporg_update( $r, $url ) {
if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/' ) ) {
return $r;
}
// Decode the JSON response.
$themes = json_decode( $r['body']['themes'] );
unset( $themes->themes->{$this->product->get_slug()} );
// Encode the updated JSON response.
$r['body']['themes'] = json_encode( $themes );
return $r;
} | php | function disable_wporg_update( $r, $url ) {
if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/' ) ) {
return $r;
}
// Decode the JSON response.
$themes = json_decode( $r['body']['themes'] );
unset( $themes->themes->{$this->product->get_slug()} );
// Encode the updated JSON response.
$r['body']['themes'] = json_encode( $themes );
return $r;
} | [
"function",
"disable_wporg_update",
"(",
"$",
"r",
",",
"$",
"url",
")",
"{",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"url",
",",
"'https://api.wordpress.org/themes/update-check/'",
")",
")",
"{",
"return",
"$",
"r",
";",
"}",
"// Decode the JSON response."... | Disable wporg updates for premium products.
@param string $r Update payload.
@param string $url The api url.
@return mixed List of themes to check for update. | [
"Disable",
"wporg",
"updates",
"for",
"premium",
"products",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L66-L81 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.register_settings | public function register_settings() {
if ( ! is_admin() ) {
return false;
}
add_settings_field(
$this->product->get_key() . '_license',
$this->product->get_name() . ' license',
array( $this, 'license_view' ),
'general'
);
} | php | public function register_settings() {
if ( ! is_admin() ) {
return false;
}
add_settings_field(
$this->product->get_key() . '_license',
$this->product->get_name() . ' license',
array( $this, 'license_view' ),
'general'
);
} | [
"public",
"function",
"register_settings",
"(",
")",
"{",
"if",
"(",
"!",
"is_admin",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"add_settings_field",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license'",
",",
"$",
"thi... | Register the setting for the license of the product.
@return bool | [
"Register",
"the",
"setting",
"for",
"the",
"license",
"of",
"the",
"product",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L88-L98 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.license_view | public function license_view() {
$status = $this->get_license_status();
$value = $this->license_key;
$activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' );
$deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' );
$valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' );
$invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' );
$license_message = apply_filters( $this->product->get_key() . '_lc_license_message', 'Enter your license from %s purchase history in order to get %s updates' );
echo '<p ><input ' . ( ( 'valid' === $status ) ? ( 'style="border:1px solid #7ad03a; "' ) : '' ) . ' type="text" id="' . $this->product->get_key() . '_license" name="' . $this->product->get_key() . '_license" value="' . $value . '" /><a ' . ( ( 'valid' === $status ) ? ( 'style="color:#fff;background: #7ad03a; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $valid_string ) : ( 'style="color:#fff;background: #dd3d36; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $invalid_string ) ) . ' </a> <button name="' . $this->product->get_key() . '_btn_trigger" ' . ( ( 'valid' === $status ) ? ( ' class="button button-primary">' . $deactivate_string ) : ( ' class="button button-primary" value="yes" type="submit" >' . $activate_string ) ) . ' </button></p><p class="description">' . sprintf( $license_message, '<a href="' . $this->get_api_url() . '">' . $this->get_distributor_name() . '</a> ', $this->product->get_type() ) . '</p>';
} | php | public function license_view() {
$status = $this->get_license_status();
$value = $this->license_key;
$activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' );
$deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' );
$valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' );
$invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' );
$license_message = apply_filters( $this->product->get_key() . '_lc_license_message', 'Enter your license from %s purchase history in order to get %s updates' );
echo '<p ><input ' . ( ( 'valid' === $status ) ? ( 'style="border:1px solid #7ad03a; "' ) : '' ) . ' type="text" id="' . $this->product->get_key() . '_license" name="' . $this->product->get_key() . '_license" value="' . $value . '" /><a ' . ( ( 'valid' === $status ) ? ( 'style="color:#fff;background: #7ad03a; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $valid_string ) : ( 'style="color:#fff;background: #dd3d36; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $invalid_string ) ) . ' </a> <button name="' . $this->product->get_key() . '_btn_trigger" ' . ( ( 'valid' === $status ) ? ( ' class="button button-primary">' . $deactivate_string ) : ( ' class="button button-primary" value="yes" type="submit" >' . $activate_string ) ) . ' </button></p><p class="description">' . sprintf( $license_message, '<a href="' . $this->get_api_url() . '">' . $this->get_distributor_name() . '</a> ', $this->product->get_type() ) . '</p>';
} | [
"public",
"function",
"license_view",
"(",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"get_license_status",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"license_key",
";",
"$",
"activate_string",
"=",
"apply_filters",
"(",
"$",
"this",
"->... | The license view field. | [
"The",
"license",
"view",
"field",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L103-L115 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.get_license_status | public function get_license_status() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return get_option( $this->product->get_key() . '_license_status', 'not_active' );
}
return isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
} | php | public function get_license_status() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return get_option( $this->product->get_key() . '_license_status', 'not_active' );
}
return isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
} | [
"public",
"function",
"get_license_status",
"(",
")",
"{",
"$",
"license_data",
"=",
"get_option",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license_data'",
",",
"''",
")",
";",
"if",
"(",
"''",
"===",
"$",
"license_data",
")"... | Return the license status.
@return string The License status. | [
"Return",
"the",
"license",
"status",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L122-L132 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.show_notice | function show_notice() {
if ( ! is_admin() ) {
return false;
}
$status = $this->get_license_status();
$no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No activations left for %s !!!. You need to upgrade your plan in order to use %s on more websites. Please ask the %s Staff for more details.' );
$no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' );
$expiration_string = apply_filters( $this->product->get_key() . '_lc_expiration_string', 'Your license is about to expire for %s. You can go to %s and renew it ' );
// No activations left for this license.
if ( 'valid' != $status && $this->check_activation() ) {
?>
<div class="error">
<p><strong>
<?php
echo sprintf(
$no_activations_string,
$this->product->get_name(),
$this->product->get_name(),
'<a href="' . $this->get_api_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
);
?>
</strong>
</p>
</div>
<?php
return false;
}
// Invalid license key.
if ( 'valid' != $status ) {
?>
<div class="error">
<p>
<strong><?php echo sprintf( $no_valid_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url(), admin_url( 'options-general.php' ) . '#' . $this->product->get_key() ); ?> </strong>
</p>
</div>
<?php
return false;
}
// Expired and soon to expire license.
if ( 'valid' == $status && $this->check_expiration() ) {
?>
<div class="update-nag">
<p>
<strong>
<?php
echo sprintf(
$expiration_string,
$this->product->get_name() . ' ' . $this->product->get_type(),
'<a href="' . $this->renew_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
);
?>
</strong>
</p>
</div>
<?php
return false;
}
return true;
} | php | function show_notice() {
if ( ! is_admin() ) {
return false;
}
$status = $this->get_license_status();
$no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No activations left for %s !!!. You need to upgrade your plan in order to use %s on more websites. Please ask the %s Staff for more details.' );
$no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' );
$expiration_string = apply_filters( $this->product->get_key() . '_lc_expiration_string', 'Your license is about to expire for %s. You can go to %s and renew it ' );
// No activations left for this license.
if ( 'valid' != $status && $this->check_activation() ) {
?>
<div class="error">
<p><strong>
<?php
echo sprintf(
$no_activations_string,
$this->product->get_name(),
$this->product->get_name(),
'<a href="' . $this->get_api_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
);
?>
</strong>
</p>
</div>
<?php
return false;
}
// Invalid license key.
if ( 'valid' != $status ) {
?>
<div class="error">
<p>
<strong><?php echo sprintf( $no_valid_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url(), admin_url( 'options-general.php' ) . '#' . $this->product->get_key() ); ?> </strong>
</p>
</div>
<?php
return false;
}
// Expired and soon to expire license.
if ( 'valid' == $status && $this->check_expiration() ) {
?>
<div class="update-nag">
<p>
<strong>
<?php
echo sprintf(
$expiration_string,
$this->product->get_name() . ' ' . $this->product->get_type(),
'<a href="' . $this->renew_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
);
?>
</strong>
</p>
</div>
<?php
return false;
}
return true;
} | [
"function",
"show_notice",
"(",
")",
"{",
"if",
"(",
"!",
"is_admin",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"status",
"=",
"$",
"this",
"->",
"get_license_status",
"(",
")",
";",
"$",
"no_activations_string",
"=",
"apply_filters",
"(",
... | Show the admin notice regarding the license status.
@return bool Should we show the notice ? | [
"Show",
"the",
"admin",
"notice",
"regarding",
"the",
"license",
"status",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L165-L227 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.check_activation | public function check_activation() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return false;
}
return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;
} | php | public function check_activation() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return false;
}
return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;
} | [
"public",
"function",
"check_activation",
"(",
")",
"{",
"$",
"license_data",
"=",
"get_option",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license_data'",
",",
"''",
")",
";",
"if",
"(",
"''",
"===",
"$",
"license_data",
")",
... | Check if the license is active or not.
@return bool | [
"Check",
"if",
"the",
"license",
"is",
"active",
"or",
"not",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L234-L242 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.check_expiration | function check_expiration() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return false;
}
if ( ! isset( $license_data->expires ) ) {
return false;
}
if ( strtotime( $license_data->expires ) - time() > 30 * 24 * 3600 ) {
return false;
}
return true;
} | php | function check_expiration() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return false;
}
if ( ! isset( $license_data->expires ) ) {
return false;
}
if ( strtotime( $license_data->expires ) - time() > 30 * 24 * 3600 ) {
return false;
}
return true;
} | [
"function",
"check_expiration",
"(",
")",
"{",
"$",
"license_data",
"=",
"get_option",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license_data'",
",",
"''",
")",
";",
"if",
"(",
"''",
"===",
"$",
"license_data",
")",
"{",
"re... | Check if the license is about to expire in the next month.
@return bool | [
"Check",
"if",
"the",
"license",
"is",
"about",
"to",
"expire",
"in",
"the",
"next",
"month",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L249-L262 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.renew_url | function renew_url() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return $this->get_api_url();
}
if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
return $this->get_api_url();
}
return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id;
} | php | function renew_url() {
$license_data = get_option( $this->product->get_key() . '_license_data', '' );
if ( '' === $license_data ) {
return $this->get_api_url();
}
if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
return $this->get_api_url();
}
return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id;
} | [
"function",
"renew_url",
"(",
")",
"{",
"$",
"license_data",
"=",
"get_option",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license_data'",
",",
"''",
")",
";",
"if",
"(",
"''",
"===",
"$",
"license_data",
")",
"{",
"return",
... | Return the renew url from the store used.
@return string The renew url. | [
"Return",
"the",
"renew",
"url",
"from",
"the",
"store",
"used",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L269-L279 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.product_valid | public function product_valid() {
if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) {
return;
}
$license = $this->check_license();
set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS );
update_option( $this->product->get_key() . '_license_data', $license );
} | php | public function product_valid() {
if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) {
return;
}
$license = $this->check_license();
set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS );
update_option( $this->product->get_key() . '_license_data', $license );
} | [
"public",
"function",
"product_valid",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"(",
"$",
"license",
"=",
"get_transient",
"(",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_license_data'",
")",
")",
")",
"{",
"return",
";",
"}",
... | Run the license check call. | [
"Run",
"the",
"license",
"check",
"call",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L284-L291 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.check_license | public function check_license() {
$status = $this->get_license_status();
if ( 'not_active' == $status ) {
$license_data = new \stdClass();
$license_data->license = 'not_active';
return $license_data;
}
$license = trim( $this->license_key );
$api_params = array(
'edd_action' => 'check_license',
'license' => $license,
'item_name' => rawurlencode( $this->product->get_name() ),
'url' => rawurlencode( home_url() ),
);
// Call the custom API.
$response = wp_remote_get(
add_query_arg( $api_params, $this->get_api_url() ),
array(
'timeout' => 15,
'sslverify' => false,
)
);
if ( is_wp_error( $response ) ) {
$license_data = new \stdClass();
$license_data->license = 'valid';
} else {
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! is_object( $license_data ) ) {
$license_data = new \stdClass();
$license_data->license = 'valid';
}
}
$license_old = get_option( $this->product->get_key() . '_license_data', '' );
if ( 'valid' == $license_old->license && ( $license_data->license != $license_old->license ) ) {
$this->increment_failed_checks();
} else {
$this->reset_failed_checks();
}
if ( $this->failed_checks <= self::$max_failed ) {
return $license_old;
}
if ( isset( $license_old->hide_valid ) ) {
$license_data->hide_valid = true;
}
if ( ! isset( $license_data->key ) ) {
$license_data->key = isset( $license_old->key ) ? $license_old->key : '';
}
if ( isset( $license_old->hide_expiration ) ) {
$license_data->hide_expiration = true;
}
if ( isset( $license_old->hide_activation ) ) {
$license_data->hide_activation = true;
}
return $license_data;
} | php | public function check_license() {
$status = $this->get_license_status();
if ( 'not_active' == $status ) {
$license_data = new \stdClass();
$license_data->license = 'not_active';
return $license_data;
}
$license = trim( $this->license_key );
$api_params = array(
'edd_action' => 'check_license',
'license' => $license,
'item_name' => rawurlencode( $this->product->get_name() ),
'url' => rawurlencode( home_url() ),
);
// Call the custom API.
$response = wp_remote_get(
add_query_arg( $api_params, $this->get_api_url() ),
array(
'timeout' => 15,
'sslverify' => false,
)
);
if ( is_wp_error( $response ) ) {
$license_data = new \stdClass();
$license_data->license = 'valid';
} else {
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! is_object( $license_data ) ) {
$license_data = new \stdClass();
$license_data->license = 'valid';
}
}
$license_old = get_option( $this->product->get_key() . '_license_data', '' );
if ( 'valid' == $license_old->license && ( $license_data->license != $license_old->license ) ) {
$this->increment_failed_checks();
} else {
$this->reset_failed_checks();
}
if ( $this->failed_checks <= self::$max_failed ) {
return $license_old;
}
if ( isset( $license_old->hide_valid ) ) {
$license_data->hide_valid = true;
}
if ( ! isset( $license_data->key ) ) {
$license_data->key = isset( $license_old->key ) ? $license_old->key : '';
}
if ( isset( $license_old->hide_expiration ) ) {
$license_data->hide_expiration = true;
}
if ( isset( $license_old->hide_activation ) ) {
$license_data->hide_activation = true;
}
return $license_data;
} | [
"public",
"function",
"check_license",
"(",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"get_license_status",
"(",
")",
";",
"if",
"(",
"'not_active'",
"==",
"$",
"status",
")",
"{",
"$",
"license_data",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";"... | Check the license status.
@return object The license data. | [
"Check",
"the",
"license",
"status",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L298-L361 | train |
Codeinwp/themeisle-sdk | src/Modules/Licenser.php | Licenser.activate_license | function activate_license() {
// listen for our activate button to be clicked.
if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
return;
}
$status = $this->get_license_status();
// retrieve the license from the database.
$license = $_POST[ $this->product->get_key() . '_license' ];
$api_params = array(
'license' => $license,
'item_name' => rawurlencode( $this->product->get_name() ),
'url' => rawurlencode( home_url() ),
);
if ( 'valid' != $status ) {
// data to send in our API request.
$api_params['edd_action'] = 'activate_license';
} else {
$api_params['edd_action'] = 'deactivate_license';
}
// Call the custom API.
$response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
// make sure the response came back okay.
if ( is_wp_error( $response ) ) {
$license_data = new \stdClass();
$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
} else {
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! is_object( $license_data ) ) {
$license_data = new \stdClass();
$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
}
if ( ! isset( $license_data->license ) ) {
$license_data->license = 'invalid';
}
}
if ( ! isset( $license_data->key ) ) {
$license_data->key = $license;
}
if ( 'valid' == $license_data->license ) {
$this->reset_failed_checks();
}
if ( isset( $license_data->plan ) ) {
update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
}
update_option( $this->product->get_key() . '_license_data', $license_data );
set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
} | php | function activate_license() {
// listen for our activate button to be clicked.
if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
return;
}
$status = $this->get_license_status();
// retrieve the license from the database.
$license = $_POST[ $this->product->get_key() . '_license' ];
$api_params = array(
'license' => $license,
'item_name' => rawurlencode( $this->product->get_name() ),
'url' => rawurlencode( home_url() ),
);
if ( 'valid' != $status ) {
// data to send in our API request.
$api_params['edd_action'] = 'activate_license';
} else {
$api_params['edd_action'] = 'deactivate_license';
}
// Call the custom API.
$response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
// make sure the response came back okay.
if ( is_wp_error( $response ) ) {
$license_data = new \stdClass();
$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
} else {
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
if ( ! is_object( $license_data ) ) {
$license_data = new \stdClass();
$license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
}
if ( ! isset( $license_data->license ) ) {
$license_data->license = 'invalid';
}
}
if ( ! isset( $license_data->key ) ) {
$license_data->key = $license;
}
if ( 'valid' == $license_data->license ) {
$this->reset_failed_checks();
}
if ( isset( $license_data->plan ) ) {
update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
}
update_option( $this->product->get_key() . '_license_data', $license_data );
set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
} | [
"function",
"activate_license",
"(",
")",
"{",
"// listen for our activate button to be clicked.",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"product",
"->",
"get_key",
"(",
")",
".",
"'_btn_trigger'",
"]",
")",
")",
"{",
"return",
... | Activate the license remotely. | [
"Activate",
"the",
"license",
"remotely",
"."
] | 7ead6c057d783ea6c827d5b5de52a25c0e72de58 | https://github.com/Codeinwp/themeisle-sdk/blob/7ead6c057d783ea6c827d5b5de52a25c0e72de58/src/Modules/Licenser.php#L382-L432 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.