2007-05-25 09:16:21 +02:00
|
|
|
<?php
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
|
|
|
* WordPress Bookmark Administration API
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-09-05 04:45:39 +02:00
|
|
|
* Add a link to using values provided in $_POST.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2007-05-25 09:16:21 +02:00
|
|
|
function add_link() {
|
|
|
|
return edit_link();
|
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Updates or inserts a link using values provided in $_POST.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2015-10-15 01:25:25 +02:00
|
|
|
* @param int $link_id Optional. ID of the link to edit. Default 0.
|
2010-09-05 04:45:39 +02:00
|
|
|
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2010-09-05 04:45:39 +02:00
|
|
|
function edit_link( $link_id = 0 ) {
|
2015-09-03 10:59:24 +02:00
|
|
|
if ( ! current_user_can( 'manage_links' ) ) {
|
|
|
|
wp_die(
|
2018-02-19 03:13:32 +01:00
|
|
|
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
|
2016-06-29 17:16:29 +02:00
|
|
|
'<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',
|
2015-09-03 10:59:24 +02:00
|
|
|
403
|
|
|
|
);
|
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$_POST['link_url'] = esc_html( $_POST['link_url'] );
|
|
|
|
$_POST['link_url'] = esc_url( $_POST['link_url'] );
|
|
|
|
$_POST['link_name'] = esc_html( $_POST['link_name'] );
|
2009-05-18 17:11:07 +02:00
|
|
|
$_POST['link_image'] = esc_html( $_POST['link_image'] );
|
2017-12-01 00:11:00 +01:00
|
|
|
$_POST['link_rss'] = esc_url( $_POST['link_rss'] );
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) {
|
2008-02-20 09:06:03 +01:00
|
|
|
$_POST['link_visible'] = 'Y';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( ! empty( $link_id ) ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
$_POST['link_id'] = $link_id;
|
2013-03-01 17:28:40 +01:00
|
|
|
return wp_update_link( $_POST );
|
2007-05-25 09:16:21 +02:00
|
|
|
} else {
|
2013-03-01 17:28:40 +01:00
|
|
|
return wp_insert_link( $_POST );
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Retrieves the default link for editing.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2015-10-15 01:25:25 +02:00
|
|
|
* @return stdClass Default link object.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2007-05-25 09:16:21 +02:00
|
|
|
function get_default_link_to_edit() {
|
2022-11-29 16:51:14 +01:00
|
|
|
$link = new stdClass();
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $_GET['linkurl'] ) ) {
|
2013-03-01 18:00:25 +01:00
|
|
|
$link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
} else {
|
2007-05-25 09:16:21 +02:00
|
|
|
$link->link_url = '';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
if ( isset( $_GET['name'] ) ) {
|
2013-03-01 18:00:25 +01:00
|
|
|
$link->link_name = esc_attr( wp_unslash( $_GET['name'] ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
} else {
|
2007-05-25 09:16:21 +02:00
|
|
|
$link->link_name = '';
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
|
|
|
$link->link_visible = 'Y';
|
|
|
|
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Deletes a specified link from the database.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2015-10-15 01:25:25 +02:00
|
|
|
* @global wpdb $wpdb WordPress database abstraction object.
|
2015-05-28 23:41:30 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @param int $link_id ID of the link to delete
|
2015-10-15 01:25:25 +02:00
|
|
|
* @return true Always true.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
function wp_delete_link( $link_id ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
global $wpdb;
|
2013-10-07 04:19:09 +02:00
|
|
|
/**
|
|
|
|
* Fires before a link is deleted.
|
|
|
|
*
|
|
|
|
* @since 2.0.0
|
|
|
|
*
|
|
|
|
* @param int $link_id ID of the link to delete.
|
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
do_action( 'delete_link', $link_id );
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
wp_delete_object_term_relationships( $link_id, 'link_category' );
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2012-03-24 16:24:31 +01:00
|
|
|
$wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) );
|
2015-10-15 01:25:25 +02:00
|
|
|
|
2013-10-07 04:19:09 +02:00
|
|
|
/**
|
|
|
|
* Fires after a link has been deleted.
|
|
|
|
*
|
|
|
|
* @since 2.2.0
|
|
|
|
*
|
|
|
|
* @param int $link_id ID of the deleted link.
|
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
do_action( 'deleted_link', $link_id );
|
2007-05-27 21:43:44 +02:00
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
clean_bookmark_cache( $link_id );
|
2008-08-28 00:04:12 +02:00
|
|
|
|
2007-05-27 21:43:44 +02:00
|
|
|
return true;
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2019-11-05 22:30:03 +01:00
|
|
|
* Retrieves the link category IDs associated with the link specified.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.1.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2019-11-05 22:30:03 +01:00
|
|
|
* @param int $link_id Link ID to look up.
|
|
|
|
* @return int[] The IDs of the requested link's categories.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
function wp_get_link_cats( $link_id = 0 ) {
|
2017-12-01 00:11:00 +01:00
|
|
|
$cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) );
|
2008-11-13 08:17:40 +01:00
|
|
|
return array_unique( $cats );
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Retrieves link data based on its ID.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2016-05-03 01:43:27 +02:00
|
|
|
* @param int|stdClass $link Link ID or object to retrieve.
|
2015-10-15 01:25:25 +02:00
|
|
|
* @return object Link object for editing.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2016-05-03 01:43:27 +02:00
|
|
|
function get_link_to_edit( $link ) {
|
|
|
|
return get_bookmark( $link, OBJECT, 'edit' );
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2020-11-03 04:52:10 +01:00
|
|
|
* Inserts a link into the database, or updates an existing link.
|
|
|
|
*
|
|
|
|
* Runs all the necessary sanitizing, provides default values if arguments are missing,
|
|
|
|
* and finally saves the link.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2015-10-15 01:25:25 +02:00
|
|
|
* @global wpdb $wpdb WordPress database abstraction object.
|
2015-05-28 23:41:30 +02:00
|
|
|
*
|
2020-11-03 04:52:10 +01:00
|
|
|
* @param array $linkdata {
|
|
|
|
* Elements that make up the link to insert.
|
|
|
|
*
|
|
|
|
* @type int $link_id Optional. The ID of the existing link if updating.
|
|
|
|
* @type string $link_url The URL the link points to.
|
|
|
|
* @type string $link_name The title of the link.
|
|
|
|
* @type string $link_image Optional. A URL of an image.
|
|
|
|
* @type string $link_target Optional. The target element for the anchor tag.
|
|
|
|
* @type string $link_description Optional. A short description of the link.
|
|
|
|
* @type string $link_visible Optional. 'Y' means visible, anything else means not.
|
|
|
|
* @type int $link_owner Optional. A user ID.
|
|
|
|
* @type int $link_rating Optional. A rating for the link.
|
|
|
|
* @type string $link_rel Optional. A relationship of the link to you.
|
|
|
|
* @type string $link_notes Optional. An extended description of or notes on the link.
|
|
|
|
* @type string $link_rss Optional. A URL of an associated RSS feed.
|
|
|
|
* @type int $link_category Optional. The term ID of the link category.
|
|
|
|
* If empty, uses default link category.
|
|
|
|
* }
|
2015-10-15 01:25:25 +02:00
|
|
|
* @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false.
|
2010-09-05 04:45:39 +02:00
|
|
|
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
function wp_insert_link( $linkdata, $wp_error = false ) {
|
2010-06-24 17:01:29 +02:00
|
|
|
global $wpdb;
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2017-12-01 00:11:00 +01:00
|
|
|
$defaults = array(
|
|
|
|
'link_id' => 0,
|
|
|
|
'link_name' => '',
|
|
|
|
'link_url' => '',
|
|
|
|
'link_rating' => 0,
|
|
|
|
);
|
2007-08-21 00:50:04 +02:00
|
|
|
|
2019-07-25 02:48:58 +02:00
|
|
|
$parsed_args = wp_parse_args( $linkdata, $defaults );
|
|
|
|
$parsed_args = wp_unslash( sanitize_bookmark( $parsed_args, 'db' ) );
|
2014-05-18 11:56:15 +02:00
|
|
|
|
2019-07-25 02:48:58 +02:00
|
|
|
$link_id = $parsed_args['link_id'];
|
|
|
|
$link_name = $parsed_args['link_name'];
|
|
|
|
$link_url = $parsed_args['link_url'];
|
2007-08-21 00:50:04 +02:00
|
|
|
|
2007-05-25 09:16:21 +02:00
|
|
|
$update = false;
|
2014-05-18 11:56:15 +02:00
|
|
|
if ( ! empty( $link_id ) ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
$update = true;
|
2014-05-15 04:28:14 +02:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( '' === trim( $link_name ) ) {
|
|
|
|
if ( '' !== trim( $link_url ) ) {
|
2014-05-18 11:56:15 +02:00
|
|
|
$link_name = $link_url;
|
2009-01-22 23:47:34 +01:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2020-05-16 20:42:12 +02:00
|
|
|
if ( '' === trim( $link_url ) ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
return 0;
|
2014-05-15 04:28:14 +02:00
|
|
|
}
|
2014-05-18 11:56:15 +02:00
|
|
|
|
2019-07-25 02:48:58 +02:00
|
|
|
$link_rating = ( ! empty( $parsed_args['link_rating'] ) ) ? $parsed_args['link_rating'] : 0;
|
|
|
|
$link_image = ( ! empty( $parsed_args['link_image'] ) ) ? $parsed_args['link_image'] : '';
|
|
|
|
$link_target = ( ! empty( $parsed_args['link_target'] ) ) ? $parsed_args['link_target'] : '';
|
|
|
|
$link_visible = ( ! empty( $parsed_args['link_visible'] ) ) ? $parsed_args['link_visible'] : 'Y';
|
|
|
|
$link_owner = ( ! empty( $parsed_args['link_owner'] ) ) ? $parsed_args['link_owner'] : get_current_user_id();
|
|
|
|
$link_notes = ( ! empty( $parsed_args['link_notes'] ) ) ? $parsed_args['link_notes'] : '';
|
|
|
|
$link_description = ( ! empty( $parsed_args['link_description'] ) ) ? $parsed_args['link_description'] : '';
|
|
|
|
$link_rss = ( ! empty( $parsed_args['link_rss'] ) ) ? $parsed_args['link_rss'] : '';
|
|
|
|
$link_rel = ( ! empty( $parsed_args['link_rel'] ) ) ? $parsed_args['link_rel'] : '';
|
|
|
|
$link_category = ( ! empty( $parsed_args['link_category'] ) ) ? $parsed_args['link_category'] : array();
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2015-10-15 01:25:25 +02:00
|
|
|
// Make sure we set a valid category.
|
2020-05-23 13:38:08 +02:00
|
|
|
if ( ! is_array( $link_category ) || 0 === count( $link_category ) ) {
|
2008-11-13 08:17:40 +01:00
|
|
|
$link_category = array( get_option( 'default_link_category' ) );
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( $update ) {
|
2020-02-15 02:55:06 +01:00
|
|
|
if ( false === $wpdb->update( $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' ), compact( 'link_id' ) ) ) {
|
2014-05-15 04:28:14 +02:00
|
|
|
if ( $wp_error ) {
|
2020-06-07 11:24:11 +02:00
|
|
|
return new WP_Error( 'db_update_error', __( 'Could not update link in the database.' ), $wpdb->last_error );
|
2014-05-15 04:28:14 +02:00
|
|
|
} else {
|
2008-08-28 00:04:12 +02:00
|
|
|
return 0;
|
2014-05-15 04:28:14 +02:00
|
|
|
}
|
2008-08-28 00:04:12 +02:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
} else {
|
2014-05-15 04:28:14 +02:00
|
|
|
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 ) {
|
2020-06-07 11:24:11 +02:00
|
|
|
return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database.' ), $wpdb->last_error );
|
2014-05-15 04:28:14 +02:00
|
|
|
} else {
|
2008-08-28 00:04:12 +02:00
|
|
|
return 0;
|
2014-05-15 04:28:14 +02:00
|
|
|
}
|
2008-08-28 00:04:12 +02:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
$link_id = (int) $wpdb->insert_id;
|
|
|
|
}
|
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
wp_set_link_cats( $link_id, $link_category );
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2013-10-07 04:19:09 +02:00
|
|
|
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.
|
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
do_action( 'edit_link', $link_id );
|
2013-10-07 04:19:09 +02:00
|
|
|
} 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.
|
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
do_action( 'add_link', $link_id );
|
2013-10-07 04:19:09 +02:00
|
|
|
}
|
2008-11-13 08:17:40 +01:00
|
|
|
clean_bookmark_cache( $link_id );
|
2008-08-28 00:04:12 +02:00
|
|
|
|
2007-05-25 09:16:21 +02:00
|
|
|
return $link_id;
|
|
|
|
}
|
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2010-09-05 04:45:39 +02:00
|
|
|
* Update link with the specified link categories.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.1.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2015-10-15 01:25:25 +02:00
|
|
|
* @param int $link_id ID of the link to update.
|
2018-03-22 21:27:32 +01:00
|
|
|
* @param int[] $link_categories Array of link category IDs to add the link to.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
// If $link_categories isn't already an array, make it one:
|
2020-05-23 13:38:08 +02:00
|
|
|
if ( ! is_array( $link_categories ) || 0 === count( $link_categories ) ) {
|
2008-11-13 08:17:40 +01:00
|
|
|
$link_categories = array( get_option( 'default_link_category' ) );
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
$link_categories = array_map( 'intval', $link_categories );
|
|
|
|
$link_categories = array_unique( $link_categories );
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
wp_set_object_terms( $link_id, $link_categories, 'link_category' );
|
2008-08-28 00:04:12 +02:00
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
clean_bookmark_cache( $link_id );
|
2010-09-05 04:45:39 +02:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2008-10-02 03:03:26 +02:00
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Updates a link in the database.
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2010-09-05 04:45:39 +02:00
|
|
|
* @since 2.0.0
|
2008-10-02 03:03:26 +02:00
|
|
|
*
|
2020-11-03 04:52:10 +01:00
|
|
|
* @param array $linkdata Link data to update. See wp_insert_link() for accepted arguments.
|
2010-09-05 04:45:39 +02:00
|
|
|
* @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success.
|
2008-10-02 03:03:26 +02:00
|
|
|
*/
|
2008-11-13 08:17:40 +01:00
|
|
|
function wp_update_link( $linkdata ) {
|
2007-05-25 09:16:21 +02:00
|
|
|
$link_id = (int) $linkdata['link_id'];
|
|
|
|
|
2010-02-13 11:35:10 +01:00
|
|
|
$link = get_bookmark( $link_id, ARRAY_A );
|
2007-05-25 09:16:21 +02:00
|
|
|
|
2013-03-01 17:28:40 +01:00
|
|
|
// Escape data pulled from DB.
|
2013-03-01 18:00:25 +01:00
|
|
|
$link = wp_slash( $link );
|
2013-03-01 17:28:40 +01:00
|
|
|
|
2007-05-25 09:16:21 +02:00
|
|
|
// Passed link category list overwrites existing category list if not empty.
|
2020-05-23 18:22:07 +02:00
|
|
|
if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] )
|
|
|
|
&& count( $linkdata['link_category'] ) > 0
|
|
|
|
) {
|
2007-05-25 09:16:21 +02:00
|
|
|
$link_cats = $linkdata['link_category'];
|
2017-12-01 00:11:00 +01:00
|
|
|
} else {
|
2007-05-25 09:16:21 +02:00
|
|
|
$link_cats = $link['link_category'];
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2007-05-25 09:16:21 +02:00
|
|
|
|
|
|
|
// Merge old and new fields with new fields overwriting old ones.
|
2017-12-01 00:11:00 +01:00
|
|
|
$linkdata = array_merge( $link, $linkdata );
|
2007-05-25 09:16:21 +02:00
|
|
|
$linkdata['link_category'] = $link_cats;
|
|
|
|
|
2008-11-13 08:17:40 +01:00
|
|
|
return wp_insert_link( $linkdata );
|
2007-05-25 09:16:21 +02:00
|
|
|
}
|
2012-11-27 01:20:27 +01:00
|
|
|
|
|
|
|
/**
|
2015-10-15 01:25:25 +02:00
|
|
|
* Outputs the 'disabled' message for the WordPress Link Manager.
|
|
|
|
*
|
2012-11-27 01:20:27 +01:00
|
|
|
* @since 3.5.0
|
|
|
|
* @access private
|
2015-05-28 23:41:30 +02:00
|
|
|
*
|
2022-04-04 20:26:06 +02:00
|
|
|
* @global string $pagenow The filename of the current screen.
|
2012-11-27 01:20:27 +01:00
|
|
|
*/
|
|
|
|
function wp_link_manager_disabled_message() {
|
|
|
|
global $pagenow;
|
2020-05-16 20:42:12 +02:00
|
|
|
|
|
|
|
if ( ! in_array( $pagenow, array( 'link-manager.php', 'link-add.php', 'link.php' ), true ) ) {
|
2012-11-27 01:20:27 +01:00
|
|
|
return;
|
2017-12-01 00:11:00 +01:00
|
|
|
}
|
2012-11-27 01:20:27 +01:00
|
|
|
|
|
|
|
add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
|
|
|
|
$really_can_manage_links = current_user_can( 'manage_links' );
|
|
|
|
remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
|
|
|
|
|
2021-05-25 22:14:59 +02:00
|
|
|
if ( $really_can_manage_links ) {
|
|
|
|
$plugins = get_plugins();
|
|
|
|
|
|
|
|
if ( empty( $plugins['link-manager/link-manager.php'] ) ) {
|
|
|
|
if ( current_user_can( 'install_plugins' ) ) {
|
|
|
|
$install_url = wp_nonce_url(
|
|
|
|
self_admin_url( 'update.php?action=install-plugin&plugin=link-manager' ),
|
|
|
|
'install-plugin_link-manager'
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_die(
|
|
|
|
sprintf(
|
|
|
|
/* translators: %s: A link to install the Link Manager plugin. */
|
|
|
|
__( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager plugin</a>.' ),
|
|
|
|
esc_url( $install_url )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} elseif ( is_plugin_inactive( 'link-manager/link-manager.php' ) ) {
|
|
|
|
if ( current_user_can( 'activate_plugins' ) ) {
|
|
|
|
$activate_url = wp_nonce_url(
|
|
|
|
self_admin_url( 'plugins.php?action=activate&plugin=link-manager/link-manager.php' ),
|
|
|
|
'activate-plugin_link-manager/link-manager.php'
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_die(
|
|
|
|
sprintf(
|
|
|
|
/* translators: %s: A link to activate the Link Manager plugin. */
|
|
|
|
__( 'Please activate the <a href="%s">Link Manager plugin</a> to use the link manager.' ),
|
|
|
|
esc_url( $activate_url )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-11-27 01:20:27 +01:00
|
|
|
}
|
|
|
|
|
2016-06-29 17:16:29 +02:00
|
|
|
wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
|
2012-11-27 01:20:27 +01:00
|
|
|
}
|