Advertisement
xaristarhov

Untitled

Sep 14th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. /* Выборка тегов для замены, начиная с картинки */
  2. function replace_text($text) {
  3.   global $wpdb;
  4.  
  5.   // Поиск инфы на странице
  6.   preg_match_all('<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>', $text, $matches);
  7.   if (empty($matches[1])) return;
  8.   //print_r($matches[1]);
  9.   // Вывод совпадений
  10.   $id = $matches[1];
  11.   // Запрос в бд
  12.   $line_img = $result = $wpdb->get_var('SELECT `smallURL` FROM `Images` where id='.(int)$id[0]);
  13.   //$line_img = json_decode($result);
  14.   //var_dump($id[0]); // выдает id строчкой
  15.   //var_dump($line_img);
  16.  
  17.     // путь до картинок (контент)
  18.     $url_img = content_url('/uploads');
  19.  
  20. // Замена картинок (ббкод на картинку из БД) две строки (одна задана с кавычками текстовыми, другая с символьными)
  21.     $text = preg_replace('/&lt;#+[a-z]+#+(\d*)#\d*#\d*#\d*##&gt;/', '<img scr="'.$url_img.$line_img.'">', $text);
  22.     $text = preg_replace('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', '<img scr="'.$url_img.$line_img.'">', $text);
  23. // Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
  24.   $text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
  25. // Замена лишнего кода на NULL  
  26.   $text = preg_replace('/<#pcat#(.*)#>/', '', $text);
  27. return $text;
  28. }
  29. add_filter('the_content', 'replace_text');
  30. add_filter('the_excerpt', 'replace_text_wps');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement