cap->create_posts ) ) {
$quick_draft_title = sprintf( '%1$s %2$s', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
}
// WordPress Events and News
wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
if ( is_network_admin() ) {
/**
* Fires after core widgets for the Network Admin dashboard have been registered.
*
* @since 3.1.0
*/
do_action( 'wp_network_dashboard_setup' );
/**
* Filters the list of widgets to load for the Network Admin dashboard.
*
* @since 3.1.0
*
* @param array $dashboard_widgets An array of dashboard widgets.
*/
$dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
} elseif ( is_user_admin() ) {
/**
* Fires after core widgets for the User Admin dashboard have been registered.
*
* @since 3.1.0
*/
do_action( 'wp_user_dashboard_setup' );
/**
* Filters the list of widgets to load for the User Admin dashboard.
*
* @since 3.1.0
*
* @param array $dashboard_widgets An array of dashboard widgets.
*/
$dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
} else {
/**
* Fires after core widgets for the admin dashboard have been registered.
*
* @since 2.5.0
*/
do_action( 'wp_dashboard_setup' );
/**
* Filters the list of widgets to load for the admin dashboard.
*
* @since 2.5.0
*
* @param array $dashboard_widgets An array of dashboard widgets.
*/
$dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
}
foreach ( $dashboard_widgets as $widget_id ) {
$name = empty( $wp_registered_widgets[$widget_id]['all_link'] ) ? $wp_registered_widgets[$widget_id]['name'] : $wp_registered_widgets[$widget_id]['name'] . " " . __('View all') . '';
wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
}
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
ob_start(); // hack - but the same hack wp-admin/widgets.php uses
wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
ob_end_clean();
wp_redirect( remove_query_arg( 'edit' ) );
exit;
}
/** This action is documented in wp-admin/edit-form-advanced.php */
do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
/** This action is documented in wp-admin/edit-form-advanced.php */
do_action( 'do_meta_boxes', $screen->id, 'side', '' );
}
/**
* Adds a new dashboard widget.
*
* @since 2.7.0
*
* @global array $wp_dashboard_control_callbacks
*
* @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
* @param string $widget_name Title of the widget.
* @param callable $callback Function that fills the widget with the desired content.
* The function should echo its output.
* @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
* @param array $callback_args Optional. Data that should be set as the $args property of the widget array
* (which is the second parameter passed to your callback). Default null.
*/
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
$screen = get_current_screen();
global $wp_dashboard_control_callbacks;
$private_callback_args = array( '__widget_basename' => $widget_name );
if ( is_null( $callback_args ) ) {
$callback_args = $private_callback_args;
} else if ( is_array( $callback_args ) ) {
$callback_args = array_merge( $callback_args, $private_callback_args );
}
if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
$wp_dashboard_control_callbacks[$widget_id] = $control_callback;
if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
$widget_name .= ' ' . __( 'Cancel' ) . '';
$callback = '_wp_dashboard_control_callback';
} else {
list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
$widget_name .= ' ' . __( 'Configure' ) . '';
}
}
$side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
$location = 'normal';
if ( in_array($widget_id, $side_widgets) )
$location = 'side';
$priority = 'core';
if ( 'dashboard_browser_nag' === $widget_id )
$priority = 'high';
add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
}
/**
* Outputs controls for the current dashboard widget.
*
* @access private
* @since 2.7.0
*
* @param mixed $dashboard
* @param array $meta_box
*/
function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
echo '
';
}
/**
* Displays the dashboard.
*
* @since 2.5.0
*/
function wp_dashboard() {
$screen = get_current_screen();
$columns = absint( $screen->get_columns() );
$columns_css = '';
if ( $columns ) {
$columns_css = " columns-$columns";
}
?>
publish ) {
if ( 'post' == $post_type ) {
$text = _n( '%s Post', '%s Posts', $num_posts->publish );
} else {
$text = _n( '%s Page', '%s Pages', $num_posts->publish );
}
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
$post_type_object = get_post_type_object( $post_type );
if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
printf( '- %2$s
', $post_type, $text );
} else {
printf( '- %2$s
', $post_type, $text );
}
}
}
// Comments
$num_comm = wp_count_comments();
if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
$text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
?>
moderated );
/* translators: Number of comments in moderation */
$text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), $moderated_comments_count_i18n );
/* translators: Number of comments in moderation */
$aria_label = sprintf( _nx( '%s comment in moderation', '%s comments in moderation', $num_comm->moderated, 'comments' ), $moderated_comments_count_i18n );
?>
' . implode( "\n- ", $elements ) . "
\n";
}
?>
$content";
}
?>
' . __( 'Create a New Site' ) . '';
if ( current_user_can('create_users') )
$actions['create-user'] = '' . __( 'Create a New User' ) . '';
$c_users = get_user_count();
$c_blogs = get_blog_count();
/* translators: 1: Number of users on the network */
$user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
/* translators: 1: Number of sites on the network */
$blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
/* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network */
$sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
if ( $actions ) {
echo '';
foreach ( $actions as $class => $action ) {
$actions[ $class ] = "\t- $action";
}
echo implode( " |
\n", $actions ) . "\n";
echo '
';
}
?>
post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
$post = get_default_post_to_edit( 'post', true );
update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
} else {
$post->post_title = ''; // Remove the auto draft title
}
} else {
$post = get_default_post_to_edit( 'post' , true);
$user_id = get_current_user_id();
// Don't create an option if this is a super admin who does not belong to this site.
if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) )
update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
}
$post_ID = (int) $post->ID;
?>
'post',
'post_status' => 'draft',
'author' => get_current_user_id(),
'posts_per_page' => 4,
'orderby' => 'modified',
'order' => 'DESC'
);
/**
* Filters the post query arguments for the 'Recent Drafts' dashboard widget.
*
* @since 4.4.0
*
* @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
*/
$query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
$drafts = get_posts( $query_args );
if ( ! $drafts ) {
return;
}
}
echo '';
if ( count( $drafts ) > 3 ) {
echo '
' . __( 'View all drafts' ) . "
\n";
}
echo '
' . __( 'Your Recent Drafts' ) . "
\n
";
$drafts = array_slice( $drafts, 0, 3 );
foreach ( $drafts as $draft ) {
$url = get_edit_post_link( $draft->ID );
$title = _draft_or_post_title( $draft->ID );
echo "- \n";
/* translators: %s: post title */
echo '';
if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
echo '
' . $the_content . '
';
}
echo " \n";
}
echo "
\n
";
}
/**
* Outputs a row for the Recent Comments widget.
*
* @access private
* @since 2.7.0
*
* @global WP_Comment $comment
*
* @param WP_Comment $comment The current comment.
* @param bool $show_date Optional. Whether to display the date.
*/
function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
$GLOBALS['comment'] = clone $comment;
if ( $comment->comment_post_ID > 0 ) {
$comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
$comment_post_url = get_the_permalink( $comment->comment_post_ID );
$comment_post_link = "$comment_post_title";
} else {
$comment_post_link = '';
}
$actions_string = '';
if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
// Pre-order it: Approve | Reply | Edit | Spam | Trash.
$actions = array(
'approve' => '', 'unapprove' => '',
'reply' => '',
'edit' => '',
'spam' => '',
'trash' => '', 'delete' => '',
'view' => '',
);
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
$approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
$unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
$spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
$trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
$delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
$actions['approve'] = "" . __( 'Approve' ) . '';
$actions['unapprove'] = "" . __( 'Unapprove' ) . '';
$actions['edit'] = "". __( 'Edit' ) . '';
$actions['reply'] = '' . __( 'Reply' ) . '';
$actions['spam'] = "" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '';
if ( ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = "" . __( 'Delete Permanently' ) . '';
} else {
$actions['trash'] = "" . _x( 'Trash', 'verb' ) . '';
}
$actions['view'] = '';
/**
* Filters the action links displayed for each comment in the 'Recent Comments'
* dashboard widget.
*
* @since 2.6.0
*
* @param array $actions An array of comment actions. Default actions include:
* 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
* 'Delete', and 'Trash'.
* @param WP_Comment $comment The comment object.
*/
$actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
$i = 0;
foreach ( $actions as $action => $link ) {
++$i;
( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
// Reply and quickedit need a hide-if-no-js span
if ( 'reply' == $action || 'quickedit' == $action ) {
$action .= ' hide-if-no-js';
}
if ( 'view' === $action && '1' !== $comment->comment_approved ) {
$action .= ' hidden';
}
$actions_string .= "$sep$link";
}
}
?>
' . get_comment_author_link( $comment ) . '', $comment_post_link, '' . __( '[Pending]' ) . '' ); } else { printf( /* translators: 1: comment author, 2: notification if the comment is pending */ __( 'From %1$s %2$s' ), '' . get_comment_author_link( $comment ) . '', '' . __( '[Pending]' ) . '' ); } ?>
comment_type ) { case 'pingback' : $type = __( 'Pingback' ); break; case 'trackback' : $type = __( 'Trackback' ); break; default : $type = ucwords( $comment->comment_type ); } $type = esc_html( $type ); ?>$type", $comment_post_link, '' . __( '[Pending]' ) . '' ); } else { printf( /* translators: 1: type of comment, 2: notification if the comment is pending */ _x( '%1$s %2$s', 'dashboard' ), "$type", '' . __( '[Pending]' ) . '' ); } ?>
' . __( 'No activity yet!' ) . '
'; echo '