{"id":252,"date":"2011-04-11T11:09:53","date_gmt":"2011-04-11T10:09:53","guid":{"rendered":"http:\/\/www.manuelmarangoni.it\/sir-bit\/?p=252"},"modified":"2015-12-22T10:48:34","modified_gmt":"2015-12-22T09:48:34","slug":"creare-e-aggiungere-il-gravatar-a-wordpress","status":"publish","type":"post","link":"https:\/\/www.manuelmarangoni.it\/sir-bit\/252\/creare-e-aggiungere-il-gravatar-a-wordpress\/","title":{"rendered":"Creare e aggiungere il gravatar a wordpress"},"content":{"rendered":"<p style=\"text-align: center;\"><a class=\"lightbox\" href=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/inserire-gravatar-wordpress.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-254\" title=\"inserire gravatar in wordpress\" src=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/inserire-gravatar-wordpress-450x190.jpg\" alt=\"inserire gravatar in wordpress\" width=\"450\" height=\"190\" srcset=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/inserire-gravatar-wordpress-450x190.jpg 450w, https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/inserire-gravatar-wordpress.jpg 949w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>Il <strong>gravatar <\/strong>\u00e8 l&#8217;immagine che identifica gli utenti controllando la loro mail o il loro ID.<br \/>\nPer capirsi, vicino al mio nome sotto il titolo dell&#8217;articolo c&#8217;\u00e8 il mio &#8220;<strong>gravatar<\/strong>&#8220;, ovvero l&#8217;avatar associato alla mia emal.<br \/>\n<!--more--><\/p>\n<p>Se non avete ancora un vostro avatar potete crearlo sul <a title=\"gravatar - avatar online\" href=\"http:\/\/it.gravatar.com\/\" target=\"_blank\">sito dei gravatar<\/a>. Altrimenti saltate pure il paragrafo <a href=\"#inserire-gravatar\">premendo qui<\/a>.<\/p>\n<h2>Come creare un Gravatar<\/h2>\n<p>Dovete registrarvi sul sito gravatar.com. Ad ogni utenza si possono associare pi\u00f9 email, cos\u00ec non \u00e8 necessario creare molteplici account per tutte le mail che avete.<br \/>\nPoi dovete caricare l&#8217;immagine che far\u00e0 da avatar (dal pc, da internet o direttamente dalla webcam) e per ogni immagine dovete scegliere il <strong>rate<\/strong>, ovvero se \u00e8 adatta a tutti, se contiene scene di nudo, etc.<\/p>\n<p style=\"text-align: center;\"><a class=\"lightbox\" href=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/gravatar-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-253 aligncenter\" title=\"creare il gravatar\" src=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/gravatar-2-450x284.jpg\" alt=\"creare il gravatar\" width=\"450\" height=\"284\" srcset=\"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/gravatar-2-450x284.jpg 450w, https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-content\/uploads\/2011\/04\/gravatar-2.jpg 939w\" sizes=\"(max-width: 450px) 100vw, 450px\" \/><\/a><\/p>\n<p>Se avete <strong>pi\u00f9 email<\/strong> potete associare immagini diverse ad ognuna. Una volta selezionata, premete sull&#8217;immagine che preferite e clickate su &#8220;conferma&#8221; per rendere primaria quell&#8217;immagine.<\/p>\n<p>Detto fatto, quando <strong>commenterete <\/strong>un blog, o <strong>creerete un articolo<\/strong> sul vostro wordpress con una delle email associate, comparir\u00e0 l&#8217;immagine che avete scelto.<br \/>\n<a name=\"inserire-gravatar\"><\/a><\/p>\n<h2>Integrare il gravatar nel vostro sito o blog<\/h2>\n<p>Con wordpress superiore a 2.5 ci viene in aiuto la funzione <a title=\"Function Reference\/get avatar\" href=\"http:\/\/codex.wordpress.org\/Function_Reference\/get_avatar\" target=\"_blank\">get_avatar<\/a>.<br \/>\nPer richiamarla si procedere semplicemente cos\u00ec:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"line_numbers\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<pre class=\"php\" style=\"font-family: monospace;\"><span style=\"color: #b1b100;\">echo<\/span> get_avatar<span style=\"color: #009900;\">(<\/span> <span style=\"color: #000088;\">$email<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #000088;\">$size<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000ff;\">'60'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>Email<\/strong> \u00e8 l&#8217;email testuale del commento o dell&#8217;autore.<br \/>\n<strong>Size<\/strong> \u00e8 la dimensione sia dell&#8217;altezza che della larghezza (\u00e8 un quadrato) definita in pixel.<\/p>\n\n<p>Se il nostro scopo \u00e8 inserirla vicino al nome dell&#8217;autore:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"line_numbers\">\n<pre>1\r\n2\r\n3<\/pre>\n<\/td>\n<td class=\"code\">\n<pre class=\"php\" style=\"font-family: monospace;\"><span style=\"color: #000088;\">$email<\/span><span style=\"color: #339933;\">=<\/span>get_the_author_meta<span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'user_email'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n<span style=\"color: #b1b100;\">echo<\/span> get_avatar<span style=\"color: #009900;\">(<\/span> <span style=\"color: #000088;\">$email<\/span><span style=\"color: #339933;\">,<\/span> <span style=\"color: #000088;\">$size<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000ff;\">'40'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span> \r\nthe_author<span style=\"color: #009900;\">(<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>get_the_author_meta(&#8216;user_email&#8217;)<\/strong> estrarr\u00e0 l&#8217;email dell&#8217;utente che ha scritto il post. Memorizzo la mail nella variabile <strong>$email<\/strong>, poi stampo il get_avatar.<br \/>\nCon <strong>the_author()<\/strong> stampo invece il nome dell&#8217;autore.<\/p>\n<p>Il codice html creato da gravatar.com \u00e8 questo:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"line_numbers\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<pre class=\"html4strict\" style=\"font-family: monospace;\"><span style=\"color: #009900;\">&lt;<span style=\"color: #000000; font-weight: bold;\">img<\/span> <span style=\"color: #000066;\">class<\/span><span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff0000;\">\"avatar avatar-$size\"<\/span> <span style=\"color: #000066;\">src<\/span><span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff0000;\">\"http:\/\/gravatarurl_or_default\"<\/span> <span style=\"color: #000066;\">alt<\/span><span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff0000;\">\"\"<\/span> <span style=\"color: #000066;\">width<\/span><span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff0000;\">\"$size\"<\/span> <span style=\"color: #000066;\">height<\/span><span style=\"color: #66cc66;\">=<\/span><span style=\"color: #ff0000;\">\"$size\"<\/span> <span style=\"color: #66cc66;\">\/<\/span>&gt;<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Aggiunger\u00e0 due classi, <strong>avatar <\/strong>e <strong>avatar-$size<\/strong>. Se la dimensione scelta era 60, le classi saranno avatar e avatar-60.<\/p>\n<p>Per inserirlo invece nei commenti invece di usare <strong>get_the_author_meta<\/strong> l&#8217;email da utilizzare si prende cos\u00ec:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"line_numbers\">\n<pre>1<\/pre>\n<\/td>\n<td class=\"code\">\n<pre class=\"php\" style=\"font-family: monospace;\"><span style=\"color: #000088;\">$email<\/span><span style=\"color: #339933;\">=<\/span><span style=\"color: #990000;\">strtolower<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #990000;\">trim<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #000088;\">$comment<\/span><span style=\"color: #339933;\">-&gt;<\/span><span style=\"color: #004000;\">comment_author_email<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Se il vostro wordpress \u00e8 pi\u00f9 vecchio, invece di usare solo get_avatar dovete usare questa funzione per renderla compatibile con tutti:<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"line_numbers\">\n<pre>1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8<\/pre>\n<\/td>\n<td class=\"code\">\n<pre class=\"php\" style=\"font-family: monospace;\"><span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">(<\/span><span style=\"color: #990000;\">function_exists<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #0000ff;\">'get_avatar'<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #009900;\">{<\/span>\r\n  <span style=\"color: #b1b100;\">echo<\/span> get_avatar<span style=\"color: #009900;\">(<\/span><span style=\"color: #000088;\">$email<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #339933;\">;<\/span>\r\n<span style=\"color: #009900;\">}<\/span> <span style=\"color: #b1b100;\">else<\/span> <span style=\"color: #009900;\">{<\/span>\r\n  <span style=\"color: #666666; font-style: italic;\">\/\/codice gravatar alternativo per wordpress &amp;lt; 2.5<\/span>\r\n  <span style=\"color: #000088;\">$grav_url<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000ff;\">\"http:\/\/www.gravatar.com\/avatar\/\"<\/span> <span style=\"color: #339933;\">.<\/span>\r\n  <span style=\"color: #990000;\">md5<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #990000;\">strtolower<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #000088;\">$email<\/span><span style=\"color: #009900;\">)<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #339933;\">.<\/span> <span style=\"color: #0000ff;\">\"?d=\"<\/span> <span style=\"color: #339933;\">.<\/span> <span style=\"color: #990000;\">urlencode<\/span><span style=\"color: #009900;\">(<\/span><span style=\"color: #000088;\">$default<\/span><span style=\"color: #009900;\">)<\/span> <span style=\"color: #339933;\">.<\/span> <span style=\"color: #0000ff;\">\"&amp;amp;s=\"<\/span> <span style=\"color: #339933;\">.<\/span> <span style=\"color: #000088;\">$size<\/span><span style=\"color: #339933;\">;<\/span>\r\n  <span style=\"color: #b1b100;\">echo<\/span> <span style=\"color: #0000ff;\">\"&lt;img src=\"<\/span><span style=\"color: #000088;\">$grav_url<\/span><span style=\"color: #0000ff;\">\" alt=\"<\/span><span style=\"color: #0000ff;\">\" \/&gt;\"<\/span><span style=\"color: #339933;\">;<\/span>\r\n<span style=\"color: #009900;\">}<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>L&#8217;articolo ufficiale in inglese <a href=\"http:\/\/codex.wordpress.org\/Using_Gravatars\" target=\"_blank\">\u00e8 questo<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Il gravatar \u00e8 l&#8217;immagine che identifica gli utenti controllando la loro mail o il loro ID. Per capirsi, vicino al mio nome sotto il titolo dell&#8217;articolo c&#8217;\u00e8 il mio &#8220;gravatar&#8220;, ovvero l&#8217;avatar associato alla mia emal.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[4,23],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-wordpress-2","tag-php","tag-wordpress","cat-79-id"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/posts\/252"}],"collection":[{"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/comments?post=252"}],"version-history":[{"count":13,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/posts\/252\/revisions"}],"predecessor-version":[{"id":2130,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/posts\/252\/revisions\/2130"}],"wp:attachment":[{"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/media?parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/categories?post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.manuelmarangoni.it\/sir-bit\/wp-json\/wp\/v2\/tags?post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}