Flea Circus Director (fleacircusdir) wrote,
Flea Circus Director
fleacircusdir

Simple wordpress plugin for updating link date

As part of another plugin I'm developping I created this test.

The plugin adds a new Meta box on the right of the links form to display the date the field was last modified. There's some code to capture the date that a link is modified. The field already exists in the table so the code ended up very simple.

Suggested changes if you wanted to use this.

1) Wrap the 3 functions into a class
2) Add a function that populates initialise all the data values that are blank when the plugin is activated



<?php
/*
Plugin Name: Andys Link Last Edited Meta Box
Plugin URI: #
Description: Updates links to current data/time when edited and then displays that on the edit link admin screen
Version: 0.2
Author: AGC based on the work of Ozh and
miekd
Author URI:
*/
// This function tells WP to add a new "meta box"
// N.B. There is no options screens for this plugin

//See http://www.code-styling.de/english/how-to-use-wordpress-metaboxes-at-own-plugins
//    http://planetozh.com/blog/2008/02/wordpress-snippet-add_meta_box/
//    http://wordpress.org/extend/plugins/link-updated/
//    http://codex.wordpress.org/Function_Reference/add_meta_box


function LinksAGC_edit_update($link_ID) {
    global $wpdb;
    $sql = "update wp_links set link_updated = NOW() where link_id = " . $link_ID . ";";
    $wpdb->query($sql);
}

function LinksAGC_add_LastMod_box() {
    
    add_meta_box(
        'linkmodifieddiv', // id of the <div> we'll add
        'Last Modified', //title
        'LinksAGC_add_last_modfied', // callback function that will echo the box content
        'link', // where to add the box: on "post", "page", or "link" page
        'side'  // location, 'normal', 'advanced', or 'side'
    );

}
// This function echoes the content of our meta box
function LinksAGC_add_last_modfied($link) {
     if (! empty($link->link_id))
     {
    echo "Last Modified Date: ";
    echo $link->link_updated;
    }
    else
    { echo "New Link";}
}
// Hook things in, late enough so that add_meta_box() is defined
if (is_admin())
{
    add_action('admin_head', 'LinksAGC_add_LastMod_box');
    add_action('edit_link', 'LinksAGC_edit_update');
    add_action('add_link', 'LinksAGC_edit_update');
}   
?>
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 2 comments