Skip to content

Commit

Permalink
Finished 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
joelworsham committed Sep 26, 2014
1 parent 9058e66 commit a97cc34
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 47 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Using this plugin is very simple. All you have to do is:

### [1.6.0](https://github.com/brashrebel/client-dash/releases/tag/v1.6.0)
* Added adminmenu customizing functionality under Settings -> Menus.
* Revised widgets area to properly use the WP Widget API.
* Made core much more extensible.
* Created Widgets, Menus, and Settings API for Client Dash.
* Other bug fixes and improvements.

### [1.5.5](https://github.com/brashrebel/client-dash/releases/tag/v1.5.5)
* Fixed PHP notice error.
Expand Down
2 changes: 1 addition & 1 deletion assets/css/clientdash.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/clientdash.min.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions assets/js/source/cd.adminmenu.js → assets/js/source/cd.menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*
* @since ClientDash 1.6
*/
var cdAdminMenu;
var cdMenus;
(function ($) {
cdAdminMenu = {
cdMenus = {
init: function () {
this.modify_max_menu_depth();
this.jQuery_extensions();
Expand Down Expand Up @@ -282,12 +282,14 @@ var cdAdminMenu;
else
subMenuTitle.hide();

// CD {
// Hide or show icon
menuIcon = ui.item.find('.dashicons');
menuIcon = ui.item.find('.item-title .dashicons');
if (currentDepth == 0)
menuIcon.removeClass('hidden');
else
menuIcon.addClass('hidden');
// } End CD

// Update depth classes
if (0 !== depthChange) {
Expand Down Expand Up @@ -437,7 +439,9 @@ var cdAdminMenu;

// Show on click
$('.edit-menu-item-cd-icon').click(function (e) {

e.stopPropagation();

if ($(this).is(':focus')) {
$(this).closest('.cd-menu-icon-field').find('.cd-menu-icon-selector').show();
}
Expand All @@ -450,18 +454,21 @@ var cdAdminMenu;

// Use new icon val on click
$('.cd-menu-icon-selector').find('li').click(function () {
var icon = $(this).attr('data-icon');

var icon = $(this).attr('data-icon'),
new_class = $(this).closest('.menu-item').hasClass('menu-item-depth-1') ? 'dashicons hidden ' + icon : 'dashicons ' + icon;

$(this).closest('.cd-menu-icon-field').find('input[type="text"]').val(icon);
$(this).closest('.menu-item').find('.item-title').find('.dashicons').attr('class', 'dashicons ' + icon);

$(this).closest('.menu-item').find('.item-title').find('.dashicons').attr('class', new_class);
});
}
};

$(function () {
// Only initialize if on CD page and if the page isn't "disabled"
if ($('body').hasClass('cd-nav-menu') && !$('#menu-settings-column').hasClass('metabox-holder-disabled')) {
cdAdminMenu.init();
cdMenus.init();
}
});
})(jQuery);
7 changes: 0 additions & 7 deletions assets/scss/_elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@
.cd-progress-bar-percent {
position: relative;
line-height: 30px;
// color: #fff;
z-index: 2;
}
}

// Error messages
.cd-message {
width: 90%;
max-width: 500px;
}
23 changes: 12 additions & 11 deletions client-dash.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Author URI: http://realbigmarketing.com/staff/kyle
*/

// FIXED Add nag on icons page if under wp 3.9 because not all icons will show
// TODO Allow dashboard meta box styling to be disabled (possibly extension?)
// TODO Correctly line break documentation to PHP guideline

// NEXTUPDATE 1.7 - Themes
// NEXTUPDATE 1.7 -

Expand Down Expand Up @@ -634,18 +638,15 @@ public function add_new_widgets() {
$widget['ID'] = isset( $widget['_cd_extension'] ) && $widget['_cd_extension'] == '1' ? $ID : $ID_base;

// Add it on
$new_widgets[ $widget['ID'] ] = $widget;

// Remove ID
unset( $new_widgets[ $widget['ID'] ]['ID'] );
$new_widgets[ ] = $widget;
}
}

if ( ! empty( $new_widgets ) ) {
foreach ( $new_widgets as $widget_ID => $widget ) {
foreach ( $new_widgets as $widget ) {

// Pass over if is a plugin / theme / WP Core widget and didn't original exist for current user
if ( $widget['plugin'] == '1' && ! array_key_exists( $widget_ID, $this->active_widgets ) ) {
if ( $widget['plugin'] == '1' && ! array_key_exists( $widget['ID'], $this->active_widgets ) ) {
return;
}

Expand All @@ -657,13 +658,13 @@ public function add_new_widgets() {

// Client Dash core widgets conditional visibility
if ( isset( $widget['_cd_core'] ) && $widget['_cd_core'] === '1' ) {
if ( ! isset( $this->content_sections[ str_replace( 'cd_', '', $widget_ID ) ] ) ) {
if ( ! isset( $this->content_sections[ str_replace( 'cd_', '', $widget['ID'] ) ] ) ) {
continue;
}
}

// If this ID already exists, change the ID to something new
if ( ! empty( $wp_meta_boxes ) && $this->array_key_exists_r( $widget_ID, $wp_meta_boxes ) ) {
if ( ! empty( $wp_meta_boxes ) && $this->array_key_exists_r( $widget['ID'], $wp_meta_boxes ) ) {

// If the ID contains "_duplicate_{n}", then we need another new ID, so
// we use a prep_replace_callback to replace the "_duplicate_{n}" with
Expand All @@ -672,7 +673,7 @@ public function add_new_widgets() {
foreach ( $wp_meta_boxes['dashboard'] as $context ) {
foreach ( $context as $priority ) {
foreach ( $priority as $ID => $wp_widget ) {
if ( strpos( $ID, $widget_ID ) !== false ) {
if ( strpos( $ID, $widget['ID'] ) !== false ) {
if ( preg_match( '/(_duplicate_)(\d+)/', $ID ) ) {
$new_ID = preg_replace_callback(
'/(_duplicate_)(\d+)/',
Expand All @@ -689,7 +690,7 @@ public function add_new_widgets() {
}

// For webmaster widget
if ( $widget_ID == 'cd_webmaster' ) {
if ( $widget['ID'] == 'cd_webmaster' ) {
$title = get_option( 'cd_webmaster_name', $this->option_defaults['webmaster_name'] );
}

Expand All @@ -702,7 +703,7 @@ public function add_new_widgets() {
}

add_meta_box(
isset( $new_ID ) ? $new_ID : $widget_ID,
isset( $new_ID ) ? $new_ID : $widget['ID'],
$title,
$widget['_callback'],
'dashboard',
Expand Down
1 change: 1 addition & 0 deletions core/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function populate_nav_menu() {
// Pass over if current role doesn't have the capabilities
$no_parent = false;
if ( array_key_exists( $menu_item['capability'], $role->capabilities ) ) {

$args = ClientDash_Core_Page_Settings_Tab_Menus::sort_original_admin_menu( $menu_item );

// Predefined menu position
Expand Down
6 changes: 4 additions & 2 deletions core/extension-apis/menus-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ public static function loop( $i, $label, $options_args ) {
*
* @since Client Dash 1.6
*
* @param string $ID The unique ID of this menu group.
* @param string $name The unique name of this menu group.
* @param array $items Array of tabs and items.
*/
public static function group_output( $ID, $items ) {
public static function group_output( $name, $items ) {

$ID = self::translate_name_to_id( $name );
?>
<div id="<?php echo $ID; ?>" class="posttypediv">

Expand Down
2 changes: 1 addition & 1 deletion core/extension-apis/settings-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function checkbox_field( $ID, $field, $title, $atts = [ ] ) {
$classes = explode( ' ', $atts['class'] );
}

$checked = isset( $value ) ? 'checked' : '';
$checked = $value === '1' ? 'checked' : '';

$html = '';

Expand Down
7 changes: 7 additions & 0 deletions core/tabs/settings/icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,17 @@ function __construct() {
*/
public function block_output() {

global $wp_version;

$account_dashicon = get_option( 'cd_dashicon_account', $this->option_defaults['dashicon_account'] );
$reports_dashicon = get_option( 'cd_dashicon_reports', $this->option_defaults['dashicon_reports'] );
$help_dashicon = get_option( 'cd_dashicon_help', $this->option_defaults['dashicon_help'] );
$webmaster_dashicon = get_option( 'cd_dashicon_webmaster', $this->option_defaults['dashicon_webmaster'] );

// Show nag if not up to date, because not all icons exist in WP pre 1.9
if ( floatval( $wp_version ) < 3.9 ) {
self::error_nag( 'You are currently running a version of WordPress below 1.9. Not all icons exist before 1.9 and will not show here properly. Please update WordPress as soon as you can.' );
}
?>

<input type="hidden" id="cd_dashicon_account" name="cd_dashicon_account"
Expand Down
45 changes: 29 additions & 16 deletions core/tabs/settings/menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class ClientDash_Core_Page_Settings_Tab_Menus extends ClientDash {
*/
public $create_new = false;

/**
* Counts the total menu items. Used for when importing via AJAX.
*
* @since Client Dash 1.6
*/
public $total_menu_items;

/**
Expand Down Expand Up @@ -84,15 +89,15 @@ class ClientDash_Core_Page_Settings_Tab_Menus extends ClientDash {
/**
* All WordPress core nav menu items (aside from post types).
*
* Unfortunatley, there's no good way to get this dynamically BECAUSE I can't tell the
* Unfortunately, there's no good way to get this dynamically BECAUSE I can't tell the
* difference between an item added by WP Core and an item added by a plugin. So my
* work-around is to define WP Core items and have the rest automatically fall into the
* plugin / theme category. This is fine, we just need to make sure this array is always
* up to date.
*
* @since Client Dash 1.6
*/
public $wp_core = array(
public static $wp_core = array(
'Dashboard' => array(
'url' => 'index.php',
'icon' => 'dashicons-dashboard',
Expand Down Expand Up @@ -369,14 +374,17 @@ function __construct() {

// Create if told so from GET
if ( isset( $_GET['cd_create_admin_menu'] ) ) {
add_action( 'admin_menu', array( $this, 'create_nav_menu' ), 99995 );
add_action( 'admin_menu', array( $this, 'create_nav_menu' ), 99996 );
}

// Create/Get CD nav menu
add_action( 'admin_menu', array( $this, 'get_cd_nav_menus' ), 99996 );
add_action( 'admin_menu', array( $this, 'get_cd_nav_menus' ), 99997 );

// Remove the original admin menu
add_action( 'admin_menu', array( $this, 'remove_orig_admin_menu' ), 99998 );

// Remove the original admin menu (and also add the modified menu)
add_action( 'admin_menu', array( $this, 'remove_orig_admin_menu' ), 99999 );
// Add the modified menu
add_action( 'admin_menu', array( $this, 'add_modified_admin_menu' ), 99999 );

// Hide the CD nav menu from the normal nav menu page
add_filter( 'wp_get_nav_menus', array( $this, 'hide_cd_nav_menu' ) );
Expand Down Expand Up @@ -463,7 +471,7 @@ private function filter_data() {
*
* @since Client Dash 1.6
*/
$this->wp_core = apply_filters( 'cd_nav_menu_wp_core_items', $this->wp_core );
$this::$wp_core = apply_filters( 'cd_nav_menu_wp_core_items', $this::$wp_core );
}

/**
Expand Down Expand Up @@ -618,6 +626,11 @@ public function modify_role() {

global $current_user, $wp_roles, $super_admins, $menu, $submenu;

// Don't bother for admin
if ( $_POST['cd_create_admin_menu'] == 'administrator' ) {
return;
}

// If we're changing the role to something that's not an administrator, we need to make sure
// that we make WP think the current user is NOT super admin, because that overrides all
// capabilities
Expand All @@ -630,7 +643,7 @@ public function modify_role() {
// Otherwise modify the current user object
$current_user->allcaps = $wp_roles->roles[ $new_role ]['capabilities'];
$current_user->roles[0] = strtolower( $new_role );
unset( $current_user->caps[ $this->get_user_role() ] );
unset( $current_user->caps[ self::get_user_role() ] );
$current_user->caps[ $new_role ] = true;
}

Expand All @@ -652,13 +665,13 @@ public function get_role_menu_items() {
);
}

set_transient( 'cd_role_menu_items', $menu_items, 60 );
set_transient( 'cd_role_menu_items', isset( $menu_items ) ? $menu_items : '', 60 );

wp_redirect(
add_query_arg(
array(
'cd_create_admin_menu' => $_POST['cd_create_admin_menu'],
'import_items' => '1',
'import_items' => $_POST['import_items'],
),
remove_query_arg( 'menu' )
)
Expand Down Expand Up @@ -688,7 +701,7 @@ public function get_role_admin_menu() {
}

// Send the data back
wp_send_json( $AJAX_output );
wp_send_json( isset( $AJAX_output ) ? $AJAX_output : array( 'no_items' => true ) );
}

/**
Expand Down Expand Up @@ -1164,9 +1177,6 @@ public function remove_orig_admin_menu() {
}
}
}

// We removed it, now add it
$this->add_modified_admin_menu();
}

/**
Expand Down Expand Up @@ -1222,9 +1232,12 @@ public function add_modified_admin_menu() {
$menu_item->cd_page_title = get_option( 'cd_webmaster_name', $ClientDash->option_defaults['webmaster_name'] );
}

// If the comments page, get original html (because when there are new comments, the title changes)
// If the comments page, get the html generated mimicked from WP core (/wp-admin/menus.php:~94)
if ( $menu_item->title == 'Comments' ) {
$menu_item->title = isset( $this->original_admin_menu[20]['menu_title'] ) ? $this->original_admin_menu[20]['menu_title'] : 'Comments';

$awaiting_mod = wp_count_comments();
$awaiting_mod = $awaiting_mod->moderated;
$menu_item->title = sprintf( __('Comments %s'), "<span class='awaiting-mod count-$awaiting_mod'><span class='pending-count'>" . number_format_i18n($awaiting_mod) . "</span></span>" );
}

if ( strpos( $menu_item->url, 'separator' ) !== false ) {
Expand Down
6 changes: 4 additions & 2 deletions core/tabs/settings/menus/availableitems-callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public static function plugin() {
$title = $submenu_item['menu_slug'] == 'cd_webmaster' ? 'webmaster' : strtolower( $submenu_item['menu_title'] );
if ( isset( $wp_core[ $menu_item['menu_title'] ]['submenus'] )
&& ! array_key_exists( $submenu_item['menu_title'], $wp_core[ $menu_item['menu_title'] ]['submenus'] )
&& ! array_key_exists( $title, ClientDash::$core_files )
&& ! array_key_exists( $title, ClientDash::$core_files ) && $title != 'client dash'
) {
$menu_item['submenus'][] = $submenu_item;
}
Expand Down Expand Up @@ -737,6 +737,7 @@ public static function separator() {
* @since Client Dash 1.6
*/
public static function custom_link() {
// MAYBETODO Sanitize url
?>
<div id="custom-link" class="posttypediv">

Expand All @@ -747,7 +748,8 @@ public static function custom_link() {
<p id="menu-item-url-wrap">
<label class="howto" for="menu-item-url">
<span>URL</span>
<input type="text" class="menu-item-url code" placeholder="Link"
<input type="text" class="menu-item-url code"
placeholder="Link"
name="menu-item[-1][menu-item-url]" value="">
</label>
</p>
Expand Down
5 changes: 5 additions & 0 deletions core/tabs/settings/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public function create_existing_dashboard_widgets() {

foreach ( get_option( 'cd_active_widgets', array() ) as $widget_ID => $widget ) {

// Issue with html in quick press title
if ( strpos( $widget['title'], 'Quick Draft' ) !== false ) {
$widget['title'] = 'Quick Draft';
}

/**
* Allows filtering of supplied values for plugin / theme / WP Core available widgets.
*
Expand Down
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Using this plugin is very simple. All you have to do is:

= 1.6.0 =
* Added adminmenu customizing functionality under Settings -> Menus.
* Revised widgets area to properly use the WP Widget API.
* Made core much more extensible.
* Created Widgets, Menus, and Settings API for Client Dash.
* Other bug fixes and improvements.

= 1.5.5 =
* Fixed PHP notice error.
Expand Down

0 comments on commit a97cc34

Please sign in to comment.