Tag: WordPress Plugins

  • Automatically import a Google Drive Sheet (CSV) into TablePress using Automatic Periodic Table Import

    To keep this post short-and-sweet, which will be the aim for future articles, I am experimenting with the Situation, Task, Action, Result (STAR) method for this write-up. Do let me know if you think it works or not in the comments or the contact form.

    Situation

    A TablePress table listing sport fixture results (e.g. football, hockey etc.) requires regular updating.

    This had been done by one person using an (offline) Excel spreadsheet and manually importing the .csv file. But the job has now been shared amongst a team of three (in different locations), so maintaining an offline spreadsheet no longer seemed practical.

    Thus it made sense to create and maintain a single version on Google Sheets that could be edited by all.

    But exporting and importing the file requires extra action. Could this process be automated?

    Task

    Automatically and periodically import a Google Sheet into TablePress to replace a table of fixture results

    Action

    1. Download, install and enable the TablePress Automatic Periodic Table Import extension. Please note this is a premium plugin and so I would strongly encourage you to make a donation to Tobias Bäthge if you find it useful (the current recommended amount is $18).
    2. Login to Google Docs and open the sheet you wish to export.
    3. Click on File → Share → Anyone with the link can view to ensure the extension can access the sheet; simply enabling File → Publish to the web does not always work for the .csv format as this only makes the HTML output public, but not the .csv version.
    4. Copy the URL of the sheet, which should have the following format (where YOUR_DOCUMENT_KEY is the primary ID of your Google Sheet):

      https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/edit?usp=sharing

    5. Paste the URL into the Source field for the relevant table and replace:
      edit?usp=sharing

      with

      export?format=csv
    6. The final format is as follows:

      https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/export?format=csv

      UPDATE with props to Alessandro: The above will import the first sheet (‘Sheet1’) or gid=0 so if you are looking to import a specific tab/sheet in a multi-sheet document, you will need to identify the GID=YOUR_GID_KEY reference and include it in the url.

      The final format of a specific sheet is as follows:

      https://docs.google.com/spreadsheets/d/YOUR_DOCUMENT_KEY/export?format=csv&gid=YOUR_GID_KEY

    7. Click the check-box to activate the Auto Import, set how frequently this should occur and save changes.

    Result

    A single online spreadsheet hosted on Google Docs/Sheets editable by multiple authors, which is then automatically and periodically imported into TablePress to replace a table of fixture results.

    Demo: https://www.wpsnippets.com/tablepress-auto-import-using-google-sheets/

    References

  • Separate theme display and functionality with a build-your-own custom functionality plugin

    Having worked with child themes for some time, it was great to learn something new today, one that will cause a paradigm shift in the way I work with themes. The epiphany came from Dave Clements, who built on Ryan Mel‘s WPCandy article How to create your own WordPress functionality plugin and essentially tells us to use a plugin to introduce custom functionality instead of putting (most) of the code into the theme functions.php file.

    The basic premise is this:

    Create custom functionality for your site but don’t tie it down to a theme

    What do you mean?

    To clarify: we all know what happens when we switch themes – custom taxonomies disappear, shortcodes cease to be of use and Favicons are no longer – unless we build them in, again.

    Why waste time and energy doing this when you can retain all these by creating your own custom functionality plugin?  Then you or your client can switch themes at will.

    Then when should I use functions.php?

    Both Dave and Ryan maintain that not everything should be put into the plugin; some things should still remain in the theme file’s functions.php, for example registering sidebars and custom nav menus, which are specific to your theme.

    Others, including custom image sizes are more open for debate and will be up to your discretion.

    Ryan produced a helpful table to provide some examples, reproduced below:

    Screenshot of comparison table for when to use a functionality plugin vs functions.php

    More content is available by clicking on the image or link above, which will take you to the full article (with even more discussion and recommendations) but hopefully this gives both you (and me) a better idea of what to put in our functionality plugins.

    So how do I create a custom functionality plugin?

    It’s as simple as taking the relevant codes from your functions.php and placing it into a plugin-name.php file. Both articles – WPCandy and Dave – kindly provide blank templates, and Ryan (on WPCandy) actually goes a step further to advise maintaining a readme.txt file.

    I have not included a blank file here since that would be duplicating the good work done by both; direct file linkage is not ideal either.

    Effectively, much like a style.css file, the header in your plugin-name.php is very important:

    /*
    Plugin Name: Site Name Functionality Plugin
    Description: Summarise the key elements of your site functionality plugin.
    Version: 0.1
    License: GPL
    Author: Your Name
    Author URI: Your URL
    */
    

    This file then goes into /wp-content/plugins/plugin-folder-name. Then you simply activate your new custom functionality plugin.

    Further comments

    It might be reassuring to know that heavy weights like Otto, Michael Fields, PTah Dunbar and Konstantin Obenland have all stated in the comments that they agree this to be good practice and some of them use it on their own sites.

    Dougal Campbell also suggested the following:

    If I switched themes, and this functionality disappeared…
    …would I miss it?
    …would it ‘break’ my site in some way? (I’m using ‘break’ loosely here, subject to interpretation)

    If I installed this theme on somebody else’s site…
    …would they need this?
    …would it expose any of my account info?

    Last but not least, Justin Tadlock also wrote a post about this as well and advises us to ask ourselves two questions:

    Is this something I only want to happen when using my current theme?

  • Is this functionality I want to keep regardless of the theme I’m using?

  • WordPress Plugin Competition 2009

    Our humble website, WPSnippets, is hardly the first stop WordPress fans will visit when they look up information regarding their beloved WordPress (I recommend visiting WP Tavern and WLTC for that!)  but I do still feel it is important to get the word out as a much as possible about this year’s:

    WordPress Plugin Competition 2009

    This is an annual competition which, I believe, began last year and has both directly and indirectly resulted in some of the most useful plugins for 2008 – I believe the concept behind one may even have been somewhat ‘integrated’ into WordPress core – it was that good!

    The incentive for plugin authors across the world is firstly, a place to publicise their plugin in a forum outside of the WordPress Plugin Directory – particularly to non developers (including myself). Secondly, as WPEngineer pointed out (with thanks to WPTavern for the Retweet), your plugin will receive a lot of feedback. I think he sums it up nicely:

    … your Plugin surely gets more attention and more feedback, as I have experienced in the past year. This year should be at least the same amount of feedback as last year, where each plugin was inspect by OZH. Also this year, you can expect to get some feedback from Ozh as you can see at contribution to the Plugin Competition. Sure, the opinion of Ozh can be different then yours, but his feedback is crucial. As a developer, I have learned a lot from last year, my knowledge expanded.

    Just to recap on last year’s plugins, the personal highlights for me from 2008 were (in no particular order):

    for the simple reason that they were really quite innovative and ones I personally found very useful (or potentially useful) for my own sites (fan and private club ones) and these were to name but a few of the multiple plugins that were submitted.

    2009 has yet to receive the same level of submissions, which is surprising, given the incentives listed above and some lovely prizes to boot. Hopefully this is because all this year’s potential competition participants are furiously writing up a changelog before posting their entry. :p

    As a non developer, some of the new submissions that have caught my eye to date are:

    where Changelogger is a plugin that I believe really offers something that should be in WordPress core, and Advanced Export for WP and WPmu will be such an essential tool when moving or even revamping a site as you can select specific content.

    The deadline for submissions is the end of July 2009, so – as a WordPress fan who loves plugin developers and their plugins – please can I humbly implore you to send in your plugin for the WordPress Plugin Competition 2009!

  • Find of the Day: The Definitive Guide on WordPress Syntax Highlighter Plugins

    As WP Snippets is going to focus on WordPress codes and tips, it was very important that we had a good code syntax highlighter to separate the content from the code clearly, and ensure the display wasn’t messed up by the visual editor!

    There are quite a number out there (at least 8!) that do the job, but it was difficult to sieve/test through so many when the new site was going live in a very short time, and it was then that I stumbled upon Chris Cagle‘s excellent article:

    The Definitive Guide on WordPress Syntax Highlighter Plugins

    The article gives a comprehensive review of 8 different code syntax highlighters that work for WordPress 2.6, including (in alphabetical order)

    The plugins have then been ranked in terms of their overall rating in ‘colouring/coloring abilities’ (with colour screen-shots for comparison included!) and their ‘ease of use’, where WP-Chili came out top in the colour rankings (which is what Chris Cagle is using, and he has helpfully provided what he uses on Cagintranet Web Design) but Syntax Highlighter Plus was #1 for ‘ease of use’.

    I found the whole guide extremely helpful, and have now ended up using Syntax Highlighter Plus for WP Snippets – it did help that it was ranked #1 overall! However, given that Andrea Ercolino has updated WP-Chili since the review, I really might look into changing over!

    If you are looking out for a good WordPress plugin that highlights code in colour/color for WordPress 2.6, then The Definitive Guide on WordPress Syntax Highlighter Plugins is definitely the article that you would not want to miss reading. To be fair, not every plugin has been updated recently (at least two are from 2007, and the most dated plugin in the list is Code Colorer from May 2007) but nevertheless, it is still an excellent guide worth archiving!

  • WP-Table plugin – Fatal Error fix for WordPress 2.5+

    10/05/2013: Everyone should now switch to TablePress by Tobias.

     
    WP-Table plugin by Alex Boelinger is a unique WordPress plugin that allows admins to create tables, by this I mean the ones with rows and columns like in Excel, easily in WordPress. It is the only one that I am aware of at the moment that makes it possible to add actual tables without putting-in extra HTML when creating new posts and pages.

    However, activating the latest version (1.52) of the plugin triggers a fatal error (shown below) in WordPress 2.5+:

    Plugin could not be activated because it triggered a fatal error.

    Fortunately there is a quick fix that can be done to resolve this issue, where the full credit for this solution goes to Michael Bester, the developer of the Kimili Flash Embed, who posted a comment on Jovel Stefan’s Embedded Video Plugin post about a fix to ensure that a plugin should check for the buttonsnap class upon activation.

    This class is used to add a button to your WordPress editor, and should only ever be loaded once, so if any other plugin uses buttonsnap, it will cause the fatal error to occur.

    To resolve this problem, find Line 344 in wp-table.php

    require_once(WPTABLE_ABSPATH.'js/buttonsnap.php');

    and add before it:

    if(!class_exists('buttonsnap'))

    So ultimately you should see this:

    // ButtonSnap needs to be loaded outside the class in order to work right
    if(!class_exists('buttonsnap'))
    require_once(WPTABLE_ABSPATH.'js/buttonsnap.php');

    I tested this on a local install of WordPress 2.5.1, and it worked very well. This quick fix has also been posted on the WordPress Support Forums, and hopefully others will find it helpful as well.

    Any feedback would be brilliant! If it works for you, please let me know by posting in the comments. Similarly, if it doesn’t work for you, then again, please do post! I don’t see the plugin requiring any further edits for the time being (apart from new features) and am confident that it will also work with later WordPress versions as well.

    UPDATE 20/07/08: Apparently the plugin does work with WP 2.6!
    UPDATE 28/12/08: And in WP 2.7 as well!
    UPDATE 25/05/09: WP-Table Reloaded supercedes WP-Table.

    FINAL UPDATE 10/05/13: TablePress is now the revamped, next-generation of WP-Table Reloaded. It is also by Tobias Bäthge and thus Alex Rabe’s WP-Table has now become even better! Many thanks to Tobias for his hard work!