author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 19 | 3d72ae0968f4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Manage link administration actions. |
|
4 |
* |
|
5 |
* This page is accessed by the link management pages and handles the forms and |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
* Ajax processes for link actions. |
0 | 7 |
* |
8 |
* @package WordPress |
|
9 |
* @subpackage Administration |
|
10 |
*/ |
|
11 |
||
12 |
/** Load WordPress Administration Bootstrap */ |
|
16 | 13 |
require_once __DIR__ . '/admin.php'; |
0 | 14 |
|
15 |
wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) ); |
|
16 |
||
9 | 17 |
if ( ! current_user_can( 'manage_links' ) ) { |
0 | 18 |
wp_link_manager_disabled_message(); |
9 | 19 |
} |
0 | 20 |
|
9 | 21 |
if ( ! empty( $_POST['deletebookmarks'] ) ) { |
0 | 22 |
$action = 'deletebookmarks'; |
9 | 23 |
} |
24 |
if ( ! empty( $_POST['move'] ) ) { |
|
0 | 25 |
$action = 'move'; |
9 | 26 |
} |
27 |
if ( ! empty( $_POST['linkcheck'] ) ) { |
|
0 | 28 |
$linkcheck = $_POST['linkcheck']; |
9 | 29 |
} |
0 | 30 |
|
9 | 31 |
$this_file = admin_url( 'link-manager.php' ); |
0 | 32 |
|
9 | 33 |
switch ( $action ) { |
34 |
case 'deletebookmarks': |
|
35 |
check_admin_referer( 'bulk-bookmarks' ); |
|
0 | 36 |
|
5 | 37 |
// For each link id (in $linkcheck[]) change category to selected value. |
16 | 38 |
if ( count( $linkcheck ) === 0 ) { |
9 | 39 |
wp_redirect( $this_file ); |
0 | 40 |
exit; |
41 |
} |
|
42 |
||
43 |
$deleted = 0; |
|
9 | 44 |
foreach ( $linkcheck as $link_id ) { |
0 | 45 |
$link_id = (int) $link_id; |
46 |
||
9 | 47 |
if ( wp_delete_link( $link_id ) ) { |
0 | 48 |
$deleted++; |
9 | 49 |
} |
0 | 50 |
} |
51 |
||
9 | 52 |
wp_redirect( "$this_file?deleted=$deleted" ); |
0 | 53 |
exit; |
54 |
||
9 | 55 |
case 'move': |
56 |
check_admin_referer( 'bulk-bookmarks' ); |
|
0 | 57 |
|
5 | 58 |
// For each link id (in $linkcheck[]) change category to selected value. |
16 | 59 |
if ( count( $linkcheck ) === 0 ) { |
9 | 60 |
wp_redirect( $this_file ); |
0 | 61 |
exit; |
62 |
} |
|
18 | 63 |
$all_links = implode( ',', $linkcheck ); |
5 | 64 |
/* |
65 |
* Should now have an array of links we can change: |
|
66 |
* $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)"); |
|
67 |
*/ |
|
0 | 68 |
|
9 | 69 |
wp_redirect( $this_file ); |
0 | 70 |
exit; |
71 |
||
9 | 72 |
case 'add': |
73 |
check_admin_referer( 'add-bookmark' ); |
|
0 | 74 |
|
75 |
$redir = wp_get_referer(); |
|
9 | 76 |
if ( add_link() ) { |
0 | 77 |
$redir = add_query_arg( 'added', 'true', $redir ); |
9 | 78 |
} |
0 | 79 |
|
80 |
wp_redirect( $redir ); |
|
81 |
exit; |
|
82 |
||
9 | 83 |
case 'save': |
0 | 84 |
$link_id = (int) $_POST['link_id']; |
9 | 85 |
check_admin_referer( 'update-bookmark_' . $link_id ); |
0 | 86 |
|
9 | 87 |
edit_link( $link_id ); |
0 | 88 |
|
9 | 89 |
wp_redirect( $this_file ); |
0 | 90 |
exit; |
91 |
||
9 | 92 |
case 'delete': |
0 | 93 |
$link_id = (int) $_GET['link_id']; |
9 | 94 |
check_admin_referer( 'delete-bookmark_' . $link_id ); |
0 | 95 |
|
9 | 96 |
wp_delete_link( $link_id ); |
0 | 97 |
|
9 | 98 |
wp_redirect( $this_file ); |
0 | 99 |
exit; |
100 |
||
9 | 101 |
case 'edit': |
102 |
wp_enqueue_script( 'link' ); |
|
103 |
wp_enqueue_script( 'xfn' ); |
|
0 | 104 |
|
9 | 105 |
if ( wp_is_mobile() ) { |
0 | 106 |
wp_enqueue_script( 'jquery-touch-punch' ); |
9 | 107 |
} |
0 | 108 |
|
9 | 109 |
$parent_file = 'link-manager.php'; |
0 | 110 |
$submenu_file = 'link-manager.php'; |
9 | 111 |
$title = __( 'Edit Link' ); |
0 | 112 |
|
113 |
$link_id = (int) $_GET['link_id']; |
|
114 |
||
16 | 115 |
$link = get_link_to_edit( $link_id ); |
116 |
if ( ! $link ) { |
|
9 | 117 |
wp_die( __( 'Link not found.' ) ); |
118 |
} |
|
0 | 119 |
|
16 | 120 |
require ABSPATH . 'wp-admin/edit-link-form.php'; |
121 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |
|
0 | 122 |
break; |
123 |
||
9 | 124 |
default: |
0 | 125 |
break; |
126 |
} |