wp/wp-admin/link.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    12 /** Load WordPress Administration Bootstrap */
    12 /** Load WordPress Administration Bootstrap */
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    13 require_once( dirname( __FILE__ ) . '/admin.php' );
    14 
    14 
    15 wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) );
    15 wp_reset_vars( array( 'action', 'cat_id', 'link_id' ) );
    16 
    16 
    17 if ( ! current_user_can('manage_links') )
    17 if ( ! current_user_can( 'manage_links' ) ) {
    18 	wp_link_manager_disabled_message();
    18 	wp_link_manager_disabled_message();
       
    19 }
    19 
    20 
    20 if ( !empty($_POST['deletebookmarks']) )
    21 if ( ! empty( $_POST['deletebookmarks'] ) ) {
    21 	$action = 'deletebookmarks';
    22 	$action = 'deletebookmarks';
    22 if ( !empty($_POST['move']) )
    23 }
       
    24 if ( ! empty( $_POST['move'] ) ) {
    23 	$action = 'move';
    25 	$action = 'move';
    24 if ( !empty($_POST['linkcheck']) )
    26 }
       
    27 if ( ! empty( $_POST['linkcheck'] ) ) {
    25 	$linkcheck = $_POST['linkcheck'];
    28 	$linkcheck = $_POST['linkcheck'];
       
    29 }
    26 
    30 
    27 $this_file = admin_url('link-manager.php');
    31 $this_file = admin_url( 'link-manager.php' );
    28 
    32 
    29 switch ($action) {
    33 switch ( $action ) {
    30 	case 'deletebookmarks' :
    34 	case 'deletebookmarks':
    31 		check_admin_referer('bulk-bookmarks');
    35 		check_admin_referer( 'bulk-bookmarks' );
    32 
    36 
    33 		// For each link id (in $linkcheck[]) change category to selected value.
    37 		// For each link id (in $linkcheck[]) change category to selected value.
    34 		if (count($linkcheck) == 0) {
    38 		if ( count( $linkcheck ) == 0 ) {
    35 			wp_redirect($this_file);
    39 			wp_redirect( $this_file );
    36 			exit;
    40 			exit;
    37 		}
    41 		}
    38 
    42 
    39 		$deleted = 0;
    43 		$deleted = 0;
    40 		foreach ($linkcheck as $link_id) {
    44 		foreach ( $linkcheck as $link_id ) {
    41 			$link_id = (int) $link_id;
    45 			$link_id = (int) $link_id;
    42 
    46 
    43 			if ( wp_delete_link($link_id) )
    47 			if ( wp_delete_link( $link_id ) ) {
    44 				$deleted++;
    48 				$deleted++;
       
    49 			}
    45 		}
    50 		}
    46 
    51 
    47 		wp_redirect("$this_file?deleted=$deleted");
    52 		wp_redirect( "$this_file?deleted=$deleted" );
    48 		exit;
    53 		exit;
    49 
    54 
    50 	case 'move' :
    55 	case 'move':
    51 		check_admin_referer('bulk-bookmarks');
    56 		check_admin_referer( 'bulk-bookmarks' );
    52 
    57 
    53 		// For each link id (in $linkcheck[]) change category to selected value.
    58 		// For each link id (in $linkcheck[]) change category to selected value.
    54 		if (count($linkcheck) == 0) {
    59 		if ( count( $linkcheck ) == 0 ) {
    55 			wp_redirect($this_file);
    60 			wp_redirect( $this_file );
    56 			exit;
    61 			exit;
    57 		}
    62 		}
    58 		$all_links = join(',', $linkcheck);
    63 		$all_links = join( ',', $linkcheck );
    59 		/*
    64 		/*
    60 		 * Should now have an array of links we can change:
    65 		 * Should now have an array of links we can change:
    61 		 *     $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
    66 		 *     $q = $wpdb->query("update $wpdb->links SET link_category='$category' WHERE link_id IN ($all_links)");
    62 		 */
    67 		 */
    63 
    68 
    64 		wp_redirect($this_file);
    69 		wp_redirect( $this_file );
    65 		exit;
    70 		exit;
    66 
    71 
    67 	case 'add' :
    72 	case 'add':
    68 		check_admin_referer('add-bookmark');
    73 		check_admin_referer( 'add-bookmark' );
    69 
    74 
    70 		$redir = wp_get_referer();
    75 		$redir = wp_get_referer();
    71 		if ( add_link() )
    76 		if ( add_link() ) {
    72 			$redir = add_query_arg( 'added', 'true', $redir );
    77 			$redir = add_query_arg( 'added', 'true', $redir );
       
    78 		}
    73 
    79 
    74 		wp_redirect( $redir );
    80 		wp_redirect( $redir );
    75 		exit;
    81 		exit;
    76 
    82 
    77 	case 'save' :
    83 	case 'save':
    78 		$link_id = (int) $_POST['link_id'];
    84 		$link_id = (int) $_POST['link_id'];
    79 		check_admin_referer('update-bookmark_' . $link_id);
    85 		check_admin_referer( 'update-bookmark_' . $link_id );
    80 
    86 
    81 		edit_link($link_id);
    87 		edit_link( $link_id );
    82 
    88 
    83 		wp_redirect($this_file);
    89 		wp_redirect( $this_file );
    84 		exit;
    90 		exit;
    85 
    91 
    86 	case 'delete' :
    92 	case 'delete':
    87 		$link_id = (int) $_GET['link_id'];
    93 		$link_id = (int) $_GET['link_id'];
    88 		check_admin_referer('delete-bookmark_' . $link_id);
    94 		check_admin_referer( 'delete-bookmark_' . $link_id );
    89 
    95 
    90 		wp_delete_link($link_id);
    96 		wp_delete_link( $link_id );
    91 
    97 
    92 		wp_redirect($this_file);
    98 		wp_redirect( $this_file );
    93 		exit;
    99 		exit;
    94 
   100 
    95 	case 'edit' :
   101 	case 'edit':
    96 		wp_enqueue_script('link');
   102 		wp_enqueue_script( 'link' );
    97 		wp_enqueue_script('xfn');
   103 		wp_enqueue_script( 'xfn' );
    98 
   104 
    99 		if ( wp_is_mobile() )
   105 		if ( wp_is_mobile() ) {
   100 			wp_enqueue_script( 'jquery-touch-punch' );
   106 			wp_enqueue_script( 'jquery-touch-punch' );
       
   107 		}
   101 
   108 
   102 		$parent_file = 'link-manager.php';
   109 		$parent_file  = 'link-manager.php';
   103 		$submenu_file = 'link-manager.php';
   110 		$submenu_file = 'link-manager.php';
   104 		$title = __('Edit Link');
   111 		$title        = __( 'Edit Link' );
   105 
   112 
   106 		$link_id = (int) $_GET['link_id'];
   113 		$link_id = (int) $_GET['link_id'];
   107 
   114 
   108 		if (!$link = get_link_to_edit($link_id))
   115 		if ( ! $link = get_link_to_edit( $link_id ) ) {
   109 			wp_die(__('Link not found.'));
   116 			wp_die( __( 'Link not found.' ) );
       
   117 		}
   110 
   118 
   111 		include( ABSPATH . 'wp-admin/edit-link-form.php' );
   119 		include( ABSPATH . 'wp-admin/edit-link-form.php' );
   112 		include( ABSPATH . 'wp-admin/admin-footer.php' );
   120 		include( ABSPATH . 'wp-admin/admin-footer.php' );
   113 		break;
   121 		break;
   114 
   122 
   115 	default :
   123 	default:
   116 		break;
   124 		break;
   117 }
   125 }