0

I want to create one extra table filed if it is multisite's main blog (While plugin activation).

I mean like this

if (main blog) {
  execute this sql;
}
else {
  execute this sql
}

PS: This is the code for "execute this sql".

If child blog:

$sql = "CREATE TABLE tablename (
                  id bigint(20) NOT NULL AUTO_INCREMENT,
                  uid bigint(20) NOT NULL,
                  type VARCHAR(256) NOT NULL,
                  data TEXT NOT NULL,
                  credits bigint(20) NOT NULL,
                  timestamp bigint(20) NOT NULL,
                  UNIQUE KEY id (id)
                );";

If main blog:

$sql = "CREATE TABLE tablename (
              id bigint(20) NOT NULL AUTO_INCREMENT,
              uid bigint(20) NOT NULL,
              type VARCHAR(256) NOT NULL,
              data TEXT NOT NULL,
              credits bigint(20) NOT NULL,
                      globalcredits bigint(20) NOT NULL,
              timestamp bigint(20) NOT NULL,
              UNIQUE KEY id (id)
            );";

Can anyone help me?

5

You can use is_main_site conditional tag like this:

if (is_main_site()) {
  execute this sql;
}
else {
  execute this sql
}
0
2

Check for the $blogid. Main site is 1.

global $wpdb;

$mainblog = $wpdb->blogid;

if ($mainblog === 1) {
   execute this sql;
}
else {
    execute this sql
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.