本文整理汇总了PHP中wp_get_link_cats函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_link_cats函数的具体用法?PHP wp_get_link_cats怎么用?PHP wp_get_link_cats使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_link_cats函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: scoper_flt_link_category
function scoper_flt_link_category($link_category)
{
if (empty($_POST['link_id'])) {
return $link_category;
}
$link_id = $_POST['link_id'];
$stored_cats = wp_get_link_cats($link_id);
$user_cats = get_terms('link_category', array('fields' => 'ids'));
if (!$link_category) {
$link_category = array();
} else {
$link_category = (array) $link_category;
}
// remove any cats user lacks permission to select
if ($unselectable_cats = array_diff($link_category, $user_cats)) {
$link_category = array_diff($link_category, $unselectable_cats);
}
// reinstate stored cats which are not selectable by logged user
if ($hidden_cats = array_diff($stored_cats, $user_cats)) {
$link_category = array_merge($link_category, $hidden_cats);
}
// don't let user remove their editing access to link
if (!array_intersect($link_category, $user_cats)) {
$link_category[] = reset($user_cats);
}
return $link_category;
}
示例2: get_bookmark
function get_bookmark($bookmark_id, $output = OBJECT) {
global $wpdb;
$link = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = '$bookmark_id'");
$link->link_category = wp_get_link_cats($bookmark_id);
if ( $output == OBJECT ) {
return $link;
} elseif ( $output == ARRAY_A ) {
return get_object_vars($link);
} elseif ( $output == ARRAY_N ) {
return array_values(get_object_vars($link));
} else {
return $link;
}
}
示例3: get_linkcatname
/**
* Gets the name of category by id.
*
* @since 0.71
* @deprecated 2.1
* @deprecated Use get_category()
* @see get_category()
*
* @param int $id The category to get. If no category supplied uses 0
* @return string
*/
function get_linkcatname($id = 0)
{
_deprecated_function(__FUNCTION__, '2.1', 'get_category()');
$id = (int) $id;
if (empty($id)) {
return '';
}
$cats = wp_get_link_cats($id);
if (empty($cats) || !is_array($cats)) {
return '';
}
$cat_id = (int) $cats[0];
// Take the first cat.
$cat = get_category($cat_id);
return $cat->name;
}
示例4: wp_link_category_checklist
/**
* Outputs a link category checklist element.
*
* @since 2.5.1
*
* @param int $link_id
*/
function wp_link_category_checklist($link_id = 0)
{
$default = 1;
$checked_categories = array();
if ($link_id) {
$checked_categories = wp_get_link_cats($link_id);
// No selected categories, strange
if (!count($checked_categories)) {
$checked_categories[] = $default;
}
} else {
$checked_categories[] = $default;
}
$categories = get_terms('link_category', array('orderby' => 'name', 'hide_empty' => 0));
if (empty($categories)) {
return;
}
foreach ($categories as $category) {
$cat_id = $category->term_id;
/** This filter is documented in wp-includes/category-template.php */
$name = esc_html(apply_filters('the_category', $category->name));
$checked = in_array($cat_id, $checked_categories) ? ' checked="checked"' : '';
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
}
}
示例5: print_column_headers
<tfoot>
<tr>
<?php
print_column_headers('link-manager', false);
?>
</tr>
</tfoot>
<tbody>
<?php
$alt = 0;
foreach ($links as $link) {
$link = sanitize_bookmark($link);
$link->link_name = esc_attr($link->link_name);
$link->link_category = wp_get_link_cats($link->link_id);
$short_url = str_replace('http://', '', $link->link_url);
$short_url = preg_replace('/^www\\./i', '', $short_url);
if ('/' == substr($short_url, -1)) {
$short_url = substr($short_url, 0, -1);
}
if (strlen($short_url) > 35) {
$short_url = substr($short_url, 0, 32) . '...';
}
$visible = $link->link_visible == 'Y' ? __('Yes') : __('No');
$rating = $link->link_rating;
$style = $alt % 2 ? '' : ' class="alternate"';
++$alt;
$edit_link = get_edit_bookmark_link();
?>
<tr id="link-<?php
示例6: dropdown_link_categories
function dropdown_link_categories($default = 0)
{
global $link_id;
if ($link_id) {
$checked_categories = wp_get_link_cats($link_id);
if (count($checked_categories) == 0) {
// No selected categories, strange
$checked_categories[] = $default;
}
} else {
$checked_categories[] = $default;
}
$categories = get_terms('link_category', 'orderby=count&hide_empty=0');
if (empty($categories)) {
return;
}
foreach ($categories as $category) {
$cat_id = $category->term_id;
$name = wp_specialchars(apply_filters('the_category', $category->name));
$checked = in_array($cat_id, $checked_categories);
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked ? ' checked="checked"' : "", '/> ', $name, "</label></li>";
}
}
示例7: display_rows
function display_rows()
{
global $cat_id;
$alt = 0;
foreach ($this->items as $link) {
$link = sanitize_bookmark($link);
$link->link_name = esc_attr($link->link_name);
$link->link_category = wp_get_link_cats($link->link_id);
$short_url = url_shorten($link->link_url);
$visible = $link->link_visible == 'Y' ? __('Yes') : __('No');
$rating = $link->link_rating;
$style = $alt++ % 2 ? '' : ' class="alternate"';
$edit_link = get_edit_bookmark_link($link);
?>
<tr id="link-<?php
echo $link->link_id;
?>
" valign="middle" <?php
echo $style;
?>
>
<?php
list($columns, $hidden) = $this->get_column_info();
foreach ($columns as $column_name => $column_display_name) {
$class = "class='column-{$column_name}'";
$style = '';
if (in_array($column_name, $hidden)) {
$style = ' style="display:none;"';
}
$attributes = $class . $style;
switch ($column_name) {
case 'cb':
?>
<th scope="row" class="check-column">
<label class="screen-reader-text" for="cb-select-<?php
echo $link->link_id;
?>
"><?php
echo sprintf(__('Select %s'), $link->link_name);
?>
</label>
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php
echo $link->link_id;
?>
" value="<?php
echo esc_attr($link->link_id);
?>
" />
</th>
<?php
break;
case 'name':
echo "<td {$attributes}><strong><a class='row-title' href='{$edit_link}' title='" . esc_attr(sprintf(__('Edit “%s”'), $link->link_name)) . "'>{$link->link_name}</a></strong><br />";
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&link_id={$link->link_id}", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>";
echo $this->row_actions($actions);
echo '</td>';
break;
case 'url':
echo "<td {$attributes}><a href='{$link->link_url}' title='" . esc_attr(sprintf(__('Visit %s'), $link->link_name)) . "'>{$short_url}</a></td>";
break;
case 'categories':
?>
<td <?php
echo $attributes;
?>
><?php
$cat_names = array();
foreach ($link->link_category as $category) {
$cat = get_term($category, 'link_category', OBJECT, 'display');
if (is_wp_error($cat)) {
echo $cat->get_error_message();
}
$cat_name = $cat->name;
if ($cat_id != $category) {
$cat_name = "<a href='link-manager.php?cat_id={$category}'>{$cat_name}</a>";
}
$cat_names[] = $cat_name;
}
echo implode(', ', $cat_names);
?>
</td><?php
break;
case 'rel':
?>
<td <?php
echo $attributes;
?>
><?php
echo empty($link->link_rel) ? '<br />' : $link->link_rel;
?>
</td><?php
break;
case 'visible':
?>
<td <?php
echo $attributes;
?>
><?php
//.........这里部分代码省略.........
示例8: wp_delete_link
function wp_delete_link($link_id)
{
global $wpdb;
do_action('delete_link', $link_id);
$categories = wp_get_link_cats($link_id);
if (is_array($categories)) {
foreach ($categories as $category) {
$wpdb->query("UPDATE {$wpdb->categories} SET link_count = link_count - 1 WHERE cat_ID = '{$category}'");
wp_cache_delete($category, 'category');
do_action('edit_category', $cat_id);
}
}
$wpdb->query("DELETE FROM {$wpdb->link2cat} WHERE link_id = '{$link_id}'");
$wpdb->query("DELETE FROM {$wpdb->links} WHERE link_id = '{$link_id}'");
do_action('deleted_link', $link_id);
return true;
}
示例9: display_rows
public function display_rows()
{
foreach ($this->items as $link) {
$link = sanitize_bookmark($link);
$link->link_name = esc_attr($link->link_name);
$link->link_category = wp_get_link_cats($link->link_id);
?>
<tr id="link-<?php
echo $link->link_id;
?>
">
<?php
$this->single_row_columns($link);
?>
</tr>
<?php
}
}
示例10: get_linkcatname
/** function get_linkcatname()
** Gets the name of category n.
** Parameters: id (default 0) - The category to get. If no category supplied
** uses 0
*/
function get_linkcatname($id = 0)
{
$id = (int) $id;
if (empty($id)) {
return '';
}
$cats = wp_get_link_cats($id);
if (empty($cats) || !is_array($cats)) {
return '';
}
$cat_id = (int) $cats[0];
// Take the first cat.
$cat = get_category($cat_id);
return $cat->name;
}
示例11: ame_ajax_save_linkcategories
/**
* SACK response function for saving link categories
*
* @since 1.8.0
* @author scripts@schloebe.de
*/
function ame_ajax_save_linkcategories()
{
global $wpdb;
$linkid = (int) $_POST['linkid'];
$ame_linkcats = $_POST['ame_linkcats'];
$ame_linkcategories = substr($ame_linkcats, 0, -1);
$catarray = explode(",", $ame_linkcategories);
wp_set_link_cats($linkid, $catarray);
do_action('edit_link', $linkid);
unset($GLOBALS['category_cache']);
$link = wp_get_link_cats($linkid);
$cat_names = array();
foreach ($link as $category) {
$cat = get_term($category, 'link_category', OBJECT, 'display');
if (is_wp_error($cat)) {
echo $cat->get_error_message();
}
$cat_name = $cat->name;
if ($linkid != $category) {
$cat_name = "<a href='link-manager.php?cat_id={$category}'>{$cat_name}</a>";
}
$cat_names[] = $cat_name;
}
$ame_link_cats = implode(', ', $cat_names);
die("re_init();jQuery('span#ame_linkcategory" . $linkid . "').fadeOut('fast', function() {\r\n\t\tjQuery('a#thickboxlink" . $linkid . "').show();\r\n\t\tjQuery('span#ame_linkcategory" . $linkid . "').html('" . addslashes_gpc($ame_link_cats) . "').fadeIn('fast');\r\n\t});");
}
示例12: display_rows
/**
*
* @global int $cat_id
*/
public function display_rows()
{
global $cat_id;
foreach ($this->items as $link) {
$link = sanitize_bookmark($link);
$link->link_name = esc_attr($link->link_name);
$link->link_category = wp_get_link_cats($link->link_id);
$short_url = url_shorten($link->link_url);
$visible = $link->link_visible == 'Y' ? __('Yes') : __('No');
$rating = $link->link_rating;
$edit_link = get_edit_bookmark_link($link);
?>
<tr id="link-<?php
echo $link->link_id;
?>
">
<?php
list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
foreach ($columns as $column_name => $column_display_name) {
$classes = "{$column_name} column-{$column_name}";
if ($primary === $column_name) {
$classes .= ' has-row-actions column-primary';
}
$style = '';
if (in_array($column_name, $hidden)) {
$style = ' style="display:none;"';
}
$attributes = "class='{$classes}'{$style}";
if ('cb' === $column_name) {
?>
<th scope="row" class="check-column">
<label class="screen-reader-text" for="cb-select-<?php
echo $link->link_id;
?>
"><?php
echo sprintf(__('Select %s'), $link->link_name);
?>
</label>
<input type="checkbox" name="linkcheck[]" id="cb-select-<?php
echo $link->link_id;
?>
" value="<?php
echo esc_attr($link->link_id);
?>
" />
</th>
<?php
} else {
echo "<td {$attributes}>";
switch ($column_name) {
case 'name':
echo "<strong><a class='row-title' href='{$edit_link}' title='" . esc_attr(sprintf(__('Edit “%s”'), $link->link_name)) . "'>{$link->link_name}</a></strong><br />";
break;
case 'url':
echo "<a href='{$link->link_url}' title='" . esc_attr(sprintf(__('Visit %s'), $link->link_name)) . "'>{$short_url}</a>";
break;
case 'categories':
$cat_names = array();
foreach ($link->link_category as $category) {
$cat = get_term($category, 'link_category', OBJECT, 'display');
if (is_wp_error($cat)) {
echo $cat->get_error_message();
}
$cat_name = $cat->name;
if ($cat_id != $category) {
$cat_name = "<a href='link-manager.php?cat_id={$category}'>{$cat_name}</a>";
}
$cat_names[] = $cat_name;
}
echo implode(', ', $cat_names);
break;
case 'rel':
echo empty($link->link_rel) ? '<br />' : $link->link_rel;
break;
case 'visible':
echo $visible;
break;
case 'rating':
echo $rating;
break;
default:
/**
* Fires for each registered custom link column.
*
* @since 2.1.0
*
* @param string $column_name Name of the custom column.
* @param int $link_id Link ID.
*/
do_action('manage_link_custom_column', $column_name, $link->link_id);
break;
}
echo $this->handle_row_actions($link, $column_name, $primary);
echo '</td>';
}
}
//.........这里部分代码省略.........
示例13: display_rows
function display_rows()
{
global $cat_id;
$alt = 0;
foreach ($this->items as $link) {
$link = sanitize_bookmark($link);
$link->link_name = esc_attr($link->link_name);
$link->link_category = wp_get_link_cats($link->link_id);
$short_url = str_replace('http://', '', $link->link_url);
$short_url = preg_replace('/^www\\./i', '', $short_url);
if ('/' == substr($short_url, -1)) {
$short_url = substr($short_url, 0, -1);
}
if (strlen($short_url) > 35) {
$short_url = substr($short_url, 0, 32) . '...';
}
$visible = $link->link_visible == 'Y' ? __('Yes') : __('No');
$rating = $link->link_rating;
$style = $alt++ % 2 ? '' : ' class="alternate"';
$edit_link = get_edit_bookmark_link($link);
?>
<tr id="link-<?php
echo $link->link_id;
?>
" valign="middle" <?php
echo $style;
?>
>
<?php
list($columns, $hidden) = $this->get_column_headers();
foreach ($columns as $column_name => $column_display_name) {
$class = "class='column-{$column_name}'";
$style = '';
if (in_array($column_name, $hidden)) {
$style = ' style="display:none;"';
}
$attributes = $class . $style;
switch ($column_name) {
case 'cb':
echo '<th scope="row" class="check-column"><input type="checkbox" name="linkcheck[]" value="' . esc_attr($link->link_id) . '" /></th>';
break;
case 'name':
echo "<td {$attributes}><strong><a class='row-title' href='{$edit_link}' title='" . esc_attr(sprintf(__('Edit “%s”'), $link->link_name)) . "'>{$link->link_name}</a></strong><br />";
$actions = array();
$actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>';
$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("link.php?action=delete&link_id={$link->link_id}", 'delete-bookmark_' . $link->link_id) . "' onclick=\"if ( confirm( '" . esc_js(sprintf(__("You are about to delete this link '%s'\n 'Cancel' to stop, 'OK' to delete."), $link->link_name)) . "' ) ) { return true;}return false;\">" . __('Delete') . "</a>";
$action_count = count($actions);
$i = 0;
echo '<div class="row-actions">';
foreach ($actions as $action => $linkaction) {
++$i;
$i == $action_count ? $sep = '' : ($sep = ' | ');
echo "<span class='{$action}'>{$linkaction}{$sep}</span>";
}
echo '</div>';
echo '</td>';
break;
case 'url':
echo "<td {$attributes}><a href='{$link->link_url}' title='" . sprintf(__('Visit %s'), $link->link_name) . "'>{$short_url}</a></td>";
break;
case 'categories':
?>
<td <?php
echo $attributes;
?>
><?php
$cat_names = array();
foreach ($link->link_category as $category) {
$cat = get_term($category, 'link_category', OBJECT, 'display');
if (is_wp_error($cat)) {
echo $cat->get_error_message();
}
$cat_name = $cat->name;
if ($cat_id != $category) {
$cat_name = "<a href='link-manager.php?cat_id={$category}'>{$cat_name}</a>";
}
$cat_names[] = $cat_name;
}
echo implode(', ', $cat_names);
?>
</td><?php
break;
case 'rel':
?>
<td <?php
echo $attributes;
?>
><?php
echo empty($link->link_rel) ? '<br />' : $link->link_rel;
?>
</td><?php
break;
case 'visible':
?>
<td <?php
echo $attributes;
?>
><?php
echo $visible;
?>
//.........这里部分代码省略.........