The MU forums have moved to WordPress.org

How do I write to the wordpress database via script? (6 posts)

  1. vestaviascott
    Member
    Posted 14 years ago #

    Hi all, I've developed a theme system and I want it to do a double duty of setting up some default option values in the database.

    So here's what I'm trying to do...

    When the template is installed, I want the installer to also...

    1) Set permalinks to /%postname%/
    (I'm assuming its a simple update statement on the wp_options table)

    2) Set "uploads_use_yearmonth_folders" to 0 (the default is true, I want it to be false)

    3) Set privacy options (blog_public) to 1 (the default is false)

    Any help much appreciated. Seems simple enough to update a few fields in the db, but I'm not sure how to create a connection and also if I can intercept the template build process to make these edits programmatically or if it will need to be a manual button click on the template's options screen (or perhaps even via a plug in)

  2. vestaviascott
    Member
    Posted 14 years ago #

    I realize all these things can be done manually from their respective dashboards, however, this template will be used by novices and it takes a 6 page PDF to describe how to do these 3 simple things.

    They should be automatically done via scripting without the user having to mess with any of this.

  3. SteveAtty
    Member
    Posted 14 years ago #

    I think that you'll find you can do all of those through the built in WPMU and WP functions:

    http://codex.wordpress.org/WPMU_Functions

  4. DeannaS
    Member
    Posted 14 years ago #

    You're going to want to use a functions.php file in your theme. If you look at my new blog defaults plugin, you can see code to do most of the things. (And, if you're just using 1 theme, or want the defaults throughout your site, you can just use that plugin.)

    http://wpmudevorg.wordpress.com/project/New-Blog-Defaults

  5. vestaviascott
    Member
    Posted 14 years ago #

    In the end it was so simple, I'm almost embarrassed to post the solution...

    <?php update_option( $option_name, $newvalue ); ?>

  6. andrea_r
    Moderator
    Posted 14 years ago #

    Just think how helpful it will be to others to learn from. :)

About this Topic

  • Started 14 years ago by vestaviascott
  • Latest reply from andrea_r