Skip to content

Instantly share code, notes, and snippets.

@jmarreros
Last active October 26, 2016 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarreros/328908b36ad62dcc816f82fec39c811e to your computer and use it in GitHub Desktop.
Save jmarreros/328908b36ad62dcc816f82fec39c811e to your computer and use it in GitHub Desktop.
Usar este código en un plugin dependiente install.php de WordPress
<?php
if (array_key_exists("step",$_REQUEST) && $_REQUEST["step"] == 2){
add_action("shutdown", "dcms_install_data");
}
function dcms_install_data() {
global $wpdb, $wp_rewrite;
if (!get_option("blogname", false)) {
return;
}
ob_start();
?>
-- AQUI VA EL CONTENIDO DE LA BASE DE DATOS
<?php
$sql = ob_get_clean();
$sql = str_replace(array("@@TABLE_PREFIX@@", "@@SITE_URL@@"),array($wpdb->prefix, get_option("siteurl")),$sql);
$lines = explode("\n", $sql);
$query = "";
foreach ($lines as $line) {
$line = trim($line);
if (strlen($line)==0) continue;
if (substr($line,-1)==";") {
$query.=" ".$line;
$wpdb->query($query);
$query = "";
} else {
$query.=" ".$line;
}
}
$wp_rewrite->flush_rules();
wp_cache_flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment