32 '<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>', |
32 '<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>', |
33 403 |
33 403 |
34 ); |
34 ); |
35 } |
35 } |
36 |
36 |
37 $_POST['link_url'] = esc_html( $_POST['link_url'] ); |
37 $_POST['link_url'] = esc_html( $_POST['link_url'] ); |
38 $_POST['link_url'] = esc_url($_POST['link_url']); |
38 $_POST['link_url'] = esc_url( $_POST['link_url'] ); |
39 $_POST['link_name'] = esc_html( $_POST['link_name'] ); |
39 $_POST['link_name'] = esc_html( $_POST['link_name'] ); |
40 $_POST['link_image'] = esc_html( $_POST['link_image'] ); |
40 $_POST['link_image'] = esc_html( $_POST['link_image'] ); |
41 $_POST['link_rss'] = esc_url($_POST['link_rss']); |
41 $_POST['link_rss'] = esc_url( $_POST['link_rss'] ); |
42 if ( !isset($_POST['link_visible']) || 'N' != $_POST['link_visible'] ) |
42 if ( ! isset( $_POST['link_visible'] ) || 'N' != $_POST['link_visible'] ) { |
43 $_POST['link_visible'] = 'Y'; |
43 $_POST['link_visible'] = 'Y'; |
44 |
44 } |
45 if ( !empty( $link_id ) ) { |
45 |
|
46 if ( ! empty( $link_id ) ) { |
46 $_POST['link_id'] = $link_id; |
47 $_POST['link_id'] = $link_id; |
47 return wp_update_link( $_POST ); |
48 return wp_update_link( $_POST ); |
48 } else { |
49 } else { |
49 return wp_insert_link( $_POST ); |
50 return wp_insert_link( $_POST ); |
50 } |
51 } |
57 * |
58 * |
58 * @return stdClass Default link object. |
59 * @return stdClass Default link object. |
59 */ |
60 */ |
60 function get_default_link_to_edit() { |
61 function get_default_link_to_edit() { |
61 $link = new stdClass; |
62 $link = new stdClass; |
62 if ( isset( $_GET['linkurl'] ) ) |
63 if ( isset( $_GET['linkurl'] ) ) { |
63 $link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) ); |
64 $link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) ); |
64 else |
65 } else { |
65 $link->link_url = ''; |
66 $link->link_url = ''; |
66 |
67 } |
67 if ( isset( $_GET['name'] ) ) |
68 |
|
69 if ( isset( $_GET['name'] ) ) { |
68 $link->link_name = esc_attr( wp_unslash( $_GET['name'] ) ); |
70 $link->link_name = esc_attr( wp_unslash( $_GET['name'] ) ); |
69 else |
71 } else { |
70 $link->link_name = ''; |
72 $link->link_name = ''; |
|
73 } |
71 |
74 |
72 $link->link_visible = 'Y'; |
75 $link->link_visible = 'Y'; |
73 |
76 |
74 return $link; |
77 return $link; |
75 } |
78 } |
120 * |
123 * |
121 * @param int $link_id Link ID to look up |
124 * @param int $link_id Link ID to look up |
122 * @return array The requested link's categories |
125 * @return array The requested link's categories |
123 */ |
126 */ |
124 function wp_get_link_cats( $link_id = 0 ) { |
127 function wp_get_link_cats( $link_id = 0 ) { |
125 $cats = wp_get_object_terms( $link_id, 'link_category', array('fields' => 'ids') ); |
128 $cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) ); |
126 return array_unique( $cats ); |
129 return array_unique( $cats ); |
127 } |
130 } |
128 |
131 |
129 /** |
132 /** |
130 * Retrieves link data based on its ID. |
133 * Retrieves link data based on its ID. |
150 * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. |
153 * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. |
151 */ |
154 */ |
152 function wp_insert_link( $linkdata, $wp_error = false ) { |
155 function wp_insert_link( $linkdata, $wp_error = false ) { |
153 global $wpdb; |
156 global $wpdb; |
154 |
157 |
155 $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 ); |
158 $defaults = array( |
|
159 'link_id' => 0, |
|
160 'link_name' => '', |
|
161 'link_url' => '', |
|
162 'link_rating' => 0, |
|
163 ); |
156 |
164 |
157 $args = wp_parse_args( $linkdata, $defaults ); |
165 $args = wp_parse_args( $linkdata, $defaults ); |
158 $r = wp_unslash( sanitize_bookmark( $args, 'db' ) ); |
166 $r = wp_unslash( sanitize_bookmark( $args, 'db' ) ); |
159 |
167 |
160 $link_id = $r['link_id']; |
168 $link_id = $r['link_id']; |
161 $link_name = $r['link_name']; |
169 $link_name = $r['link_name']; |
162 $link_url = $r['link_url']; |
170 $link_url = $r['link_url']; |
163 |
171 |
243 * Update link with the specified link categories. |
251 * Update link with the specified link categories. |
244 * |
252 * |
245 * @since 2.1.0 |
253 * @since 2.1.0 |
246 * |
254 * |
247 * @param int $link_id ID of the link to update. |
255 * @param int $link_id ID of the link to update. |
248 * @param array $link_categories Array of link categories to add the link to. |
256 * @param int[] $link_categories Array of link category IDs to add the link to. |
249 */ |
257 */ |
250 function wp_set_link_cats( $link_id = 0, $link_categories = array() ) { |
258 function wp_set_link_cats( $link_id = 0, $link_categories = array() ) { |
251 // If $link_categories isn't already an array, make it one: |
259 // If $link_categories isn't already an array, make it one: |
252 if ( !is_array( $link_categories ) || 0 == count( $link_categories ) ) |
260 if ( ! is_array( $link_categories ) || 0 == count( $link_categories ) ) { |
253 $link_categories = array( get_option( 'default_link_category' ) ); |
261 $link_categories = array( get_option( 'default_link_category' ) ); |
|
262 } |
254 |
263 |
255 $link_categories = array_map( 'intval', $link_categories ); |
264 $link_categories = array_map( 'intval', $link_categories ); |
256 $link_categories = array_unique( $link_categories ); |
265 $link_categories = array_unique( $link_categories ); |
257 |
266 |
258 wp_set_object_terms( $link_id, $link_categories, 'link_category' ); |
267 wp_set_object_terms( $link_id, $link_categories, 'link_category' ); |
275 |
284 |
276 // Escape data pulled from DB. |
285 // Escape data pulled from DB. |
277 $link = wp_slash( $link ); |
286 $link = wp_slash( $link ); |
278 |
287 |
279 // Passed link category list overwrites existing category list if not empty. |
288 // Passed link category list overwrites existing category list if not empty. |
280 if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) |
289 if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && 0 != count( $linkdata['link_category'] ) ) { |
281 && 0 != count( $linkdata['link_category'] ) ) |
|
282 $link_cats = $linkdata['link_category']; |
290 $link_cats = $linkdata['link_category']; |
283 else |
291 } else { |
284 $link_cats = $link['link_category']; |
292 $link_cats = $link['link_category']; |
|
293 } |
285 |
294 |
286 // Merge old and new fields with new fields overwriting old ones. |
295 // Merge old and new fields with new fields overwriting old ones. |
287 $linkdata = array_merge( $link, $linkdata ); |
296 $linkdata = array_merge( $link, $linkdata ); |
288 $linkdata['link_category'] = $link_cats; |
297 $linkdata['link_category'] = $link_cats; |
289 |
298 |
290 return wp_insert_link( $linkdata ); |
299 return wp_insert_link( $linkdata ); |
291 } |
300 } |
292 |
301 |
298 * |
307 * |
299 * @global string $pagenow |
308 * @global string $pagenow |
300 */ |
309 */ |
301 function wp_link_manager_disabled_message() { |
310 function wp_link_manager_disabled_message() { |
302 global $pagenow; |
311 global $pagenow; |
303 if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) |
312 if ( 'link-manager.php' != $pagenow && 'link-add.php' != $pagenow && 'link.php' != $pagenow ) { |
304 return; |
313 return; |
|
314 } |
305 |
315 |
306 add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
316 add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
307 $really_can_manage_links = current_user_can( 'manage_links' ); |
317 $really_can_manage_links = current_user_can( 'manage_links' ); |
308 remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
318 remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
309 |
319 |
310 if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) { |
320 if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) { |
311 $link = network_admin_url( 'plugin-install.php?tab=search&s=Link+Manager' ); |
321 $link = network_admin_url( 'plugin-install.php?tab=search&s=Link+Manager' ); |
|
322 /* translators: %s: URL of link manager plugin */ |
312 wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) ); |
323 wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) ); |
313 } |
324 } |
314 |
325 |
315 wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) ); |
326 wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) ); |
316 } |
327 } |