Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Выборка тегов для замены, начиная с картинки */
- function replace_text($text) {
- global $wpdb;
- // Поиск инфы на странице
- preg_match_all('<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>', $text, $matches);
- if (empty($matches[1])) return;
- //print_r($matches[1]);
- // Вывод совпадений
- $id = $matches[1];
- // Запрос в бд
- $line_img = $result = $wpdb->get_var('SELECT `smallURL` FROM `Images` where id='.(int)$id[0]);
- //$line_img = json_decode($result);
- //var_dump($id[0]); // выдает id строчкой
- //var_dump($line_img);
- // путь до картинок (контент)
- $url_img = content_url('/uploads');
- // Замена картинок (ббкод на картинку из БД) две строки (одна задана с кавычками текстовыми, другая с символьными)
- $text = preg_replace('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', '<img scr="'.$url_img.$line_img.'">', $text);
- $text = preg_replace('/<#+[a-z]+#+(\d*)#\d*#\d*#\d*##>/', '<img scr="'.$url_img.$line_img.'">', $text);
- // Замена ссылок на человекопонятные (ббкод на обычные ссылки-урл)
- $text = preg_replace('/<#link#(.*)#URL:(.*)#>/', ' <a href="$2">$1</a>', $text);
- // Замена лишнего кода на NULL
- $text = preg_replace('/<#pcat#(.*)#>/', '', $text);
- return $text;
- }
- add_filter('the_content', 'replace_text');
- add_filter('the_excerpt', 'replace_text_wps');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement