Sunday, January 29, 2023
HomeWordPress Developmentmultisite - customers followin the weblog submit writer

multisite – customers followin the weblog submit writer


I’ve a code which is meant to observe the writer of weblog submit however each time the observe button is typed it will get an essential error on the wordpress.
heres the script

<?php 
// Get present person
$current_user = wp_get_current_user();

// Get present person ID
$current_user_id = $current_user->ID;

// Get ID of submit writer
$post_author_id = get_the_author_meta('ID');

// Verify if present person is following submit writer
$is_following = in_array( $post_author_id, get_user_meta( $current_user_id, 'following', true ) );

// Comply with button
if ( !$is_following && $current_user_id != $post_author_id ) {
    echo '<kind methodology="submit">';
    echo '<enter kind="hidden" identify="post_author_id" worth="' . $post_author_id . '">';
    echo '<enter kind="submit" identify="observe" worth="Comply with">';
    echo '</kind>';
}

// Unfollow button
if ( $is_following ) {
    echo '<kind methodology="submit">';
    echo '<enter kind="hidden" identify="post_author_id" worth="' . $post_author_id . '">';
    echo '<enter kind="submit" identify="unfollow" worth="Unfollow">';
    echo '</kind>';
}

// Comply with submit writer
if ( isset( $_POST['follow'] ) ) {
    $following = get_user_meta( $current_user_id, 'following', true );
    $following[] = $_POST['post_author_id'];
    update_user_meta( $current_user_id, 'following', $following );

    // Add present person to submit writer's followers checklist
    $followers = get_user_meta( $_POST['post_author_id'], 'followers', true );
    $followers[] = $current_user_id;
    update_user_meta( $_POST['post_author_id'], 'followers', $followers );
}

// Unfollow submit writer
if ( isset( $_POST['unfollow'] ) ) {
    $following = get_user_meta( $current_user_id, 'following', true );
    $following = array_diff( $following, array( $_POST['post_author_id'] ) );
    update_user_meta( $current_user_id, 'following', $following );

    // Take away present person from submit writer's followers checklist
    $followers = get_user_meta( $_POST['post_author_id'], 'followers', true );
    $followers = array_diff( $followers, array( $current_user_id ) );
    update_user_meta( $_POST['post_author_id'], 'followers', $followers );
}

?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments