public function importWidgets($custom) { if (!@$custom || !@is_array($custom["sidebar"]) || !@is_array($custom["options"])) { return; } update_option("sidebars_widgets", $custom["sidebar"]); // when importing widget conf, rewrite any absolute url pointing to original theme folder $origThemeAssetUrl = $this->importer->getOrigThemeAssetUrl(); $newThemeAssetUrl = PE_THEME_URL; foreach ($custom["options"] as $name => $value) { $value = serialize($value); if (strpos($value, $origThemeAssetUrl) !== false) { $value = PeThemeUtils::fix_serialize(str_replace($origThemeAssetUrl, $newThemeAssetUrl, $value)); } $value = maybe_unserialize($value); update_option("widget_{$name}", $value); } }
public function backfill_attachment_urls() { $this->updateStats(__("Fixing urls", 'Pixelentity Theme/Plugin'), true); $url = $this->origUploadUrl; global $wpdb; $pt = $wpdb->posts; $pm = $wpdb->postmeta; $op = $wpdb->options; // replace all img/links pointing to an attachment (not imported) with url of first imported attachment $posts = $wpdb->get_results("SELECT ID,post_content FROM {$pt} WHERE {$pt}.post_content LIKE '%{$url}%'"); if (is_array($posts)) { $url = addcslashes($url, "/"); $replace = wp_get_attachment_url($wpdb->get_var("SELECT ID FROM {$pt} WHERE {$pt}.post_type = 'attachment' LIMIT 1")); foreach ($posts as $post) { $newContent = preg_replace("/{$url}[^\"]+\\.(jpg|jpeg|gif|png)/i", $replace, $post->post_content); if ($newContent != $post->post_content) { $wpdb->update($pt, array("post_content" => $newContent), array("ID" => $post->ID)); } } } // replaces all img/links pointing to an attachment residing in theme folder. $origThemeAssetUrl = $this->getOrigThemeAssetUrl(); $newThemeAssetUrl = PE_THEME_URL; // fix post metas $metaKey = 'pe_theme_meta'; $posts = $wpdb->get_results("SELECT post_id,meta_value FROM {$pm} WHERE {$pm}.meta_key = '{$metaKey}'"); if (is_array($posts)) { foreach ($posts as $post) { $value = $post->meta_value; if (strpos($value, $origThemeAssetUrl) !== false) { $value = PeThemeUtils::fix_serialize(str_replace($origThemeAssetUrl, $newThemeAssetUrl, $value)); update_post_meta($post->post_id, $metaKey, maybe_unserialize($value)); } } } }