wordcamp-bristol-2019/wp-admin/link.php

126 lines
2.7 KiB
PHP
Raw Normal View History

2019-03-12 09:27:46 +00:00
<?php
/**
* Manage link administration actions.
*
* This page is accessed by the link management pages and handles the forms and
* Ajax processes for link actions.
*
* @package WordPress
* @subpackage Administration
*/
/** Load WordPress Administration Bootstrap */
require_once( dirname( __FILE__ ) . '/admin.php' );
wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) );
2019-04-16 19:56:22 +00:00
if ( ! current_user_can( 'manage_links' ) ) {
2019-03-12 09:27:46 +00:00
wp_link_manager_disabled_message();
2019-04-16 19:56:22 +00:00
}
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
if ( ! empty( $_POST['deletebookmarks'] ) ) {
2019-03-12 09:27:46 +00:00
$action = 'deletebookmarks';
2019-04-16 19:56:22 +00:00
}
if ( ! empty( $_POST['move'] ) ) {
2019-03-12 09:27:46 +00:00
$action = 'move';
2019-04-16 19:56:22 +00:00
}
if ( ! empty( $_POST['linkcheck'] ) ) {
2019-03-12 09:27:46 +00:00
$linkcheck = $_POST['linkcheck'];
2019-04-16 19:56:22 +00:00
}
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
$this_file = admin_url( 'link-manager.php' );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
switch ( $action ) {
case 'deletebookmarks':
check_admin_referer( 'bulk-bookmarks' );
2019-03-12 09:27:46 +00:00
// For each link id (in $linkcheck[]) change category to selected value.
2019-04-16 19:56:22 +00:00
if ( count( $linkcheck ) == 0 ) {
wp_redirect( $this_file );
2019-03-12 09:27:46 +00:00
exit;
}
$deleted = 0;
2019-04-16 19:56:22 +00:00
foreach ( $linkcheck as $link_id ) {
2019-03-12 09:27:46 +00:00
$link_id = (int) $link_id;
2019-04-16 19:56:22 +00:00
if ( wp_delete_link( $link_id ) ) {
2019-03-12 09:27:46 +00:00
$deleted++;
2019-04-16 19:56:22 +00:00
}
2019-03-12 09:27:46 +00:00
}
2019-04-16 19:56:22 +00:00
wp_redirect( "$this_file?deleted=$deleted" );
2019-03-12 09:27:46 +00:00
exit;
2019-04-16 19:56:22 +00:00
case 'move':
check_admin_referer( 'bulk-bookmarks' );
2019-03-12 09:27:46 +00:00
// For each link id (in $linkcheck[]) change category to selected value.
2019-04-16 19:56:22 +00:00
if ( count( $linkcheck ) == 0 ) {
wp_redirect( $this_file );
2019-03-12 09:27:46 +00:00
exit;
}
2019-04-16 19:56:22 +00:00
$all_links = join( ',', $linkcheck );
2019-03-12 09:27:46 +00:00
/*
* Should now have an array of links we can change:
* $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
*/
2019-04-16 19:56:22 +00:00
wp_redirect( $this_file );
2019-03-12 09:27:46 +00:00
exit;
2019-04-16 19:56:22 +00:00
case 'add':
check_admin_referer( 'add-bookmark' );
2019-03-12 09:27:46 +00:00
$redir = wp_get_referer();
2019-04-16 19:56:22 +00:00
if ( add_link() ) {
2019-03-12 09:27:46 +00:00
$redir = add_query_arg( 'added', 'true', $redir );
2019-04-16 19:56:22 +00:00
}
2019-03-12 09:27:46 +00:00
wp_redirect( $redir );
exit;
2019-04-16 19:56:22 +00:00
case 'save':
2019-03-12 09:27:46 +00:00
$link_id = (int) $_POST['link_id'];
2019-04-16 19:56:22 +00:00
check_admin_referer( 'update-bookmark_' . $link_id );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
edit_link( $link_id );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
wp_redirect( $this_file );
2019-03-12 09:27:46 +00:00
exit;
2019-04-16 19:56:22 +00:00
case 'delete':
2019-03-12 09:27:46 +00:00
$link_id = (int) $_GET['link_id'];
2019-04-16 19:56:22 +00:00
check_admin_referer( 'delete-bookmark_' . $link_id );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
wp_delete_link( $link_id );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
wp_redirect( $this_file );
2019-03-12 09:27:46 +00:00
exit;
2019-04-16 19:56:22 +00:00
case 'edit':
wp_enqueue_script( 'link' );
wp_enqueue_script( 'xfn' );
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
if ( wp_is_mobile() ) {
2019-03-12 09:27:46 +00:00
wp_enqueue_script( 'jquery-touch-punch' );
2019-04-16 19:56:22 +00:00
}
2019-03-12 09:27:46 +00:00
2019-04-16 19:56:22 +00:00
$parent_file = 'link-manager.php';
2019-03-12 09:27:46 +00:00
$submenu_file = 'link-manager.php';
2019-04-16 19:56:22 +00:00
$title = __( 'Edit Link' );
2019-03-12 09:27:46 +00:00
$link_id = (int) $_GET['link_id'];
2019-04-16 19:56:22 +00:00
if ( ! $link = get_link_to_edit( $link_id ) ) {
wp_die( __( 'Link not found.' ) );
}
2019-03-12 09:27:46 +00:00
include( ABSPATH . 'wp-admin/edit-link-form.php' );
include( ABSPATH . 'wp-admin/admin-footer.php' );
break;
2019-04-16 19:56:22 +00:00
default:
2019-03-12 09:27:46 +00:00
break;
}