本文整理汇总了PHP中wp_set_link_cats函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_link_cats函数的具体用法?PHP wp_set_link_cats怎么用?PHP wp_set_link_cats使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_set_link_cats函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: link_library_insert_link
function link_library_insert_link($linkdata, $wp_error = false, $addlinknoaddress = false)
{
global $wpdb;
$defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0);
$linkdata = wp_parse_args($linkdata, $defaults);
$linkdata = sanitize_bookmark($linkdata, 'db');
extract(stripslashes_deep($linkdata), EXTR_SKIP);
$update = false;
if (!empty($link_id)) {
$update = true;
}
if (isset($link_name) && trim($link_name) == '') {
if (isset($link_url) && trim($link_url) != '') {
$link_name = $link_url;
} else {
return 0;
}
}
if ($addlinknoaddress == false) {
if (trim($link_url) == '') {
return 0;
}
}
if (empty($link_rating)) {
$link_rating = 0;
}
if (empty($link_image)) {
$link_image = '';
}
if (empty($link_target)) {
$link_target = '';
}
if (empty($link_visible)) {
$link_visible = 'Y';
}
if (empty($link_owner)) {
$link_owner = get_current_user_id();
}
if (empty($link_notes)) {
$link_notes = '';
}
if (empty($link_description)) {
$link_description = '';
}
if (empty($link_rss)) {
$link_rss = '';
}
if (empty($link_rel)) {
$link_rel = '';
}
// Make sure we set a valid category
if (!isset($link_category) || 0 == count($link_category) || !is_array($link_category)) {
$link_category = array(get_option('default_link_category'));
}
if ($update) {
if (false === $wpdb->update($wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss'), compact('link_id'))) {
if ($wp_error) {
return new WP_Error('db_update_error', __('Could not update link in the database', 'link-library'), $wpdb->last_error);
} else {
return 0;
}
}
} else {
if (false === $wpdb->insert($wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss'))) {
if ($wp_error) {
return new WP_Error('db_insert_error', __('Could not insert link into the database', 'link-library'), $wpdb->last_error);
} else {
return 0;
}
}
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats($link_id, $link_category);
if ($update) {
do_action('edit_link', $link_id);
} else {
do_action('add_link', $link_id);
}
clean_bookmark_cache($link_id);
return $link_id;
}
示例2: wp_insert_link
function wp_insert_link($linkdata)
{
global $wpdb, $current_user;
extract($linkdata, EXTR_SKIP);
$update = false;
if (!empty($link_id)) {
$update = true;
}
$link_id = (int) $link_id;
if (trim($link_name) == '') {
return 0;
}
$link_name = apply_filters('pre_link_name', $link_name);
if (trim($link_url) == '') {
return 0;
}
$link_url = apply_filters('pre_link_url', $link_url);
if (empty($link_rating)) {
$link_rating = 0;
} else {
$link_rating = (int) $link_rating;
}
if (empty($link_image)) {
$link_image = '';
}
$link_image = apply_filters('pre_link_image', $link_image);
if (empty($link_target)) {
$link_target = '';
}
$link_target = apply_filters('pre_link_target', $link_target);
if (empty($link_visible)) {
$link_visible = 'Y';
}
$link_visibile = preg_replace('/[^YNyn]/', '', $link_visible);
if (empty($link_owner)) {
$link_owner = $current_user->id;
} else {
$link_owner = (int) $link_owner;
}
if (empty($link_notes)) {
$link_notes = '';
}
$link_notes = apply_filters('pre_link_notes', $link_notes);
if (empty($link_description)) {
$link_description = '';
}
$link_description = apply_filters('pre_link_description', $link_description);
if (empty($link_rss)) {
$link_rss = '';
}
$link_rss = apply_filters('pre_link_rss', $link_rss);
if (empty($link_rel)) {
$link_rel = '';
}
$link_rel = apply_filters('pre_link_rel', $link_rel);
// Make sure we set a valid category
if (0 == count($link_category) || !is_array($link_category)) {
$link_category = array(get_option('default_link_category'));
}
if ($update) {
$wpdb->query("UPDATE {$wpdb->links} SET link_url='{$link_url}',\n\t\t\tlink_name='{$link_name}', link_image='{$link_image}',\n\t\t\tlink_target='{$link_target}',\n\t\t\tlink_visible='{$link_visible}', link_description='{$link_description}',\n\t\t\tlink_rating='{$link_rating}', link_rel='{$link_rel}',\n\t\t\tlink_notes='{$link_notes}', link_rss = '{$link_rss}'\n\t\t\tWHERE link_id='{$link_id}'");
} else {
$wpdb->query("INSERT INTO {$wpdb->links} (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('{$link_url}','{$link_name}', '{$link_image}', '{$link_target}', '{$link_description}', '{$link_visible}', '{$link_owner}', '{$link_rating}', '{$link_rel}', '{$link_notes}', '{$link_rss}')");
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats($link_id, $link_category);
if ($update) {
do_action('edit_link', $link_id);
} else {
do_action('add_link', $link_id);
}
return $link_id;
}
示例3: wp_insert_link
/**
* {@internal Missing Short Description}}
*
* @since unknown
*
* @param unknown_type $linkdata
* @return unknown
*/
function wp_insert_link( $linkdata, $wp_error = false ) {
global $wpdb, $current_user;
$defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 );
$linkdata = wp_parse_args( $linkdata, $defaults );
$linkdata = sanitize_bookmark( $linkdata, 'db' );
extract( stripslashes_deep( $linkdata ), EXTR_SKIP );
$update = false;
if ( !empty( $link_id ) )
$update = true;
if ( trim( $link_name ) == '' )
return 0;
if ( trim( $link_url ) == '' )
return 0;
if ( empty( $link_rating ) )
$link_rating = 0;
if ( empty( $link_image ) )
$link_image = '';
if ( empty( $link_target ) )
$link_target = '';
if ( empty( $link_visible ) )
$link_visible = 'Y';
if ( empty( $link_owner ) )
$link_owner = $current_user->id;
if ( empty( $link_notes ) )
$link_notes = '';
if ( empty( $link_description ) )
$link_description = '';
if ( empty( $link_rss ) )
$link_rss = '';
if ( empty( $link_rel ) )
$link_rel = '';
// Make sure we set a valid category
if ( ! isset( $link_category ) ||0 == count( $link_category ) || !is_array( $link_category ) ) {
$link_category = array( get_option( 'default_link_category' ) );
}
if ( $update ) {
if ( false === $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->links SET link_url = %s,
link_name = %s, link_image = %s, link_target = %s,
link_visible = %s, link_description = %s, link_rating = %s,
link_rel = %s, link_notes = %s, link_rss = %s
WHERE link_id = %s", $link_url, $link_name, $link_image, $link_target, $link_visible, $link_description, $link_rating, $link_rel, $link_notes, $link_rss, $link_id ) ) ) {
if ( $wp_error )
return new WP_Error( 'db_update_error', __( 'Could not update link in the database' ), $wpdb->last_error );
else
return 0;
}
} else {
if ( false === $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->links (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
$link_url,$link_name, $link_image, $link_target, $link_description, $link_visible, $link_owner, $link_rating, $link_rel, $link_notes, $link_rss ) ) ) {
if ( $wp_error )
return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database' ), $wpdb->last_error );
else
return 0;
}
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats( $link_id, $link_category );
if ( $update )
do_action( 'edit_link', $link_id );
else
do_action( 'add_link', $link_id );
clean_bookmark_cache( $link_id );
return $link_id;
}
示例4: wp_insert_link
/**
* This function inserts/updates links into/in the database.
*
* @since 2.0.0
*
* @param array $linkdata Elements that make up the link to insert.
* @param bool $wp_error Optional. If true return WP_Error object on failure.
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
*/
function wp_insert_link($linkdata, $wp_error = false)
{
global $wpdb;
$defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0);
$args = wp_parse_args($linkdata, $defaults);
$r = wp_unslash(sanitize_bookmark($args, 'db'));
$link_id = $r['link_id'];
$link_name = $r['link_name'];
$link_url = $r['link_url'];
$update = false;
if (!empty($link_id)) {
$update = true;
}
if (trim($link_name) == '') {
if (trim($link_url) != '') {
$link_name = $link_url;
} else {
return 0;
}
}
if (trim($link_url) == '') {
return 0;
}
$link_rating = !empty($r['link_rating']) ? $r['link_rating'] : 0;
$link_image = !empty($r['link_image']) ? $r['link_image'] : '';
$link_target = !empty($r['link_target']) ? $r['link_target'] : '';
$link_visible = !empty($r['link_visible']) ? $r['link_visible'] : 'Y';
$link_owner = !empty($r['link_owner']) ? $r['link_owner'] : get_current_user_id();
$link_notes = !empty($r['link_notes']) ? $r['link_notes'] : '';
$link_description = !empty($r['link_description']) ? $r['link_description'] : '';
$link_rss = !empty($r['link_rss']) ? $r['link_rss'] : '';
$link_rel = !empty($r['link_rel']) ? $r['link_rel'] : '';
$link_category = !empty($r['link_category']) ? $r['link_category'] : array();
// Make sure we set a valid category
if (!is_array($link_category) || 0 == count($link_category)) {
$link_category = array(get_option('default_link_category'));
}
if ($update) {
if (false === $wpdb->update($wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_rating', 'link_rel', 'link_notes', 'link_rss'), compact('link_id'))) {
if ($wp_error) {
return new WP_Error('db_update_error', __('Could not update link in the database'), $wpdb->last_error);
} else {
return 0;
}
}
} else {
if (false === $wpdb->insert($wpdb->links, compact('link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss'))) {
if ($wp_error) {
return new WP_Error('db_insert_error', __('Could not insert link into the database'), $wpdb->last_error);
} else {
return 0;
}
}
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats($link_id, $link_category);
if ($update) {
/**
* Fires after a link was updated in the database.
*
* @since 2.0.0
*
* @param int $link_id ID of the link that was updated.
*/
do_action('edit_link', $link_id);
} else {
/**
* Fires after a link was added to the database.
*
* @since 2.0.0
*
* @param int $link_id ID of the link that was added.
*/
do_action('add_link', $link_id);
}
clean_bookmark_cache($link_id);
return $link_id;
}
示例5: wp_insert_link
function wp_insert_link($linkdata)
{
global $wpdb, $current_user;
$defaults = array('link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0);
$linkdata = wp_parse_args($linkdata, $defaults);
$linkdata = sanitize_bookmark($linkdata, 'db');
extract($linkdata, EXTR_SKIP);
$update = false;
if (!empty($link_id)) {
$update = true;
}
if (trim($link_name) == '') {
return 0;
}
if (trim($link_url) == '') {
return 0;
}
if (empty($link_rating)) {
$link_rating = 0;
}
if (empty($link_image)) {
$link_image = '';
}
if (empty($link_target)) {
$link_target = '';
}
if (empty($link_visible)) {
$link_visible = 'Y';
}
if (empty($link_owner)) {
$link_owner = $current_user->id;
}
if (empty($link_notes)) {
$link_notes = '';
}
if (empty($link_description)) {
$link_description = '';
}
if (empty($link_rss)) {
$link_rss = '';
}
if (empty($link_rel)) {
$link_rel = '';
}
// Make sure we set a valid category
if (0 == count($link_category) || !is_array($link_category)) {
$link_category = array(get_option('default_link_category'));
}
if ($update) {
$wpdb->query("UPDATE {$wpdb->links} SET link_url='{$link_url}',\n\t\t\tlink_name='{$link_name}', link_image='{$link_image}',\n\t\t\tlink_target='{$link_target}',\n\t\t\tlink_visible='{$link_visible}', link_description='{$link_description}',\n\t\t\tlink_rating='{$link_rating}', link_rel='{$link_rel}',\n\t\t\tlink_notes='{$link_notes}', link_rss = '{$link_rss}'\n\t\t\tWHERE link_id='{$link_id}'");
} else {
$wpdb->query("INSERT INTO {$wpdb->links} (link_url, link_name, link_image, link_target, link_description, link_visible, link_owner, link_rating, link_rel, link_notes, link_rss) VALUES('{$link_url}','{$link_name}', '{$link_image}', '{$link_target}', '{$link_description}', '{$link_visible}', '{$link_owner}', '{$link_rating}', '{$link_rel}', '{$link_notes}', '{$link_rss}')");
$link_id = (int) $wpdb->insert_id;
}
wp_set_link_cats($link_id, $link_category);
if ($update) {
do_action('edit_link', $link_id);
} else {
do_action('add_link', $link_id);
}
return $link_id;
}
示例6: 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});");
}