Plugins Development Update

Posted by & filed under Wordpress.

It’s been a while since I last updated the website and the plugins. I’ve received a lot of feedback of my plugins, some change requests, bugs, and general comments about the code.

I would like to say that I really appreciate all the comments about my plugins. It makes me feel good knowing that the piece of code I wrote for the community is currently being used.

I’m going to make an effort to update some of my plugins to work with latest versions of WordPress and bbPress and try to do some of the work specified on the TODO list.

Supported plugins

Unsupported plugins

Stay tuned for updates!

bbPress Like Button Plugin

Posted by & filed under Wordpress Plugins.

You can download my WordPress Plugin: bbPress Like Button clicking here.

What does the plugin?

bbPress Like button adds automatically a Like Button (Youtube alike) in all your forum posts and replies. It allows users to give some greetings to others contributions.

Plugin fully compatible with bbPress 2.5 and WordPress 3.8

How do I install de plugin?

Just download it from the WordPress plugins repository, activate it and enjoy!

Screenshots

Likes Log Screen. You are able to see all likes in a fancy grid.

bbPress Like Button

Likes Stadistics. This screen shows top 10 users

bbPress Like Button

Example of Like Button

bbPress Like Button

TODO/Wishlist

Dashboard

  • export likes log to CSV
  • reply/post list view column with like number in the dashboard
  • reset logs button
  • add do_action and apply_filters
  • BuddyPress Activity Stream integration
  • Option: allow like only replies (exclude OP)
  • Option: email notification on like

Frontend

  • icons set
  • unlike
  • widget most liked post/user

Plugin info

Current version: 1.4
Author: Jordi Plana
Release log:

1.4

  • **MAJOR UPGRADE**
  • Fixed broken plugin
  • Removed custom database table creation and usage
  • Moved all data saving to WordPress native tables
  • Fixed static files loading
  • Rework on Like logs (removed date timestamp and sortable options for the grid)
  • Code clean up
  • New translation: Serbo-Croatian

1.3

  • Fixed activation hook error (creating plugin table)
  • Added Macedonian language

1.2

  • Fixed error with the Grid (Likes Log)
  • Fixed AJAX Error
  • Settings page
  • Data sanitization (security)

1.1

  • Typo Errors

1.0

  • Initial release.

bbPress Protected Forums Plugin

Posted by & filed under Web development, Wordpress, Wordpress Plugins.

You can download my WordPress Plugin: bbPress Protected Forums clicking here.

What does the plugin?

bbPress Protected Forums adds a metabox, shown while editing a forum, that allows you to disable new topic creation for determined user roles.

The plugin is perfect for those situations that you may want your users to see the list of topics of a forum but don’t want them to create new topics.

Plugin fully compatible with bbPress 2.x

How do I install de plugin?

Just download it from the WordPress plugins repository, activate it and enjoy!

Screenshots

Plugin info

Current version: 1.0
Author: Jordi Plana
Release log:

1.0

  • First version

WordPress: Broken plugins, missing sidebar and widgets gone after migration

Posted by & filed under Web development, Wordpress.

Scenario

It is very common that we want to change our WordPress URL. For example when moving from development stage to final public release.

Problem

WordPress makes an intense use of serialize in order to make array persistent in the database. Serialization converts Arrays to Strings and stores some information the Array, such as the length of each value. If we make a massive URL update with the new URL we may look our plugins stop working, sidebar disappearing, widgets not showing and other kind of settings not working.

Solution

After several migrations I have made a tiny script that fixes this issue. The script searchs for serialized settings inside the wp_options table, it unserializes and replaces the old URL for the new one and updates this option.

Download WordPress Serialize Fix Script clicking here.

For a safe migration you should follow this instructions:

Caution:
Before doing any database modification be sure to make a backup. In case of error you should restore the backup.

  1. Backup the original database (with the old URL).
  2. Import the database to the new host, if necessary.
  3. Download the script from here, and upload to your WordPress root folder.
  4. Edit wp-fixserial.php. Change oldomain.com and newdomain.com values.
  5. Execute wp-fixserial.php and wait for the script to finish.
  6. Follow the instructions in this post to update your database: http://jordiplana.com/wordpress-how-to-update-database-urls-in-a-recently-moved-installation
  7. Flush permalinks.
  8. EXTRA: Search in your theme and plugins for hardcoded URLs. Is a really ugly practise but you will be surprised how many times people do it…

I hope you ended successfully. Please let me know in that case!

WordPress + W3 Total Cache: Force cache reload for CSS, JS or Images

Posted by & filed under Web development, Wordpress.

Scenario

It is very common to use W3 Total Caché plugin to optimize our WordPress loading time. This plugin provides lots of tools to achieve web caching: page cache, database cache, browser cache, minification, etc.

Problem

After uploading changes in a file (css, js or image) we don’t see any update. Probably if we force browser caché reload with Ctrl + F5, or just empty cache, we will be able to see the update.

How can we avoid our users to force their browser’s cache reload?

Solution

The solution to this ‘residual browser cache’ is the file versioning. Let’s see how does this work.

We have to add a suffix to the filename in every include in our theme or plugin. For example:


<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>?v=0.1" />


<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/functions.js?v=0.5a"></script>

