Exemplo n.º 1
0
  public static function admin_bar_menu() {
    
    global $wp_admin_bar, $wf;
    
    $caps = array(
      "manage_masterplan" => MasterPress::get_cap_key("manage_masterplan"),
      "manage_post_types" => MasterPress::get_cap_key("manage_post_types"),
      "manage_taxonomies" => MasterPress::get_cap_key("manage_taxonomies"),
      "manage_templates" => MasterPress::get_cap_key("manage_templates"),
      "manage_user_roles" => MasterPress::get_cap_key("manage_user_roles"),
      "manage_site_field_sets" => MasterPress::get_cap_key("manage_site_field_sets"),
      "manage_shared_field_sets" => MasterPress::get_cap_key("manage_shared_field_sets"),
      "manage_mp_settings" => MasterPress::get_cap_key("manage_mp_settings")
    );
    
    
    $menu_items = array(
      array(
        'id' => 'masterpress',
        'title' => 'Masterplan',
        'href' => admin_url('admin.php?page=masterpress')
      )
    );
    
    
    if (self::current_user_can('manage_mp_tools')) {
    
      $menu_items[] = array(
        'id' => 'masterpress-tools',
        'parent' => 'masterpress',
        'title' => __('Tools', MASTERPRESS_DOMAIN),
        'href' => '#',
        'meta' => array('class' => "secondary")
      );

      $menu_items[] = array(
        "id" => "masterpress-flush-rewrite-rules",
        "title" => __("Flush Rewrite Rules"),
        'parent' => 'masterpress-tools',
        "href" => add_query_arg( array("mp_rewrite" => 1), $wf->current_url() )
      );

      $menu_items[] = array(
        "id" => "masterpress-image-cache-site",
        "title" => __("Clear Image Cache (Site)"),
        'parent' => 'masterpress-tools',
        "href" => add_query_arg( array("mp_image_cache_site" => 1), $wf->current_url() )
      );
      
      $menu_items[] = array(
        "id" => "masterpress-image-cache-admin",
        "title" => __("Clear Image Cache (Admin)"),
        'parent' => 'masterpress-tools',
        "href" => add_query_arg( array("mp_image_cache_admin" => 1), $wf->current_url() ) 
      );
      
    }
    
    
    
    if (self::current_user_can('manage_post_types')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-post-types',
        'parent' => 'masterpress',
        'title' => __('Post Types', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-post-types'), 'masterpress')
      );
      
    }

    if (self::current_user_can('edit_post_types')) {
      
      foreach (self::$post_types as $post_type) {
        if ($post_type->still_registered()) {
          $menu_items[] = array(
            'id' => 'masterpress-post-type-'.$post_type->name,
            'parent' => 'masterpress-post-types',
            'title' => '<b class="mp-icon mp-icon-post-type mp-icon-post-type-'.$post_type->name.'">'.$post_type->display_label().'</b>',
            'href' => MasterPress::admin_url("post-types", "edit", "id=".$post_type->id)
          );
        }
      }
      
    }



    if (self::current_user_can('manage_taxonomies')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-taxonomies',
        'parent' => 'masterpress',
        'title' => __('Taxonomies', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-taxonomies'), 'masterpress')
      );
      
    }    
    
      if (self::current_user_can('edit_taxonomies')) {
      
        foreach (self::$taxonomies as $tax) {
          if ($tax->still_registered()) {

            $menu_items[] = array(
              'id' => 'masterpress-post-type-'.$tax->name,
              'parent' => 'masterpress-taxonomies',
              'title' => '<b class="mp-icon mp-icon-taxonomy mp-icon-taxonomy-'.$tax->name.'">'.$tax->display_label().'</b>',
              'href' => MasterPress::admin_url("taxonomies", "edit", "id=".$tax->id)
            );
            
          }
        }
      
      }


    if (self::current_user_can('manage_templates')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-templates',
        'parent' => 'masterpress',
        'title' => __('Templates', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-templates'), 'masterpress')
      );

    }
  
    if (self::current_user_can('manage_shared_field_sets')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-shared-field-sets',
        'parent' => 'masterpress',
        'title' => __('Shared Field Sets', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-shared-field-sets'), 'masterpress')
      );
      
    }
    
    if (self::current_user_can('manage_user_roles')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-roles',
        'parent' => 'masterpress',
        'title' => __('User Roles', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-roles'), 'masterpress')
      );

    }
    

    if (self::current_user_can('manage_site_field_sets')) {
      
      $menu_items[] = array(
        'id' => 'masterpress-site-field-sets',
        'parent' => 'masterpress',
        'title' => __('Site Field Sets', MASTERPRESS_DOMAIN),
        'href' => wp_nonce_url(admin_url('admin.php?page=masterpress-site-field-sets'), 'masterpress')
      );

    }
    
    $add_menu_items = array(
      
      array(
        'id' => 'masterpress-add-new',
        'parent' => 'masterpress',
        'title' => __('Add New', MASTERPRESS_DOMAIN),
        'href' => '#',
        'meta' => array('class' => "secondary")
      )
      
    );
    
    if (self::current_user_can('create_post_types')) {
      
      $add_menu_items[] = array(
        'id' => 'masterpress-add-new-post-type',
        'parent' => 'masterpress-add-new',
        'title' => __('Post Type', MASTERPRESS_DOMAIN),
        'href' => MasterPress::admin_url("post-types", "create")
      );
      
    }

    if (self::current_user_can('create_taxonomies')) {
      
      $add_menu_items[] = array(
        'id' => 'masterpress-add-new-taxonomy',
        'parent' => 'masterpress-add-new',
        'title' => __('Taxonomy', MASTERPRESS_DOMAIN),
        'href' => MasterPress::admin_url("taxonomies", "create")
      );
      
    }

    if (self::current_user_can('create_user_roles')) {

      $add_menu_items[] = array(
        'id' => 'masterpress-add-new-user-role',
        'parent' => 'masterpress-add-new',
        'title' => __('User Role', MASTERPRESS_DOMAIN),
        'href' => MasterPress::admin_url("roles", "create")
      );
      
    }
    
    if (self::current_user_can('create_shared_field_sets')) {

      $add_menu_items[] = array(
        'id' => 'masterpress-add-new-shared-field-set',
        'parent' => 'masterpress-add-new',
        'title' => __('Shared Field Set', MASTERPRESS_DOMAIN),
        'href' => MasterPress::admin_url("shared-field-sets", "create")
      );
      
    }

    if (self::current_user_can('create_site_field_sets')) {

      $add_menu_items[] = array(
        'id' => 'masterpress-add-new-site-field-set',
        'parent' => 'masterpress-add-new',
        'title' => __('Site Field Set', MASTERPRESS_DOMAIN),
        'href' => MasterPress::admin_url("site-field-sets", "create")
      );
      
    }
    
    if (count($add_menu_items) > 1) {
      $menu_items = array_merge($menu_items, $add_menu_items);
    } 


    


    if (count($menu_items) > 1) {

      foreach ($menu_items as $menu_item) {
        $wp_admin_bar->add_menu($menu_item);
      }
        
    }
        
  }