static function update_shortcodes() { // Check to see if we need to migrate any old ad tags to new ad tags global $advman_engine; $data = $advman_engine->dal->data; $patterns = array('/<!--adsense-->/', '/<!--adsense-->/', '/<!--adsense#(.*?)-->/', '/<!--adsense#(.*?)-->/', '/<!--am-->/', '/<!--am-->/', '/<!--am#(.*?)-->/', '/<!--am#(.*?)-->/', '/\\[ad#(.*?)\\]/'); $offset = 0; $numberposts = 10; $args = array('numberposts' => $numberposts, 'offset' => $offset, 'post_type' => array('post', 'page'), 'suppress_filters' => false); $posts = get_posts($args); while ($posts) { foreach ($posts as $post) { if (!empty($post->post_content)) { $post_content = $post->post_content; foreach ($patterns as $pattern) { if (preg_match_all($pattern, $post->post_content, $matches)) { if (!empty($matches[1])) { for ($i = 0; $i < sizeof($matches[1]); $i++) { $name = $matches[1][$i]; $ad = Advman_Upgrade::_selectAd($data, $name); if (!$ad) { $name = html_entity_decode($name); $ad = Advman_Upgrade::_selectAd($data, $name); } if (!$ad) { $name = str_replace(";", "\\;", $name); $ad = Advman_Upgrade::_selectAd($data, $name); } if ($ad) { $search = $matches[0][$i]; $replace = "[ad name=\"{$name}\"]"; $post_content = str_replace($search, $replace, $post_content); } } } else { $search = str_replace("/", "", $pattern); $replace = "[ad]"; $post_content = str_replace($search, $replace, $post_content); } } } if ($post->post_content != $post_content) { $post->post_content = $post_content; wp_update_post($post); } } } $offset += $numberposts; $args = array('numberposts' => $numberposts, 'offset' => $offset, 'post_type' => array('post', 'page'), 'suppress_filters' => false); $posts = get_posts($args); } }