Edit File by line
/home/barbar84/public_h.../wp-admin/includes
File: bookmark.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Bookmark Administration API
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Add a link to using values provided in $_POST.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.0.0
[11] Fix | Delete
*
[12] Fix | Delete
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
[13] Fix | Delete
*/
[14] Fix | Delete
function add_link() {
[15] Fix | Delete
return edit_link();
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Updates or inserts a link using values provided in $_POST.
[20] Fix | Delete
*
[21] Fix | Delete
* @since 2.0.0
[22] Fix | Delete
*
[23] Fix | Delete
* @param int $link_id Optional. ID of the link to edit. Default 0.
[24] Fix | Delete
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
[25] Fix | Delete
*/
[26] Fix | Delete
function edit_link( $link_id = 0 ) {
[27] Fix | Delete
if ( ! current_user_can( 'manage_links' ) ) {
[28] Fix | Delete
wp_die(
[29] Fix | Delete
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
[30] Fix | Delete
'<p>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '</p>',
[31] Fix | Delete
403
[32] Fix | Delete
);
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
$_POST['link_url'] = esc_html( $_POST['link_url'] );
[36] Fix | Delete
$_POST['link_url'] = esc_url( $_POST['link_url'] );
[37] Fix | Delete
$_POST['link_name'] = esc_html( $_POST['link_name'] );
[38] Fix | Delete
$_POST['link_image'] = esc_html( $_POST['link_image'] );
[39] Fix | Delete
$_POST['link_rss'] = esc_url( $_POST['link_rss'] );
[40] Fix | Delete
if ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) {
[41] Fix | Delete
$_POST['link_visible'] = 'Y';
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
if ( ! empty( $link_id ) ) {
[45] Fix | Delete
$_POST['link_id'] = $link_id;
[46] Fix | Delete
return wp_update_link( $_POST );
[47] Fix | Delete
} else {
[48] Fix | Delete
return wp_insert_link( $_POST );
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Retrieves the default link for editing.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 2.0.0
[56] Fix | Delete
*
[57] Fix | Delete
* @return stdClass Default link object.
[58] Fix | Delete
*/
[59] Fix | Delete
function get_default_link_to_edit() {
[60] Fix | Delete
$link = new stdClass;
[61] Fix | Delete
if ( isset( $_GET['linkurl'] ) ) {
[62] Fix | Delete
$link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) );
[63] Fix | Delete
} else {
[64] Fix | Delete
$link->link_url = '';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
if ( isset( $_GET['name'] ) ) {
[68] Fix | Delete
$link->link_name = esc_attr( wp_unslash( $_GET['name'] ) );
[69] Fix | Delete
} else {
[70] Fix | Delete
$link->link_name = '';
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
$link->link_visible = 'Y';
[74] Fix | Delete
[75] Fix | Delete
return $link;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Deletes a specified link from the database.
[80] Fix | Delete
*
[81] Fix | Delete
* @since 2.0.0
[82] Fix | Delete
*
[83] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[84] Fix | Delete
*
[85] Fix | Delete
* @param int $link_id ID of the link to delete
[86] Fix | Delete
* @return true Always true.
[87] Fix | Delete
*/
[88] Fix | Delete
function wp_delete_link( $link_id ) {
[89] Fix | Delete
global $wpdb;
[90] Fix | Delete
/**
[91] Fix | Delete
* Fires before a link is deleted.
[92] Fix | Delete
*
[93] Fix | Delete
* @since 2.0.0
[94] Fix | Delete
*
[95] Fix | Delete
* @param int $link_id ID of the link to delete.
[96] Fix | Delete
*/
[97] Fix | Delete
do_action( 'delete_link', $link_id );
[98] Fix | Delete
[99] Fix | Delete
wp_delete_object_term_relationships( $link_id, 'link_category' );
[100] Fix | Delete
[101] Fix | Delete
$wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) );
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* Fires after a link has been deleted.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 2.2.0
[107] Fix | Delete
*
[108] Fix | Delete
* @param int $link_id ID of the deleted link.
[109] Fix | Delete
*/
[110] Fix | Delete
do_action( 'deleted_link', $link_id );
[111] Fix | Delete
[112] Fix | Delete
clean_bookmark_cache( $link_id );
[113] Fix | Delete
[114] Fix | Delete
return true;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Retrieves the link category IDs associated with the link specified.
[119] Fix | Delete
*
[120] Fix | Delete
* @since 2.1.0
[121] Fix | Delete
*
[122] Fix | Delete
* @param int $link_id Link ID to look up.
[123] Fix | Delete
* @return int[] The IDs of the requested link's categories.
[124] Fix | Delete
*/
[125] Fix | Delete
function wp_get_link_cats( $link_id = 0 ) {
[126] Fix | Delete
$cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) );
[127] Fix | Delete
return array_unique( $cats );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
/**
[131] Fix | Delete
* Retrieves link data based on its ID.
[132] Fix | Delete
*
[133] Fix | Delete
* @since 2.0.0
[134] Fix | Delete
*
[135] Fix | Delete
* @param int|stdClass $link Link ID or object to retrieve.
[136] Fix | Delete
* @return object Link object for editing.
[137] Fix | Delete
*/
[138] Fix | Delete
function get_link_to_edit( $link ) {
[139] Fix | Delete
return get_bookmark( $link, OBJECT, 'edit' );
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Inserts a link into the database, or updates an existing link.
[144] Fix | Delete
*
[145] Fix | Delete
* Runs all the necessary sanitizing, provides default values if arguments are missing,
[146] Fix | Delete
* and finally saves the link.
[147] Fix | Delete
*
[148] Fix | Delete
* @since 2.0.0
[149] Fix | Delete
*
[150] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[151] Fix | Delete
*
[152] Fix | Delete
* @param array $linkdata {
[153] Fix | Delete
* Elements that make up the link to insert.
[154] Fix | Delete
*
[155] Fix | Delete
* @type int $link_id Optional. The ID of the existing link if updating.
[156] Fix | Delete
* @type string $link_url The URL the link points to.
[157] Fix | Delete
* @type string $link_name The title of the link.
[158] Fix | Delete
* @type string $link_image Optional. A URL of an image.
[159] Fix | Delete
* @type string $link_target Optional. The target element for the anchor tag.
[160] Fix | Delete
* @type string $link_description Optional. A short description of the link.
[161] Fix | Delete
* @type string $link_visible Optional. 'Y' means visible, anything else means not.
[162] Fix | Delete
* @type int $link_owner Optional. A user ID.
[163] Fix | Delete
* @type int $link_rating Optional. A rating for the link.
[164] Fix | Delete
* @type string $link_updated Optional. When the link was last updated.
[165] Fix | Delete
* @type string $link_rel Optional. A relationship of the link to you.
[166] Fix | Delete
* @type string $link_notes Optional. An extended description of or notes on the link.
[167] Fix | Delete
* @type string $link_rss Optional. A URL of an associated RSS feed.
[168] Fix | Delete
* @type int $link_category Optional. The term ID of the link category.
[169] Fix | Delete
* If empty, uses default link category.
[170] Fix | Delete
* }
[171] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false.
[172] Fix | Delete
* @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success.
[173] Fix | Delete
*/
[174] Fix | Delete
function wp_insert_link( $linkdata, $wp_error = false ) {
[175] Fix | Delete
global $wpdb;
[176] Fix | Delete
[177] Fix | Delete
$defaults = array(
[178] Fix | Delete
'link_id' => 0,
[179] Fix | Delete
'link_name' => '',
[180] Fix | Delete
'link_url' => '',
[181] Fix | Delete
'link_rating' => 0,
[182] Fix | Delete
);
[183] Fix | Delete
[184] Fix | Delete
$parsed_args = wp_parse_args( $linkdata, $defaults );
[185] Fix | Delete
$parsed_args = wp_unslash( sanitize_bookmark( $parsed_args, 'db' ) );
[186] Fix | Delete
[187] Fix | Delete
$link_id = $parsed_args['link_id'];
[188] Fix | Delete
$link_name = $parsed_args['link_name'];
[189] Fix | Delete
$link_url = $parsed_args['link_url'];
[190] Fix | Delete
[191] Fix | Delete
$update = false;
[192] Fix | Delete
if ( ! empty( $link_id ) ) {
[193] Fix | Delete
$update = true;
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
if ( '' === trim( $link_name ) ) {
[197] Fix | Delete
if ( '' !== trim( $link_url ) ) {
[198] Fix | Delete
$link_name = $link_url;
[199] Fix | Delete
} else {
[200] Fix | Delete
return 0;
[201] Fix | Delete
}
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
if ( '' === trim( $link_url ) ) {
[205] Fix | Delete
return 0;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
$link_rating = ( ! empty( $parsed_args['link_rating'] ) ) ? $parsed_args['link_rating'] : 0;
[209] Fix | Delete
$link_image = ( ! empty( $parsed_args['link_image'] ) ) ? $parsed_args['link_image'] : '';
[210] Fix | Delete
$link_target = ( ! empty( $parsed_args['link_target'] ) ) ? $parsed_args['link_target'] : '';
[211] Fix | Delete
$link_visible = ( ! empty( $parsed_args['link_visible'] ) ) ? $parsed_args['link_visible'] : 'Y';
[212] Fix | Delete
$link_owner = ( ! empty( $parsed_args['link_owner'] ) ) ? $parsed_args['link_owner'] : get_current_user_id();
[213] Fix | Delete
$link_notes = ( ! empty( $parsed_args['link_notes'] ) ) ? $parsed_args['link_notes'] : '';
[214] Fix | Delete
$link_description = ( ! empty( $parsed_args['link_description'] ) ) ? $parsed_args['link_description'] : '';
[215] Fix | Delete
$link_rss = ( ! empty( $parsed_args['link_rss'] ) ) ? $parsed_args['link_rss'] : '';
[216] Fix | Delete
$link_rel = ( ! empty( $parsed_args['link_rel'] ) ) ? $parsed_args['link_rel'] : '';
[217] Fix | Delete
$link_category = ( ! empty( $parsed_args['link_category'] ) ) ? $parsed_args['link_category'] : array();
[218] Fix | Delete
[219] Fix | Delete
// Make sure we set a valid category.
[220] Fix | Delete
if ( ! is_array( $link_category ) || 0 === count( $link_category ) ) {
[221] Fix | Delete
$link_category = array( get_option( 'default_link_category' ) );
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
if ( $update ) {
[225] Fix | Delete
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' ) ) ) {
[226] Fix | Delete
if ( $wp_error ) {
[227] Fix | Delete
return new WP_Error( 'db_update_error', __( 'Could not update link in the database.' ), $wpdb->last_error );
[228] Fix | Delete
} else {
[229] Fix | Delete
return 0;
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
} else {
[233] Fix | Delete
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' ) ) ) {
[234] Fix | Delete
if ( $wp_error ) {
[235] Fix | Delete
return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database.' ), $wpdb->last_error );
[236] Fix | Delete
} else {
[237] Fix | Delete
return 0;
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
$link_id = (int) $wpdb->insert_id;
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
wp_set_link_cats( $link_id, $link_category );
[244] Fix | Delete
[245] Fix | Delete
if ( $update ) {
[246] Fix | Delete
/**
[247] Fix | Delete
* Fires after a link was updated in the database.
[248] Fix | Delete
*
[249] Fix | Delete
* @since 2.0.0
[250] Fix | Delete
*
[251] Fix | Delete
* @param int $link_id ID of the link that was updated.
[252] Fix | Delete
*/
[253] Fix | Delete
do_action( 'edit_link', $link_id );
[254] Fix | Delete
} else {
[255] Fix | Delete
/**
[256] Fix | Delete
* Fires after a link was added to the database.
[257] Fix | Delete
*
[258] Fix | Delete
* @since 2.0.0
[259] Fix | Delete
*
[260] Fix | Delete
* @param int $link_id ID of the link that was added.
[261] Fix | Delete
*/
[262] Fix | Delete
do_action( 'add_link', $link_id );
[263] Fix | Delete
}
[264] Fix | Delete
clean_bookmark_cache( $link_id );
[265] Fix | Delete
[266] Fix | Delete
return $link_id;
[267] Fix | Delete
}
[268] Fix | Delete
[269] Fix | Delete
/**
[270] Fix | Delete
* Update link with the specified link categories.
[271] Fix | Delete
*
[272] Fix | Delete
* @since 2.1.0
[273] Fix | Delete
*
[274] Fix | Delete
* @param int $link_id ID of the link to update.
[275] Fix | Delete
* @param int[] $link_categories Array of link category IDs to add the link to.
[276] Fix | Delete
*/
[277] Fix | Delete
function wp_set_link_cats( $link_id = 0, $link_categories = array() ) {
[278] Fix | Delete
// If $link_categories isn't already an array, make it one:
[279] Fix | Delete
if ( ! is_array( $link_categories ) || 0 === count( $link_categories ) ) {
[280] Fix | Delete
$link_categories = array( get_option( 'default_link_category' ) );
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$link_categories = array_map( 'intval', $link_categories );
[284] Fix | Delete
$link_categories = array_unique( $link_categories );
[285] Fix | Delete
[286] Fix | Delete
wp_set_object_terms( $link_id, $link_categories, 'link_category' );
[287] Fix | Delete
[288] Fix | Delete
clean_bookmark_cache( $link_id );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Updates a link in the database.
[293] Fix | Delete
*
[294] Fix | Delete
* @since 2.0.0
[295] Fix | Delete
*
[296] Fix | Delete
* @param array $linkdata Link data to update. See wp_insert_link() for accepted arguments.
[297] Fix | Delete
* @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success.
[298] Fix | Delete
*/
[299] Fix | Delete
function wp_update_link( $linkdata ) {
[300] Fix | Delete
$link_id = (int) $linkdata['link_id'];
[301] Fix | Delete
[302] Fix | Delete
$link = get_bookmark( $link_id, ARRAY_A );
[303] Fix | Delete
[304] Fix | Delete
// Escape data pulled from DB.
[305] Fix | Delete
$link = wp_slash( $link );
[306] Fix | Delete
[307] Fix | Delete
// Passed link category list overwrites existing category list if not empty.
[308] Fix | Delete
if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] )
[309] Fix | Delete
&& count( $linkdata['link_category'] ) > 0
[310] Fix | Delete
) {
[311] Fix | Delete
$link_cats = $linkdata['link_category'];
[312] Fix | Delete
} else {
[313] Fix | Delete
$link_cats = $link['link_category'];
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
// Merge old and new fields with new fields overwriting old ones.
[317] Fix | Delete
$linkdata = array_merge( $link, $linkdata );
[318] Fix | Delete
$linkdata['link_category'] = $link_cats;
[319] Fix | Delete
[320] Fix | Delete
return wp_insert_link( $linkdata );
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
/**
[324] Fix | Delete
* Outputs the 'disabled' message for the WordPress Link Manager.
[325] Fix | Delete
*
[326] Fix | Delete
* @since 3.5.0
[327] Fix | Delete
* @access private
[328] Fix | Delete
*
[329] Fix | Delete
* @global string $pagenow
[330] Fix | Delete
*/
[331] Fix | Delete
function wp_link_manager_disabled_message() {
[332] Fix | Delete
global $pagenow;
[333] Fix | Delete
[334] Fix | Delete
if ( ! in_array( $pagenow, array( 'link-manager.php', 'link-add.php', 'link.php' ), true ) ) {
[335] Fix | Delete
return;
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
[339] Fix | Delete
$really_can_manage_links = current_user_can( 'manage_links' );
[340] Fix | Delete
remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 );
[341] Fix | Delete
[342] Fix | Delete
if ( $really_can_manage_links && current_user_can( 'install_plugins' ) ) {
[343] Fix | Delete
$link = network_admin_url( 'plugin-install.php?tab=search&amp;s=Link+Manager' );
[344] Fix | Delete
/* translators: %s: URL to install the Link Manager plugin. */
[345] Fix | Delete
wp_die( sprintf( __( 'If you are looking to use the link manager, please install the <a href="%s">Link Manager</a> plugin.' ), $link ) );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) );
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function