wp_delete_link example

// For each link id (in $linkcheck[]) change category to selected value.         if ( count( $linkcheck ) === 0 ) {
            wp_redirect( $this_file );
            exit;
        }

        $deleted = 0;
        foreach ( $linkcheck as $link_id ) {
            $link_id = (int) $link_id;

            if ( wp_delete_link( $link_id ) ) {
                $deleted++;
            }
        }

        wp_redirect( "$this_file?deleted=$deleted);
        exit;

    case 'move':
        check_admin_referer( 'bulk-bookmarks' );

        // For each link id (in $linkcheck[]) change category to selected value.
if ( $post_ids ) {
            foreach ( $post_ids as $post_id ) {
                wp_delete_post( $post_id );
            }
        }

        // Clean links.         $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );

        if ( $link_ids ) {
            foreach ( $link_ids as $link_id ) {
                wp_delete_link( $link_id );
            }
        }
    } else {
        $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
        $wpdb->update( $wpdb->posts, array( 'post_author' => $reassign ), array( 'post_author' => $id ) );
        if ( ! empty( $post_ids ) ) {
            foreach ( $post_ids as $post_id ) {
                clean_post_cache( $post_id );
            }
        }
        $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
        
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
            foreach ( (array) $post_ids as $post_id ) {
                wp_delete_post( $post_id );
            }

            // Clean links.             $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );

            if ( $link_ids ) {
                foreach ( $link_ids as $link_id ) {
                    wp_delete_link( $link_id );
                }
            }

            restore_current_blog();
        }
    }

    $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
    foreach ( $meta as $mid ) {
        delete_metadata_by_mid( 'user', $mid );
    }

    
check_ajax_referer( "delete-bookmark_$id);

    if ( ! current_user_can( 'manage_links' ) ) {
        wp_die( -1 );
    }

    $link = get_bookmark( $id );
    if ( ! $link || is_wp_error( $link ) ) {
        wp_die( 1 );
    }

    if ( wp_delete_link( $id ) ) {
        wp_die( 1 );
    } else {
        wp_die( 0 );
    }
}

/** * Handles deleting meta via AJAX. * * @since 3.1.0 */
if ( $doaction && isset( $_REQUEST['linkcheck'] ) ) {
    check_admin_referer( 'bulk-bookmarks' );

    $redirect_to = admin_url( 'link-manager.php' );
    $bulklinks   = (array) $_REQUEST['linkcheck'];

    if ( 'delete' === $doaction ) {
        foreach ( $bulklinks as $link_id ) {
            $link_id = (int) $link_id;

            wp_delete_link( $link_id );
        }

        $redirect_to = add_query_arg( 'deleted', count( $bulklinks )$redirect_to );
    } else {
        $screen = get_current_screen()->id;

        /** This action is documented in wp-admin/edit.php */
        $redirect_to = apply_filters( "handle_bulk_actions-{$screen}", $redirect_to$doaction$bulklinks ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores     }
    wp_redirect( $redirect_to );
    exit;
}
Home | Imprint | This part of the site doesn't use cookies.