Пример #1
0
 public static function AttachCustomWritePanelMenuItems()
 {
     global $submenu, $menu, $wp_version;
     global $mf_domain, $wpdb;
     require_once 'RCCWP_Options.php';
     $assignToRole = RCCWP_Options::Get('assign-to-role');
     $requiredPostsCap = 'edit_posts';
     $requiredPagesCap = 'edit_pages';
     $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
     $new_indicator_text = __('New', $mf_domain);
     $edit_indicator_text = __('Manage', $mf_domain);
     $new_menu = array();
     ksort($menu);
     foreach ($menu as $k => $v) {
         if ($k > 5) {
             break;
         }
         $new_menu[$k] = $v;
     }
     $base = 5;
     $offset = 0;
     $add_post = false;
     // fix for WP 3.0
     if (substr($wp_version, 0, 3) < 3.0) {
         // WP <= 2.9
         $page_new = "page-new.php?";
         $page_edit = "page.php?";
         $page_manage = "edit-pages.php?";
     } else {
         // WP > 3.0
         $page_new = "post-new.php?post_type=page&";
         $page_edit = "post.php?";
         $page_manage = "edit.php?post_type=page&";
     }
     // end fix
     foreach ($customWritePanels as $panel) {
         if ($panel->name != '_Global') {
             // traversal: fix to ignore the global group
             //exists a single write panel? and if exists  this write panel have posts?
             if ($panel->single == 1) {
                 $table_name = $wpdb->prefix . "postmeta";
                 $sql = $wpdb->prepare("SELECT post_id FROM {$table_name}  where meta_key = %s and  meta_value = %d ", array("_mf_write_panel_id", $panel->id));
                 $has_posts = $wpdb->get_var($sql);
                 if (empty($has_posts)) {
                     $add_post = true;
                 } else {
                     $add_post = false;
                 }
             }
             $offset++;
             if ($panel->type == "post") {
                 $type_write_panel = "edit-posts";
             } else {
                 $type_write_panel = "edit-pages";
             }
             if ($assignToRole == 1) {
                 $requiredPostsCap = $panel->capability_name;
                 $requiredPagesCap = $panel->capability_name;
             }
             require_once 'RCCWP_Options.php';
             $condence = RCCWP_Options::Get('condense-menu');
             //IF we has unactivated the condenced menu
             if (!$condence) {
                 //adding the top parent menus
                 $new_menu[$base + $offset] = array(__($panel->name), $type_write_panel, $base + $offset . '.php', '', 'mf-menu-' . sanitize_title_with_dashes($panel->name) . ' menu-top mf-menu-' . $type_write_panel, 'mf-menu-' . $panel->id, 'div');
                 //adding submenu options (add new and manage for each write panel)
                 if ($panel->type == "post") {
                     if ($panel->single == 1) {
                         //if the post is single
                         if ($add_post) {
                             //if the post is single and don't have any related post
                             add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                         } else {
                             //if have one related post we just can  edit the post
                             add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPostsCap, 'post.php?action=edit&post=' . $has_posts);
                         }
                     } else {
                         add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPostsCap, 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     }
                 } else {
                     if ($panel->single == 1) {
                         //if the page is single
                         if ($add_post) {
                             //if the page is single and don't have any related post
                             add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, $page_new . 'custom-write-panel-id=' . $panel->id);
                         } else {
                             add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPagesCap, $page_edit . 'action=edit&post=' . $has_posts);
                         }
                     } else {
                         add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPagesCap, $page_manage . 'filter-posts=1&custom-write-panel-id=' . $panel->id);
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, $page_new . 'custom-write-panel-id=' . $panel->id);
                     }
                 }
             } else {
                 //if condenced is activated
                 if ($panel->type == "post") {
                     if ($panel->single == 1) {
                         //if the post is single
                         if ($add_post) {
                             //if the post is single and don't have any related post
                             add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                         }
                     } else {
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     }
                 } else {
                     if ($panel->single == 1) {
                         //if the page is single
                         if ($add_post) {
                             //if the page is single and don't have any related post
                             add_submenu_page('page-new.php', __($panel->name), __($panel->name), $requiredPagesCap, $page_new . 'custom-write-panel-id=' . $panel->id);
                         } else {
                             add_submenu_page('page-new.php', __($panel->name), __($panel->name) . " (Edit)", $requiredPagesCap, $page_edit . 'action=edit&post=' . $has_posts);
                         }
                     } else {
                         add_submenu_page('page-new.php', __($panel->name), __($panel->name), $requiredPagesCap, $page_new . 'custom-write-panel-id=' . $panel->id);
                     }
                 }
             }
         }
         // traversal: endif '$panel->name == '_Global'
     }
     foreach ($menu as $k => $v) {
         if ($k > 5) {
             $new_menu[$k + $offset] = $v;
         }
     }
     global $_wp_last_utility_menu;
     $_wp_last_utility_menu += $offset;
     $menu = $new_menu;
     RCCWP_Menu::SetCurrentCustomWritePanelMenuItem();
 }
