array(__('Rayachat: customers waiting for you', 'raya-ai'), 'normal', 'high', true),
'activity' => array(__('Rayachat: conversations and leads', 'raya-ai'), 'normal', 'core', true),
'plan' => array(__('Rayachat: plan and messages', 'raya-ai'), 'side', 'high', true),
'unanswered' => array(__('Rayachat: questions the bot couldn’t answer', 'raya-ai'), 'side', 'core', false),
'leads' => array(__('Rayachat: latest leads', 'raya-ai'), 'side', 'core', false),
'products' => array(__('Rayachat: products the bot showed', 'raya-ai'), 'normal', 'core', false),
'recent' => array(__('Rayachat: latest conversations', 'raya-ai'), 'normal', 'core', false),
);
}
function rayachat_dashboard_setup()
{
if (rayachat_settings()['secret'] === '' || !rayachat_inbox_can()) {
return;
}
if (!rayachat_inbox_active()) {
// One card that says what the others would show, until the site has the inbox.
wp_add_dashboard_widget('rayachat_card_waiting', esc_html__('Rayachat', 'raya-ai'), 'rayachat_render_dashboard_offer', null, null, 'normal', 'high');
return;
}
foreach (rayachat_dashboard_cards() as $card => $info) {
// Context and priority are read from WordPress 5.6 on; before it, every card starts in the main column.
wp_add_dashboard_widget('rayachat_card_' . $card, esc_html($info[0]), 'rayachat_render_dashboard_card', null, array('card' => $card), $info[1], $info[2]);
}
rayachat_dashboard_offer_cards();
}
/**
* WordPress applies a plugin's default-hidden boxes only to an admin who never
* saved a Screen Options choice, and most have one. So the first time an admin
* meets a card, an optional one is added to their own hidden list, once; from
* then on their choice is the only one that counts.
*/
function rayachat_dashboard_offer_cards()
{
$user = get_current_user_id();
$met = get_user_meta($user, 'rayachat_dashboard_cards', true);
$met = is_array($met) ? $met : array();
$cards = rayachat_dashboard_cards();
$new = array_diff(array_keys($cards), $met);
if (!$new) {
return;
}
$hidden = get_user_option('metaboxhidden_dashboard', $user);
if (is_array($hidden)) {
foreach ($new as $card) {
if (!$cards[$card][3]) {
$hidden[] = 'rayachat_card_' . $card;
}
}
update_user_meta($user, 'metaboxhidden_dashboard', array_values(array_unique($hidden)));
}
update_user_meta($user, 'rayachat_dashboard_cards', array_keys($cards));
}
// For an admin who never saved a Screen Options choice.
function rayachat_dashboard_hidden($hidden, $screen)
{
if (!$screen || $screen->id !== 'dashboard') {
return $hidden;
}
foreach (rayachat_dashboard_cards() as $card => $info) {
if (!$info[3]) {
$hidden[] = 'rayachat_card_' . $card;
}
}
return $hidden;
}
function rayachat_render_dashboard_card($unused, $box)
{
$card = isset($box['args']['card']) ? (string) $box['args']['card'] : '';
?>
is_array($cached) ? rayachat_inbox_summary_for_user($cached) : null,
'strings' => array(
/* translators: %s: number of customers. */
'waiting' => __('%s customers are waiting for you', 'raya-ai'),
'waitingOne' => __('A customer is waiting for you', 'raya-ai'),
'answer' => __('Answer in the inbox', 'raya-ai'),
'calm' => __('Nobody is waiting for a person right now.', 'raya-ai'),
'today' => __('Conversations today', 'raya-ai'),
'week' => __('Conversations this week', 'raya-ai'),
'solo' => __('Handled by the bot alone', 'raya-ai'),
'leadsWeek' => __('New leads this week', 'raya-ai'),
/* translators: %s: a change in percent, such as +12%. */
'vsYesterday' => __('%s vs. the day before', 'raya-ai'),
/* translators: %s: a change in percent, such as +12%. */
'vsLastWeek' => __('%s vs. the week before', 'raya-ai'),
/* translators: %s: number of replies. */
'botReplies' => __('%s replies by the bot this week', 'raya-ai'),
'noChats' => __('No conversations this week', 'raya-ai'),
'chart' => __('Conversations, last 14 days', 'raya-ai'),
/* translators: %s: number of conversations. */
'chartDay' => __('%s conversations', 'raya-ai'),
/* translators: %s: the plan's name. */
'plan' => __('Plan: %s', 'raya-ai'),
/* translators: 1: messages used, 2: messages in the plan. */
'planUse' => __('%1$s of %2$s messages used', 'raya-ai'),
/* translators: %s: messages used. */
'planUnlimited' => __('%s messages used, no limit', 'raya-ai'),
/* translators: %s: number of days. */
'planDays' => __('%s days left', 'raya-ai'),
'planLastDay' => __('Ends today', 'raya-ai'),
'overage' => __('The plan’s messages are used up; replies are being paid from the Rayachat wallet.', 'raya-ai'),
'noUnanswered' => __('Nothing in the last 30 days: the bot found an answer to every question.', 'raya-ai'),
/* translators: %s: how many times the question was asked. */
'asked' => __('asked %s times', 'raya-ai'),
'noLeads' => __('No leads yet. Turn on the lead form in the Rayachat dashboard: your chatbot → Widget.', 'raya-ai'),
'noProducts' => __('The bot hasn’t shown any product cards in the last 30 days.', 'raya-ai'),
/* translators: %s: number of conversations. */
'shownIn' => __('shown in %s conversations', 'raya-ai'),
'noRecent' => __('No conversations yet.', 'raya-ai'),
'openInbox' => __('Open the inbox', 'raya-ai'),
'retry' => __('Try again', 'raya-ai'),
// Each card's way to the page in the Rayachat dashboard that has all of it.
'moreWaiting' => __('Requests in Rayachat', 'raya-ai'),
'moreActivity' => __('Analytics in Rayachat', 'raya-ai'),
'morePlan' => __('Plans and billing in Rayachat', 'raya-ai'),
'moreUnanswered' => __('Teach the bot in Rayachat', 'raya-ai'),
'moreLeads' => __('All leads in Rayachat', 'raya-ai'),
'moreProducts' => __('Products in Rayachat', 'raya-ai'),
'moreRecent' => __('Inbox in Rayachat', 'raya-ai'),
),
));
}