Support » Networking WordPress » Adding Pages to Every WordPressMu Subdomain With a Script

  • Hello I have multiple User Blogs that I want to have certain pages on every user blog. For Example say I have the /page-1/ page that I want to mirror on ever blog user. When I have 25 blogs it gets really annoying to constantly go to the backend of the blog then create the page 25 times!

    user1.wpinstall.com/page-1/
    user2.wpinstall.com/page-1/
    user3.wpinstall.com/page-1/
    user4.wpinstall.com/page-1/

    So I want to write a script that creates these pages for ever subdomain

    I wrote a script that checks for the page and creates the page if it is not found;

    $pages=
    array(
        array("visualization.php","visualization","Visualization"),
        array("my-study.php","study","Study")
         );
    $page=$pages[0];
    
    function checkPage(array $page,$i)
    {
        echo "Searching ".$page[1]." ";
    
        $Command="SELECT ID FROM ".DATABASE."_wordpressmu.wp_".$i."_posts WHERE <code>post_type</code> = 'page' AND <code>post_name</code>='$page[1]'";
        $query=SQLWrap::Execute($Command, __line__, __file__);
        $row=mysql_fetch_array($query);
    
        if(isset($row['ID']))
        {
            echo "<b>ENTRY FOUND</b>";
            return $row['ID'];
        }
        else
        {
            echo "<i>NO</i>";
            return false;
        }
    
    }
    function createPage(array $page,$i,$domain)
    {
    
          $root=$domain;
    
          if(isset($page[3]))
          {
             $root.=$page[3];
          }
          else
          {
              $root.=$page[1]."/";
          }
          //root is for guid
    
          //create page
          $Command="
          INSERT INTO ".DATABASE."_wordpressmu.wp_".$i."_posts
          (<code>post_author</code>, <code>post_date</code>,              <code>post_date_gmt</code>,             <code>post_content</code>, <code>post_title</code>,    <code>post_excerpt</code>, <code>post_status</code>, <code>comment_status</code>, <code>ping_status</code>, <code>post_password</code>, <code>post_name</code>,    <code>to_ping</code>, <code>pinged</code>, <code>post_modified</code>,          <code>post_modified_gmt</code>,         <code>post_content_filtered</code>, <code>post_parent</code>, <code>guid</code>,                                              <code>menu_order</code>, <code>post_type</code>, <code>post_mime_type</code>, <code>comment_count</code>) VALUES
          (2,             '".date("Y-m-d h:i:s")."','".gmdate("Y-m-d h:i:s")."', '',             '$page[2]',       '',            'publish',     'closed',         'closed',      '',              '$page[1]',     '',       '',       '".date("Y-m-d h:i:s")."','".gmdate("Y-m-d h:i:s")."',  '',                       0,            '$root', 0,           'page',      '',                0);";
    
           $query=SQLWrap::Execute($Command, __line__, __file__);
    
           //after creating the page get the page's ID and add meta data
           $ID=checkPage($page,$i);
    
           $Command="
            INSERT INTO ".DATABASE."_wordpressmu.wp_".$i."_postmeta
            (<code>post_id</code>, <code>meta_key</code>,          <code>meta_value</code>) VALUES
            ($ID,       '_wp_page_template', '$page[0]'),
            ($ID,       '_aioseop_title',    '$page[2]'),
            ($ID,       '_edit_lock',        '".time()."'),
            ($ID,       '_edit_last',        '2');";
    
          $query=SQLWrap::Execute($Command, __line__, __file__);
    }

    However this script doesn’t work consistently. It works for a few blogs but not all of them.

    My question is

    What SQL commands should I execute to create a new page on the fly?

  • The topic ‘Adding Pages to Every WordPressMu Subdomain With a Script’ is closed to new replies.