function rcl_ignored_feed_author($author_id)
{
    global $user_ID;
    $feed = rcl_get_author_feed_data($author_id);
    $args = array('user_id' => $user_ID, 'object_id' => $author_id, 'feed_type' => 'author', 'feed_status' => 0);
    if (!$feed) {
        $result = rcl_insert_feed_data($args);
    } else {
        if (!$feed->feed_status) {
            $args['feed_status'] = 1;
        }
        $args['feed_id'] = $feed->feed_id;
        $result = rcl_update_feed_data($args);
    }
    if ($result) {
        $data['success'] = __('The subscription status changed', 'wp-recall');
        $data['all'] = !$feed || $feed->feed_status ? __('Subscribe', 'wp-recall') : __('Unsubscribe', 'wp-recall');
    } else {
        $data['error'] = 'Error';
    }
    $data['return'] = 'notice';
    return $data;
}
Example #2
0
function rcl_update_feed_current_user($author_id)
{
    global $user_ID;
    $ignored_id = rcl_is_ignored_feed_author($author_id);
    if ($ignored_id) {
        $args = array('feed_id' => $ignored_id, 'user_id' => $user_ID, 'object_id' => $author_id, 'feed_type' => 'author', 'feed_status' => 1);
        $result = rcl_update_feed_data($args);
        if ($result) {
            $data['success'] = __('Signed up for a subscription', 'wp-recall');
            $data['this'] = __('Unsubscribe', 'wp-recall');
        } else {
            $data['error'] = __('Error', 'wp-recall');
        }
    } else {
        $feed = rcl_get_feed_author_current_user($author_id);
        if ($feed) {
            $result = rcl_remove_feed_author($author_id);
            if ($result) {
                $data['success'] = __('Subscription has been dropped', 'wp-recall');
                $data['this'] = __('Subscribe', 'wp-recall');
            } else {
                $data['error'] = __('Error', 'wp-recall');
            }
        } else {
            $result = rcl_add_feed_author($author_id);
            if ($result) {
                $data['success'] = __('Signed up for a subscription', 'wp-recall');
                $data['this'] = __('Unsubscribe', 'wp-recall');
            } else {
                $data['error'] = __('Error', 'wp-recall');
            }
        }
    }
    $data['return'] = 'notice';
    return $data;
}