| 1 |
<?php |
| 2 |
/************************************************************* |
| 3 |
* |
| 4 |
* user.class.php |
| 5 |
* |
| 6 |
* Add Users |
| 7 |
* |
| 8 |
* |
| 9 |
* Copyright (c) 2011 Prelovac Media |
| 10 |
* www.prelovac.com |
| 11 |
**************************************************************/ |
| 12 |
|
| 13 |
class MMB_Link extends MMB_Core |
| 14 |
{ |
| 15 |
function __construct() |
| 16 |
{ |
| 17 |
parent::__construct(); |
| 18 |
} |
| 19 |
|
| 20 |
function add_link($args) |
| 21 |
{ |
| 22 |
extract($args); |
| 23 |
|
| 24 |
$params['link_url'] = esc_html($url); |
| 25 |
$params['link_url'] = esc_url($params['link_url']); |
| 26 |
$params['link_name'] = esc_html($name); |
| 27 |
$params['link_id'] = ''; |
| 28 |
$params['link_description'] = $description; |
| 29 |
$params['link_target'] = $link_target; |
| 30 |
$params['link_category'] = array(); |
| 31 |
|
| 32 |
//Add Link category |
| 33 |
if(is_array($link_category) && !empty($link_category)){ |
| 34 |
$terms = get_terms('link_category',array('hide_empty' => 0)); |
| 35 |
|
| 36 |
if($terms){ |
| 37 |
foreach($terms as $term){ |
| 38 |
if(in_array($term->name,$link_category)){ |
| 39 |
$params['link_category'][] = $term->term_id; |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
//Add Link Owner |
| 46 |
$user_obj = get_userdatabylogin($user); |
| 47 |
if($user_obj && $user_obj->ID){ |
| 48 |
$params['link_owner'] = $user_obj->ID; |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
if(!function_exists('wp_insert_link')) |
| 53 |
include_once (ABSPATH . 'wp-admin/includes/bookmark.php'); |
| 54 |
|
| 55 |
$is_success = wp_insert_link($params); |
| 56 |
|
| 57 |
return $is_success ? true : array('error' => 'Failed to add link.'); |
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
?> |