'publish_'.self::$post_type_name_cap,
'edit_posts' => 'edit_'.self::$post_type_name_cap,
'edit_others_posts' => 'edit_others_'.self::$post_type_name_cap,
'delete_posts' => 'delete_'.self::$post_type_name_cap,
'delete_others_posts' => 'delete_others_'.self::$post_type_name_cap,
'read_private_posts' => 'read_private_'.self::$post_type_name_cap,
'edit_post' => 'edit_'.self::$post_type_name,
'delete_post' => 'delete_'.self::$post_type_name,
'read_post' => 'read_'.self::$post_type_name,
);
// cache our options before doing anything, since everything else depends on them
self::$options = self::get_all_options();
// fill all of our variables
self::$instruction_nav_title = self::$options['manual_nav'];
self::$instruction_page_title = self::$options['manual_title'];
self::$admin_page_title = __("Site Notes Configuration", DSNMANAGER_TEXTDOMAIN);
self::$admin_nav_title = __("Site Notes", DSNMANAGER_TEXTDOMAIN);
self::$base = plugin_basename(__FILE__);
// create the site note content type
if(!defined('DSN_DISABLE_CHANGES')) {
self::add_content_type();
}
// add hooks
add_filter('plugin_row_meta',array($this,'extra_plugin_links'),10,2);
add_action('all_admin_notices',array($this,'all_admin_notices'));
add_action('admin_init',array($this,'admin_init'));
// add styles/scripts
add_action('admin_enqueue_scripts',array($this,'enqueue_includes'));
// add dashboard notes if there are any
if(self::has_dashboard_notes()) {
add_action('wp_dashboard_setup', array($this,'setup_dashboard'));
}
// add instruction manual page if entries exist
if(self::has_instruction_notes()) {
add_action( 'admin_menu', array($this,'admin_menu') );
}
// add the options page if this user can manage the options
if(self::user_has_admin()) {
if(!defined('DSN_DISABLE_CHANGES')) {
add_action('admin_menu', array($this,'add_config_menu'));
add_action('admin_init', array($this,'register_settings'));
}
}
}
public static function enqueue_includes() {
wp_register_style(self::$plugin_stylesheet_id, plugins_url('admin-dashboard-site-notes/admin-styles.css'));
wp_enqueue_style(self::$plugin_stylesheet_id);
wp_register_script(self::$plugin_script_id, plugins_url('admin-dashboard-site-notes/admin-scripts.js'),'jquery' );
wp_enqueue_script(self::$plugin_script_id);
}
// check if user is allowed to configure the plugin
// only super admins are allowed, unless DSN_ADMIN_CONFIG is true, in which case any admin is allowed
public static function user_has_admin() {
return is_super_admin() || (defined('DSN_ADMIN_CONFIG') && current_user_can('manage_options'));
}
// get all wordpress roles, allowing them to be filtered by other plugins
public static function get_roles() {
global $wp_roles;
if(!$wp_roles) {
return array();
}
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
return $editable_roles;
}
// add the content type to the admin navigation
public function admin_menu() {
add_dashboard_page(self::$instruction_page_title, self::$instruction_nav_title, 'read', self::$plugin_id, array($this,'admin_page'));
}
// echo the instruction manual
public static function admin_page() {
echo "
';
return $output;
}
// recursively get the post and it's children
public static function note_with_children($post,$depth=0,$full_post=false) {
if($depth > 64) { // sanity check
return __("Error: note output aborted, hierarchy too deep (>64)", DSNMANAGER_TEXTDOMAIN);
}
$output = "
";
$output .= self::get_checkbox("loc_dashboard",__("Include in the dashboard widget", DSNMANAGER_TEXTDOMAIN));
$output .= "
";
/* TODO: manual action settings
$output .= "
";
$output .= "
";
$output .= self::get_checkbox("dsn_loc_manual",__("Include this note on the following pages (eg, options-general.php to appear on the Settings->General page)."));
$output .= "
";
*/
$output .= "
";
$output .= self::get_checkbox("instructions_exclude",__("Exclude from site instruction manual.", DSNMANAGER_TEXTDOMAIN));
$output .= "
";
$output .= "
";
$output .= self::get_checkbox("hide_title",__("Hide the title of this post for inline notes.", DSNMANAGER_TEXTDOMAIN));
$output .= "
";
$output .= "
"; // close #dsn_meta_other
$roles = self::get_roles();
$output .= "
";
$output .= "
" . __("Show for the following roles:", DSNMANAGER_TEXTDOMAIN) . "
";
foreach($roles as $role_name=>$role_arr) {
$output .= "