_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS', ''); $this->_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); $this->_frontend->tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); } function run($hook, &$post) { if (! $this->active) return; $tpl =& $this->_frontend->tpl; $context =& $this->_frontend->context; if (is_null($this->_user)) { $this->_user = $this->_frontend->userFromWpCookie(); if (!$this->_user) { // not logged in, show login template, blank out edit templates and disable plugin $tpl->setFile('adminoptions_login', 'plugins/adminoptions_login.xml'); $tpl->parse('PLUGIN_ADMINOPTIONS', 'adminoptions_login'); $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); $this->active = false; return; } if ($this->_user['user_level'] > 7) $this->_show_edit_links = true; else if (isset($this->_user['capabilities']['administrator'])) $this->_show_edit_links = true; else if (isset($this->_user['capabilities']['editor'])) $this->_show_edit_links = true; else $this->_show_edit_links = false; } switch ($hook) { case 'parse_post': // handle post edit links if ($this->_frontend->local_context & (LP_CONTEXT_POST | LP_CONTEXT_STATIC)) { // check if user can edit this post if ($this->_show_edit_links || (($this->_user['user_level'] > 1) && ($this->_user['user_login'] == $post['post_author_login']))) { // edit post link $tpl->setFile('adminoptions_editpost', 'plugins/adminoptions_editpost.xml'); $tpl->setVar('post_id', $post['post_id']); $tpl->parse('PLUGIN_ADMINOPTIONS_EDITPOST', 'adminoptions_editpost'); return; } } // hide template for this post $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITPOST', ''); break; case 'render_comments': // set post author $this->_post_author = $post['post_author_login']; break; case 'parse_comment': // handle comment edit links if ($this->_frontend->local_context & (LP_CONTEXT_POST | LP_CONTEXT_STATIC)) { // check if user can edit this comment (WordPress allows any user that can edit the post to edit its comments) if ($this->_show_edit_links || ($this->_post_author && ($this->_user['user_level'] > 1) && ($this->_user['user_login'] == $this->_post_author))) { // edit comment link $tpl->setFile('adminoptions_editcomment', 'plugins/adminoptions_editcomment.xml'); $tpl->setVar('comment_ID', $post['comment_ID']); $tpl->parse('PLUGIN_ADMINOPTIONS_EDITCOMMENT', 'adminoptions_editcomment'); return; } } // hide template for this comment $tpl->setVar('PLUGIN_ADMINOPTIONS_EDITCOMMENT', ''); break; case 'post_render': // login/logout/admin block $tpl->setFile('adminoptions_login', 'plugins/adminoptions_admin.xml'); $tpl->parse('PLUGIN_ADMINOPTIONS', 'adminoptions_login'); break; } } } ?>