A pal created a plugin for me which permits the customers to mark posts as learn or unread.
The code of this plugin is the next :
edit of the code !
<?php
/**
* @package deal Learn-Unread
* @model 1.0
*/
/*
Plugin Identify: Learn-Unread
Plugin URI: http://www.google.fr
Description: Learn-Unread plugin
Creator: Moi
Model: 1.0
Creator URI: http://www.google.fr
*/
international $wpdb;
$table_name = $wpdb->prefix . "users_read";
$sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
`ID_USER` int(11) NOT NULL,
`ID_POST` int(11) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;";
require_once( ABSPATH . 'wp-admin/consists of/improve.php' );
dbDelta( $sql );
operate all_css()
{
echo '
<fashion>
.post-read
{
cursor: pointer;
}
</fashion>';
}
operate all_js()
{
echo '
<script>
jQuery(operate($)
{
$(".post-read").click on(operate()
{
motion = $(this).information("motion");
if($(this).information("motion") == "learn")
{
$(this).attr("src", "http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/LU.png");
$(this).attr("title", "Marquer comme Non lu");
$(this).information("motion", "unread");
}
else
{
$(this).attr("src", "http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/NON_LU.png");
$(this).attr("title", "Marquer comme Lu");
$(this).information("motion", "learn");
}
postID = $(this).information("id");
var information = {
"motion": motion,
"idPost": postID
};
$.put up("/wp-admin/admin-ajax.php", information, operate(response)
{
});
});
});
</script>';
}
operate ajax_read() {
international $wpdb;
$idUser = intval(get_current_user_id());
$idPost = intval($_POST['idPost']);
$desk = $wpdb->prefix . "users_read";
$information = array('ID_USER' => $idUser, 'ID_POST' => $idPost);
$format = array('%d','%d');
$res = $wpdb->insert( $desk, $information, $format );
if($res == false)
{
return 1;
}
return 0;
die();
}
operate ajax_unread() {
international $wpdb;
$idUser = intval(get_current_user_id());
$idPost = intval($_POST['idPost']);
$desk = $wpdb->prefix . "users_read";
$the place = array('ID_USER' => $idUser, 'ID_POST' => $idPost);
$where_format = array('%d','%d');
$res = $wpdb->delete( $desk, $the place, $where_format );
if($res == false)
{
return 1;
}
return 0;
die();
}
add_action( 'wp_ajax_read', 'ajax_read' );
add_action( 'wp_ajax_unread', 'ajax_unread' );
operate get_img_read_unread()
{
international $wpdb;
$idUser = intval(get_current_user_id());
$idPost = intval(get_the_ID());
$msg = '';
if($idUser > 0 && $idPost > 0)
{
$learn = $wpdb->get_var( "SELECT COUNT(*) FROM wp_users_read WHERE ID_POST=$idPost AND ID_USER=$idUser");
if($learn == 1)
{
echo '<img class="post-read" data-action="unread" data-id="' . $idPost . '" src="http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/LU.png" title="Marquer comme Non lu">';
}
else
{
echo '<img class="post-read" data-action="learn" data-id="' . $idPost . '" src="http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/NON_LU.png" title="Marquer comme Lu">';
}
}
}
operate add_button($content material)
{
international $wpdb;
$idUser = intval(get_current_user_id());
$idPost = intval(get_the_ID());
$msg = '';
if($idUser > 0 && $idPost > 0)
{
$learn = $wpdb->get_var( "SELECT COUNT(*) FROM wp_users_read WHERE ID_POST=$idPost AND ID_USER=$idUser");
if($learn == 1)
{
$msg = '<img class="post-read" data-action="unread" data-id="' . $idPost . '" src="http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/LU.png" title="Marquer comme Non lu">';
}
else
{
$msg = '<img class="post-read" data-action="learn" data-id="' . $idPost . '" src="http://corentinbuet.fr/wordpress/wp-content/plugins/Learn-Unread/NON_LU.png" title="Marquer comme Lu">';
}
}
$posttype = get_post_type( get_the_ID() );
if ($posttype == put up)
{
return $content material . $msg;
}
else
{
return $content material;
}
}
add_filter('the_content', 'add_button');
add_action( 'wp_footer', 'all_js' );
add_action( 'wp_head', 'all_css' );
?>
I wish to mark as learn a put up when a put up is opened by a person. So how may I do this ?
If i’m not comprehensible sufficient, please let me know and that i’ll attempt to clarify higher.
Thanks.
Corentin