<?php
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
//add_action('login_init', 'jvbLoginFormText');
|
function jvbLoginFormText()
|
{
|
add_filter('gettext', 'jvbTranslations', 10, 2);
|
add_filter('ngettext', 'jvbTranslations', 10, 2);
|
}
|
|
function jvbTranslations($translation, $text)
|
{
|
if (!$GLOBALS['pagenow'] == 'wp-login.php') {
|
return $translation;
|
}
|
global $_GET;
|
if (array_key_exists('action', $_GET) && $_GET['action'] == 'register') {
|
$translation = str_ireplace('Register', 'Join the Scene', $translation);
|
$translation = str_ireplace('Log in', 'Already joined? Log in', $translation);
|
} else {
|
$translation = str_ireplace('Register', 'No account? Join In!', $translation);
|
$translation = str_ireplace('Log in', 'Get In', $translation);
|
}
|
|
return $translation;
|
}
|
|
add_filter('login_title', 'jvbLoginTitle');
|
function jvbLoginTitle($title):string
|
{
|
global $_GET;
|
// return (array_key_exists('action', $_GET) &&
|
// $_GET['action'] === 'register') ?
|
// 'Join the Scene | edmonton.ink' :
|
// 'Get Backstage | edmonton.ink';
|
return (array_key_exists('action', $_GET) &&
|
$_GET['action'] === 'register') ?
|
'Register | North\'eh Smoke & Smash' :
|
'Log in | North\'eh Smoke & Smash';
|
}
|
|
|
/**
|
* Checks if the logged in user is one of us
|
* @return bool
|
*/
|
function isOurPeople():bool
|
{
|
if (!is_user_logged_in()) {
|
return false;
|
}
|
$user = wp_get_current_user();
|
|
return count(
|
array_intersect(
|
array_values($user->roles),
|
array_map(function ($role) {
|
return BASE.$role;
|
},
|
jvbRolesWithDashboard())
|
)
|
)>0;
|
}
|
|
/**
|
* The basis for the dashboard navigation
|
* @return array
|
*/
|
function jvbGetUserDashboardPages():array
|
{
|
if (!isOurPeople() && !current_user_can('manage_options')) {
|
return [];
|
}
|
$user = wp_get_current_user();
|
$pages = get_transient('jvb_'.$user->ID.'_dashboard_pages');
|
$pages = false;
|
if (!$pages) {
|
$pages = ['dash'];
|
$roles = array_intersect(
|
jvbRolesWithDashboard(),
|
array_map(function ($role) {
|
return jvbNoBase($role);
|
},
|
$user->roles)
|
);
|
|
$content = [];
|
|
foreach ($roles as $role) {
|
$content = array_unique(array_merge(jvbRolePages($role), $content));
|
}
|
error_log('Content: '.print_r($content, true));
|
foreach ($content as $c) {
|
|
$permission = JVB_CONTENT[$c]['plural']??$c.'s';
|
if (current_user_can('edit_'.$permission)) {
|
$pages[] = $c;
|
}
|
}
|
|
|
if (jvbCheck('can_invite', JVB_MEMBERSHIP) && jvbUserIsVerified()) {
|
$pages[] = 'invites';
|
}
|
if (jvbCheck('term_approval', JVB_MEMBERSHIP) && jvbUserIsVerified()) {
|
$pages[] = 'approvals';
|
}
|
if (jvbSiteHasTermContent()) {
|
$terms = array_filter(JVB_TAXONOMY, function ($tax) {
|
return jvbCheck('is_content', $tax);
|
});
|
foreach ($terms as $term => $config) {
|
if (current_user_can('manage_'.$term)) {
|
$pages[] = $config['plural'];
|
}
|
}
|
}
|
|
if (jvbSiteHasIntegrations()) {
|
//TODO: Check that user has integrations enabled
|
$pages[] = 'integrations';
|
}
|
if (jvbSiteHasForum() &&
|
(empty(JVB_MEMBERSHIP['member_only']??[]) || array_intersect(JVB_MEMBERSHIP['member_only'], $roles) > 0)) {
|
$pages[] = 'news';
|
}
|
|
if (jvbCheck('member_content', JVB_MEMBERSHIP) && jvbUserCanCreate()) {
|
$pages[] = 'metrics';
|
}
|
|
if (jvbCheck('favourites', JVB_SITE)) {
|
$pages[] = 'favourites';
|
}
|
|
if (jvbSiteHasSupport()) {
|
$pages[] = 'support';
|
}
|
$pages = apply_filters('jvbUserDashboardPages', $pages, $user->roles);
|
set_transient('jvb_'.$user->ID.'_dashboard_pages', $pages, WEEK_IN_SECONDS);
|
}
|
|
return $pages;
|
}
|
|
|
/**
|
* Feed Block Helpers
|
*/
|
function jvbGetUserContentTypes(int $postID):array
|
{
|
$types = get_post_meta($postID, BASE.'content_types', true);
|
if ($types === '') {
|
$types = [];
|
$link = (int) get_post_meta($postID, BASE.'link', true);
|
if ($link === '' || !is_numeric($link)) {
|
return $types;
|
}
|
|
$user = get_userdata($link);
|
|
if (!$user) {
|
return $types;
|
}
|
|
$role = jvbUserRole((int) $link);
|
$config = JVB_USER[$role];
|
foreach ($config['can_create'] as $type) {
|
if (is_array($type)) {
|
$types = array_unique(array_merge($types, array_values($type)[0]));
|
} else {
|
$types[] = $type;
|
}
|
}
|
$temp = [];
|
foreach ($types as $t) {
|
$permission = JVB_CONTENT[$t]['plural']??$t.'s';
|
if (user_can($link, 'edit_'.$permission)){
|
$temp[] = $t;
|
}
|
}
|
|
global $jvb_feed;
|
$types = array_filter($temp, function ($type) use ($jvb_feed) {
|
return array_key_exists($type, $jvb_feed);
|
});
|
|
update_post_meta($postID, BASE.'content_types', $types);
|
}
|
|
return $types;
|
}
|