Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • Nuno Morgadinho 12:16 pm on March 8, 2010 Permalink | Reply  

    Support Fernando Nobre 

    For the 2011 Portuguese Presidential elections I will be supporting Fernando Nobre. Not that anyone cares but I thought I should mention it. For that reason I’ve added to my blog a small support banner linking to the campaign site.

    I’ve also been thinking how I can contribute and help with the campaign, and how to enable people that are interested in helping out to do so effectively, besides the obvious sign-up for voluntary help at the campaign site.

    If you have a Wordpress blog, I’ve made public a widget you can use on the sidebar of your blog to display a small image banner just like the one I’m using. It’s an easy way of showing our support and it’s very easy to install:

    1. Inside the WordPress admin, go to Plugins -> Add New and search for ‘Fernando Nobre’.
    2. Click ‘Install’.
    3. Inside the WordPress admin, go to Appearance > Widgets, and add the ‘Apoio Fernando Nobre’ widget where you want, then save the changes.
    4. That’s it!

    And here’s the link to the plugin page:

     
  • Nuno Morgadinho 3:16 pm on February 16, 2010 Permalink | Reply  

    Internationalizing Your Wordpress Plugin 

    We call “internationalization” to the process of setting up software so that it can be used in different languages. In my case I had a plugin with text strings in English and I wanted to add a Portuguese translation. In wp-config.php I set up the WPLANG variable to pt_PT:

    define ('WPLANG', 'pt_PT');

    I then used poEdit, a localization tool that works with Mac OS X and that can be downloaded from the poEdit download page. In poEdit, from the File menu select ‘New Catalog’. Fill in the information there and in the ‘Paths’ tab put the plugin directory. In the ‘Keywords’ tab add the missing entries so it looks like this:

    At this point it should recognize all the text strings in your code and present a screen where you can add the translations. After that be sure to save the file as pluginname-pt_PT.po, preferably in a directory called ‘translations’ or ‘locales’ (but anything will do). After that you’re all set. In your code you should load the translation like this:

    load_plugin_textdomain ( 'your-plugin-name' , FALSE , '/your-plugin-name/translations' );

    And strings should have the form:

    _e('Choose a Category','your-plugin-name');

    That’s it. Let me know if you run into troubles :)

    Resources & Further Reading for the Geeks:

     
  • Nuno Morgadinho 11:53 am on January 12, 2010 Permalink | Reply  

    WPMU posts return 404 not found 

    I’ve installed Wordpress MU on a fresh Apache httpd and I go to try it out. I start by clicking on the ‘hello world’ post that comes as default and the page returns a 404 “not found” message. What is happening? This keeps happening to me all the time so I might as well share it here for others.

    This can be fixed this by setting “AllowOverride to All” in the httpd.conf file, in the relevant Directory directive section where MU is installed.

     
  • Nuno Morgadinho 3:43 pm on November 26, 2009 Permalink | Reply  

    Manage Multiple Wordpress Installs 

    I was wondering how to admin several Wordpress installs from the same interface and came out with this simple idea of having a tab container where each tab would give access to the Wordpress admin panel.

    This can be quite simple to develop by putting together a jQuery tab container and iframes.

    This could be further extended in a way that one single login would authenticate across all the Wordpress installations. In this way we can manage the several installs from one single interface with full flexibility, i.e. we have exactly the same options as if we open separate windows and log into the installations.

    Check out the example demo. Try going to Tab number 2 and logging in as user: admin / password: demo123

     
  • Nuno Morgadinho 6:07 pm on November 25, 2009 Permalink | Reply  

    Authentication by POST/GET in Wordpress 

    For a project I’m working on I needed to trigger an action in a remote Wordpress installation. I had a bit of trouble understanding how I could authenticate myself against the remote site. Eventually I found a clean and nice way and I want to share it here with you. Of course, if you’re not into Wordpress you can safely skip this post.

    The Problem

    Where I first stumbled was when from my plugin I tried to access directly the other plugin in the remote site. The code I was using for doing this was something like:


    // create curl resource
    $ch = curl_init();
    // set url
    curl_setopt($ch, CURLOPT_URL, "http://wordpress.mu/wp-admin/admin.php?page=myplugin");
    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // $output contains the output string
    $output = curl_exec($ch);
    // close curl resource to free up system resources
    curl_close($ch);
    // print the result of the whole request:
    print "CONTENT = ".$output;

    And this wouldn’t work because although I was authenticated in the remote site via the browser, the session that the curl request creates is not, and so this request results in us being redirected to the login page.

    What to do?

    Ideally we want to do a POST request that we execute before and that authenticates us. I searched around on how to do this but couldn’t find anything. What I found was one of the many third-party applications that allow talking to Wordpress remotely. I then looked at how they work and how they authenticate themselves.

    Instead of doing a POST request to the plugin page like before, they do a POST request to the site’s index.php. A plugin is registered to catch a particular POST request. Then you simple use the Wordpress function user_pass_ok(), that authenticates the user against the database.

    Here I demonstrate how to do this using a GET request, because its simpler, but the same thing would work with a POST request.

    add_action('plugins_loaded', 'unpackimport_createblog', -1);
    function unpackimport_createblog() {
    if(isset($_GET['myplugin'])) {
    if(user_pass_ok($_REQUEST['username'], $_REQUEST['password']))
    echo 'Authentication successful';
    }

    And the client request:

    curl_setopt($ch, CURLOPT_URL, "http://wordpress.mu/index.php?myplugin=true&username=test&password=testpass");

    Screencast

    I wanted to show a working example rather than just saying this works so I did this screencast. You can also download the plugins yourself and try them out.

    Download

    unpack_import_demo.tar.gz
    dump_pack_demo.tar.gz

     
  • Nuno Morgadinho 1:06 pm on November 19, 2009 Permalink | Reply  

    Changing the Default Blog in Wordpress MU 

    Wordpress MU is a platform that allows you to host and manage multiple Wordpress installations. It is used to power Wordpress.com, among other sites.

    The basic of Wordpress MU is that the user registers and upon the click of a button, a blog is generated for him, available to use immediately.

    The default blog that is generated is the most basic thing you can get. It uses the default Kubrick theme, no plugins or widgets, and a bit of example content (a post, a page, a comment and some links).

    I’m working on a Wordpress MU project now and I had to change the default blog to something more elaborate. So I went and researched a bit what can be done and what is supported. Here’s what I’ve found.

    There are a couple of MU plugins that allow you through an admin panel to edit some defaults (blog title, default theme, stuff like that). If you’re into that kind of thing see the New Blog Defaults plugin. But in fact what I wanted was something more along the lines of developing my default blog locally (in a local MU installation) and then deploy to the production site with minimum hassle.

    I found another plugin called Blog Templates and with it you can create a template from a blog. This template will be saved in a different database table ‘wp_gp_templates’ and will contain posts, pages, links, post categories and some blog options. You can easily extend it by adding more options to be saved if you need to. You can then upload the template to the production server and it will be applied as a template to new blogs. Pretty cool.

    exclude pages plugin

    I had a plugin to exclude certain pages from the menu. This was a question of adding an extra option to be saved in the template. *

    copying plugin settings

    Information about what plugins are active is kept inside the options table and so it can be saved quite easily:

    $newoptions['active_plugins'] = get_option(‘active_plugins’);

    A problem with this is you still need to make sure all the plugins you had locally installed are on the server. Not a big deal but something to keep in mind.

    copying widget settings

    Widget settings are also kept inside the options table so it’s not a big deal to extend the plugin to also save them (you still need to work out which options to save though). Because normally widgets are registered from plugins you again need to make sure all the plugins you had locally are on the server.

    theme

    The theme name is saved in the template but you still need to manually make sure all the theme files are on the server, and if not, upload them.

    post meta / custom fields

    I extended the plugin to clone all of the meta items for a post. This seems to work quite well without any problems. I might work together with the plugin author to include this as an option in the plugin or maybe release the code here separately.

    * A problem with this is that because the pages are excluded based on their ID, you need to be sure that the pages will be created with the same ID that is saved to the template (this is a problem if you have created pages and then deleted them because the IDs will not be the first ones).

     
    • dr. noam sadovnik 3:50 pm on November 21, 2009 Permalink

      Are you planning on making your updated version of this plugin available to public either here or via plugin author?

      I’m interested in your modifired version of this plugin and also some other options. What about the ability to manage multiple wodpress MU installs and automate bulk blog creation with blog template preferrences applied?

      I manage a bunch of seperate MU installs and would like the ability to bulk create blogs say 5 at a time each blog though on a seperate MU install.

      Thanks.

    • tabard 11:26 am on November 22, 2009 Permalink

      The most relevant part of it is the functionality that clones the postmeta/custom fields. I’ve sent that to the plugin author and he has integrated it, which is very cool :-)

      Take a look here if you’re interested:
      http://gregbreese.wordpress.com/2009/11/22/cloning-a-blog-now-copies-all-post-meta-items/

    • eDDi Hughes 2:22 pm on December 29, 2009 Permalink

      This is great. I Googled “wordpress mu new blog clone” and found this on the front page. I was wondering if anyone else out there was doing this. Basically what I was looking for was a way to clone a wordpress blog, duplicate a blog or rewrite what the default content was. I looked at wpmu-functions.php and index-install.php – I DID NOT want to alter core files because in an upgrade it would be overwritten.

      Tabard, I’m really happy you blogged about this and provided links. I was worried I’d have to start digging in the trenches!

      I found a similar thread, but they were in the database copying tables. I think it was for a specific application, but I thought I’d shine some light on your post for future searchers.

      Happy Holidays!

    • eDDi Hughes 1:37 pm on December 30, 2009 Permalink

      Question on extending Blog Templates, by extending, do you mean manually adding the wanted options / tabels to ‘wp_gp_templates’?

    • eDDi Hughes 2:48 pm on December 30, 2009 Permalink

      Excuse my previous post, I misunderstood what you mean in your post. I went into template_url/tools/theme_options.php change the defaults, then created default for Blog Templates and went crazy. ^_^

  • Nuno Morgadinho 5:24 pm on November 17, 2009 Permalink | Reply  

    Wordpress JSON API 

    dphiffer created a plugin that exposes a JSON API for Wordpress. This is quite cool and can be used to create a front-end that displays content served from a WordPress back-end. In his case he was using Ruby on Rails for the front-end but I can imagine other cases where this would be useful. I’ll definitely going to give this a try sometime.

    http://wordpress.org/extend/plugins/json-api/

     
  • Nuno Morgadinho 1:58 pm on November 13, 2009 Permalink | Reply  

    Wordpress Child Themes 

    What are Wordpress Child Themes and why are they useful?
    http://themehybrid.com/themes/hybrid/child-themes

    A case for including child themes in the official Wordpress theme directory
    http://developdaly.com/wordpress/child-theme-inclusion-in-the-wordpress-directory/

    Vote for Child Theme Inclusion in the WordPress Directory
    http://wordpress.org/extend/ideas/topic.php?id=3264

     
  • Nuno Morgadinho 9:30 pm on October 16, 2009 Permalink  

    Wordpress Media Buttons 

    If you know Wordpress, you know it is a great publishing platform. For a particular plugin I wanted to build I started looking at how to add one of those little icons you have access while writing a post, e.g. ‘Add an Image’, etc.

    I was looking at how other plugins do this and found this code:

    function wp_myplugin_media_button() {
    	$context = __('Add media: %s');
    	$wp_myplugin_media_button_image = '/path/media_button.gif';
    	$wp_myplugin_media_button = '<a href="media-upload.php?type=wp_myplugin&amp;TB_iframe=true" class="thickbox">
      <img src='".$wp_myplugin_media_button_image."' /></a>".' %s';
    	return sprintf($context, $wp_myplugin_media_button);
    }
    add_filter('media_buttons_context', 'wp_myplugin_media_button');
    

    But when I tried this in my plugin something weird happened. If both my plugin and the one from where I took this code were active, then only the button from the other plugin would appear. If I disabled the second one then it worked. Why, oh why? After struggling a bit I found the answer.

    The way the function is receiving the context is not correct. Both functions are asking for the default “context” (this is the media buttons themselves) and then adding something to it. The correct way to receive the context is to have it as an argument of the function. In that way it can be updated without a problem. Example follows:

    function wp_myplugin_media_button($context) {
    	$wp_myplugin_media_button_image = '/path/media_button.gif';
    	$wp_myplugin_media_button = '<a href="media-upload.php?type=wp_myplugin&amp;TB_iframe=true" class="thickbox">
      <img src='".$wp_myplugin_media_button_image."' /></a>".' %s';
    	return sprintf($context, $wp_myplugin_media_button);
    }
    add_filter('media_buttons_context', 'wp_myplugin_media_button');
    

    Update: if you want to add the button to the end of the media button list just append the %s first, e.g.:

    function wp_myplugin_media_button($context) {
    	$wp_myplugin_media_button_image = '/path/media_button.gif';
    	$wp_myplugin_media_button = ' %s' . '<a href="media-upload.php?type=wp_myplugin&amp;TB_iframe=true" class="thickbox">
      <img src='".$wp_myplugin_media_button_image."' /></a>";
    	return sprintf($context, $wp_myplugin_media_button);
    }
    add_filter('media_buttons_context', 'wp_myplugin_media_button');
    

    Hope it helps someone. Cheers.

     
    • k3 10:31 pm on October 25, 2009 Permalink

      This is actually really helpful, thank you! I was struggling with a similar issue.

      This isn’t specifically related to your code above, but I’m not sure how to add my custom media button to the end of the media button list instead of the beginning (as this code does). Any suggestions?

    • Nuno Morgadinho 4:12 pm on October 26, 2009 Permalink

      Hi k3,

      I’ve updated the post to show how to add it to the end of the media button list. It’s actually quite simple.

      Cheers,
      Nuno

  • Nuno Morgadinho 2:16 pm on March 14, 2006 Permalink
    Tags: Wordpress   

    Extracting Wordpress: The Right Way 

    Yesterday I worked ten hours. That’s not bad, at least for me. From 15:30h-20h and then from 21:30h-2h. Today I’m taking the morning to relax and get my news “fix”.

    I must confess, this blog thing never quite worked for me. I always think too much before I write something and so spend a lot of time before writing anything and I can’t not always afford that. I got myself a blog in the first place because I wanted to be able to update my site on-the-fly and though this was the best way.

    People change. And that’s good. For example, until recently, I never seriously consider the chance of buying a Mac. And now I do, so you never know what will happen.

    Upgraded to Wordpress 2.0.2. I’m curious on how others are dealing with the plugin deactivation on the upgrade process. For example, for me, since I’m using Dokupress, while I’m upgrading, the posts fall back to normal syntax instead of Doku syntax.

    Also, when upgrading Wordpress, when you need to extract the WordPress package, if you issue tar within the blog directory you will end with a wordpress directory inside your blog, which sucks. Of course I could extract it and then ‘mv wordpress morgadinho.org’ but that isn’t sexy enough as I have other directories inside my blog directory. I tryed creating a symlink in ../blogdirectory called wordpress but then tar would destroy the link instead of following it.

    Then I found the -h option to tar that makes it follow symlinks and so this worked:

    $ ln -s morgadinho.org wordpress
    $ tar
    -zxvf ~/latest.tar.gz -h -C .
    

    Of course I could also talk about what I’m working on, but I’ll leave that for another day.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel