本文整理汇总了PHP中wp_insert_link函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_insert_link函数的具体用法?PHP wp_insert_link怎么用?PHP wp_insert_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_insert_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: link_insert
/**
* Insert plugin link into Blogroll
*
* @return void
*/
function link_insert($config)
{
$support = $config->get_string('common.support');
$matches = null;
if ($support != '' && preg_match('~^link_category_(\\d+)$~', $support, $matches)) {
require_once ABSPATH . 'wp-admin/includes/bookmark.php';
wp_insert_link(array('link_url' => W3TC_LINK_URL, 'link_name' => W3TC_LINK_NAME, 'link_category' => array((int) $matches[1]), 'link_rel' => 'nofollow'));
}
}
示例2: test_deleted_link_action
public function test_deleted_link_action()
{
$this->instantiate_link_manager('link.php');
$args = array("link_url" => 'http://test.com', "link_name" => 'The link name', "link_description" => 'The link description');
$link_id = wp_insert_link($args);
$link = get_bookmark($link_id);
$package = $this->lm_helper->get_package($link, 'link');
$this->assertTrue($this->package_exist_in_DB($package));
$this->lm->deleted_link_action($link_id);
$this->assertFalse($this->package_exist_in_DB($package));
}
示例3: test_adding_bookmark_should_bust_get_bookmarks_cache
public function test_adding_bookmark_should_bust_get_bookmarks_cache()
{
global $wpdb;
$bookmarks = self::factory()->bookmark->create_many(2);
// Prime cache.
$found1 = get_bookmarks(array('orderby' => 'link_id'));
$num_queries = $wpdb->num_queries;
$bookmarks[] = wp_insert_link(array('link_name' => 'foo', 'link_url' => 'http://example.com'));
$found2 = get_bookmarks(array('orderby' => 'link_id'));
$this->assertEqualSets($bookmarks, wp_list_pluck($found2, 'link_id'));
$this->assertTrue($num_queries < $wpdb->num_queries);
}
示例4: nn_add_link
function nn_add_link($blog_id, $user_id, $domain, $path, $site_id, $meta)
{
$blog_details = get_blog_details($blog_id);
if (preg_match("/.*Test.*/i", $blog_details->blogname)) {
/*
* We don't create links to test sites
*/
return;
} elseif (link_exists($domain)) {
return;
} elseif (preg_match("/^Nerd Nite (.*)\$/", $blog_details->blogname, $matches)) {
$city_name = strtolower($matches[1]);
$term = get_term_by('slug', 'nerdnite', 'link_category');
$linkdata = array('link_name' => $city_name, 'link_url' => $domain, 'link_category' => $term->term_id, 'link_rel' => 'friend');
wp_insert_link($linkdata);
}
return;
}
示例5: add_link
function add_link($args)
{
extract($args);
$params['link_url'] = esc_html($url);
$params['link_url'] = esc_url($params['link_url']);
$params['link_name'] = esc_html($name);
$params['link_id'] = '';
$params['link_description'] = $description;
$params['link_target'] = $link_target;
$params['link_category'] = array();
//Add Link category
if (is_array($link_category) && !empty($link_category)) {
$terms = get_terms('link_category', array('hide_empty' => 0));
if ($terms) {
foreach ($terms as $term) {
if (in_array($term->name, $link_category)) {
$params['link_category'][] = $term->term_id;
$link_category = $this->remove_element($link_category, $term->name);
}
}
}
if (!empty($link_category)) {
foreach ($link_category as $linkkey => $linkval) {
if (!empty($linkval)) {
$link = wp_insert_term($linkval, 'link_category');
if (isset($link['term_id']) && !empty($link['term_id'])) {
$params['link_category'][] = $link['term_id'];
}
}
}
}
}
//Add Link Owner
$user_obj = get_userdatabylogin($user);
if ($user_obj && $user_obj->ID) {
$params['link_owner'] = $user_obj->ID;
}
if (!function_exists('wp_insert_link')) {
include_once ABSPATH . 'wp-admin/includes/bookmark.php';
}
$is_success = wp_insert_link($params);
return $is_success ? true : array('error' => 'Failed to add link.', 'error_code' => 'failed_to_add_link');
}
示例6: wp_update_link
function wp_update_link($linkdata)
{
global $wpdb;
$link_id = (int) $linkdata['link_id'];
$link = get_link($link_id, ARRAY_A);
// Escape data pulled from DB.
$link = add_magic_quotes($link);
// Passed link category list overwrites existing category list if not empty.
if (isset($linkdata['link_category']) && is_array($linkdata['link_category']) && 0 != count($linkdata['link_category'])) {
$link_cats = $linkdata['link_category'];
} else {
$link_cats = $link['link_category'];
}
// Merge old and new fields with new fields overwriting old ones.
$linkdata = array_merge($link, $linkdata);
$linkdata['link_category'] = $link_cats;
return wp_insert_link($linkdata);
}
示例7: wp_remote_fopen
if ( $blogrolling === true ) {
$opml = wp_remote_fopen($opml_url);
} else {
$opml = file_get_contents($opml_url);
}
include_once('link-parse-opml.php');
$link_count = count($names);
for ( $i = 0; $i < $link_count; $i++ ) {
if ('Last' == substr($titles[$i], 0, 4))
$titles[$i] = '';
if ( 'http' == substr($titles[$i], 0, 4) )
$titles[$i] = '';
$link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i]);
wp_insert_link($link);
echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]);
}
?>
<p><?php printf(__('Inserted %1$d links into category %2$s. All done! Go <a href="%3$s">manage those links</a>.'), $link_count, $cat_id, 'link-manager.php') ?></p>
<?php
} // end if got url
else
{
echo "<p>" . __("You need to supply your OPML url. Press back on your browser and try again") . "</p>\n";
} // end else
if ( ! $blogrolling )
apply_filters( 'wp_delete_file', $opml_url);
示例8: tp_insert_link
function tp_insert_link($data)
{
global $wpdb;
$link_id = $wpdb->get_var("SELECT link_id FROM {$wpdb->links} WHERE link_url='" . $data['link_url'] . "'");
if ($link_id == null) {
$link_id = wp_insert_link($data);
}
update_option('tp_link_id', $link_id);
}
示例9: links2wp
function links2wp($links = '')
{
// General Housekeeping
global $wpdb;
$count = 0;
// Deal with the links
if (is_array($links)) {
echo '<p>' . __('Importing Links...') . '<br /><br /></p>';
foreach ($links as $link) {
$count++;
extract($link);
if ($title != "") {
if ($cinfo = is_term(csc($title), 'link_category')) {
$category = $cinfo['term_id'];
} else {
$category = wp_insert_term($wpdb->escape(csc($title)), 'link_category');
$category = $category['term_id'];
}
} else {
$linkname = $wpdb->escape(csc($label));
$description = $wpdb->escape(csc($title));
if ($linfo = link_exists($linkname)) {
$ret_id = wp_insert_link(array('link_id' => $linfo, 'link_url' => $href, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description));
} else {
$ret_id = wp_insert_link(array('link_url' => $url, 'link_name' => $linkname, 'link_category' => $category, 'link_description' => $description));
}
$dclinks2wplinks[$link_id] = $ret_id;
}
}
add_option('dclinks2wplinks', $dclinks2wplinks);
echo '<p>';
printf(__('Done! <strong>%s</strong> links or link categories imported'), $count);
echo '<br /><br /></p>';
return true;
}
echo __('No Links to Import!');
return false;
}
示例10: syndicate_link
function syndicate_link($name, $uri, $rss)
{
// Get the category ID#
$cat_id = FeedWordPress::link_category_id();
if (!is_wp_error($cat_id)) {
$link_category = array($cat_id);
} else {
$link_category = array();
}
// WordPress gets cranky if there's no homepage URI
if (!is_string($uri) or strlen($uri) < 1) {
$uri = $rss;
}
// Check if this feed URL is already being syndicated.
$link_id = wp_insert_link(array("link_id" => FeedWordPress::find_link($rss), "link_rss" => $rss, "link_name" => $name, "link_url" => $uri, "link_category" => $link_category, "link_visible" => 'Y'));
return $link_id;
}
示例11: process
function process()
{
global $wp_rewrite, $wpcc_options;
$langs = array();
foreach ($this->langs as $key => $value) {
if (isset($_POST['wpcco_variant_' . $key])) {
$langs[] = $key;
}
}
$options = array('wpcc_used_langs' => $langs, 'wpcc_search_conversion' => intval($_POST['wpcco_search_conversion']), 'wpcc_browser_redirect' => intval($_POST['wpcco_browser_redirect']), 'wpcc_use_cookie_variant' => intval($_POST['wpcco_use_cookie_variant']), 'wpcc_use_fullpage_conversion' => isset($_POST['wpcco_use_fullpage_conversion']) ? 1 : 0, 'wpcc_trackback_plugin_author' => isset($_POST['wpcco_trackback_plugin_author']) ? intval($_POST['wpcco_trackback_plugin_author']) : 0, 'wpcc_add_author_link' => isset($_POST['wpcco_add_author_link']) ? 1 : 0, 'wpcc_use_permalink' => intval($_POST['wpcco_use_permalink']), 'wpcc_auto_language_recong' => isset($_POST['wpcco_auto_language_recong']) ? 1 : 0, 'wpcc_no_conversion_tag' => trim($_POST['wpcco_no_conversion_tag'], " \t\n\r\v,|"), 'wpcc_no_conversion_ja' => isset($_POST['wpcco_no_conversion_ja']) ? 1 : 0, 'wpcc_no_conversion_qtag' => isset($_POST['wpcco_no_conversion_qtag']) ? 1 : 0, 'nctip' => trim($_POST['wpcco_no_conversion_tip']));
foreach ($this->langs as $lang => $value) {
if (!empty($_POST[$value[1]])) {
$options[$value[1]] = trim($_POST[$value[1]]);
}
}
if ($this->get_cache_status() == 2 && empty($options['wpcc_browser_redirect']) && empty($options['wpcc_use_cookie_variant'])) {
$this->uninstall_cache_module();
}
if ($options['wpcc_trackback_plugin_author'] == 1) {
$options['wpcc_trackback_plugin_author'] = $this->trackback();
if ($options['wpcc_trackback_plugin_author'] == 2) {
$this->message .= '已成功向<a href="https://oogami.name/project/wpcc/" target="_blank">插件主页</a>发送Trackback。感谢您的支持。<br />';
} else {
$this->message .= '向<a href="https://oogami.name/project/wpcc/" target="_blank">插件主页</a>发送Trackback失败,你可以尝试重新提交。<br />';
}
}
if ($options['wpcc_add_author_link'] == 1 && $this->options['wpcc_add_author_link'] == 0) {
if ($options['wpcc_add_author_link'] = wp_insert_link(array('link_target' => '_blank', 'link_description' => '小野大神的 Blog,关注文明与幻想。', 'link_rss' => 'https://oogami.name/feed/', 'link_name' => '小野大神', 'link_url' => 'https://oogami.name/'))) {
$this->message .= '已成功添加<a href="https://oogami.name/" target="_blank">插件作者</a>的主页链接。感谢您的支持<br />';
} else {
$options['wpcc_add_author_link'] = 0;
$this->message .= '添加插件作者主页链接失败。请重试。<br />';
}
} else {
if ($options['wpcc_add_author_link'] == 0 && $this->options['wpcc_add_author_link'] != 0) {
if (wp_delete_link($this->options['wpcc_add_author_link'])) {
$this->message .= '已删除插件作者的主页链接。<br />';
}
}
}
$wpcc_options = $options;
//因为可能需要刷新rewrite规则, 必须立即更新wpcc_options全局变量
if ($this->options['wpcc_use_permalink'] != $options['wpcc_use_permalink'] || $this->options['wpcc_use_permalink'] != 0 && $this->options['wpcc_used_langs'] != $options['wpcc_used_langs']) {
if (!has_filter('rewrite_rules_array', 'wpcc_rewrite_rules')) {
add_filter('rewrite_rules_array', 'wpcc_rewrite_rules');
}
$wp_rewrite->flush_rules();
}
update_option('wpcc_options', $options);
$this->options = $options;
$this->is_success = true;
$this->message .= '<br />设置已更新。';
}
示例12: edit_link
function edit_link( $link_id = '' ) {
if (!current_user_can( 'manage_links' ))
wp_die( __( 'Cheatin’ uh?' ));
$_POST['link_url'] = wp_specialchars( $_POST['link_url'] );
$_POST['link_url'] = preg_match('/^(https?|ftps?|mailto|news|irc|gopher|nntp|feed|telnet):/is', $_POST['link_url']) ? $_POST['link_url'] : 'http://' . $_POST['link_url'];
$_POST['link_name'] = wp_specialchars( $_POST['link_name'] );
$_POST['link_image'] = wp_specialchars( $_POST['link_image'] );
$_POST['link_rss'] = wp_specialchars( $_POST['link_rss'] );
$_POST['link_category'] = $_POST['post_category'];
if ( !empty( $link_id ) ) {
$_POST['link_id'] = $link_id;
return wp_update_link( $_POST);
} else {
return wp_insert_link( $_POST);
}
}
示例13: syndicate_link
function syndicate_link($name, $uri, $rss)
{
global $wpdb;
// Get the category ID#
$cat_id = FeedWordPress::link_category_id();
// WordPress gets cranky if there's no homepage URI
if (!isset($uri) or strlen($uri) < 1) {
$uri = $rss;
}
if (function_exists('wp_insert_link')) {
// WordPress 2.x
$link_id = wp_insert_link(array("link_name" => $name, "link_url" => $uri, "link_category" => fwp_test_wp_version(0, FWP_SCHEMA_21) ? $cat_id : array($cat_id), "link_rss" => $rss));
} else {
// WordPress 1.5.x
$result = $wpdb->query("\n\t\t\tINSERT INTO {$wpdb->links}\n\t\t\tSET\n\t\t\t\tlink_name = '" . $wpdb->escape($name) . "',\n\t\t\t\tlink_url = '" . $wpdb->escape($uri) . "',\n\t\t\t\tlink_category = '" . $wpdb->escape($cat_id) . "',\n\t\t\t\tlink_rss = '" . $wpdb->escape($rss) . "'\n\t\t\t");
$link_id = $wpdb->insert_id;
}
// if
return $link_id;
}
示例14: demodata_create_link
function demodata_create_link($blogdomain, $linkx)
{
$link = array('link_id' => 0, 'link_name' => 'Bookmark ' . $linkx, 'link_url' => 'http://' . $blogdomain . '/#bookmark' . $linkx, 'link_rating' => 0);
return wp_insert_link($link);
}
示例15: syndicate_link
function syndicate_link ($name, $uri, $rss) {
// Get the category ID#
$cat_id = FeedWordPress::link_category_id();
if (!is_wp_error($cat_id)) :
$link_category = array($cat_id);
else :
$link_category = array();
endif;
// WordPress gets cranky if there's no homepage URI
if (!is_string($uri) or strlen($uri)<1) : $uri = $rss; endif;
// Check if this feed URL is already being syndicated.
$link_id = wp_insert_link(array(
"link_id" => FeedWordPress::find_link($rss), // insert if nothing was found; else update
"link_rss" => $rss,
"link_name" => $name,
"link_url" => $uri,
"link_category" => $link_category,
"link_visible" => 'Y', // reactivate if inactivated
));
return $link_id;
} /* function FeedWordPress::syndicate_link() */