| Server IP : 68.183.124.220 / Your IP : 216.73.217.137 Web Server : Apache/2.4.18 (Ubuntu) System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64 User : gavin ( 1000) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/wp-content/plugins/usp-pro/inc/ |
Upload File : |
<?php // USP Pro - Dashboard Widget
if (!defined('ABSPATH')) die();
function usp_pro_dashboard_widget_draft_posts() {
global $post, $usp_advanced;
if (apply_filters('usp_dashboard_widget', false)) return;
$display = (apply_filters('usp_widget_drafts_display', true) && usp_pro_display_all_posts()) ? true : false;
$message_none = '<p>'. apply_filters('usp_widget_drafts_message_none', esc_html__('No posts in queue.', 'usp-pro')) .'</p>';
$message_some = '<p>'. apply_filters('usp_widget_drafts_message_some', esc_html__('Submitted posts in queue:', 'usp-pro')) .'</p>';
$userid = apply_filters('usp_widget_drafts_user', get_current_user_id());
$posts_per_page = apply_filters('usp_widget_drafts_number', -1);
$post_types = apply_filters('usp_widget_drafts_type', array('post', 'page', 'usp_post'));
$existing_post_type = (isset($usp_advanced['other_type']) && !empty($usp_advanced['other_type'])) ? $usp_advanced['other_type'] : null;
if (post_type_exists($existing_post_type)) $post_types[] = $existing_post_type;
$post_status = apply_filters('usp_widget_drafts_status', array('draft', 'future', 'pending'));
$args = array(
'author' => $userid,
'posts_per_page' => $posts_per_page,
'post_type' => $post_types,
'post_status' => $post_status,
'meta_key' => 'is_submission',
'meta_value' => '1'
);
if ($display || empty($userid)) unset($args['author']);
$submitted_posts = get_posts($args);
$post_count = count($submitted_posts);
if (isset($post_count) && (int) $post_count > 0) {
echo $message_some;
echo '<ul>';
foreach ($submitted_posts as $post) {
setup_postdata($post);
$post_author = get_the_author();
$post_title = get_the_title();
$post_edit = get_edit_post_link();
$post_schedule = apply_filters('usp_widget_drafts_time', get_the_time('l, F j, Y @ h:i:s a'));
$post_date = get_post_meta(get_the_ID(), 'usp-post-time', true) ? get_post_meta(get_the_ID(), 'usp-post-time', true) : $post_schedule;
$post_status = get_post_status() === 'future' ? esc_html__(' Scheduled: ', 'usp-pro') . $post_schedule : ucfirst(get_post_status());
$post_type = get_post_type();
$post_type_obj = get_post_type_object($post_type);
$post_type_name = is_object($post_type_obj) ? $post_type_obj->labels->singular_name : ucwords(str_replace('_', ' ', $post_type));
$post_type_name = strcasecmp($post_type_name, 'usp post') == 0 ? 'USP Post' : $post_type_name;
if (current_user_can('edit_posts') && !empty($post_edit)) {
$post_link = '<a href="'. $post_edit .'" title="'. esc_attr__('Edit this post', 'usp-pro') .'">'. $post_title .'</a>';
} else {
$post_link = $post_title;
}
echo '<li>';
echo '<strong>'. $post_link .'</strong> – <small><em>'. $post_status .'</em></small><br />';
echo '<small>'. $post_type_name . esc_html__(' submitted by ', 'usp-pro') . $post_author . esc_html__(' on ', 'usp-pro') . $post_date .'</small>';
echo '</li>';
}
echo '</ul>';
wp_reset_postdata();
} else {
echo $message_none;
}
}
function usp_pro_get_current_user_roles() {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$roles = (array) $user->roles;
return $roles;
} else {
return array();
}
}
function usp_pro_display_all_posts() {
$roles = usp_pro_get_current_user_roles();
$allowed = apply_filters('usp_widget_display_all_posts', array('administrator', 'editor'));
foreach ($allowed as $allow) {
if (in_array($allow, $roles)) return true;
}
return false;
}
function usp_pro_dashboard_widgets() {
wp_add_dashboard_widget('usp_pro_dashboard_widget_draft_posts', esc_html__('Submitted Post Queue', 'usp-pro'), 'usp_pro_dashboard_widget_draft_posts');
}
add_action('wp_dashboard_setup', 'usp_pro_dashboard_widgets');
function usp_pro_add_glance_items() {
global $post, $usp_advanced;
if (apply_filters('usp_add_glance_items', false)) return;
$post_types = array(
'post' => __('Submitted Post', 'usp-pro'),
'page' => __('Submitted Page', 'usp-pro'),
'usp_post' => __('Submitted USP Post', 'usp-pro'),
);
$existing_post_type = (isset($usp_advanced['other_type']) && !empty($usp_advanced['other_type'])) ? $usp_advanced['other_type'] : null;
if (post_type_exists($existing_post_type)) {
$post_type_object = get_post_type_object($existing_post_type);
$existing_label = $post_type_object->labels->singular_name;
$post_types[$existing_post_type] = $existing_label;
}
$post_types = apply_filters('usp_widget_submitted_type', $post_types);
$post_status = apply_filters('usp_widget_submitted_status', array('draft', 'future', 'pending', 'publish'));
foreach ($post_types as $post_type => $post_name) {
if (!$post_type || !$post_name) continue;
$count = 0;
$args = array(
'posts_per_page' => -1,
'post_type' => $post_type,
'post_status' => $post_status,
);
$posts = get_posts($args);
if (!$posts) continue;
foreach ($posts as $post) {
if (usp_is_submitted($post->ID)) $count++;
}
if (!$count) continue;
$count = number_format_i18n($count);
$post_name = ($count == 1) ? $post_name : $post_name .'s';
$link = '<a href="'. admin_url('edit.php?post_type='. esc_attr($post_type)) .'">'. esc_html($count) .' '. esc_html($post_name) .'</a>';
echo '<li class="post-count '. esc_attr($post_type) .'-count">'. $link .'</li>';
}
}
add_action('dashboard_glance_items', 'usp_pro_add_glance_items');