PLG itemSaved

From GeeklogWiki
Revision as of 09:46, 6 February 2009 by Dirk (talk | contribs) (PLG itemSaved)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

The motivation for PLG_itemSaved is to have a call that plugins can hook into whenever Geeklog (or another plugin) saves one of its items (article, comment, ...) so that plugins can perform actions on their own if they want to track changes on an item.

The original implementation, however, was very complex and included a rollback mechanism that was called when one of the plugins indicated a problem. As a result, it was only ever implemented for stories (and not even correctly at that ...).

So as of Geeklog 1.6.0, this API has been simplified and implemented not only for stories but also for Events, Links, Polls, and Static Pages (more to come).

The API

function PLG_itemSaved($id, $type, $old_id = '')

where $id is the unique ID of the item being saved. If the item's ID is changed with this save operation, then $id will contain the new ID and $old_id contains the previous ID (otherwise it's empty).

$type is the item's type, e.g. 'article' for a story. For plugins, the item's type is usually identical with the plugin's internal name, e.g. 'links' for a link from the Links plugin.

Subtypes

(not finalized yet)

For plugins that support more than one type of item (e.g. the Links plugin, which has links and link categories), the type can consist of two parts: The main type (identical with the plugin's name) and a subtype, separated by a dot '.', e.g.

links.category

Return value

The return value of PLG_itemSaved is void, i.e. it does not return anything (actually, it does currently return false for backward compatibility with the old API implementation but that should not be relied upon).

PLG_itemDeleted

When an item is deleted, PLG_itemDeleted is called (PLG_itemSaved is not called for deleted items):

function PLG_itemDeleted($id, $type)</code>


[[Category:Plugin Development]]