140 function get_link_to_edit( $link ) { |
140 function get_link_to_edit( $link ) { |
141 return get_bookmark( $link, OBJECT, 'edit' ); |
141 return get_bookmark( $link, OBJECT, 'edit' ); |
142 } |
142 } |
143 |
143 |
144 /** |
144 /** |
145 * Inserts/updates links into/in the database. |
145 * Inserts a link into the database, or updates an existing link. |
|
146 * |
|
147 * Runs all the necessary sanitizing, provides default values if arguments are missing, |
|
148 * and finally saves the link. |
146 * |
149 * |
147 * @since 2.0.0 |
150 * @since 2.0.0 |
148 * |
151 * |
149 * @global wpdb $wpdb WordPress database abstraction object. |
152 * @global wpdb $wpdb WordPress database abstraction object. |
150 * |
153 * |
151 * @param array $linkdata Elements that make up the link to insert. |
154 * @param array $linkdata { |
|
155 * Elements that make up the link to insert. |
|
156 * |
|
157 * @type int $link_id Optional. The ID of the existing link if updating. |
|
158 * @type string $link_url The URL the link points to. |
|
159 * @type string $link_name The title of the link. |
|
160 * @type string $link_image Optional. A URL of an image. |
|
161 * @type string $link_target Optional. The target element for the anchor tag. |
|
162 * @type string $link_description Optional. A short description of the link. |
|
163 * @type string $link_visible Optional. 'Y' means visible, anything else means not. |
|
164 * @type int $link_owner Optional. A user ID. |
|
165 * @type int $link_rating Optional. A rating for the link. |
|
166 * @type string $link_updated Optional. When the link was last updated. |
|
167 * @type string $link_rel Optional. A relationship of the link to you. |
|
168 * @type string $link_notes Optional. An extended description of or notes on the link. |
|
169 * @type string $link_rss Optional. A URL of an associated RSS feed. |
|
170 * @type int $link_category Optional. The term ID of the link category. |
|
171 * If empty, uses default link category. |
|
172 * } |
152 * @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false. |
173 * @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false. |
153 * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. |
174 * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. |
154 */ |
175 */ |
155 function wp_insert_link( $linkdata, $wp_error = false ) { |
176 function wp_insert_link( $linkdata, $wp_error = false ) { |
156 global $wpdb; |
177 global $wpdb; |
272 /** |
293 /** |
273 * Updates a link in the database. |
294 * Updates a link in the database. |
274 * |
295 * |
275 * @since 2.0.0 |
296 * @since 2.0.0 |
276 * |
297 * |
277 * @param array $linkdata Link data to update. |
298 * @param array $linkdata Link data to update. See wp_insert_link() for accepted arguments. |
278 * @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success. |
299 * @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success. |
279 */ |
300 */ |
280 function wp_update_link( $linkdata ) { |
301 function wp_update_link( $linkdata ) { |
281 $link_id = (int) $linkdata['link_id']; |
302 $link_id = (int) $linkdata['link_id']; |
282 |
303 |
318 |
339 |
319 add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
340 add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
320 $really_can_manage_links = current_user_can( 'manage_links' ); |
341 $really_can_manage_links = current_user_can( 'manage_links' ); |
321 remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
342 remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); |
322 |
343 |
323 if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) { |
344 if ( $really_can_manage_links ) { |
324 $link = network_admin_url( 'plugin-install.php?tab=search&s=Link+Manager' ); |
345 $plugins = get_plugins(); |
325 /* translators: %s: URL to install the Link Manager plugin. */ |
346 |
326 wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) ); |
347 if ( empty( $plugins['link-manager/link-manager.php'] ) ) { |
|
348 if ( current_user_can( 'install_plugins' ) ) { |
|
349 $install_url = wp_nonce_url( |
|
350 self_admin_url( 'update.php?action=install-plugin&plugin=link-manager' ), |
|
351 'install-plugin_link-manager' |
|
352 ); |
|
353 |
|
354 wp_die( |
|
355 sprintf( |
|
356 /* translators: %s: A link to install the Link Manager plugin. */ |
|
357 __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager plugin</a>.' ), |
|
358 esc_url( $install_url ) |
|
359 ) |
|
360 ); |
|
361 } |
|
362 } elseif ( is_plugin_inactive( 'link-manager/link-manager.php' ) ) { |
|
363 if ( current_user_can( 'activate_plugins' ) ) { |
|
364 $activate_url = wp_nonce_url( |
|
365 self_admin_url( 'plugins.php?action=activate&plugin=link-manager/link-manager.php' ), |
|
366 'activate-plugin_link-manager/link-manager.php' |
|
367 ); |
|
368 |
|
369 wp_die( |
|
370 sprintf( |
|
371 /* translators: %s: A link to activate the Link Manager plugin. */ |
|
372 __( 'Please activate the <a href="%s">Link Manager plugin</a> to use the link manager.' ), |
|
373 esc_url( $activate_url ) |
|
374 ) |
|
375 ); |
|
376 } |
|
377 } |
327 } |
378 } |
328 |
379 |
329 wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) ); |
380 wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) ); |
330 } |
381 } |