2019-03-08 15:36:23 +00:00
|
|
|
<?php
|
|
|
|
|
2019-04-11 22:11:03 +00:00
|
|
|
require_once( get_stylesheet_directory() . '/includes/wasmo-directory-widget.php' );
|
2019-04-11 22:53:56 +00:00
|
|
|
require_once( get_stylesheet_directory() . '/includes/wasmo-posts-widget.php' );
|
2019-04-11 22:11:03 +00:00
|
|
|
|
|
|
|
// register Foo_Widget widget
|
2019-04-11 22:53:56 +00:00
|
|
|
function register_wasmo_widgets() {
|
2022-10-21 17:44:27 +00:00
|
|
|
register_widget( 'wasmo\Directory_Widget' );
|
|
|
|
register_widget( 'wasmo\Posts_Widget' );
|
2019-04-11 22:11:03 +00:00
|
|
|
}
|
2019-04-11 22:53:56 +00:00
|
|
|
add_action( 'widgets_init', 'register_wasmo_widgets' );
|
2019-04-11 22:11:03 +00:00
|
|
|
|
2019-03-08 15:36:23 +00:00
|
|
|
// Enqueue styles - get parent theme styles first.
|
2019-04-01 13:16:53 +00:00
|
|
|
function wasmo_enqueue() {
|
2019-03-08 15:36:23 +00:00
|
|
|
|
2022-10-21 17:44:27 +00:00
|
|
|
$parent_style = 'parent-style'; // This is 'twentynineteen-style' for the Twenty Nineteen theme.
|
2019-03-08 15:36:23 +00:00
|
|
|
|
2022-10-21 17:44:27 +00:00
|
|
|
wp_enqueue_style(
|
2019-04-01 13:16:53 +00:00
|
|
|
$parent_style,
|
2021-03-12 15:20:38 +00:00
|
|
|
get_stylesheet_directory_uri() . '/twentynineteen.css',
|
2019-04-01 13:16:53 +00:00
|
|
|
);
|
2022-10-21 17:44:27 +00:00
|
|
|
wp_enqueue_style(
|
2019-04-01 13:16:53 +00:00
|
|
|
'wasmo-style',
|
2022-10-21 17:44:27 +00:00
|
|
|
get_stylesheet_directory_uri() . '/style.css',
|
|
|
|
array( $parent_style ),
|
|
|
|
wp_get_theme()->get('Version')
|
2019-04-01 13:16:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script(
|
|
|
|
'wasmo-script',
|
|
|
|
get_stylesheet_directory_uri() . '/js/script.js',
|
|
|
|
array ( 'jquery' ),
|
|
|
|
wp_get_theme()->get('Version'),
|
|
|
|
true
|
|
|
|
);
|
2019-03-08 15:36:23 +00:00
|
|
|
}
|
2019-04-01 13:16:53 +00:00
|
|
|
add_action( 'wp_enqueue_scripts', 'wasmo_enqueue' );
|
2019-03-08 15:36:23 +00:00
|
|
|
|
2020-02-27 10:40:34 +00:00
|
|
|
function wasmo_add_google_fonts() {
|
|
|
|
wp_enqueue_style(
|
|
|
|
'wasmo-google-fonts',
|
|
|
|
'https://fonts.googleapis.com/css?family=Crimson+Text:400,700|Open+Sans:400,700&display=swap',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'wp_enqueue_scripts', 'wasmo_add_google_fonts' );
|
2019-03-08 15:36:23 +00:00
|
|
|
|
|
|
|
// theme mods
|
|
|
|
// set_theme_mod( 'page_layout', 'one-column' );
|
|
|
|
|
|
|
|
|
2019-03-08 15:36:51 +00:00
|
|
|
|
2019-03-11 17:31:32 +00:00
|
|
|
// hide admin bar for non admin users
|
|
|
|
add_action( 'set_current_user', 'wasmo_hide_admin_bar' );
|
|
|
|
function wasmo_hide_admin_bar() {
|
2019-03-12 13:36:03 +00:00
|
|
|
if ( !current_user_can( 'publish_posts' ) ) {
|
2019-03-11 17:31:32 +00:00
|
|
|
show_admin_bar( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 13:36:03 +00:00
|
|
|
function cptui_register_my_taxes() {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Taxonomy: Questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$labels = array(
|
|
|
|
"name" => __( "Questions", "wasmo" ),
|
|
|
|
"singular_name" => __( "Question", "wasmo" ),
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = array(
|
|
|
|
"label" => __( "Questions", "wasmo" ),
|
|
|
|
"labels" => $labels,
|
|
|
|
"public" => true,
|
|
|
|
"publicly_queryable" => true,
|
|
|
|
"hierarchical" => false,
|
|
|
|
"show_ui" => true,
|
|
|
|
"show_in_menu" => true,
|
|
|
|
"show_in_nav_menus" => true,
|
|
|
|
"query_var" => true,
|
|
|
|
"rewrite" => array( 'slug' => 'question', 'with_front' => true, ),
|
|
|
|
"show_admin_column" => true,
|
|
|
|
"show_in_rest" => true,
|
|
|
|
"rest_base" => "question",
|
|
|
|
"rest_controller_class" => "WP_REST_Terms_Controller",
|
|
|
|
"show_in_quick_edit" => true,
|
|
|
|
"capabilities" =>
|
|
|
|
array(
|
|
|
|
'manage_terms' => 'edit_posts',
|
|
|
|
'edit_terms' => 'edit_posts',
|
|
|
|
'delete_terms' => 'edit_posts',
|
|
|
|
'assign_terms' => 'edit_posts'
|
|
|
|
)
|
2019-04-11 22:11:03 +00:00
|
|
|
);
|
2019-03-12 13:36:03 +00:00
|
|
|
register_taxonomy( "question", array( "post" ), $args );
|
2019-04-11 22:11:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Taxonomy: Spectrum.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$labels = array(
|
|
|
|
"name" => __( "Spectrum", "wasmo" ),
|
|
|
|
"singular_name" => __( "Spectrum", "wasmo" ),
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = array(
|
|
|
|
"label" => __( "Spectrum", "wasmo" ),
|
|
|
|
"labels" => $labels,
|
|
|
|
"public" => true,
|
|
|
|
"publicly_queryable" => true,
|
|
|
|
"hierarchical" => false,
|
|
|
|
"show_ui" => true,
|
|
|
|
"show_in_menu" => true,
|
|
|
|
"show_in_nav_menus" => true,
|
|
|
|
"query_var" => true,
|
|
|
|
"rewrite" => array( 'slug' => 'spectrum', 'with_front' => true, ),
|
|
|
|
"show_admin_column" => false,
|
|
|
|
"show_in_rest" => true,
|
|
|
|
"rest_base" => "spectrum",
|
|
|
|
"rest_controller_class" => "WP_REST_Terms_Controller",
|
|
|
|
"show_in_quick_edit" => false,
|
2020-05-12 19:21:19 +00:00
|
|
|
);
|
2019-04-11 22:11:03 +00:00
|
|
|
register_taxonomy( "spectrum", array( "post", "user" ), $args );
|
2020-05-12 19:21:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Taxonomy: Shelf Items.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$labels = array(
|
|
|
|
"name" => __( "Shelf Items", "wasmo" ),
|
|
|
|
"singular_name" => __( "Shelf Item", "wasmo" ),
|
|
|
|
);
|
|
|
|
|
|
|
|
$args = array(
|
|
|
|
"label" => __( "Shelf Items", "wasmo" ),
|
|
|
|
"labels" => $labels,
|
|
|
|
"public" => true,
|
|
|
|
"publicly_queryable" => true,
|
|
|
|
"hierarchical" => false,
|
|
|
|
"show_ui" => true,
|
|
|
|
"show_in_menu" => true,
|
|
|
|
"show_in_nav_menus" => true,
|
|
|
|
"query_var" => true,
|
|
|
|
"rewrite" => array( 'slug' => 'shelf', 'with_front' => true, ),
|
|
|
|
"show_admin_column" => false,
|
|
|
|
"show_in_rest" => true,
|
|
|
|
"rest_base" => "shelf",
|
|
|
|
"rest_controller_class" => "WP_REST_Terms_Controller",
|
|
|
|
"show_in_quick_edit" => false,
|
|
|
|
);
|
|
|
|
register_taxonomy( "shelf", array( "post", "user" ), $args );
|
2019-03-12 13:36:03 +00:00
|
|
|
}
|
|
|
|
add_action( 'init', 'cptui_register_my_taxes' );
|
|
|
|
|
|
|
|
|
|
|
|
function wasmo_widgets_init() {
|
|
|
|
|
|
|
|
register_sidebar(
|
|
|
|
array(
|
|
|
|
'name' => __( 'Sidebar', 'twentynineteen' ),
|
|
|
|
'id' => 'sidebar',
|
|
|
|
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentynineteen' ),
|
|
|
|
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
|
|
|
'after_widget' => '</section>',
|
|
|
|
'before_title' => '<h2 class="widget-title">',
|
|
|
|
'after_title' => '</h2>',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
add_action( 'widgets_init', 'wasmo_widgets_init' );
|
|
|
|
|
2021-03-24 14:54:53 +00:00
|
|
|
function wasmo_setup() {
|
|
|
|
register_nav_menus(
|
|
|
|
array(
|
|
|
|
'utility' => __( 'Utility Menu', 'twentynineteen' ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
set_theme_mod( 'image_filter', 0 );
|
|
|
|
}
|
2019-03-12 13:36:03 +00:00
|
|
|
add_action( 'after_setup_theme', 'wasmo_setup' );
|
2019-03-11 17:31:32 +00:00
|
|
|
|
2021-03-24 14:54:53 +00:00
|
|
|
// add hard coded utility menu items
|
2019-03-12 14:39:56 +00:00
|
|
|
function wasmo_loginout_menu_link( $items, $args ) {
|
2019-03-12 16:04:11 +00:00
|
|
|
if ($args->theme_location == 'utility') {
|
2021-03-24 14:54:53 +00:00
|
|
|
$edit_svg = twentynineteen_get_icon_svg( 'edit', 24 );
|
|
|
|
$user_svg = twentynineteen_get_icon_svg( 'person', 24 );
|
|
|
|
$join_svg = '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"><path d="M0 0h24v24H0z" fill="none"/><path d="M15 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm-9-2V7H4v3H1v2h3v3h2v-3h3v-2H6zm9 4c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>';
|
|
|
|
$login_svg = '<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24" viewBox="0 0 24 24" width="24"><g><rect fill="none" height="24" width="24"/></g><g><path d="M11,7L9.6,8.4l2.6,2.6H2v2h10.2l-2.6,2.6L11,17l5-5L11,7z M20,19h-8v2h8c1.1,0,2-0.9,2-2V5c0-1.1-0.9-2-2-2h-8v2h8V19z"/></g></svg>';
|
|
|
|
$login = '<li class="login"><a href="' . home_url('/login/') . '" class="register">' . $join_svg . __(" Join") . '</a></li>';
|
|
|
|
$login .= '<li class="login"><a href="' . home_url('/login/') . '" class="nav-login">' . $login_svg . __(" Login") . '</a></li>';
|
|
|
|
// $logout = '<li class="logout"><a href="' . wp_logout_url() . '">' . __("Log Out") . '</a></li>';
|
2019-04-15 13:14:28 +00:00
|
|
|
$profile = '<li class="view"><a href="' . get_author_posts_url( get_current_user_id() ) . '">' . $user_svg . 'View</a></li>';
|
|
|
|
$edit = '<li class="edit"><a href="' . home_url('/edit/') . '">' . $edit_svg . 'Edit</a></li>';
|
2019-03-12 16:04:11 +00:00
|
|
|
if ( is_user_logged_in() ) {
|
2021-03-24 14:54:53 +00:00
|
|
|
$items = $profile . $edit;
|
2019-03-12 16:04:11 +00:00
|
|
|
} else {
|
2019-04-15 13:14:28 +00:00
|
|
|
$items = $login;
|
2019-03-12 16:04:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $items;
|
2019-03-12 14:39:56 +00:00
|
|
|
}
|
|
|
|
add_filter( 'wp_nav_menu_items', 'wasmo_loginout_menu_link', 10, 2 );
|
|
|
|
|
|
|
|
|
|
|
|
function wasmo_login_redirect_page() {
|
2019-04-15 19:18:41 +00:00
|
|
|
return home_url('/edit/');
|
2019-03-12 14:39:56 +00:00
|
|
|
}
|
|
|
|
add_filter('login_redirect', 'wasmo_login_redirect_page');
|
|
|
|
|
|
|
|
function wasmo_logout_redirect_page() {
|
2021-03-24 14:54:53 +00:00
|
|
|
return home_url('/profiles/');
|
2019-03-12 14:39:56 +00:00
|
|
|
}
|
|
|
|
add_filter('logout_redirect', 'wasmo_logout_redirect_page');
|
|
|
|
|
|
|
|
|
2021-03-24 14:54:53 +00:00
|
|
|
// function my_acf_init() {
|
2020-02-10 11:05:42 +00:00
|
|
|
|
2021-03-24 14:54:53 +00:00
|
|
|
// }
|
2019-03-11 22:31:02 +00:00
|
|
|
|
2020-02-10 11:05:42 +00:00
|
|
|
// add_action('acf/init', 'my_acf_init');
|
2019-03-08 15:36:51 +00:00
|
|
|
|
2019-03-14 17:44:11 +00:00
|
|
|
/**
|
2019-04-15 19:18:41 +00:00
|
|
|
* Plugin Name: Multisite: Password Reset on Local Blog
|
2019-03-14 17:44:11 +00:00
|
|
|
* Plugin URI: https://gist.github.com/eteubert/293e07a49f56f300ddbb
|
|
|
|
* Description: By default, WordPress Multisite uses the main blog for passwort resets. This plugin enables users to stay in their blog during the whole reset process.
|
|
|
|
* Version: 1.0.0
|
|
|
|
* Author: Eric Teubert
|
|
|
|
* Author URI: http://ericteubert.de
|
|
|
|
* License: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
// fixes "Lost Password?" URLs on login page
|
|
|
|
add_filter("lostpassword_url", function ($url, $redirect) {
|
|
|
|
|
|
|
|
$args = array( 'action' => 'lostpassword' );
|
|
|
|
|
|
|
|
if ( !empty($redirect) )
|
|
|
|
$args['redirect_to'] = $redirect;
|
|
|
|
|
|
|
|
return add_query_arg( $args, site_url('wp-login.php') );
|
|
|
|
}, 10, 2);
|
|
|
|
|
|
|
|
// fixes other password reset related urls
|
|
|
|
add_filter( 'network_site_url', function($url, $path, $scheme) {
|
2019-03-14 17:53:52 +00:00
|
|
|
|
|
|
|
if (stripos($url, "action=rp") !== false)
|
|
|
|
// return site_url('wp-login.php?action=lostpassword', $scheme);
|
|
|
|
return str_replace( 'circlecube.com', 'wasmormon.org', $url );
|
|
|
|
|
|
|
|
if (stripos($url, "action=lostpassword") !== false)
|
2019-03-14 17:44:11 +00:00
|
|
|
return site_url('wp-login.php?action=lostpassword', $scheme);
|
|
|
|
|
2019-03-14 17:53:52 +00:00
|
|
|
if (stripos($url, "action=resetpass") !== false)
|
2019-03-14 17:44:11 +00:00
|
|
|
return site_url('wp-login.php?action=resetpass', $scheme);
|
|
|
|
|
|
|
|
return $url;
|
|
|
|
}, 10, 3 );
|
|
|
|
|
|
|
|
// fixes URLs in email that goes out.
|
|
|
|
add_filter("retrieve_password_message", function ($message, $key) {
|
2021-04-07 19:28:35 +00:00
|
|
|
$message = str_replace(get_site_url(1), get_site_url(), $message);
|
|
|
|
$message = str_replace('circlecubes', 'wasmormon.org', $message);
|
|
|
|
|
|
|
|
return $message;
|
2019-03-14 17:44:11 +00:00
|
|
|
}, 10, 2);
|
|
|
|
|
|
|
|
// fixes email title
|
|
|
|
add_filter("retrieve_password_title", function($title) {
|
|
|
|
return "[" . wp_specialchars_decode(get_option('blogname'), ENT_QUOTES) . "] Password Reset";
|
2019-03-15 17:10:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-30 14:02:24 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Custom user hook summary
|
|
|
|
|
|
|
|
Register
|
|
|
|
-add custom has_received_welcome and set to false
|
|
|
|
|
|
|
|
Login
|
|
|
|
-update Last login field
|
|
|
|
-check if has_received_welcome
|
|
|
|
-send welcome?
|
|
|
|
-update has_received_welcome
|
|
|
|
|
|
|
|
Profile Save/Update
|
|
|
|
-update user nicename/displayname from acf fields
|
2021-03-24 14:54:53 +00:00
|
|
|
-resave values back to user acf fields
|
2019-04-30 14:02:24 +00:00
|
|
|
-clear directory transients
|
2021-03-24 14:54:53 +00:00
|
|
|
-send belated welcome email if is_admin and not yet received welcome
|
2019-04-30 14:02:24 +00:00
|
|
|
-update question counts if user includes any
|
|
|
|
-update last_save timestamp for this user
|
|
|
|
-increment save_count
|
2020-02-10 10:21:27 +00:00
|
|
|
-admin notify email
|
2019-04-30 14:02:24 +00:00
|
|
|
-redirect user to their own profile
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-10-21 14:33:42 +00:00
|
|
|
// custom wp-login logo
|
|
|
|
function wasmo_login_logo() { ?>
|
2022-10-21 17:44:27 +00:00
|
|
|
<style type="text/css">
|
|
|
|
#login h1 a, .login h1 a {
|
|
|
|
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/img/wasmormon-logo.png);
|
2022-10-21 14:33:42 +00:00
|
|
|
height: 190px;
|
|
|
|
width: 190px;
|
|
|
|
background-size: 190px 190px;
|
|
|
|
background-repeat: no-repeat;
|
2022-10-21 17:44:27 +00:00
|
|
|
padding-bottom: 30px;
|
|
|
|
}
|
|
|
|
</style>
|
2022-10-21 14:33:42 +00:00
|
|
|
<?php }
|
|
|
|
add_action( 'login_enqueue_scripts', 'wasmo_login_logo' );
|
2019-04-30 14:02:24 +00:00
|
|
|
|
2022-10-21 14:46:25 +00:00
|
|
|
function wasmo_login_logo_url() {
|
2022-10-21 17:44:27 +00:00
|
|
|
return home_url();
|
2022-10-21 14:46:25 +00:00
|
|
|
}
|
|
|
|
add_filter( 'login_headerurl', 'wasmo_login_logo_url' );
|
|
|
|
|
|
|
|
function wasmo_login_logo_url_title() {
|
2022-10-21 17:44:27 +00:00
|
|
|
return 'wasmormon.org';
|
2022-10-21 14:46:25 +00:00
|
|
|
}
|
|
|
|
add_filter( 'login_headertext', 'wasmo_login_logo_url_title' );
|
|
|
|
|
2019-03-15 17:10:30 +00:00
|
|
|
// Capture user login and add it as timestamp in user meta data
|
|
|
|
function wasmo_user_lastlogin( $user_login, $user ) {
|
2022-10-21 17:44:27 +00:00
|
|
|
update_user_meta( $user->ID, 'last_login', time() );
|
2019-03-15 17:10:30 +00:00
|
|
|
}
|
|
|
|
add_action( 'wp_login', 'wasmo_user_lastlogin', 10, 2 );
|
|
|
|
|
|
|
|
// Display last login time
|
|
|
|
function wasmo_get_lastlogin() {
|
2022-10-21 17:44:27 +00:00
|
|
|
$last_login = get_the_author_meta('last_login');
|
|
|
|
$the_login_date = human_time_diff($last_login);
|
|
|
|
return $the_login_date;
|
2019-03-19 13:43:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:57:19 +00:00
|
|
|
function get_default_display_name_value($value, $post_id, $field) {
|
|
|
|
if ( $value === NULL || $value === '' ) {
|
|
|
|
$user_id = intval( substr( $post_id, 5 ) );
|
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
$user_displayname = $user_info->display_name;
|
|
|
|
|
|
|
|
$value = $user_displayname;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
add_filter('acf/load_value/name=display_name', 'get_default_display_name_value', 20, 3);
|
|
|
|
|
|
|
|
function get_default_profile_id_value($value, $post_id, $field) {
|
|
|
|
if ( $value === NULL || $value === '' ) {
|
|
|
|
$user_id = intval( substr( $post_id, 5 ) );
|
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
$user_nicename = $user_info->user_nicename;
|
|
|
|
|
|
|
|
$value = $user_nicename;
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
add_filter('acf/load_value/name=profile_id', 'get_default_profile_id_value', 20, 3);
|
|
|
|
|
2019-03-19 13:43:13 +00:00
|
|
|
function wasmo_update_user( $post_id ) {
|
2019-04-15 14:57:19 +00:00
|
|
|
// only for users - skip for posts etc
|
2019-04-15 12:51:34 +00:00
|
|
|
if ( strpos( $post_id, 'user_' ) !== 0 ) {
|
2019-03-19 13:43:13 +00:00
|
|
|
return;
|
2019-04-15 12:51:34 +00:00
|
|
|
}
|
2019-04-04 15:14:04 +00:00
|
|
|
|
2019-04-15 14:57:19 +00:00
|
|
|
$user_id = intval( substr( $post_id, 5 ) );
|
|
|
|
|
|
|
|
// update user nicename/displayname from acf fields
|
|
|
|
wp_update_user( array(
|
|
|
|
'ID' => $user_id,
|
|
|
|
'user_nicename' => sanitize_title( get_field( 'profile_id', 'user_'. $user_id ) ),
|
|
|
|
'display_name' => sanitize_text_field( get_field( 'display_name', 'user_'. $user_id ) )
|
|
|
|
) );
|
|
|
|
// resave values back ot user acf fields
|
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
$user_loginname = $user_info->user_login;
|
|
|
|
$user_displayname = $user_info->display_name;
|
|
|
|
$user_nicename = $user_info->user_nicename;
|
|
|
|
update_field( 'display_name', $user_displayname, 'user_' . $user_id );
|
|
|
|
update_field( 'profile_id', $user_nicename, 'user_' . $user_id );
|
|
|
|
|
2022-10-27 21:33:06 +00:00
|
|
|
// clear all directory transients
|
|
|
|
wasmo_delete_transients_with_prefix( 'wasmo_directory-' );
|
2019-03-19 13:43:13 +00:00
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
// update question counts if user includes any
|
|
|
|
if( have_rows( 'questions', 'user_' . $user_id ) ){
|
|
|
|
wasmo_update_user_question_count();
|
|
|
|
}
|
|
|
|
|
2019-04-30 14:02:24 +00:00
|
|
|
// increment save_count
|
2019-04-15 12:51:34 +00:00
|
|
|
$save_count = get_user_meta( $user_id, 'save_count', true );
|
|
|
|
if ('' === $save_count ) {
|
|
|
|
$save_count = 0;
|
|
|
|
}
|
2019-04-15 19:18:41 +00:00
|
|
|
$save_count = intval($save_count) + 1;
|
2019-04-15 12:51:34 +00:00
|
|
|
update_user_meta( $user_id, 'save_count', $save_count );
|
2020-05-12 19:18:13 +00:00
|
|
|
|
2022-10-27 21:35:04 +00:00
|
|
|
// Add event to simple history logs
|
|
|
|
apply_filters(
|
|
|
|
'simple_history_log',
|
|
|
|
'Updated profile for {displayname}({nicename}) (edit #{savecount}) {link}',
|
|
|
|
[
|
|
|
|
'nicename' => $user_nicename,
|
|
|
|
'displayname' => $user_displayname,
|
|
|
|
'savecount' => $save_count,
|
|
|
|
'link' => get_author_posts_url( $user_id ),
|
|
|
|
],
|
|
|
|
'info'
|
|
|
|
);
|
|
|
|
|
2020-05-12 19:18:13 +00:00
|
|
|
//only if not edited by an admin
|
|
|
|
if ( !current_user_can( 'administrator' ) ) {
|
|
|
|
// notify email
|
|
|
|
wasmo_send_admin_email__profile_update( $user_id, $save_count );
|
|
|
|
// update last_save timestamp for this user
|
|
|
|
update_user_meta( $user_id, 'last_save', time() );
|
|
|
|
/*
|
2020-02-10 09:58:31 +00:00
|
|
|
// if admin - check if welcome email has been sent.
|
|
|
|
$has_received_welcome = get_user_meta( $user_id, 'has_received_welcome', true );
|
|
|
|
if ( '' === $has_received_welcome ) {
|
|
|
|
// if not - send a belated welcome email
|
2020-02-10 10:21:27 +00:00
|
|
|
wasmo_send_user_email__belated_welcome( $user_id );
|
2020-02-10 09:58:31 +00:00
|
|
|
update_user_meta( $user_id, 'has_received_welcome', true );
|
|
|
|
}
|
2020-05-12 19:18:13 +00:00
|
|
|
*/
|
2020-02-10 09:58:31 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:57:19 +00:00
|
|
|
wp_redirect( get_author_posts_url( $user_id ), 301);
|
2020-02-10 09:58:31 +00:00
|
|
|
|
2019-04-15 14:57:19 +00:00
|
|
|
exit;
|
2019-03-19 13:43:13 +00:00
|
|
|
}
|
2019-04-04 19:07:28 +00:00
|
|
|
add_action( 'acf/save_post', 'wasmo_update_user', 10 );
|
2019-03-21 14:21:00 +00:00
|
|
|
|
2019-04-30 14:02:24 +00:00
|
|
|
function wasmo_send_user_email__welcome( $user_id ){
|
|
|
|
$sitename = get_bloginfo( 'name' );
|
|
|
|
$sitemail = get_bloginfo( 'admin_email' );
|
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
// $user_loginname = $user_info->user_login;
|
|
|
|
if ( $user_info ) {
|
2019-04-15 19:18:41 +00:00
|
|
|
$user_displayname = $user_info->display_name;
|
|
|
|
// $user_nicename = $user_info->user_nicename;
|
|
|
|
$welcome_mail_to = $user_info->user_email;
|
|
|
|
$welcome_headers = 'From: '. $sitemail;
|
|
|
|
$welcome_mail_subject = 'Welcome to '.$sitename;
|
|
|
|
$welcome_mail_message = $user_displayname . ',
|
|
|
|
|
|
|
|
Welcome to ' . $sitename . '! We\'re glad you\'ve joined. Visit the following links (also found in the site header when you\'re logged in).
|
|
|
|
|
2022-10-21 14:46:25 +00:00
|
|
|
Edit your proflie: ' . home_url('/edit/') . '
|
|
|
|
View/share your profile: ' . get_author_posts_url( $user_id ) . ' (you can change this on your profile)
|
2019-04-15 19:18:41 +00:00
|
|
|
|
|
|
|
We are genuinely excited to meet you and read your story. Please, don\'t hesitate to reach out if you have any questions or suggestions to improve the site.
|
|
|
|
|
|
|
|
Best,
|
|
|
|
'. $sitename;
|
2019-04-30 14:02:24 +00:00
|
|
|
// the send
|
2019-04-15 19:18:41 +00:00
|
|
|
wp_mail( $welcome_mail_to, $welcome_mail_subject, $welcome_mail_message, $welcome_headers );
|
2019-04-30 14:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function wasmo_send_user_email__belated_welcome( $user_id ){
|
|
|
|
$sitename = get_bloginfo( 'name' );
|
|
|
|
$sitemail = get_bloginfo( 'admin_email' );
|
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
// $user_loginname = $user_info->user_login;
|
|
|
|
if ( $user_info ) {
|
|
|
|
$user_displayname = $user_info->display_name;
|
|
|
|
// $user_nicename = $user_info->user_nicename;
|
|
|
|
$welcome_mail_to = $user_info->user_email;
|
|
|
|
$welcome_headers = 'From: '. $sitemail;
|
|
|
|
$welcome_mail_subject = 'A belated welcome to '.$sitename;
|
|
|
|
$welcome_mail_message = $user_displayname . ',
|
|
|
|
|
|
|
|
Thank you for joining ' . $sitename . '! We want to personally welcome you to the site (sorry we\'re a little late). We hope you have appreciated seeing all the faith transition stories. We hope you will contribute your own profile too.
|
|
|
|
|
2022-10-21 14:46:25 +00:00
|
|
|
Edit your proflie: ' . home_url('/edit/') . '
|
|
|
|
View/share your own profile: ' . get_author_posts_url( $user_id ) . '
|
2019-04-30 14:02:24 +00:00
|
|
|
|
|
|
|
We are genuinely excited to meet you and read your story. Remember, you can return to the site anytime to update your story, so there is no need to write the whole thing in one go. Start with a basic couple sentences if you wish. Also, take note that there is a setting to control the visibility of your profile - you can select if you want your profile to be displayed publicly, only to other site members or even to not display it anywhere.
|
|
|
|
|
|
|
|
Thank you again for being a part of our mission to share honest faith transitions. Please, don\'t hesitate to reach out if you have any questions or suggestions to improve the site.
|
|
|
|
|
|
|
|
Best,
|
|
|
|
'. $sitename . '
|
|
|
|
|
|
|
|
P.S. We have a few thoughts published on the site as well as a facebook page if you want to follow along.';
|
|
|
|
// the send
|
|
|
|
wp_mail( $welcome_mail_to, $welcome_mail_subject, $welcome_mail_message, $welcome_headers );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-14 17:56:42 +00:00
|
|
|
function wasmo_send_admin_email__profile_update( $user_id, $save_count ){
|
2019-04-30 14:02:24 +00:00
|
|
|
$user_info = get_userdata( $user_id );
|
|
|
|
$user_nicename = $user_info->user_nicename;
|
|
|
|
$notify_mail_to = get_bloginfo( 'admin_email' );
|
|
|
|
$sitename = get_bloginfo( 'name' );
|
|
|
|
$headers = 'From: '. $notify_mail_to;
|
|
|
|
if ( $user_info ) {
|
2020-02-14 17:56:42 +00:00
|
|
|
$notify_mail_message = '';
|
|
|
|
if ( $save_count <= 1 ) {
|
2022-10-21 14:33:42 +00:00
|
|
|
$notify_mail_subject = $sitename . ' New Profile Added: ' . $user_nicename;
|
2020-02-14 17:56:42 +00:00
|
|
|
$notify_mail_message .= 'New profile created ';
|
|
|
|
}
|
|
|
|
if ( $save_count > 1 ) {
|
2022-10-21 14:46:25 +00:00
|
|
|
$notify_mail_subject = $sitename . ' Profile Update ( #' . $save_count . '): ' . $user_nicename;
|
2020-02-14 17:56:42 +00:00
|
|
|
$notify_mail_message .= 'Profile updated ';
|
|
|
|
}
|
2020-05-12 19:21:19 +00:00
|
|
|
$notify_mail_message .= 'by ' . $user_nicename .': ' . get_author_posts_url( $user_id );
|
2019-04-30 14:02:24 +00:00
|
|
|
// send mail
|
|
|
|
wp_mail( $notify_mail_to, $notify_mail_subject, esc_html( $notify_mail_message ), $headers );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function wasmo_register_add_meta($user_id) {
|
|
|
|
add_user_meta( $user_id, 'has_received_welcome', false );
|
|
|
|
}
|
|
|
|
add_action( 'user_register', 'wasmo_register_add_meta' );
|
|
|
|
|
|
|
|
function wasmo_first_user_login( $user_login, $user ) {
|
|
|
|
$user_id = $user->ID;
|
|
|
|
$has_received_welcome = get_user_meta( $user_id, 'has_received_welcome', true );
|
2020-02-10 09:58:31 +00:00
|
|
|
if ( '' === $has_received_welcome || ! $has_received_welcome ) {
|
2019-04-30 14:02:24 +00:00
|
|
|
wasmo_send_user_email__welcome( $user_id );
|
2019-04-15 19:18:41 +00:00
|
|
|
update_user_meta( $user_id, 'has_received_welcome', true );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action('wp_login', 'wasmo_first_user_login', 10, 2);
|
|
|
|
|
2020-02-10 09:58:31 +00:00
|
|
|
|
2019-04-30 14:02:24 +00:00
|
|
|
// https://github.com/wp-plugins/oa-social-login/blob/master/filters.txt
|
|
|
|
//This function will be called after Social Login has added a new user
|
|
|
|
function oa_social_login_do_after_user_insert ($user_data, $identity) {
|
2020-02-10 09:58:31 +00:00
|
|
|
// These are the fields from the WordPress database
|
|
|
|
// print_r($user_data);
|
|
|
|
// This is the full social network profile of this user
|
2019-04-30 14:02:24 +00:00
|
|
|
// print_r($identity);
|
|
|
|
|
2020-02-10 09:58:31 +00:00
|
|
|
// record last login
|
2019-04-30 14:02:24 +00:00
|
|
|
wasmo_user_lastlogin($user_data->user_login, $user_data);
|
2020-02-10 09:58:31 +00:00
|
|
|
// send welcome?
|
2019-04-30 14:02:24 +00:00
|
|
|
wasmo_first_user_login($user_data->user_login, $user_data);
|
|
|
|
}
|
2020-02-10 09:58:31 +00:00
|
|
|
add_action ('oa_social_login_action_after_user_insert', 'oa_social_login_do_after_user_insert', 10, 2);
|
2019-04-30 14:02:24 +00:00
|
|
|
|
2022-10-21 14:46:25 +00:00
|
|
|
//This function will be called before Social Login logs the user in
|
2019-04-30 14:02:24 +00:00
|
|
|
function oa_social_login_do_before_user_login ($user_data, $identity, $new_registration) {
|
2020-02-10 09:58:31 +00:00
|
|
|
// record last login
|
2019-04-30 14:02:24 +00:00
|
|
|
wasmo_user_lastlogin($user_data->user_login, $user_data);
|
2020-02-10 09:58:31 +00:00
|
|
|
// send welcome?
|
2019-04-30 14:02:24 +00:00
|
|
|
wasmo_first_user_login($user_data->user_login, $user_data);
|
|
|
|
}
|
2019-04-15 19:18:41 +00:00
|
|
|
|
2019-04-30 14:02:24 +00:00
|
|
|
add_action ('oa_social_login_action_before_user_login', 'oa_social_login_do_before_user_login', 10, 3);
|
2020-02-10 09:58:31 +00:00
|
|
|
|
2019-04-15 19:18:41 +00:00
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
function wasmo_update_user_question_count(){
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
//get terms
|
|
|
|
$tempterms = [];
|
|
|
|
$terms = get_terms( 'question' );
|
|
|
|
$terms = get_terms([
|
|
|
|
'taxonomy' => 'question',
|
|
|
|
'hide_empty' => false,
|
|
|
|
]);
|
|
|
|
// set count to 0 for each term - reset to count fresh
|
|
|
|
foreach ( $terms as $term ) {
|
|
|
|
$termtaxid = $term->id;
|
|
|
|
$tempterms[$termtaxid] = 0;
|
|
|
|
}
|
|
|
|
// reset terms to empty array
|
|
|
|
// $terms = ['users'=>0];
|
|
|
|
|
|
|
|
// get all users
|
|
|
|
$users = get_users();
|
|
|
|
// user loop
|
|
|
|
foreach ( $users as $user ) {
|
|
|
|
$userid = $user->ID;
|
|
|
|
$tempterms['users']++;
|
|
|
|
// only use public users - so we don't end up with blank question pages
|
2022-10-26 13:56:26 +00:00
|
|
|
$in_directory = get_field( 'in_directory', 'user_' . $userid );
|
|
|
|
if (
|
|
|
|
'true' === $in_directory ||
|
|
|
|
'website' === $in_directory
|
|
|
|
) {
|
2019-03-22 18:16:04 +00:00
|
|
|
// get questions for user
|
|
|
|
if( have_rows( 'questions', 'user_' . $userid ) ) {
|
|
|
|
|
|
|
|
// question loop
|
|
|
|
while ( have_rows( 'questions', 'user_' . $userid ) ) {
|
|
|
|
the_row();
|
|
|
|
$termtaxid = get_sub_field( 'question', 'users_' . $userid );
|
|
|
|
$term = get_term( $termtaxid, 'questions' );
|
|
|
|
$tempterms[$termtaxid]++; // increment term
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// write new counts to db
|
|
|
|
foreach ( $tempterms as $key => $value ) {
|
|
|
|
$termtaxid = $key;
|
|
|
|
$termcount = $value;
|
|
|
|
$wpdb->update(
|
|
|
|
$wpdb->term_taxonomy,
|
|
|
|
array( 'count' => $termcount ),
|
|
|
|
array( 'term_taxonomy_id' => $termtaxid )
|
|
|
|
);
|
|
|
|
}
|
2019-03-21 14:21:00 +00:00
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
}
|
2019-03-21 14:21:00 +00:00
|
|
|
|
|
|
|
//override twentynineteen_entry_footer
|
|
|
|
function wasmo_entry_footer() {
|
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
// Hide author, post date, category and tag text for pages.
|
|
|
|
if ( 'post' === get_post_type() ) {
|
|
|
|
|
|
|
|
// Posted by
|
2019-04-02 11:56:12 +00:00
|
|
|
//twentynineteen_posted_by(); // hide author
|
2019-03-22 18:16:04 +00:00
|
|
|
|
|
|
|
// Posted on
|
|
|
|
twentynineteen_posted_on();
|
|
|
|
|
|
|
|
/* translators: used between list items, there is a space after the comma. */
|
|
|
|
$categories_list = get_the_category_list( __( ', ', 'twentynineteen' ) );
|
|
|
|
if ( $categories_list ) {
|
|
|
|
printf(
|
|
|
|
/* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of categories. */
|
|
|
|
'<span class="cat-links">%1$s<span class="screen-reader-text">%2$s</span>%3$s</span>',
|
|
|
|
twentynineteen_get_icon_svg( 'archive', 16 ),
|
|
|
|
__( 'Posted in', 'twentynineteen' ),
|
|
|
|
$categories_list
|
|
|
|
); // WPCS: XSS OK.
|
2019-03-21 14:21:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
/* translators: used between list items, there is a space after the comma. */
|
|
|
|
$tags_list = get_the_tag_list( '', __( ', ', 'twentynineteen' ) );
|
|
|
|
if ( $tags_list ) {
|
|
|
|
printf(
|
|
|
|
/* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of tags. */
|
|
|
|
'<span class="tags-links">%1$s<span class="screen-reader-text">%2$s </span>%3$s</span>',
|
|
|
|
twentynineteen_get_icon_svg( 'tag', 16 ),
|
|
|
|
__( 'Tags:', 'twentynineteen' ),
|
|
|
|
$tags_list
|
|
|
|
); // WPCS: XSS OK.
|
2019-03-21 14:21:00 +00:00
|
|
|
}
|
2019-03-22 18:16:04 +00:00
|
|
|
}
|
2019-03-21 14:21:00 +00:00
|
|
|
|
2019-03-22 18:16:04 +00:00
|
|
|
// Comment count.
|
|
|
|
if ( ! is_singular() ) {
|
|
|
|
twentynineteen_comment_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edit post link.
|
|
|
|
edit_post_link(
|
|
|
|
sprintf(
|
|
|
|
wp_kses(
|
|
|
|
/* translators: %s: Name of current post. Only visible to screen readers. */
|
|
|
|
__( 'Edit <span class="screen-reader-text">%s</span>', 'twentynineteen' ),
|
|
|
|
array(
|
|
|
|
'span' => array(
|
|
|
|
'class' => array(),
|
|
|
|
),
|
|
|
|
)
|
2019-03-21 14:21:00 +00:00
|
|
|
),
|
2019-03-22 18:16:04 +00:00
|
|
|
get_the_title()
|
|
|
|
),
|
|
|
|
'<span class="edit-link">' . twentynineteen_get_icon_svg( 'edit', 16 ),
|
|
|
|
'</span>'
|
|
|
|
);
|
|
|
|
}
|
2019-04-10 12:09:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
function wasmo_excerpt_link() {
|
2022-10-21 17:44:27 +00:00
|
|
|
return '<a class="more-link button button-small" href="' . get_permalink() . '">Read more</a>';
|
2019-04-10 12:09:26 +00:00
|
|
|
}
|
2019-04-16 13:31:51 +00:00
|
|
|
add_filter( 'excerpt_more', 'wasmo_excerpt_link' );
|
|
|
|
|
|
|
|
|
|
|
|
add_shortcode( 'wasmo_directory', 'wasmo_directory_shortcode' );
|
|
|
|
function wasmo_directory_shortcode( $atts ) {
|
|
|
|
$atts = shortcode_atts( array(
|
|
|
|
'max' => 12,
|
|
|
|
'title' => ''
|
|
|
|
), $atts, 'wasmo_directory' );
|
|
|
|
$directory = '';
|
|
|
|
if ( $atts['title'] !== '' ) {
|
|
|
|
$directory .= '<h3>' . $atts['title'] . '</h3>';
|
|
|
|
}
|
|
|
|
ob_start();
|
|
|
|
set_query_var( 'max_profiles', $atts['max'] );
|
|
|
|
set_query_var( 'context', 'shortcode' );
|
|
|
|
get_template_part( 'template-parts/content/content', 'directory' );
|
|
|
|
$directory .= ob_get_clean();
|
2022-10-21 17:44:27 +00:00
|
|
|
return $directory;
|
2020-02-10 09:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add ACF options page
|
|
|
|
*/
|
|
|
|
if( function_exists('acf_add_options_page') ) {
|
|
|
|
|
|
|
|
acf_add_options_page(array(
|
|
|
|
'page_title' => 'wasmo Settings',
|
|
|
|
'menu_title' => 'wasmo Settings',
|
|
|
|
'menu_slug' => 'wasmo-settings',
|
|
|
|
'capability' => 'edit_posts',
|
|
|
|
'redirect' => false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add callout to create a profile to the top of each post
|
|
|
|
* Only when user is not logged in
|
|
|
|
*/
|
|
|
|
function wasmo_before_after($content) {
|
2020-02-14 17:56:42 +00:00
|
|
|
if ( is_user_logged_in() || ! is_single() ) {
|
2020-02-10 09:58:31 +00:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
// top
|
|
|
|
if ( get_field( 'before_post_callout', 'option' ) ) {
|
2021-04-16 22:34:19 +00:00
|
|
|
$top_callout = '<div class="callout callout-top">';
|
|
|
|
$top_callout .= get_field( 'before_post_callout', 'option' );
|
|
|
|
$top_callout .= '<h5>Recent Profiles</h5>';
|
|
|
|
ob_start();
|
|
|
|
set_query_var( 'max_profiles', 4 );
|
|
|
|
set_query_var( 'context', 'bumper' );
|
|
|
|
get_template_part( 'template-parts/content/content', 'directory' );
|
|
|
|
$top_callout .= ob_get_clean();
|
|
|
|
$top_callout .= '</div>';
|
2020-02-10 09:58:31 +00:00
|
|
|
} else {
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<div class="callout callout-top">
|
|
|
|
<h4>Thank you for visiting wasmormon.org!</h4>
|
|
|
|
<p>This site is mainly a repository of mormon faith transition stories. Hearing others stories is therapeutic, check out the <a href="/profiles/">was mormon profiles</a>.</p>
|
2022-10-26 17:47:05 +00:00
|
|
|
<p>Telling your own story is therapeutic too, consider joining the movement and <a class="register" href="/login/">tell your own story now</a>!</p>
|
2020-02-10 09:58:31 +00:00
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
$top_callout = ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom
|
|
|
|
if ( get_field( 'after_post_callout', 'option' ) ) {
|
2020-02-10 10:21:27 +00:00
|
|
|
$bottom_callout = '<div class="callout callout-bottom">' . get_field( 'after_post_callout', 'option' ) . '</div>';
|
2020-02-10 09:58:31 +00:00
|
|
|
} else {
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<div class="callout callout-bottom">
|
|
|
|
<h4>Thank you for reading!</h4>
|
|
|
|
<p>Don't forget to also check out the <a href="/profiles/">mormon faith transition stories</a>.</p>
|
|
|
|
<div class="wp-block-button"><a class="wp-block-button__link" href="/login/">Tell Your Own Story</a></div>
|
|
|
|
</div>
|
|
|
|
<?php
|
|
|
|
$bottom_callout = ob_get_clean();
|
|
|
|
}
|
|
|
|
|
|
|
|
$fullcontent = $top_callout . $content . $bottom_callout;
|
|
|
|
|
|
|
|
|
2022-10-21 17:44:27 +00:00
|
|
|
return $fullcontent;
|
2020-02-10 09:58:31 +00:00
|
|
|
}
|
2020-02-18 11:28:23 +00:00
|
|
|
add_filter('the_content', 'wasmo_before_after');
|
|
|
|
|
|
|
|
|
2020-02-18 11:47:39 +00:00
|
|
|
add_filter( 'wpseo_title', 'wasmo_filter_profile_wpseo_title' );
|
2020-09-18 19:40:05 +00:00
|
|
|
add_filter( 'wpseo_metadesc', 'wasmo_user_profile_wpseo_metadesc' );
|
2020-02-18 11:47:39 +00:00
|
|
|
add_filter( 'wpseo_opengraph_image', 'wasmo_user_profile_set_og_image' );
|
2020-02-18 11:57:08 +00:00
|
|
|
add_filter( 'wpseo_twitter_image', 'wasmo_user_profile_set_og_image' );
|
2020-02-18 11:28:23 +00:00
|
|
|
|
|
|
|
// filter to update user profile page title for seo
|
|
|
|
function wasmo_filter_profile_wpseo_title( $title ) {
|
2022-10-21 17:44:27 +00:00
|
|
|
if( is_author() ) {
|
2020-02-18 11:28:23 +00:00
|
|
|
$curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
|
|
|
|
$userid = $curauth->ID;
|
|
|
|
$title = esc_html( get_field( 'hi', 'user_' . $userid ) ) . ' - ';
|
2020-02-18 11:47:39 +00:00
|
|
|
$title .= 'Learn why I\'m no longer mormon at wasmormon.org';
|
2022-10-21 17:44:27 +00:00
|
|
|
}
|
|
|
|
return $title;
|
2020-02-18 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 19:40:05 +00:00
|
|
|
// filter to update user profile page description for seo
|
|
|
|
function wasmo_user_profile_wpseo_metadesc( $metadesc ) {
|
2022-10-21 17:44:27 +00:00
|
|
|
if( is_author() ) {
|
2020-09-18 19:40:05 +00:00
|
|
|
$curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
|
|
|
|
$userid = $curauth->ID;
|
|
|
|
$metadesc = esc_html( get_field( 'tagline', 'user_' . $userid ) );
|
2022-10-21 17:44:27 +00:00
|
|
|
}
|
|
|
|
return $metadesc;
|
2020-09-18 19:40:05 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 11:28:23 +00:00
|
|
|
// Filter to update profile page open graph image to user profile image if there is one
|
|
|
|
function wasmo_user_profile_set_og_image( $image ) {
|
|
|
|
// if author page
|
|
|
|
if ( is_author() ) {
|
2020-02-18 11:47:39 +00:00
|
|
|
$curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) );
|
|
|
|
$userid = $curauth->ID;
|
2020-02-18 11:28:23 +00:00
|
|
|
// if has author image
|
|
|
|
$userimg = get_field( 'photo', 'user_' . $userid );
|
|
|
|
if ( $userimg ) {
|
2020-02-18 11:47:39 +00:00
|
|
|
$image = wp_get_attachment_image_url( $userimg, 'large' );
|
2020-02-18 11:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $image;
|
2021-03-12 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 20:52:31 +00:00
|
|
|
/**
|
|
|
|
* Replace links in text with html links
|
|
|
|
*
|
|
|
|
* @param string $text Text to add links to
|
|
|
|
* @return string Text with links added
|
|
|
|
*/
|
|
|
|
function auto_link_text( $text )
|
|
|
|
{
|
|
|
|
$pattern = "#\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'.,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b/?(?!@)))#";
|
|
|
|
return preg_replace_callback( $pattern, function( $matches ) {
|
|
|
|
$url = array_shift( $matches );
|
|
|
|
|
|
|
|
// force http if no protocol included
|
|
|
|
if ( !startsWith( $url, 'http' ) ) {
|
|
|
|
$url = 'http://' . $url;
|
|
|
|
}
|
2021-03-12 19:29:29 +00:00
|
|
|
|
2021-03-23 20:52:31 +00:00
|
|
|
// make link text from url - removing protocol
|
|
|
|
$text = parse_url( $url, PHP_URL_HOST ) . parse_url( $url, PHP_URL_PATH );
|
|
|
|
|
|
|
|
// remove the www from the link text
|
|
|
|
$text = preg_replace( "/^www./", "", $text );
|
2021-03-12 19:29:29 +00:00
|
|
|
|
2021-03-23 20:52:31 +00:00
|
|
|
// remove any long trailing path from url
|
|
|
|
$last = -( strlen( strrchr( $text, "/" ) ) ) + 1;
|
|
|
|
if ( $last < 0 ) {
|
|
|
|
$text = substr( $text, 0, $last ) . "…";
|
|
|
|
}
|
2021-03-12 19:29:29 +00:00
|
|
|
|
2021-03-23 20:52:31 +00:00
|
|
|
// update
|
|
|
|
return sprintf(
|
2022-10-21 14:17:04 +00:00
|
|
|
'<a rel="nofollow" target="_blank" href="%s">%s</a>',
|
2021-03-23 20:52:31 +00:00
|
|
|
$url,
|
|
|
|
$text
|
|
|
|
);
|
|
|
|
}, $text );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check strings for starting match
|
|
|
|
*
|
|
|
|
* @param string $string String to check.
|
|
|
|
* @param string $startString Startin string to match.
|
|
|
|
* @return boolean Wether string begins with startString.
|
|
|
|
*/
|
|
|
|
function startsWith( $string, $startString )
|
|
|
|
{
|
|
|
|
$len = strlen($startString);
|
|
|
|
return (substr($string, 0, $len) === $startString);
|
|
|
|
}
|
|
|
|
|
2021-03-24 14:54:53 +00:00
|
|
|
|
|
|
|
// Some custom structure to apply to the signup form page `local-signup` via NSUR plugin
|
2021-03-23 20:52:31 +00:00
|
|
|
function wasmo_before_signup() {
|
|
|
|
?>
|
|
|
|
<div class="site-content entry">
|
|
|
|
<div class="entry-content">
|
|
|
|
<h1>Register</h1>
|
|
|
|
<p>Choose a username (lowercase letters and numbers only) and enter your email address.</p>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'before_signup_form', 'wasmo_before_signup', 10 );
|
|
|
|
|
|
|
|
function wasmo_after_signup() {
|
|
|
|
echo '</div></div>';
|
2021-03-12 19:29:29 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 20:52:31 +00:00
|
|
|
add_action( 'after_signup_form', 'wasmo_after_signup', 10 );
|
2022-10-21 17:44:27 +00:00
|
|
|
|
|
|
|
// Random profile
|
|
|
|
add_action('init','wasmo_random_add_rewrite');
|
|
|
|
function wasmo_random_add_rewrite() {
|
|
|
|
global $wp;
|
|
|
|
$wp->add_query_var('randomprofile');
|
2022-10-26 17:35:45 +00:00
|
|
|
add_rewrite_rule('random/?$', '?randomprofile=1', 'top');
|
2022-10-21 17:44:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add_action('template_redirect','wasmo_random_profile_template');
|
|
|
|
function wasmo_random_profile_template() {
|
|
|
|
if (get_query_var('randomprofile')) {
|
|
|
|
$args = array(
|
|
|
|
'orderby' => 'rand',
|
|
|
|
'numberposts' => 1
|
|
|
|
);
|
|
|
|
$users = get_users( $args );
|
|
|
|
foreach ( $users as $user ) {
|
|
|
|
$link = get_author_posts_url( $user->ID );
|
|
|
|
}
|
2022-10-26 17:35:45 +00:00
|
|
|
wp_redirect( $link, 307 );
|
2022-10-21 17:44:27 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2022-10-26 17:35:45 +00:00
|
|
|
add_action( 'pre_user_query', 'wasmo_random_user_query' );
|
|
|
|
|
|
|
|
function wasmo_random_user_query( $class ) {
|
|
|
|
if( 'rand' == $class->query_vars['orderby'] )
|
|
|
|
$class->query_orderby = str_replace( 'user_login', 'RAND()', $class->query_orderby );
|
|
|
|
|
|
|
|
return $class;
|
2022-10-27 21:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete all transients from the database whose keys have a specific prefix.
|
|
|
|
*
|
|
|
|
* @param string $prefix The prefix. Example: 'my_cool_transient_'.
|
|
|
|
*/
|
|
|
|
function wasmo_delete_transients_with_prefix( $prefix ) {
|
|
|
|
foreach ( wasmo_get_transient_keys_with_prefix( $prefix ) as $key ) {
|
|
|
|
delete_transient( $key );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets all transient keys in the database with a specific prefix.
|
|
|
|
*
|
|
|
|
* Note that this doesn't work for sites that use a persistent object
|
|
|
|
* cache, since in that case, transients are stored in memory.
|
|
|
|
*
|
|
|
|
* @param string $prefix Prefix to search for.
|
|
|
|
* @return array Transient keys with prefix, or empty array on error.
|
|
|
|
*/
|
|
|
|
function wasmo_get_transient_keys_with_prefix( $prefix ) {
|
|
|
|
global $wpdb;
|
|
|
|
|
|
|
|
$prefix = $wpdb->esc_like( '_transient_' . $prefix );
|
|
|
|
$sql = "SELECT `option_name` FROM $wpdb->options WHERE `option_name` LIKE '%s'";
|
|
|
|
$keys = $wpdb->get_results( $wpdb->prepare( $sql, $prefix . '%' ), ARRAY_A );
|
|
|
|
|
|
|
|
if ( is_wp_error( $keys ) ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return array_map( function( $key ) {
|
|
|
|
// Remove '_transient_' from the option name.
|
|
|
|
return substr( $key['option_name'], strlen( '_transient_' ) );
|
|
|
|
}, $keys );
|
2022-10-26 17:35:45 +00:00
|
|
|
}
|