This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // used here only for enabling syntax highlighting. Leave this out if it's already included in your plugin file. | |
// define the actions for the two hooks created, first for logged in users and the next for logged out users | |
add_action("wp_ajax_my_user_like", "my_user_like"); | |
add_action("wp_ajax_nopriv_my_user_like", "please_login"); | |
// define the function to be fired for logged in users | |
function my_user_like() { | |
// nonce check for an extra layer of security, the function will exit if it fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The 'likes' meta key value will store the total like count for a specific post, it'll show 0 if it's an empty string | |
<?php | |
$likes = get_post_meta($post->ID, "likes", true); | |
$likes = ($likes == "") ? 0 : $likes; | |
?> | |
This post has <span id='like_counter'><?php echo $likes ?></span> likes<br> | |
// Linking to the admin-ajax.php file. Nonce check included for extra security. Note the "user_like" class for JS enabled clients. | |
<?php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add a new widget to the dashboard using a custom function | |
function wpmudev_add_dashboard_widgets() { | |
wp_add_dashboard_widget( | |
'wpmudev_dashboard_widget', // Widget slug | |
'My Custom Dashboard Widget', // Widget title | |
'wpmudev_new_dashboard_widget_function' // Function name to display the widget | |
); | |
} | |
// Register the new dashboard widget with the 'wp_dashboard_setup' action | |
add_action( 'wp_dashboard_setup', 'wpmudev_add_dashboard_widgets' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function to remove the dashboard widgets, but only for non-admin users | |
// if you want to remove the widgets for admin(s) too, remove the 'if' statement within the function | |
function remove_dashboard_widgets() { | |
if ( ! current_user_can( 'manage_options' ) ) { | |
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' ); | |
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); | |
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); |
NewerOlder