Пример #2
0
 function AttachCustomWritePanelMenuItems()
 {
     global $submenu, $menu;
     global $mf_domain, $wpdb;
     require_once 'RCCWP_Options.php';
     $assignToRole = RCCWP_Options::Get('assign-to-role');
     $requiredPostsCap = 'edit_posts';
     $requiredPagesCap = 'edit_pages';
     $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
     $new_indicator_text = __('New', $mf_domain);
     $edit_indicator_text = __('Manage', $mf_domain);
     $new_menu = array();
     ksort($menu);
     foreach ($menu as $k => $v) {
         if ($k > 5) {
             break;
         }
         $new_menu[$k] = $v;
     }
     $base = 5;
     $offset = 0;
     $add_post = false;
     foreach ($customWritePanels as $panel) {
         //exists a single write panel? and if exists  this write panel have posts?
         if ($panel->single == 1) {
             $has_posts = $wpdb->get_var('SELECT post_id FROM ' . $wpdb->prefix . 'postmeta  where meta_key = "_mf_write_panel_id" and  meta_value = ' . $panel->id);
             if (empty($has_posts)) {
                 $add_post = true;
             } else {
                 $add_post = false;
             }
         }
         $offset++;
         if ($panel->type == "post") {
             $type_write_panel = "edit-posts";
         } else {
             $type_write_panel = "edit-pages";
         }
         if ($assignToRole == 1) {
             $requiredPostsCap = $panel->capability_name;
             $requiredPagesCap = $panel->capability_name;
         }
         require_once 'RCCWP_Options.php';
         $condence = RCCWP_Options::Get('condense-menu');
         //IF we has unactivated the condenced menu
         if (!$condence) {
             //adding the top parent menus
             $new_menu[$base + $offset] = array(__($panel->name), $type_write_panel, $base + $offset . '.php', '', 'wp-menu-open menu-top mf-menu-' . $type_write_panel, 'mf-menu-' . ($base + $offset), 'div');
             //adding submenu options (add new and manage for each write panel)
             if ($panel->type == "post") {
                 if ($panel->single == 1) {
                     //if the post is single
                     if ($add_post) {
                         //if the post is single and don't have any related post
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         //if have one related post we just can  edit the post
                         add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPostsCap, 'post.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPostsCap, 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             } else {
                 if ($panel->single == 1) {
                     //if the page is single
                     if ($add_post) {
                         //if the page is single and don't have any related post
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPagesCap, 'page.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPagesCap, 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             }
         } else {
             //if condenced is activated
             if ($panel->type == "post") {
                 if ($panel->single == 1) {
                     //if the post is single
                     if ($add_post) {
                         //if the post is single and don't have any related post
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     }
                 } else {
                     add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                 }
             } else {
                 if ($panel->single == 1) {
                     //if the page is single
                     if ($add_post) {
                         //if the page is single and don't have any related post
                         add_submenu_page('page-new.php', __($panel->name), __($panel->name), $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     }
                 } else {
                     add_submenu_page('page-new.php', __($panel->name), __($panel->name), $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                 }
             }
         }
     }
     foreach ($menu as $k => $v) {
         if ($k > 5) {
             $new_menu[$k + $offset] = $v;
         }
     }
     $menu = $new_menu;
     RCCWP_Menu::SetCurrentCustomWritePanelMenuItem();
 }
Пример #3
0
 function AttachCustomWritePanelMenuItems()
 {
     global $wp_version;
     global $submenu, $menu;
     global $flutter_domain, $wpdb;
     require_once 'RCCWP_Options.php';
     $assignToRole = RCCWP_Options::Get('assign-to-role');
     $requiredPostsCap = 'edit_posts';
     $requiredPagesCap = 'edit_pages';
     $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
     if ($wp_version < 2.7) {
         $add_post = false;
         foreach ($customWritePanels as $panel) {
             if ($panel->single == 1) {
                 $has_posts = $wpdb->get_var('SELECT post_id FROM ' . $wpdb->prefix . 'postmeta  where meta_key = "_rc_cwp_write_panel_id" and  meta_value = ' . $panel->id);
                 if (empty($has_posts)) {
                     $add_post = true;
                 } else {
                     $add_post = false;
                 }
             }
             if ($assignToRole == 1) {
                 $requiredPostsCap = $panel->capability_name;
                 $requiredPagesCap = $panel->capability_name;
             }
             if ($panel->type == "post") {
                 if ($panel->single == 1) {
                     //if the post is single
                     if ($add_post) {
                         //if the post is single and don't have any related post
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         //if have one related post we just can  edit the post
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), 8, 'post.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page('edit.php', __($panel->name), __($panel->name), $requiredPostsCap, 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             } else {
                 if ($panel->single == 1) {
                     //if the page is single
                     if ($add_post) {
                         //if the page is single and don't have any related post
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         add_submenu_page('post-new.php', __($panel->name), __($panel->name), 8, 'page.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page('edit.php', __($panel->name), __($panel->name), $requiredPagesCap, 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             }
         }
     }
     if ($wp_version >= 2.7) {
         $new_indicator_text = __('New', $flutter_domain);
         $edit_indicator_text = __('Manage', $flutter_domain);
         $new_menu = array();
         foreach ($menu as $k => $v) {
             if ($k > 5) {
                 break;
             }
             $new_menu[$k] = $v;
         }
         $base = 5;
         $offset = 0;
         $add_post = false;
         foreach ($customWritePanels as $panel) {
             //exists a single write panel? and if exists  this write panel have posts?
             if ($panel->single == 1) {
                 $has_posts = $wpdb->get_var('SELECT post_id FROM ' . $wpdb->prefix . 'postmeta  where meta_key = "_rc_cwp_write_panel_id" and  meta_value = ' . $panel->id);
                 if (empty($has_posts)) {
                     $add_post = true;
                 } else {
                     $add_post = false;
                 }
             }
             $offset++;
             //thanks a Ashish Puliyel <*****@*****.**> by observing the roles of users
             if ($panel->type == "post") {
                 $type_write_panel = "edit-posts";
             } else {
                 $type_write_panel = "edit-pages";
             }
             $new_menu[$base + $offset] = array(__($panel->name), $type_write_panel, $base + $offset . '.php', '', 'wp-menu-open menu-top', 'menu-pages', 'div');
             if ($assignToRole == 1) {
                 $requiredPostsCap = $panel->capability_name;
                 $requiredPagesCap = $panel->capability_name;
             }
             if ($panel->type == "post") {
                 if ($panel->single == 1) {
                     //if the post is single
                     if ($add_post) {
                         //if the post is single and don't have any related post
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         //if have one related post we just can  edit the post
                         add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPostsCap, 'post.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPostsCap, 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             } else {
                 if ($panel->single == 1) {
                     //if the page is single
                     if ($add_post) {
                         //if the page is single and don't have any related post
                         add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     } else {
                         add_submenu_page($base + $offset . '.php', __($panel->name), "Edit", $requiredPagesCap, 'page.php?action=edit&post=' . $has_posts);
                     }
                 } else {
                     add_submenu_page($base + $offset . '.php', __($panel->name), $new_indicator_text, $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
                     add_submenu_page($base + $offset . '.php', __($panel->name), $edit_indicator_text, $requiredPagesCap, 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
                 }
             }
         }
         foreach ($menu as $k => $v) {
             if ($k > 5) {
                 $new_menu[$k + $offset] = $v;
             }
         }
         $menu = $new_menu;
     }
     RCCWP_Menu::SetCurrentCustomWritePanelMenuItem();
 }