Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-02-27 14:55:20

greek
New Member
Registered: 2013-02-27
Posts: 2

Article info in admin side plugin

I can’t get newly created article info in admin side plugin. I tried $GLOBALS[‘ID’], gps(“ID”), etc, but no luck. Im registering for publish event through a callback. The function gets called, but I can’t access any article info (like ID). Any tips?

v4.5.4

Offline

#2 2013-02-27 15:21:35

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Article info in admin side plugin

greek wrote:

Any tips?

If you are hooking to article > publish (with $pre set to FALSE) event, then the issue is that the event is executed prior to the whole panel or the saving process.

If you want to track article saves and updates, attach your handlers to article_posted and article_saved events. Both are invoked when, and only when, an article is successfully saved. On of the arguments also gets populated with an an data array that contains the article ID. E.g.

class abc_my_plugin
{
	/**
	 * Constructor.
	 */

	public function __construct()
	{
		register_callback(array($this, 'posted'), 'article_posted');
		register_callback(array($this, 'saved'), 'article_saved');
	}

	/**
	 * Hooks to article posting process.
	 *
	 * @param string $event Callback event
	 * @param string $step   Callback step
	 * @param array  $r         Article data
	 */

	public function posted($event, $step, $r)
	{
		echo (int) $r['ID'];
	}

	/**
	 * Hooks to article saving process.
	 *
	 * @param string $event Callback event
	 * @param string $step   Callback step
	 * @param array  $r         Article data
	 */

	public function saved($event, $step, $r)
	{
		send_script_response('alert(Article updated).');
	}
}

new abc_my_plugin();

Last edited by Gocom (2013-02-27 15:22:14)

Offline

#3 2013-02-27 16:16:16

greek
New Member
Registered: 2013-02-27
Posts: 2

Re: Article info in admin side plugin

Wow! Thank you so much for your help! It worked like a charm! :)

Offline

#4 2016-09-15 01:03:59

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Article info in admin side plugin

Just for the record, this line has syntax errors:

send_script_response('alert(Article updated).');

This works:

send_script_response('alert("Article updated")');

Offline

Board footer

Powered by FluxBB