我正在开发一个Wordpress Collaboration插件。
这是一种创建和管理群组的方式。
我的“添加群组”页面效果很好,现在正尝试创建“编辑群组”页面。
所以我从“添加组”页面复制了代码和html,将其粘贴到编辑页面,并链接到它,就像我添加页面一样......
但我得到了
You do not have sufficient permissions to access this page.
我是该网站的唯一管理员,它是Wordpress 4.0。我已经把文件chmod到777到目前为止无济于事。
我该如何解决这个问题呢?
<?php
if($_POST){
/*
$grpTitle = $_POST['grpTitle'];
$grpDescription = $_POST['grpDescription'];
// Create the group
$wpdb->insert(EMC_GROUP_TABLE, array('gTitle' => $grpTitle, 'gDescription' => $grpDescription),
array('%s', '%s'));
$grpID = $wpdb->insert_id;
// Insert the selected members
$grpMember = $_POST['grpMember'];
$gmCt = count($grpMember);
for($gm = 0; $gm < $gmCt; ++$gm){
$wpdb->insert(EMC_USERS_TABLE, array('groupID' => $grpID, 'userID' => $grpMember[$gm], 'cuType'=>2),
array('%d', '%d', '%d'));
}
// Insert the selected Admins
$grpAdmins = $_POST['grpAdmins'];
$aCt = count(grpAdmins);
for($am = 0; $am < $aCt; ++$am){
$wpdb->insert(EMC_USERS_TABLE, array('groupID' => $grpID, 'userID' => $grpAdmins[$am], 'cuType'=>1),
array('%d', '%d', '%d'));
}
$grpInclude = $_POST['grpInclude'];
$giCt = count($grpInclude);
for($g = 0; $g < $giCt; ++$g){
$wpdb->insert(EMC_POSTS_TABLE, array('groupID' => $grpID, 'post_id' => $grpInclude[$g]),
array('%d', '%d', '%d'));
}
echo '<div id="message" class="updated fade" style="padding:10px;">Your group has been created.</div>';
*/
}
?>
<style type="text/css">
.ui-widget{font-family:auto;}
.ui-widget th{font-weight:bold;}
.tab1{width:24% !important;display:block-inline !important;float:left !important;padding:2px;font-family:inherit;}
.panel1{background:none !important;border:none !important;}
.grpSelAll{text-decoration:underline !important;}
.grpSelAll:hover{text-decoration:none !important;}
</style>
<div class="wrap" style="width:65% !important;">
<h2><span class="dashicons dashicons-welcome-add-page" style="display:inline-block;padding-top:5px;"></span> Update This Group</h2>
<div class="form-wrap">
<form method="post">
<div id="tabs" class="panel1">
<ul class="panel1">
<li class="tab1"><a href="#tabs-1">Main Properties</a></li>
<li class="tab1"><a href="#tabs-2">Group Members</a></li>
<li class="tab1"><a href="#tabs-3">Page/Post Permissions</a></li>
<li class="tab1"><a href="#tabs-4">Group Administrators</a></li>
</ul>
<div id="tabs-1" class="group-panel panel1">
<h2>Main Properties</h2>
<div class="form-field">
<h3>
<label for="grpTitle">Group Title</label>
<input type="text" name="grpTitle" id="grpTitle" required />
</h3>
</div>
<div class="clearfix"></div>
<h3>
<label for="grpDescription">Group Description</label>
<textarea rows="6" style="width:100%;" name="grpDescription" id="grpDescription"></textarea>
</h3>
</div>
<div id="tabs-2" class="group-panel panel1">
<h2>Group Members</h2>
<?php
// Grab all users with the proper permissions from WP (not admins)
$uc = new EM_Collaboration_Users;
$u = $uc->get_wp_allowed_users();
$uCt = count($u);
if($uCt > 0){
echo '<table id="section-groups" class="wp-list-table widefat">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Type</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpMember" title="Click to Select/De-Select All">Group Member</a></th>
</tr>
</thead>
<tbody>';
for($i=0;$i<$uCt;++$i){
$un = new WP_User($u[$i]->ID);
$uL = $un->roles[0];
echo '<tr>
<td>' . $u[$i]->display_name . '</td>
<td>' . $u[$i]->user_email . '</td>
<td>' . ucwords($uL) . '</td>
<td style="text-align:center;"><input type="checkbox" id="grpMember' . $u[$i]->ID . '" name="grpMember[]" value="' . $u[$i]->ID . '" /></td>
</tr>';
}
echo ' </tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Email</th>
<th>Type</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpMember" title="Click to Select/De-Select All">Group Member</a></th>
</tr>
</tfoot>
</table>';
}else{
echo '<p class="error" style="padding:10px;">There are no users with the correct permissions.<br />You will not be able to create this group until you have at least 1 user with proper permissions.</p>';
}
?>
</div>
<div id="tabs-3" class="group-panel panel1" style="background:none !important;border:none !important;">
<h2>Page/Post Permissions</h2>
<?php
$pc = new EM_Collaboration_Posts();
$pub_posts = $pc->get_allowed_public_posts();
$ppCt = count($pub_posts);
if($ppCt > 0){
echo '<table id="section-groups" class="wp-list-table widefat">
<thead>
<tr>
<th>Title</th>
<th>Type</th>
<th>Status</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpInclude" title="Click to Select/De-Select All">Include In Group?</a></th>
</tr>
</thead>
<tbody>';
for($p=0;$p<$ppCt;++$p){
echo '<tr>';
echo '<td>' . $pub_posts[$p]['POST'] . '</td>
<td>' . ucwords($pub_posts[$p]['TYPE']) . '</td>
<td>' . ucwords($pub_posts[$p]['STATUS']) . '</td>
<td style="text-align:center;"><input type="checkbox" id="grpInclude' . $pub_posts[$p]['ID'] . '" name="grpInclude[]" value="' . $pub_posts[$p]['ID'] . '" /></td>';
echo '</tr>';
}
echo ' </tbody>
<tfoot>
<tr>
<th>Title</th>
<th>Type</th>
<th>Status</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpInclude" title="Click to Select/De-Select All">Include In Group?</a></th>
</tr>
</tfoot>
</table>';
}else{
echo '<p class="error" style="padding:10px;">There are no public posts/pages yet.</p>';
}
?>
</div>
<div id="tabs-4" class="group-panel panel1" style="background:none !important;border:none !important;">
<h2>Group Administrators</h2>
<?php
// Grab all administrators from WP
$a = $uc->get_wp_admins();
$aCt = count($a);
if($aCt > 0){
echo '<table id="section-groups" class="wp-list-table widefat">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Joined On</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpAdmins" title="Click to Select/De-Select All">Group Admin</a></th>
</tr>
</thead>
<tbody>';
for($i=0;$i<$aCt;++$i){
echo '<tr>';
echo ' <td>' . $a[$i]->display_name . '</td>';
echo ' <td>' . $a[$i]->user_email . '</td>';
echo ' <td>' . date('m/d/Y H:i:s', strtotime($a[$i]->user_registered)) . '</td>';
echo ' <td style="text-align:center;"><input type="checkbox" id="grpAdmins' . $a[$i]->ID . '" name="grpAdmins[]" value="' . $a[$i]->ID . '" /></td>';
echo '</tr>';
}
echo ' </tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Email</th>
<th>Joined On</th>
<th style="text-align:center;"><a href="#" class="grpSelAll" data-rel="grpAdmins" title="Click to Select/De-Select All">Group Admin</a></th>
</tr>
</tfoot>
</table>';
}else{
echo '<p class="error" style="padding:10px;">There are no administrators.</p>';
}
?>
</div>
<div style="display:block;float:right;">
<?php submit_button('Update This Group', 'primary large'); ?>
</div>
</div>
</form>
</div>
</div>
<script>
jQuery(function() {
jQuery("#tabs").tabs();
jQuery('.grpSelAll').on('click', function(e){
e.preventDefault();
var $which = jQuery(this).attr('data-rel');
var checkBoxes = jQuery("input[id^=" + $which + "]");
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
});
</script>
<?php defined('ABSPATH') or die("No script kiddies please!");
/*
Plugin Name: My Collaboration
Version: 0.0.1
Author: My Communications ~ Kevin C. Pirnie
Author URI: http://www.arealsite.com
Description: Collaborate pages and posts with other group members. Allows for revisioning selection, emailed changes, member permissions on a per post/page basis, works with custom post/page types.
@author Kevin C. Pirnie <kevin@pirnie.us>
Copyright 2014 My Communications (email: kevin@pirnie.us)
*/
// Show all errors
// Report all PHP errors
// error_reporting(-1);
// ini_set('error_reporting', E_ALL);
// Plugin Wide Constants
global $wpdb;
define('EMC_PLUGIN_PATH', dirname(__FILE__));
define('EMC_GROUP_TABLE', $wpdb->prefix . "em_collab_groups");
define('EMC_USERS_TABLE', $wpdb->prefix . "em_collab_users");
define('EMC_POSTS_TABLE', $wpdb->prefix . "em_collab_posts");
define('EM_OPTION_GROUP', 'em_options_group');
define('EM_OPTION_ENABLE_MAIL', 'em_email_enable');
define('EM_OPTION_ALLOWED_POST_TYPES', 'em_allowed_post_types');
define('EM_OPTION_EMAIL_DRAFTS', 'em_email_drafts');
if(!class_exists('EM_Collaboration')) {
// The main plugin class
class EM_Collaboration {
public function __construct(){
// add in the admin menu items, only for an administrative user
add_action('admin_init', array(&$this, 'admin_init'));
add_action('admin_menu', array(&$this, 'add_menu'));
}
// On Activating the plugin
public static function em_activate(){
global $wpdb;
// Add in our tables if they are needed
$em_posts = EMC_POSTS_TABLE;
$em_groups = EMC_GROUP_TABLE;
$em_users = EMC_USERS_TABLE;
if($wpdb->get_var("SHOW TABLES LIKE '$em_users'") != $em_users) {
$sql = "CREATE TABLE IF NOT EXISTS `$em_users` (
`cuID` bigint(20) NOT NULL auto_increment,
`groupID` bigint(20) NOT NULL,
`userID` bigint(20) NOT NULL,
`cuType` int(11) NOT NULL,
`cuSettings` longtext NOT NULL,
`cuCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`cuUpdated` datetime DEFAULT NULL,
PRIMARY KEY (`cuID`),
KEY `groupID` (`groupID`),
KEY `userID` (`userID`),
KEY `cuType` (`cuType`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// Create the table
dbDelta($sql);
}
if($wpdb->get_var("SHOW TABLES LIKE '$em_posts'") != $em_posts) {
$sql = "CREATE TABLE IF NOT EXISTS `$em_posts` (
`cpID` bigint(20) NOT NULL auto_increment,
`groupID` bigint(20) NOT NULL,
`post_id` bigint(20) NOT NULL,
`cpSettings` longtext NOT NULL,
`cpCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`cpUpdated` datetime DEFAULT NULL,
PRIMARY KEY (`cpID`),
KEY `groupID` (`groupID`),
KEY `post_id` (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// Create the table
dbDelta($sql);
}
if($wpdb->get_var("SHOW TABLES LIKE '$em_groups'") != $em_groups) {
$sql = "CREATE TABLE IF NOT EXISTS `$em_groups` (
`groupID` bigint(20) NOT NULL auto_increment,
`gTitle` varchar(50) NOT NULL,
`gDescription` longtext NOT NULL,
`gSettings` longtext NOT NULL,
`gCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gUpdated` datetime DEFAULT NULL,
PRIMARY KEY (`groupID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// Create the table
dbDelta($sql);
}
}
public static function em_deactivate(){
delete_option(EMC_OPTIONS);
}
// Initialize the administration
public function admin_init(){
// Include necessary classes to do all the work
require_once(EMC_PLUGIN_PATH . '/classes/em.class.emails.php');
require_once(EMC_PLUGIN_PATH . '/classes/em.class.group.php');
require_once(EMC_PLUGIN_PATH . '/classes/em.class.posts.php');
require_once(EMC_PLUGIN_PATH . '/classes/em.class.users.php');
require_once(EMC_PLUGIN_PATH . '/classes/em.class.settings.php');
// Include some needed scripts
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui');
wp_enqueue_script('jquery-ui-tabs');
// Include the admin styles
wp_enqueue_style('dashicons');
// Register our custom settings
register_setting(EM_OPTION_GROUP, EM_OPTION_ENABLE_MAIL);
register_setting(EM_OPTION_GROUP, EM_OPTION_ALLOWED_POST_TYPES);
register_setting(EM_OPTION_GROUP, EM_OPTION_EMAIL_DRAFTS);
}
// Add the menu, only for administrators
public function add_menu(){
if(is_admin()){
// Top Menu Item
add_menu_page(__('EM Collaboration All Groups', 'em-collaboration'),
__('EM Collaboration', 'em-collaboration'), NULL, 'em-collab-top', NULL, '', 21);
// Inner Items
add_submenu_page('em-collab-top',
__('EM Collaboration All Groups', 'em-collaboration'),
__('All Groups', 'em-collaboration'),
'manage_options',
'em-collaboration/interface/em-main.php');
add_submenu_page('em-collab-top',
__('Add a New EM Collaboration Group', 'em-collaboration'),
__('Add New Group', 'em-collaboration'),
'manage_options',
'em-collaboration/interface/em-add-group.php');
add_submenu_page('em-collab-top',
__('EM Collaboration Settings', 'em-collaboration'),
__('Settings', 'em-collaboration'),
'manage_options',
'em-collaboration/interface/em-settings.php');
}
}
}
// Installation hook
register_activation_hook(__FILE__, array('EM_Collaboration', 'em_activate'));
register_deactivation_hook(__FILE__, array('EM_Collaboration', 'em_deactivate'));
// instantiate the plugin class
$em_collaboration_plugin = new EM_Collaboration();
if(isset($em_collaboration_plugin)) {
function plugin_settings_link($links) {
return $links;
}
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'plugin_settings_link');
}
}
答案 0 :(得分:-1)
更改此行:
add_menu_page(__('EM Collaboration All Groups', 'em-collaboration'), __('EM Collaboration', 'em-collaboration'), NULL, 'em-collab-top', NULL, '', 21);
为:
add_menu_page(__('EM Collaboration All Groups', 'em-collaboration'), __('EM Collaboration', 'em-collaboration'), 'manage_options', 'em-collab-top', NULL, '', 21);
此函数中的第三个参数是要求访问页面所需的功能,您将其设置为null,这不是有效的功能。
同样在add_menu函数中,您将所有内容都包含在is_admin()中。这不是必需的,并且不会以它听起来的方式工作。它不检查当前用户是否是管理员,它正在检查正在查看的屏幕是否在wp-admin区域。当然,所有管理页面都是天生的。
答案 1 :(得分:-1)
您的“编辑”页面是否是单独的页面,或者您是否在其他页面中包含该页面。此外,如果您想为编辑页面创建新的子菜单,则需要为其创建新的子菜单。此外,如果您可以向我们发送您收到此错误的页面的URL“您没有足够的权限来访问此页面”。那么我可以告诉你更多关于你的问题的信息。基本上,如果您尝试访问不存在的资源,则会导致此类错误。
谢谢