How to let a user choose an authors and save it to the database?

I have a multi-author WordPress site which reads different rss feeds and posts them to my page. I was wondering if it is possible to make a code that would provide an opportunity to registered user choice of which authors/sources to follow. There is already a few plugins that allow users to subscribe or ‘follow’ an author with email notifications (Example). But what I’m looking for is how to allow a user to select which feeds they want to read and this plugin would show only those feeds on my website.

I have little knowledge of php but none from WordPress really. Where should I start developing it? It needs to remember each user’s follows so it has to be saved database for what i know.

Read More

function select_authors_fields( $user ) {
$authors = get_users();
$user_tags = get_the_author_meta( 'select_authors', $user->ID );
?>
<table class="form-table">
    <tr>
        <th>My interests:</th>
        <td>
    <?php
    if ( count( $authors ) ) {
        foreach ($authors as $author) {
             if (user_can($author->ID, 'publish_posts')) { ?>
        <p><label for="select_authors_<?php echo esc_attr( $author->ID); ?>">
            <input
                id="select_authors_<?php echo esc_attr( $author->ID); ?>"
                name="select_authors[<?php echo esc_attr( get_the_author_meta('display_name', $author->ID) ); ?>]"
                type="checkbox"
                value="<?php echo esc_attr( get_the_author_meta('ID', $author->ID) ); ?>"
                <?php if ( in_array( get_the_author_meta('ID', $author->ID), $user_tags ) ) echo ' checked="checked"'; ?> />
            <?php echo esc_html(get_the_author_meta('display_name', $author->ID)); ?>
        </label></p><?php
             }
         }
    } ?>
        </td>
    </tr>
</table>
<?php
    }

add_action( ‘show_user_profile’, ‘select_authors_fields’ );
add_action( ‘edit_user_profile’, ‘select_authors_fields’ );

// store authors
function select_authors_fields_save( $user_id ) {
    if ( !current_user_can( 'edit_user', $user_id ) )
        return false;
    update_user_meta( $user_id, 'select_authors', $_POST['select_authors'] );
}
add_action( 'personal_options_update', 'select_authors_fields_save' );
add_action( 'edit_user_profile_update', 'select_authors_fields_save' );

This ones prints authors in user preferences with checkboxes. Now i need to make post_query depending selections. Any clues?

Related posts

Leave a Reply