Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2013, 15:20
Avatar de deknisone
deknisone
 
Fecha de Ingreso: marzo-2010
Ubicación: lado obscuro del tiempo
Mensajes: 80
Antigüedad: 14 años
Puntos: 1
este codigo me tira error "Can't use method return value in write contex"

Estoy intentando agregar el atributo title automaticamente a los links de wordpress me encontre con esta funcion pero me tira error en esta linea

Código:
    if ($link->getAttribute('title') == '' || empty($link->getAttribute('title')))
Me tira este error
Fatal error: Can't use method return value in write context


Código PHP:
Ver original
  1. function get_page_title($url){
  2.         if( !class_exists( 'WP_Http' ) )
  3.             include_once( ABSPATH . WPINC. '/class-http.php' );
  4.         $request = new WP_Http;
  5.         $result = $request->request( $url );
  6.         if( is_wp_error( $result ) )
  7.             return false;
  8.  
  9.         if( preg_match("#<title>(.+)<\/title>#iU", $result, $t))  {
  10.             return trim($t[1]);
  11.         } else {
  12.             return false;
  13.         }
  14.     }
  15.  
  16.     add_filter('the_content','auto_add_title_to_link');
  17.  
  18.     function auto_add_title_to_link($content){
  19.         $html = new DomDocument;
  20.         $html->loadHTML($content);
  21.         $html->preserveWhiteSpace = false;
  22.         //get all links
  23.         foreach($html->getElementsByTagName('a') as $link) {
  24.         //make sure it dosent have a title
  25.             if ($link->getAttribute('title') == '' || empty($link->getAttribute('title')))
  26.                 $links[] = $link->getAttribute('href');
  27.         }
  28.         //get title and add it
  29.         foreach ($links as $link){
  30.             $title = get_page_title($link);
  31.             if (false !== $title){
  32.                 $replace = $link.' title="'.$title.'"';
  33.                 $content = str_replace($link,$replace,$content);
  34.             }
  35.  
  36.         }