MB Favorite Posts
Overview
MB Favorite Posts is a WordPress plugin that helps you create the “Favorite Post” button easily. Users can click the button to bookmark posts as favorites, and then review them on a Dashboard page. You can enable this feature for both guests and logged-in users.
Note: MB Favorite Posts plugin is only available for the Lifetime Bundle.
Installation
First, you need to install and activate Meta Box from wordpress.org. Next, download MB Favorite Posts plugin from the My Account page, then upload the .zip
file from the Admin Dashboard. MB Favorite Posts and other solutions are not included in Meta Box AIO, so you can install them independently without Meta Box AIO.
Upon finishing, the Favorite Posts Button will be automatically added to your WordPress website with the default settings:
To configure the Favorite Posts button to fit your needs, move to the next step.
Settings
Go to Settings > Favorite Posts. You will see the UI with sections as follows:
Here you can change the style for the button. We create 3 predefined styles for you to choose from:
- Default: which has a form of a button
- Like: a simple like icon (similar to Facebook like button)
- Rounded: a rounded button with an icon only
You can customize the style for all elements of the button, such as text, text color, icon, etc.
There are also options to let you specify where and when the button is displayed.
Dashboard Page and Register Page
MB Favorite Posts are integrated with MB User Profile to help users create the Dashboard page and the Register page automatically without coding.
The Dashboard page shows all the favorite posts of a user, and the Register page contains a form that users can sign up for accounts to use the Favorite Posts feature.
Note: when a user signs up for an account on the Register Page, his user role will be Subscriber.
You can choose available pages on the website and change them to the Dashboard page and the Register page.
For example, I choose these pages:
Better yet, you should create brand new pages for this purpose. To do so, go to Pages > Add New, fill in the name for the page and click Publish.
The Register page and the Dashboard page will be displayed on the front end as follows:
To delete a post from the favorite list, just click the icon on the right of the post name:
Shortcodes
The plugin provides 3 shortcodes: You can put them anywhere on the website (sidebar, page content, etc.).
[mbfp-posts]
: to show the list of favorite objects
[mbfp-button]
: to show the "Add to favorite" button
[mbfp-button id="post_id" class="custom_class" add="add_text" added="added_text" show_count="true"]
It accepts the following parameters:
Name | Description |
---|---|
id | The ID of the post. Optional. If missed, the shortcode will get the current object ID. |
class | Custom class name. Optional. |
add | Custom button text when the post isn't added to favorites. Optional. If missed, the shortcode will get the value from the plugin settings. |
added | Custom button text when the post is added to favorites. Optional. If missed, the shortcode will get the value from the plugin settings. |
font_size | Size of text. Optional. Default 14px. |
show_count | Show the total favorites of a post. Optional. Default false. |
show_icon | Show icon in button. Optional. Default false. |
icon | Custom icon. You can choose one of these [ heart, star, pin, like, award ]. Optional. Default heart icon. |
icon_only | Show icon only. Optional. Default false. |
icon_size | Size of icon. Optional. Default 16px. |
[mbfp-count]
: to show the total number favorite of a object
[mbfp-count id="post_id" ]
It accepts the following parameters:
Name | Description |
---|---|
id | The ID of the post. Optional. If missed, the shortcode will get the current object ID. |
Data
The data of favorites is stored in 2 places:
- User meta: the plugin stores array (serialized) of favorite post IDs in the user meta with key
mbfp_posts
. If you enable for non-logged in users, then the array of favorite post IDs is stored in the cookie. - Post meta: the plugin also stores array (serialized) of user IDs, who added a post to their favorites, in the post meta with key
mbfp_count
. This post meta is used to count how many favorites a post has.
So if you want to query favorite posts of an user, you can do the following:
$post_ids = get_user_meta( $user_id, 'mbfp_posts', true );
$query = new WP_Query( [
'post_type' => 'post',
'post__in' => $post_ids,
] );
// Do something with $query.
You can also query which users favorite a post:
$user_ids = get_post_meta( $post_id, 'mbfp_count', true );
$users = get_users( [
'include' => $user_ids,
] );
// Do something with $users.
Hook
mbfp_cookie_expiration
:
This filter is used to allow developers to change the cookie expiration day
add_filter( 'mbfp_cookie_expiration', function( $days ) {
$days = '1 month';
return $days;
}, 10, 3 );
mbfp_limit
:
This filter is used to define the maximum number of favorite posts.
add_filter( 'mbfp_limit', function( $limit ) {
$limit = 100;
return $limit;
} );