adding plugin hooks to panels (experimental)

This commit is contained in:
real_nowhereman 2010-08-25 17:40:09 +00:00
parent 9c577211fd
commit 8177592469
2 changed files with 28 additions and 6 deletions

View File

@ -110,30 +110,37 @@
function exec() { function exec() {
global $panel,$action;
foreach($this->args as $mandatory_argument) { foreach($this->args as $mandatory_argument) {
if (!isset($_REQUEST[$mandatory_argument])) { if (!isset($_REQUEST[$mandatory_argument])) {
return PANEL_REDIRECT_DEFAULT; return PANEL_REDIRECT_DEFAULT;
} }
} }
$this->setup(); $this->setup();
do_action("admin_{$panel}_{$action}_setup");
$result = 0; // if !=0, defaultaction for this panel is called $result = 0; // if !=0, defaultaction for this panel is called
if (empty($_POST)) { if (empty($_POST)) {
if ($this->commands) { if ($this->commands) {
foreach($this->commands as $cmd) { foreach($this->commands as $cmd) {
if (isset($_GET[ $cmd ])) { if (isset($_GET[ $cmd ])) {
return $this->docommand($cmd, $_GET[ $cmd ]); $result = $this->docommand($cmd, $_GET[ $cmd ]);
return apply_filters("admin_{$panel}_{$action}_{$cmd}_{$_GET[ $cmd ]}", $result);
//return $result;
} }
} }
} }
$result = $this->main(); $result = $this->main();
do_action("admin_{$panel}_{$action}_main");
lang_load($this->langres); lang_load($this->langres);
} else { } else {
$result = $this->onsubmit(); $data = apply_filters("admin_{$panel}_{$action}_onsubmit", null);
$result = $this->onsubmit($data);
} }
return $result; return $result;
@ -161,13 +168,17 @@
function onsubmit($data = null) { function onsubmit($data = null) {
global $panel,$action;
$returnvalue = 1; $returnvalue = 1;
$valid_evts = array_intersect(array_keys($_POST), $this->events); $valid_evts = array_intersect(array_keys($_POST), $this->events);
if ($the_event=array_pop($valid_evts)) { if ($the_event=array_pop($valid_evts)) {
$event = "on{$the_event}"; $event = "on{$the_event}";
if (method_exists($this, $event)) if (method_exists($this, $event)) {
$data = apply_filters("admin_{$panel}_{$action}_{$event}", $data);
$returnvalue = call_user_func(array(&$this, $event), $data); $returnvalue = call_user_func(array(&$this, $event), $data);
}
} }
return $returnvalue; return $returnvalue;
@ -207,7 +218,7 @@
function onsubmit() { function onsubmit() {
global $lang; global $lang, $panel, $action;
$result = 0; $result = 0;
@ -268,7 +279,8 @@
$result = parent::onsubmit($content); $result = parent::onsubmit($content);
} else { } else {
$this->smarty->assign('error', $errors); $this->smarty->assign('error', $errors);
$result = $this->onerror();
$result = apply_filters("admin_{$panel}_{$action}_onerror", $this->onerror());
} }
return $result; return $result;

View File

@ -116,6 +116,7 @@
} }
// smarty tag
function admin_filter_action($string, $action) { function admin_filter_action($string, $action) {
if (strpos($string, '?')===false) if (strpos($string, '?')===false)
return $string .= "?action={$action}"; return $string .= "?action={$action}";
@ -123,6 +124,7 @@
return $string .= wp_specialchars("&action={$action}"); return $string .= wp_specialchars("&action={$action}");
} }
// smarty tag
function admin_filter_command($string, $cmd, $val) { function admin_filter_command($string, $cmd, $val) {
global $panel, $action; global $panel, $action;
@ -170,6 +172,14 @@
} }
add_filter('wp_title', 'admin_title', 10, 2); add_filter('wp_title', 'admin_title', 10, 2);
// setup admin_header
function admin_header_default_action() {
global $panel, $action;
do_action("admin_{$panel}_{$action}_head");
}
add_filter('admin_head', 'admin_header_default_action');
$fp_config = config_load(); $fp_config = config_load();