In the previous example I have added the suffix ?v=XX, to the filename, where XX is the number of the version.

When we do any update on these files we have to change the number of the version (or revision) and clean the page cache in order to force browsers to update.

Comments, questions, suggestions?

bbPress 2.1 Spanish Language Pack Complete

Posted by & filed under Web development, Wordpress, Wordpress Plugins.

Recently I have been working in a project based in BuddyPress that uses bbPress as forum platform.

After a long time searching for the spanish language pack for bbPress 2.1, with no success, I have decided to download the language pack half-translated from Glotpress and complete the translation to Spanish (Spain).

Download language pack Spanish (Spain) for bbPress 2.1 clicking here.

Installation instructions

  1. Download the language pack from here.
  2. Unzip the files and upload to your WordPress directory /plugins/bbpress/bbp-languages/

P.D. If  you don’t see any change be sure that your file wp-config , in the WordPress root folder, contains the next line of code:

define('BBLANG', 'es_ES');

Notes

  • I have made the translation by myself for free.
  • If you find any string that you want to change feel free to do it by editing the file bbpress-es_ES.po with Poedit.
  • If you post this language pack anywhere else I would appreciate a backlink.

Links

WordPress Plugin: 404 Simple Redirect

Posted by & filed under Web development, Wordpress.

You can download my WordPress Plugin: 404 Simple Redirect clicking here.

What does the plugin?

This plugin hooks the normal WordPress workflow in order to determine if the request is processing will cause a 404 HTTP error. In that case it prevents WordPress to do any other processing and sends the user to the page defined in the plugin options.

How do I install de plugin?

Just download it from the WordPress plugins repository, activate it and enjoy!

Plugin info

Current version: 1.2
Author: Jordi Plana
Release log:

1.2

  • Fixed empty URL bug +info
  • Added localization

1.1

  • Fixed typo errors
  • Added settings link from plugin page

1.0

  • First version

WordPress Multisite: How to query posts from any site from the network

Posted by & filed under Web development, Wordpress.

Scenario

WordPress Multisite allows us to have a network of blogs. Many times the sites from the network may be related, and also the information they contain.

Problem

What to do if you are developing a theme, or a plugin, for one of your sites and you want to query posts from another site?

Solution

You can use the function switch_to_blog() to change the database we are using. A way to do this would be:

  1. Save current blog_id
  2. Change blog_id with switch_to_blog function
  3. Do the query (query_posts, get_posts, etc)
  4. Restore original blog_id

Here is an example code snippet:

global $blog_id;
$original_blog_id = $blog_id;

//$new_blog_id should contain the blog_id we want to query
switch_to_blog( $new_blog_id );

//query instructions ...

switch_to_blog( $original_blog_id );

Comments, questions, suggestions?

WordPress: How to redirect 404 errors to plain HTML pages

Posted by & filed under Web development, Wordpress.

Scenario

Sites with high volume of content may have some moved, deleted or badly referenced content. This situation will cause a 404 http error.

Problem

In high performance sites the previously described situation can be a resource problem. It is not necessary that we load completely the site to show a 404 error page.

Solution

Loading a plain HTML page will result easier for our web server than loading a complete CMS instance.

With a few lines of code we can hook the WordPress normal loading in order to determine if a 404 error has been produced. If we detect this situation we will make a redirection to a plain HTML page, interrupting the normal WordPress loading process.

Copy and paste the next code snippet into your functions.php, in your theme folder. Create a new plain HTML, name it 404.html and upload it to the site’s root.

add_action('wp','determine_if_404'); 

function determine_if_404(&$arr){
    global $wp_query;
    
    if($wp_query->is_404){
        header('Location: '.get_bloginfo('siteurl').'/404.html');
        die;
    }
}

Comments, questions, suggestions?

WordPress: Widgets anywhere using Custom Sidebars

Posted by & filed under Web development, Wordpress.

Scenario

WordPress uses the theme defined sidebars as widget containers. In most of the themes you will find that sidebars are located on right/left hand of the post content. Maybe we will want to define sidebars in another position of the theme.

Problem

For example if we want to show the language selector widget in the header area. We should be able to define a custom sidebar in the header of the theme.

Solution

First of all we need to register a new sidebar in functions.php, in the root folder of our theme. We will use the register_sidebar WordPress function to do it. You can copy and paste the following code snippet:

<?php
//We hook our action on widgets_init
add_action('widgets_init','jplana_widgets_init');

function jplana_widgets_init(){
    $args = array(
        'name'          => 'Header Widget Zone',
        'id'            => 'header-widget-zone',
        'description'   => '',
        'before_widget' => '<div class="side-nav header-widget-zone">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>' );
    register_sidebar($args);
}
?>

Now we have registered our new sidebar and we should be able to see it at the backend side. You can find the new sidebar in Appeareance > Widgets. We add and configure all widgets we want to show in that zone.

The next step is to render the new sidebar. We will use the WordPress function dynamic_sidebar. In our example, we open header.php and paste the next code snippet:

<?php if ( ! dynamic_sidebar( 'header-widget-zone' ) ) {} ?>

Now we can see our new sidebar showing the previous configured widgets.

Questions, comments, suggestions?