Half-Elf on Tech

Thoughts From a Professional Lesbian

Tag: unsupported

  • WordPress Upgrade Script

    WordPress Upgrade Script

    I don’t like the automated updater. I don’t know why, I just don’t. I have this stupid simple script I use instead. I cleaned it up before posting here. But this is what I use when I want to upgrade my various installs to the latest version, or the nightly build. I didn’t bother to put the svn stuff in here, since the script I use for that is fairly weird and particular to me.

    #!/bin/bash
    
    ####################################################################
    # WORDPRESS.SH - WordPress Upgrade Script for BASH SHELL           #
    #                                                                  #
    # This script will download and copy up WordPress to the account.  #
    # It's pretty simple, with the bare minimum of error checking. So  #
    # be careful.                                                      #
    #                                                                  #
    # Author: Mika Epstein                                             #
    # URL: https://halfelf.org/hacks/wordpress-upgrade-script/     #
    #                                                                  #
    # Usage: ./wordpress.sh version                                    #
    #                                                                  #
    #                                                                  #
    # This program is free software; you can redistribute it and/or    #
    # modify it under the terms of the GNU General Public License as   #
    # published by the Free Software Foundation; either version 2 of   #
    # the License, or (at your option) any later version.              #
    #                                                                  #
    # This program is distributed in the hope that it will be useful,  #
    # but WITHOUT ANY WARRANTY; without even the implied warranty of   #
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    #
    # GNU General Public License for more details.                     #
    #                                                                  #
    ####################################################################
    
    if [ "$1" = "" ]
    then
      echo "EXIT: FAILURE! Call this as './wordpress.sh VERSION', you nut!"
      exit
    fi
    
    # Quick check if someone wants the nightly build with a 'You sure?' 
    # double check.
    # This sets the URL, as it's different for the nightly builds.
    if [ "$1" = "nightly" ]
    then
      DOMAIN=wordpress.org/nightly-builds
      VERSION=wordpress-latest
     
      read -p "Are you sure you want to install the NIGHTLY build? (y/n) " -n 1
        if [[ ! $REPLY =~ ^[Yy]$ ]]
        then
          echo
    	  echo "You have opted NOT to install the nightly build of WordPress."
          exit 1
        else
    	  echo
        fi
    
    else
      DOMAIN=wordpress.org
      if [ "$1" = "latest" ]
      then
        VERSION=latest
      else
        VERSION=wordpress-$1
      fi
    fi
    
    # Download WordPress
    wget -q http://$DOMAIN/$VERSION.zip
    
    # If the file didn't download, then you probably got the URL wrong. Fail.
    if ! [ -f $VERSION.zip ]
    then
      echo "EXIT: FAILURE! Could not download $VERSION.zip - Did you get the version right?"
      exit
    else
      echo
      unzip -q $VERSION.zip
    fi
    
    # This is ONE LAST CHANCE. If you say anything other than yes, then it cleans up.
    read -p "Last chance.  You sure you want to install WordPress $1 for $USER? (y/n) " -n 1
      if [[ ! $REPLY =~ ^[Yy]$ ]]
      then
        rm -rf wordpress/
        rm $VERSION.zip
    	echo
    	echo "EXIT: You have chosen NOT to install WordPress $1 at this time."
    	exit 1
      else
        echo
      fi
    
    # Get rid of hello dolly and akismet 
    rm -rf wordpress/wp-content/plugins/akismet
    rm wordpress/wp-content/plugins/hello.php
    
    # Copy the files up to root public_html
    # Change this if you want to install to a subfolder or whatever.
    cp -r wordpress/* public_html/
    
    # Post install clean up with a 'I don't know what you did!' error.
    if [ -f $VERSION.zip ]
    then
      rm -rf wordpress/
      rm $VERSION.zip
      echo "SUCCESS! You're on WordPress $1."
    else
      echo "POSSIBLE FAILURE. Could not clean up the files, so there's a chance everything went pear shaped."
      echo "Please review your WordPress install and remember: Blame Nacin."
    fi
    
    exit
    

    The fix to ‘Oh shit, I installed WordPress 2.1 instead of 3.1!’ is to re-run it correctly, by the way. So long as you haven’t logged in to your site, you won’t update the database, so a backout is always a re-run, even in the real world.

  • bbPress 1.x Functions

    bbPress 1.x Functions

    Since I don’t actively develop for bbPress 1.x at this time, you’re on your own with these ones.

    bbPress is a forum platform by the same people who do WordPress. It’s very much a barebones bulletin board system (which makes layers on layers of bb jokes). bbPress is not for the non-techy at this point. It’s still in alpha mode, with a lot of rough edges, and is comparable to WordPress 1. Maybe. Most of the features are done as plugins, rather than defaults, so you don’t get things like PMing and Quick Tags and inline images. You have to add in plugins for that. While I was using it, I wrote a few of my own plugins and hacks to make things work like I wanted.

    All of these hacks can be directly applied to the functions.php file of your theme.

    Change ‘Sticky’ to an image

    If you make a topic sticky it gets ‘pinned’ to the top of the forum. This great for things like announcements etc. It’s really annoying that it’s hard to change. I wanted a post-it image to show that it was pinned, so I made a function to delete the default function and replace it with my own.

    This goes in your functions.php for your theme, just like it would for WordPress

    <?php
    // This sets sticky label as an image
    remove_filter('bb_topic_labels', 'bb_sticky_label', 20);
    function my_sticky_label( $label ) {
            global $topic;
            if (is_front()) {
                    if ( '2' === $topic->topic_sticky ) {
                            return sprintf(__('<img src="/images/sticky.png" alt="&#91;sticky&#93;" /> %s'), $label);
                    }
            } else {
                    if ( '1' === $topic->topic_sticky || '2' === $topic->topic_sticky ) {
                            return sprintf(__('<img src="/images/sticky.png" alt="&#91;sticky&#93;" /> %s'), $label);
                    }
            }
            return $label;
    }
    add_filter('bb_topic_labels', 'my_sticky_label', 20);
    ?>
    

    Change the text of a ‘Closed’ topic

    By default when you close a topic it renames the topic to Closed: Topic Name. I wanted to change that to Read Only: Topic Name, so what I did was delete the old closed filter and replaced it with my own.

    <?php
    // This sets closed lable to read as 'read only'
    remove_filter('bb_topic_labels', 'bb_closed_label');
    function my_closed_label( $label ) {
            global $topic;
            if ( '0' === $topic->topic_open )
                    return sprintf(__('[Read Only] %s'), $label);
            return $label;
    }
    add_filter('bb_topic_labels', 'my_closed_label');
    ?>
    

    Woopra

    If you use Woopra to monitor traffic and Gravatar for icons, you may notice that just slapping Woopra’s tracker in the bottom of your site doesn’t show the Gravars. Since bbPress themeing is what it is, I put this in my theme’s footer.php file to make gravatars show up in my Woopra console. The trick was getting it to extract the logged in user’s email. So here it is. Put this in your footer file and Woopra will show gravatars.

    <!-- Woopra Code Start -->
    <?php
            global $user_id, $user_email, $user_identity;
            $woopra_name = bb_get_current_user_info( 'login' );
            $woopra_email = bb_get_current_user_info( 'email' );
            if ( $woopra_name == '') {
                    echo "<script type=\"text/javascript\">";
                    echo "\n";
            }
            else {
                    echo '<script type="text/javascript">';
                    echo "\nvar woopra_visitor = new Array();";
                    echo "\nwoopra_visitor['name'] = '$woopra_name';";
                    echo "\nwoopra_visitor['email'] =  '$woopra_email';";
                    echo "\nwoopra_visitor['avatar'] = 'http://www.gravatar.com/avatar/" . md5(strtolower($woopra_email)) . 
                    "&amp;size=60&amp;default=http%3A%2F%2Fstatic.woopra.com%2Fimages%2Favatar.png';";
                    echo "\n";
            }
    ?>
    var _wh = ((document.location.protocol=='https:') ? "https://sec1.woopra.com" : "http://static.woopra.com");
    document.write(unescape("%3Cscript src='" + _wh + "/js/woopra.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <!-- Woopra Code End -->