本文整理汇总了PHP中Str::human方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::human方法的具体用法?PHP Str::human怎么用?PHP Str::human使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::human方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeErrorMessage
public function makeErrorMessage($type, $key)
{
$errors = self::getErrorMessages();
if ($type == 'required') {
return sprintf($errors['required'], Str::human($key));
}
if ($type == 'email') {
return sprintf($errors['email'], Str::human($key));
}
if ($type == 'us_zip') {
return sprintf($errors['us_zip'], Str::human($key));
}
if ($type == 'url') {
return sprintf($errors['url'], Str::human($key));
}
}
示例2: get_edit_link
/**
* Get edit link when admin is logged in
* @param int $id (post ID or term ID)
* @param string $edit_type (post type or taxonomy slug)
* @param string $label (optional admin-facing name for $edit_type)
* @param bool $display_inline (omit wrapping paragraph)
* @return string (HTML)
*/
function get_edit_link($id = null, $edit_type = 'post', $label = null, $display_inline = false)
{
if (!(is_user_logged_in() && current_user_can('manage_options'))) {
return null;
}
$link_class = 'class="front-end-edit-link"';
$link_tag = $display_inline ? 'span' : 'p';
if (is_null($label)) {
$label = Str::human(str_replace('-', ' ', $edit_type));
}
$subclasses = \Taco\Post\Loader::getSubclasses();
$subclasses_machine = array_map(function ($el) {
$el = substr($el, strrpos($el, '\\'));
$el = Str::camelToHuman($el);
$el = Str::machine($el, '-');
return $el;
}, $subclasses);
if (in_array($edit_type, $subclasses_machine)) {
// Edit post or display list of posts of this type
$post_type_link = !is_null($id) ? get_edit_post_link($id) : '/wp-admin/edit.php?post_type=' . $edit_type;
return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, $post_type_link, $label, $link_tag);
}
// Find an applicable post type for editing a custom term
$post_type = null;
$post_types_by_taxonomy = [];
foreach ($subclasses as $subclass) {
if (strpos($subclass, '\\') !== false) {
$subclass = '\\' . $subclass;
}
$taxonomies = \Taco\Post\Factory::create($subclass)->getTaxonomies();
if (Arr::iterable($taxonomies)) {
foreach ($taxonomies as $key => $taxonomy) {
$taxonomy_slug = is_array($taxonomy) ? $key : $taxonomy;
$post_types_by_taxonomy[$taxonomy_slug][] = $subclass;
}
}
}
$post_types_by_taxonomy = array_unique($post_types_by_taxonomy);
if (array_key_exists($edit_type, $post_types_by_taxonomy)) {
$post_type = reset($post_types_by_taxonomy[$edit_type]);
$post_type = substr($post_type, strrpos($post_type, '\\'));
$post_type = Str::camelToHuman($post_type);
$post_type = Str::machine($post_type, '-');
} else {
$post_type = 'post';
}
if (is_null($id)) {
// View taxonomy term list
return sprintf('<%s %s><a href="/wp-admin/edit-tags.php?taxonomy=%s&post_type=%s">View %ss</a></%s>', $link_tag, $link_class, $edit_type, $post_type, $label, $link_tag);
}
// Edit term
return sprintf('<%s %s><a href="%s">Edit %s</a></%s>', $link_tag, $link_class, get_edit_term_link($id, $edit_type, $post_type), $label, $link_tag);
}