{"id":233148,"date":"2023-02-05T10:37:00","date_gmt":"2023-02-05T07:37:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=233148"},"modified":"2023-02-05T10:38:15","modified_gmt":"2023-02-05T07:38:15","slug":"come-consentire-immagini-anziche-url-nei-commenti-di-wordpress","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/it\/come-consentire-immagini-anziche-url-nei-commenti-di-wordpress\/","title":{"rendered":"Come consentire immagini anzich\u00e9 URL nei commenti di WordPress?"},"content":{"rendered":"<p>Per impostazione predefinita, gli URL nel commento vengono mantenuti come sono. Se un utente inserisce direttamente l&#8217;URL di un&#8217;immagine, sarebbe utile sostituire l&#8217;URL con il tag img HTML effettivo. Aggiungi il seguente pezzo di <a href=\"https:\/\/wordpress.mediadoma.com\/it\/come-memorizzare-nella-cache-il-token-wechat-tramite-php\/\" title=\"codice PHP\">codice PHP<\/a> nel tuo tema <a href=\"https:\/\/helloacm.com\/how-to-remove-product-review-in-woocommercewordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">wordpress<\/a> <a href=\"https:\/\/helloacm.com\/how-to-remove-admin-topbar-in-wordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">functions.php<\/a> :<\/p>\n<pre><code>\/\/ empty - allow all posts, otherwise, put post IDs joined by comma\ndefine('ALLOW_POSTS', '');\nfunction helloacm_allow_comment_image( $comment) {\n\u00a0 \u00a0 $post_ID = $comment[\"comment_post_ID\"];\n\u00a0 \u00a0 $allow_posts = ALLOW_POSTS? explode(',', ALLOW_POSTS): array();\n\u00a0 \u00a0 if(empty($allow_posts) || in_array($post_ID, $allow_posts)){\n\u00a0 \u00a0 \u00a0 \u00a0 global $allowedtags;\n\u00a0 \u00a0 \u00a0 \u00a0 $content = $comment[\"comment_content\"];\n\u00a0 \u00a0 \u00a0 \u00a0 $content = preg_replace('\/(https?:\/\/S+.(?:jpg|png|jpeg|gif|bmp))+\/','&lt;img \u00a0title=\"$0 How to Allow Images Instead of URL in WordPress Comments? wordpress \" src=\"$0\" \u00a0alt=\"$0 How to Allow Images Instead of URL in WordPress Comments? wordpress \" \u00a0\/&gt;',$content);\n\u00a0 \u00a0 \u00a0 \u00a0 $allowedtags['img'] = array('src' =&gt; array(), 'alt' =&gt; array());\n\u00a0 \u00a0 \u00a0 \u00a0 $comment[\"comment_content\"] = $content;\n\u00a0 \u00a0 }\n\u00a0 \u00a0 return $comment;\n}\nadd_filter('preprocess_comment', 'helloacm_allow_comment_image');<\/code><\/pre>\n<p>Usiamo un&#8217;espressione regolare per trovare gli URL delle immagini (che terminano con le estensioni jpg\/png\/jpeg\/gif\/bmp) e le sostituiamo con il tag HTML img. Dobbiamo anche consentire il tag IMG nella sezione commenti, in modo da visualizzarlo correttamente. La funzione di cui sopra deve essere aggiunta al filtro preprocess_comment che viene invocato prima che un commento venga inserito nel <a href=\"https:\/\/helloacm.com\/easy-round-robin-scheduled-database-backup-on-linux\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">database<\/a>.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Fonte di registrazione:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Come consentire immagini anzich\u00e9 URL nei commenti di WordPress?<\/p>\n","protected":false},"author":1,"featured_media":224757,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[896,835,804,844,865],"tags":[1168],"class_list":["post-233148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codice","category-guida-per-principianti","category-php-6","category-tutorial","category-wordpress-6","tag-affiai-it"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/233148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/comments?post=233148"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/233148\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media\/224757"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media?parent=233148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/categories?post=233148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/tags?post=233148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}