WP Cerber 127.0.0.2

Ho installato e configurato la versione free di WP-Cerber e ho subito notato che gli molti indirzzi IP venivano letti come 127.0.0.2, dopo una brevissima ricerca google sono arrivato all’esaustiva pagina dell’assistenza di tophost, che al momento riporta:

IP visitatore sempre 127.0.0.2
Supporto / Domande tecniche / PHP e MySQL / IP visitatore sempre 127.0.0.2

Utilizzando il supporto HTTPS, il sistema di logging delle visite del proprio CMS, darà sempre con IP visitatore: 127.0.0.2.

Questo purtroppo accade a causa di un BUG di sistema. Per il momento, l’unica soluzione è inserire all’inizio del file PHP di ingresso (es index.php o il file di configurazione) la seguente istruzione:

$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];

Creato a: 11/05/2018 12:24pm
L’ultima volta a: 11/05/2018 12:26pm

Ho quindi provveduto a modificare il file wp-config.php inserendo questa minuscola condizione tra le primissime righe, e ha subito funzionato come da aspettativa:

if ( $_SERVER['REMOTE_ADDR'] == "127.0.0.2" ) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}

 

Add Missing Alt Tags To WordPress Images

Le immagini sono importanti per il coinvolgimento con i tuoi visitatori, il problema è che non significano nulla per i motori di ricerca, e l’unico modo in cui i motori di ricerca possono capire di cosa tratta l’immagine è leggere le informazioni all’interno dell’attributo alt.

In WordPress è possibile includere facilmente le immagini sulla pagina utilizzando la libreria multimediale e inserire il testo alternativo per l’immagine, ma se ti dimentichi di inserire il testo alternativo hai bisogno di un modo per popolare automaticamente i tag img con un attributo alt.

Di seguito è riportato uno snippet di WordPress (visto in origine su GitHub e modificato) da inserire nel file functions.php del tema in uso per cercare nei contenuti tutte le le immagini che non hanno un attributo alt, o che lo hanno vuoto: se ce ne sono questa funzione lo aggiungerà con un valore predefinito del nome del file immagine.

Non è il massimo, ma è meglio di nulla.

function add_alt_tags($content)
{
        global $post;
        preg_match_all('/<img (.*?)\/>/', $content, $images);
        if(!is_null($images))
        {
                foreach($images[1] as $index => $value)
                {
                        if(!preg_match('/alt=/', $value) || preg_match('/alt=""/', $value))
                        {
                                preg_match('/src="([^"]*)"/i', $value, $src);
                                $src_tag = pathinfo($src[0]);
                                $new_img = str_replace('<img', '<img alt="'.$src_tag['filename'].'"', $images[0][$index]);
                                $content = str_replace($images[0][$index], $new_img, $content);
                        }
                }
        }
        return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);

relevanssi italian stopwords

Senza tanti preamboli, un elenco dei termini italiani di uso comune da escludere dai risultati di ricerca da poter utilizzare con il plugin per wordpress (al momento della pubblicazione 3.5.2) “relevanssi” (al momento della pubblicazione 3.1.6).

Il file .zip contiene un file .txt e un file .it_IT, quest’ultimo pronto per essere inserito nella cartella \wp-content\plugins\relevanssi\stopwords.

L’elenco è stato ottenuto unendo queste risorse:

download stopwords.zip | download stopwords.txt
Continua a leggere

wordpress php internet explorer browser detection, add body class

ie_detection_to_body aggiunge delle classi css utilizzando body_class di wordpress, adottando un approcio simile a questo snippet

/*
    ie_detection_to_body uses worpress body_class filter
    http://codex.wordpress.org/Function_Reference/body_class
    it has a similar approach of http://simplemediacode.info/?p=1006
Copyright (C) 2013 Valerio Vendrame (lelebart) http://www.valeriovendrame.it/
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function ie_detection_to_body( $classes ) {
    global $is_IE; $browser = $_SERVER['HTTP_USER_AGENT'];
    if ( $is_IE ) {    
        $classes[] = 'ie';    
        if ( isset( $browser ) && ( strpos( $browser , 'MSIE' ) !== false ) ) {
            preg_match('/MSIE (.*?);/', $browser, $matches);
            if ( count ( $matches ) > 1 ) {
                $classes[] = 'ie' . intval( $matches[1] );
                $classes[] = 'ie' . str_replace(".", "-", $matches[1] );
            }
        }
    }
    return $classes;
}
add_filter( 'body_class', 'ie_detection_to_body' );

pensato per un uso del tipo

.regola { /* per tutti */ }
.ie .regola { /* per internet explorer */ }
.ie.ie5.ie5-5 .regola { /* per internet explorer 5.5 */ }
.ie.ie7 .regola { /* per internet explorer 7.0 */ }