get('Version') ); wp_enqueue_script( 'wasmo-script', get_stylesheet_directory_uri() . '/js/script.js', array ( 'jquery' ), wp_get_theme()->get('Version'), true ); } add_action( 'wp_enqueue_scripts', 'wasmo_enqueue' ); 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' ); // theme mods // set_theme_mod( 'page_layout', 'one-column' ); 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' ) ); register_taxonomy( "question", array( "post" ), $args ); /** * 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" => false, "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, ); register_taxonomy( "spectrum", array( "post", "user" ), $args ); /** * 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" => false, "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 ); } add_action( 'init', 'cptui_register_my_taxes' ); function wasmo_widgets_init() { register_sidebar( array( 'name' => __( 'Sidebar', 'wasmo' ), 'id' => 'sidebar', 'description' => __( 'Add widgets here to appear in your sidebar.', 'wasmo' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'wasmo_widgets_init' ); function wasmo_setup() { register_nav_menus( array( 'utility' => __( 'Utility Menu', 'wasmo' ), ) ); set_theme_mod( 'image_filter', 0 ); } add_action( 'after_setup_theme', 'wasmo_setup' ); // add hard coded utility menu items function wasmo_loginout_menu_link( $items, $args ) { if ($args->theme_location == 'utility') { $userid = get_current_user_id(); $login = '
  • ' . wasmo_get_icon_svg( 'join', 24 ) . __(" Join", 'wasmo') . '
  • '; $login .= '
  • ' . wasmo_get_icon_svg( 'login', 24 ) . __(" Login", 'wasmo') . '
  • '; // $logout = '
  • ' . __("Log Out", 'wasmo') . '
  • '; $profile = '
  • ' . wasmo_get_icon_svg( 'person', 24 ) . 'View
  • '; $edit = '
  • ' . wasmo_get_icon_svg( 'edit', 24 ) . 'Edit
  • '; $post = ''; $writeposts = get_field( 'i_want_to_write_posts', 'user_'.$userid ); if ( !empty( $writeposts ) && 'No thanks' !== $writeposts ) { $post = '
  • ' . wasmo_get_icon_svg( 'edit-page', 24 ) . 'Submit Post
  • '; } if ( is_user_logged_in() ) { $items = $profile . $edit . $post; } else { $items = $login; } } return $items; } add_filter( 'wp_nav_menu_items', 'wasmo_loginout_menu_link', 10, 2 ); function wasmo_login_redirect_page() { return home_url('/edit/'); } add_filter('login_redirect', 'wasmo_login_redirect_page'); function wasmo_logout_redirect_page() { return home_url('/profiles/'); } add_filter('logout_redirect', 'wasmo_logout_redirect_page'); // function my_acf_init() { // } // add_action('acf/init', 'my_acf_init'); /** * Plugin Name: Multisite: Password Reset on Local Blog * 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) { 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) return site_url('wp-login.php?action=lostpassword', $scheme); if (stripos($url, "action=resetpass") !== false) 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) { $message = str_replace(get_site_url(1), get_site_url(), $message); $message = str_replace('circlecubes', 'wasmormon.org', $message); return $message; }, 10, 2); // fixes email title add_filter("retrieve_password_title", function($title) { return "[" . wp_specialchars_decode(get_option('blogname'), ENT_QUOTES) . "] Password Reset"; }); /* 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 -resave values back to user acf fields -clear directory transients -send belated welcome email if is_admin and not yet received welcome -update question counts if user includes any -update last_save timestamp for this user -increment save_count -admin notify email -redirect user to their own profile */ // custom wp-login logo function wasmo_login_logo() { ?> ID, 'last_login', time() ); } add_action( 'wp_login', 'wasmo_user_lastlogin', 10, 2 ); // Display last login time function wasmo_get_lastlogin() { $last_login = get_the_author_meta('last_login'); $the_login_date = human_time_diff($last_login); return $the_login_date; } 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); function wasmo_update_user( $post_id ) { // only for users - skip for posts etc if ( strpos( $post_id, 'user_' ) !== 0 ) { return; } $user_id = intval( substr( $post_id, 5 ) ); // update user_nicename and display_name from the equivalent acf fields $userDisplayname = sanitize_text_field( $_POST['acf']['field_5cb486045a336'] ); $userSlug = sanitize_title( $_POST['acf']['field_5cb486165a337'] ); // $user_displayname = sanitize_text_field( get_field( 'display_name', 'user_'. $user_id ) ); // $user_slug = sanitize_title( get_field( 'profile_id', 'user_'. $user_id ) ); update_user_meta( $user_id, 'nickname', $userSlug ); $user_id = wp_update_user( array( 'ID' => $user_id, 'display_name' => $userDisplayname, 'user_nicename' => $userSlug, ) ); // Purge cloudflare super page cache do_action( 'swcfpc_purge_cache' ); // clear all directory transients wasmo_delete_transients_with_prefix( 'wasmo_directory-' ); // update question counts if user includes any if( have_rows( 'questions', 'user_' . $user_id ) ){ wasmo_update_user_question_count(); } // increment save_count $save_count = get_user_meta( $user_id, 'save_count', true ); if ('' === $save_count ) { $save_count = 0; } $save_count = intval($save_count) + 1; update_user_meta( $user_id, 'save_count', $save_count ); // Add event to simple history logs apply_filters( 'simple_history_log', 'Updated profile for {displayname}({nicename}) (edit #{savecount}) {link}', [ 'nicename' => $userSlug, 'displayname' => $userDisplayname, 'savecount' => $save_count, 'link' => get_author_posts_url( $user_id ), ], 'info' ); //only if not edited by an admin if ( !current_user_can( 'administrator' ) ) { // update last_save timestamp for this user update_user_meta( $user_id, 'last_save', time() ); // email notification to admin wasmo_send_admin_email__profile_update( $user_id, $save_count ); /* // 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 wasmo_send_user_email__belated_welcome( $user_id ); update_user_meta( $user_id, 'has_received_welcome', true ); } */ } // redirect to view the profile on save wp_safe_redirect( get_author_posts_url( $user_id, $userSlug ), 301); exit(); } function wasmo_update_spotlight( $post_id ) { // only if category for spotlight posts if ( !has_category( 'spotlight', $post_id ) ) { return; } // get spotlight focus user $user_id = get_field( 'spotlight_for', $post_id ); // acf set to return user id only // update user meta with spotlight post, if found if ( $user_id ) { update_user_meta( $user_id, 'spotlight_post', $post_id ); } } add_action( 'acf/save_post', 'wasmo_update_user', 10 ); add_action( 'acf/save_post', 'wasmo_update_spotlight', 10 ); // when a user has been deleted function wasmo_delete_user( $user_id ) { // clear all directory transients wasmo_delete_transients_with_prefix( 'wasmo_directory-' ); } add_action( 'delete_user', 'wasmo_delete_user' ); function wasmo_send_user_email__welcome( $user_id ){ $sitename = get_bloginfo( 'name' ); $sitemail = get_bloginfo( 'admin_email' ); $user_info = get_userdata( $user_id ); if ( $user_info ) { $user_displayname = $user_info->display_name; $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). Edit your proflie: ' . home_url('/edit/') . ' View/share your profile: ' . get_author_posts_url( $user_id ) . ' (you can change this on your profile) 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 (you can reply to this email). Best, '. $sitename; // the send wp_mail( $welcome_mail_to, $welcome_mail_subject, $welcome_mail_message, $welcome_headers ); } } function wasmo_send_user_email__belated_welcome( $user_id ){ $sitename = get_bloginfo( 'name' ); $sitemail = get_bloginfo( 'admin_email' ); $user_info = get_userdata( $user_id ); if ( $user_info ) { $user_displayname = $user_info->display_name; $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. Edit your proflie: ' . home_url('/edit/') . ' View/share your own profile: ' . get_author_posts_url( $user_id ) . ' 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 ); } } function wasmo_send_admin_email__profile_update( $user_id, $save_count ){ $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 ) { $notify_mail_message = ''; if ( $save_count <= 1 ) { $notify_mail_subject = $sitename . ' New Profile Added: ' . $user_nicename; $notify_mail_message .= 'New profile created '; } if ( $save_count > 1 ) { $notify_mail_subject = $sitename . ' Profile Update (#' . $save_count . '): ' . $user_nicename; $notify_mail_message .= 'Profile updated '; } $notify_mail_message .= 'by ' . $user_nicename .': ' . get_author_posts_url( $user_id ); // profile content ob_start(); set_query_var( 'userid', $user_id ); get_template_part( 'template-parts/content/content', 'usertext' ); $notify_mail_message .= ob_get_clean(); $notify_mail_message .= get_author_posts_url( $user_id ); // send mail wp_mail( $notify_mail_to, $notify_mail_subject, $notify_mail_message , $headers ); } } function wasmo_get_profile_text( $userid ) { $profile_text = ''; ob_start(); set_query_var( 'userid', $userid ); get_template_part( 'template-parts/content/content', 'usertext' ); $profile_text .= ob_get_clean(); return $profile_text; } 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 ); if ( '' === $has_received_welcome || ! $has_received_welcome ) { wasmo_send_user_email__welcome( $user_id ); update_user_meta( $user_id, 'has_received_welcome', true ); } } add_action('wp_login', 'wasmo_first_user_login', 10, 2); // 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) { // These are the fields from the WordPress database // print_r($user_data); // This is the full social network profile of this user // print_r($identity); // record last login wasmo_user_lastlogin($user_data->user_login, $user_data); // send welcome? wasmo_first_user_login($user_data->user_login, $user_data); } // add_action ('oa_social_login_action_after_user_insert', 'oa_social_login_do_after_user_insert', 10, 2); //This function will be called before Social Login logs the user in function oa_social_login_do_before_user_login ($user_data, $identity, $new_registration) { // record last login wasmo_user_lastlogin($user_data->user_login, $user_data); // send welcome? wasmo_first_user_login($user_data->user_login, $user_data); } // add_action ('oa_social_login_action_before_user_login', 'oa_social_login_do_before_user_login', 10, 3); // changing default gutenberg image block alignment to "center" // function wasmo_change_default_gutenberg_image_block_options (){ // $block_type = WP_Block_Type_Registry::get_instance()->get_registered( "core/image" ); // $block_type->attributes['align']['default'] = 'center'; // } // add_action( 'init', 'wasmo_change_default_gutenberg_image_block_options'); function wasmo_update_user_question_count(){ global $wpdb; //get terms $tempterms = []; // $terms = get_terms( 'question' ); $terms = get_terms([ 'taxonomy' => 'question', 'hide_empty' => false, 'number' => 0, ]); // 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 $in_directory = get_field( 'in_directory', 'user_' . $userid ); if ( 'true' === $in_directory || 'website' === $in_directory ) { // 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' ); if ( array_key_exists( $termtaxid, $tempterms ) ) { $tempterms[$termtaxid]++; // increment term } else { $tempterms[$termtaxid] = 1; } } } } } // 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 ) ); } } //override twentynineteen_entry_footer function wasmo_entry_footer() { // Hide author, post date, category and tag text for pages. if ( 'post' === get_post_type() ) { // Profile link if (has_category( 'spotlight', get_the_ID() ) && get_field( 'spotlight_for', get_the_ID() ) ) { $user_id = get_field( 'spotlight_for', get_the_ID() ); $user = get_user_by( 'id', $user_id ); ?>

    This post spotlights a real user's profile, please view the full profile for display_name;?> here.

    has_cap( 'manage_options' ) ) { twentynineteen_posted_by(); // hide author } // Posted on twentynineteen_posted_on(); /* translators: used between list items, there is a space after the comma. */ $categories_list = get_the_category_list( __( ', ', 'wasmo' ) ); if ( $categories_list ) { printf( /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of categories. */ '%1$s%2$s%3$s', wasmo_get_icon_svg( 'archive', 16 ), __( 'Posted in', 'wasmo' ), $categories_list ); // WPCS: XSS OK. } /* translators: used between list items, there is a space after the comma. */ $tags_list = get_the_tag_list( '', __( ', ', 'wasmo' ) ); if ( $tags_list ) { printf( /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of tags. */ '%1$s%2$s %3$s', wasmo_get_icon_svg( 'tag', 16 ), __( 'Tags:', 'wasmo' ), $tags_list ); // WPCS: XSS OK. } // Related Shelf items $shelf_list = get_the_term_list( get_the_ID(), 'shelf', '', ', ', '' ); if ( $shelf_list ) { printf( /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of tags. */ '%1$s%2$s %3$s', wasmo_get_icon_svg( 'shelf', 18, 'style="margin-top:-3px;"' ), __( 'Shelf items', 'wasmo' ), $shelf_list ); // WPCS: XSS OK. } // Related Spectrum $spectrum_list = get_the_term_list( get_the_ID(), 'spectrum', '', ', ', '' ); if ( $spectrum_list ) { printf( /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of tags. */ '%1$s%2$s %3$s', wasmo_get_icon_svg( 'spectrum', 16 ), __( 'Mormon Spectrum', 'wasmo' ), $spectrum_list ); // WPCS: XSS OK. } // Related Questions $question_list = get_the_term_list( get_the_ID(), 'question', '', '
    ' . wasmo_get_icon_svg( 'question', 18, 'style="margin-top:-3px;"'), '' ); if ( $question_list ) { printf( /* translators: 1: SVG icon. 2: posted in label, only visible to screen readers. 3: list of tags. */ '%1$s%2$s %3$s', wasmo_get_icon_svg( 'question', 18, 'style="margin-top:-3px;"'), __( 'Questions', 'wasmo' ), $question_list ); // WPCS: XSS OK. } wasmo_post_navi(); } // 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 %s', 'wasmo' ), array( 'span' => array( 'class' => array(), ), ) ), get_the_title() ), '' . wasmo_get_icon_svg( 'edit', 16 ), '' ); } /** * Pagination Helper Method * * @param Number $paged Page Number * @param Number $max_page Max Page * @param Boolean $profile Flag for profile nav, this updates the baseurl and format so they work for the custom pagination * @return String Pagination links */ function wasmo_pagination( $paged = '', $max_page = '', $profiles = false ) { $big = 999999999; // need an unlikely integer if( ! $paged ) { $paged = get_query_var('paged'); } if( ! $max_page ) { global $wp_query; $max_page = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; } if ( $max_page > 7 ) { $show_all = false; } else { $show_all = true; } $base_url = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); $format = '?paged=%#%'; if ( $profiles ) { $base_url = get_permalink( get_page_by_path( 'profiles' ) ) . 'page/%_%'; $format = '%#%'; } $paginated_links = paginate_links( array( 'base' => $base_url, 'format' => $format, 'current' => max( 1, $paged ), 'total' => $max_page, 'mid_size' => 1, 'end_size' => 1, 'prev_text' => sprintf( '%s %s', wasmo_get_icon_svg( 'chevron_left', 22 ), __( 'Newer', 'twentynineteen' ) ), 'next_text' => sprintf( '%s %s', __( 'Older', 'twentynineteen' ), wasmo_get_icon_svg( 'chevron_right', 22 ) ), 'type' => 'list', 'show_all' => $show_all, ) ); return '
    ' . $paginated_links . '
    '; } function wasmo_post_navi() { if( !is_singular('post') ) { return; } $prev_post = get_previous_post(); $next_post = get_next_post(); ?>

    ID, 'medium', array('class' => 'pagination-prev') ); previous_post_link( '%link', wasmo_get_icon_svg( 'chevron_left', 22 ) . 'Older Post%title' . $prev_post_img . '' ); } ?> ID, 'medium', array('class' => 'pagination-next') ); next_post_link( '%link', 'Newer Post '.wasmo_get_icon_svg( 'chevron_right', 22 ).'%title' . $next_post_img . '' ); } ?>

    Read more'; } 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 .= '

    ' . $atts['title'] . '

    '; } 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(); return $directory; } /** * 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' => 'manage_options', '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) { // skip if if ( is_user_logged_in() || // logged in or !is_single() || // not a single post or !is_main_query() || // not the main loop or is_embed() // is a post embed ) { return $content; } // top if ( get_field( 'before_post_callout', 'option' ) ) { $top_callout = ''; } else { ob_start(); ?> ' . get_field( 'after_post_callout', 'option' ) . ''; } else { ob_start(); ?> ID; $title = esc_html( get_field( 'hi', 'user_' . $userid ) ) . ' - '; $title .= 'Learn why I\'m no longer mormon at wasmormon.org'; } return $title; } // filter to update user profile page description for seo function wasmo_user_profile_wpseo_metadesc( $metadesc ) { if( is_author() ) { $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 ) ); } return $metadesc; } // 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() ) { $curauth = ( get_query_var( 'author_name' ) ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); $userid = $curauth->ID; // if has author image $userimg = get_field( 'photo', 'user_' . $userid ); if ( $userimg ) { $image = wp_get_attachment_image_url( $userimg, 'large' ); } } return $image; } /** * 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`!()\[\]{};:'.,<>?«»“”‘’])|(?:(?%s', $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); } /** * Replace pseudo __HTML__ in text with elements * * @param string $text Text to add hrs to * @return string Text with hrs added */ function auto_htmlize_text( $text ) { $patterns = array( '

    __HR__

    ', // make hr 'BLOCKQUOTE__', // open blockquote '__BLOCKQUOTE', // close blockquote 'CITE__', // open cite '__CITE', // close cite 'STRONG__', // open strong '__STRONG', // close strong 'EM__', // open italics '__EM', // close italics ); $replacements = array( '
    ', '
    ', '
    ', '', '', '', '', '', '', ); return str_replace( $patterns, $replacements, $text ); } // Some custom structure to apply to the signup form page `local-signup` via NSUR plugin function wasmo_before_signup() { ?>

    Register

    Choose a username (lowercase letters and numbers only) and enter your email address.

    '; } add_action( 'after_signup_form', 'wasmo_after_signup', 10 ); // Random profile add_action('init','wasmo_random_add_rewrite'); function wasmo_random_add_rewrite() { global $wp; $wp->add_query_var('randomprofile'); add_rewrite_rule('random/?$', '?randomprofile=1', 'top'); } add_action('template_redirect','wasmo_random_profile_template'); function wasmo_random_profile_template() { if (get_query_var('randomprofile')) { wp_redirect( wasmo_get_random_profile_url(), 307 ); exit; } } add_action( 'pre_user_query', 'wasmo_random_user_query' ); function wasmo_get_random_profile_url() { $args = array( 'orderby' => 'rand', // 'numberposts' => 1 ); $users = get_users( $args ); foreach ( $users as $user ) { // check that user has content and is public if ( ! get_field( 'hi', 'user_' . $user->ID ) || 'private' === get_user_meta( $user->ID, 'in_directory', true ) || 'false' === get_user_meta( $user->ID, 'in_directory', true ) ) { continue; } return get_author_posts_url( $user->ID ); } } 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; } /** * 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 ); } // set up the block pattern category // define theme specific block patterns in theme patterns folder function wasmo_register_pattern_categories() { register_block_pattern_category( 'wasmormon', array( 'label' => __( 'wasmormon', 'wasmo' ) ) ); } add_action( 'init', 'wasmo_register_pattern_categories' ); // hide admin menu items for non admin users function wasmo_remove_menu_items() { if ( !current_user_can( 'administrator' ) ) : // IF NON ADMIN USER remove_menu_page( 'index.php' ); // DASHBOARD //remove_menu_page( 'edit.php?post_type=custom_post_type' ); //remove_submenu_page( 'edit.php?post_type=custom_post_type', 'post-new.php?post_type=custom_post_type' ); //remove_menu_page( 'edit.php' ); remove_menu_page( 'upload.php' ); remove_menu_page( 'edit-comments.php' ); remove_menu_page( 'edit.php?post_type=page' ); remove_menu_page( 'plugins.php' ); remove_menu_page( 'themes.php' ); remove_menu_page( 'users.php' ); remove_menu_page( 'profile.php' ); remove_menu_page( 'tools.php' ); remove_menu_page( 'options-general.php' ); remove_menu_page( 'jetpack' ); remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=question' ); //questions taxonomy remove_submenu_page( 'index.php', 'my-sites.php' ); endif; } add_action( 'admin_menu', 'wasmo_remove_menu_items', 1000 ); // hide admin bar for non admin users function wasmo_hide_admin_bar() { if ( !current_user_can( 'publish_posts' ) ) { show_admin_bar( false ); } } // add_action( 'set_current_user', 'wasmo_hide_admin_bar' ); // hide admin bar for non admin users // function remove_admin_bar() { // if ( !current_user_can('administrator') && !is_admin() ) { // show_admin_bar( false ); // } // } // add_action('after_setup_theme', 'remove_admin_bar'); // remove links/menus from the admin bar function wasmo_admin_bar_render() { global $wp_admin_bar; // hide stuff in admin bar for everyone $wp_admin_bar->remove_menu('aioseo-main'); // alter user admin bar if ( !current_user_can('administrator') ) { $wp_admin_bar->remove_menu('search'); $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('comments'); // $wp_admin_bar->remove_menu('my-account-with-avatar'); // $wp_admin_bar->remove_menu('my-account'); // $wp_admin_bar->remove_menu('get-shortlink'); // $wp_admin_bar->remove_menu('appearance'); // $wp_admin_bar->remove_menu('updates'); // $wp_admin_bar->remove_menu('notes'); // $wp_admin_bar->remove_menu('edit'); //add menu items for user profile view and edit $wp_admin_bar->add_menu( array( 'id' => 'profile-edit', 'parent' => null, 'group' => null, 'title' => wasmo_get_icon_svg( 'edit', 14 ) . ' Edit Profile', 'href' => site_url('/edit/'), 'meta' => [ 'title' => 'Edit Profile', ] )); $wp_admin_bar->add_menu( array( 'id' => 'profile-view', 'parent' => null, 'group' => null, 'title' => wasmo_get_icon_svg( 'person', 14 ) . ' View Profile', 'href' => get_author_posts_url( get_current_user_id() ), 'meta' => [ 'title' => 'View Profile', ] )); if ( !is_admin() ) { // $wp_admin_bar->remove_menu('site-name'); } } } add_action( 'wp_before_admin_bar_render', 'wasmo_admin_bar_render' ); // only show users own posts function posts_for_current_author($query) { global $pagenow; if( 'edit.php' != $pagenow || !$query->is_admin ) return $query; if( !current_user_can( 'edit_others_posts' ) ) { global $user_ID; $query->set('author', $user_ID ); add_filter('views_edit-post', 'wasmo_fix_post_counts'); } return $query; } add_filter('pre_get_posts', 'posts_for_current_author'); // Fix post counts function wasmo_fix_post_counts($views) { global $current_user, $wp_query; unset($views['mine']); $types = array( array( 'status' => NULL ), array( 'status' => 'publish' ), array( 'status' => 'draft' ), array( 'status' => 'future' ), array( 'status' => 'pending' ), array( 'status' => 'trash' ) ); foreach( $types as $type ) { $query = array( 'author' => $current_user->ID, 'post_type' => 'post', 'post_status' => $type['status'] ); $result = new WP_Query($query); if( $type['status'] == NULL ): $class = ($wp_query->query_vars['post_status'] == NULL) ? ' class="current"' : ''; $views['all'] = sprintf( __('All (%d)', 'wasmo'), admin_url('edit.php?post_type=post'), $result->found_posts ); elseif( $type['status'] == 'publish' ): if ( $result->found_posts === 0 ) { unset($views['publish']); } else { $class = ($wp_query->query_vars['post_status'] == 'publish') ? ' class="current"' : ''; $views['publish'] = sprintf( __('Published (%d)', 'wasmo'), admin_url('edit.php?post_status=publish&post_type=post'), $result->found_posts ); } elseif( $type['status'] == 'draft' ): if ( $result->found_posts === 0 ) { unset($views['draft']); } else { $class = ($wp_query->query_vars['post_status'] == 'draft') ? ' class="current"' : ''; $views['draft'] = sprintf( __('Draft'. ((sizeof($result->posts) > 1) ? "s" : "") .' (%d)', 'wasmo'), admin_url('edit.php?post_status=draft&post_type=post'), $result->found_posts ); } elseif( $type['status'] == 'future' ): if ( $result->found_posts === 0 ) { unset($views['future']); } else { $class = ($wp_query->query_vars['post_status'] == 'future') ? ' class="future"' : ''; $views['future'] = sprintf( __('Scheduled (%d)', 'wasmo'), admin_url('edit.php?post_status=future&post_type=post'), $result->found_posts ); } elseif( $type['status'] == 'pending' ): if ( $result->found_posts === 0 ) { unset($views['pending']); } else { $class = ($wp_query->query_vars['post_status'] == 'pending') ? ' class="current"' : ''; $views['pending'] = sprintf( __('Pending (%d)', 'wasmo'), admin_url('edit.php?post_status=pending&post_type=post'), $result->found_posts ); } elseif( $type['status'] == 'trash' ): if ( $result->found_posts === 0 ) { unset($views['trash']); } else { $class = ($wp_query->query_vars['post_status'] == 'trash') ? ' class="current"' : ''; $views['trash'] = sprintf( __('Trash (%d)', 'wasmo'), admin_url('edit.php?post_status=trash&post_type=post'), $result->found_posts ); } endif; } return $views; } /** * Allow author pages to be indexed, unless unlisted */ add_filter( 'wp_robots', function( $robots ) { if ( is_author() ) { $curauth = ( get_query_var('author_name') ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); $userid = $curauth->ID; // check privacy setting, noindex if not public $in_directory = get_field( 'in_directory', 'user_' . $userid ); if( !$in_directory || 'false' === $in_directory || 'private' === $in_directory ) { $robots['noindex'] = true; } else { // otherwise, index $robots['noindex'] = false; } } return $robots; }); /** * Filter authors in sitemap to include all who are public and have required fields */ add_filter('aioseo_sitemap_author_archives', function( $entries ) { $authors = get_users(); $entries = []; foreach ( $authors as $author ) { // check that profile has required content // require both hi and tagline content, bail early if not present if ( !get_field( 'hi', 'user_' . $author->ID ) || !get_field( 'tagline', 'user_' . $author->ID ) ) { continue; } // check privacy setting, bail if not public $in_directory = get_field( 'in_directory', 'user_' . $author->ID ); if( !$in_directory || 'false' === $in_directory || 'private' === $in_directory ) { continue; } // get the last save time $last_save = intval( get_user_meta( $author->ID, 'last_save', true ) ); // $user = get_userdata( $author->ID ); // $registered = strtotime( $user->user_registered ); $entries[] = [ 'loc' => get_author_posts_url( $author->ID ), 'lastmod' => $last_save ? date('Y-m-d', $last_save ) : false, 'changefreq' => aioseo()->sitemap->priority->frequency( 'author' ), 'priority' => aioseo()->sitemap->priority->priority( 'author' ), ]; } return $entries; }); /** * Filter aioseo description for profile pages with acf custom fields */ add_filter( 'aioseo_description', function ( $description ) { if ( is_author() ) { $curauth = ( get_query_var('author_name') ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); $userid = $curauth->ID; $description .= get_field( 'hi', 'user_' . $userid ) . '. ' . get_field( 'tagline', 'user_' . $userid ); } return $description; }); /** * Add og meta values for author pages */ add_action( 'wp_head', function () { if ( is_author() ) { $curauth = ( get_query_var('author_name') ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); $userid = $curauth->ID; ?> user_email ) ) ); $default_img = urlencode( 'https://raw.githubusercontent.com/circlecube/wasmo-theme/main/img/default.png' ); $gravatar = $hash . '?s=300&d='.$default_img; return "https://www.gravatar.com/avatar/" . $gravatar; } } /** * Get user image * * @param Number $userid The user's id. * @param Boolean $isItempropImage Flag to determine wether to include itemProp=image (for structured data) (default false). * @return String html for image tag */ function wasmo_get_user_image( $userid, $isItempropImage = false ) { $userimg = get_field( 'photo', 'user_' . $userid ); $user = get_userdata( $userid ); $alt = $user->display_name . ' profile image for wasmormon.org'; if ( $userimg ) { return wp_get_attachment_image( $userimg, 'medium', false, array( 'alt' => $alt, 'itemProp' => $isItempropImage ? 'image' : '', ) ); } else { $img_url = wasmo_get_user_image_url( $userid ); $atts = $isItempropImage ? 'itemProm="image"' : ''; return '' . $alt . ''; } } /** * Send out email depending on who updates the status of the post. * * @param String $new_status New post status. * @param String $old_status Old post status. * @param WP_Post $post Post object. */ function wasmo_pending_submission_notifications_send_email( $new_status, $old_status, $post ) { $admin_email = get_bloginfo( 'admin_email' ); $headers = 'From: '. $admin_email; $user = get_userdata( $post->post_author ); // Notify Admin that Contributor has written a post. if ( 'pending' === $new_status && user_can( $post->post_author, 'edit_posts' ) && !user_can( $post->post_author, 'publish_posts' ) && !empty($_POST) ) { $edit_link = get_edit_post_link( $post->ID, '' ); $preview_link = get_permalink( $post->ID ) . '&preview=true'; $last_edit = get_the_modified_author(); $subject = __( 'New post submission pending review', 'wasmo' ) . ': "' . $post->post_title . '"'; $message = __( 'A new submission is pending review.', 'wasmo' ); $message .= "\r\n\r\n"; $message .= __( 'Author', 'wasmo' ) . ': ' . $user->user_login . "\r\n"; $message .= __( 'Profile', 'wasmo' ) . ': ' . get_author_posts_url( $user->ID ) . "\r\n"; $message .= __( 'Title', 'wasmo' ) . ': ' . $post->post_title . "\r\n"; $message .= __( 'Last edited by', 'wasmo' ) . ': ' . $last_edit . "\r\n"; $message .= __( 'Last edit date', 'wasmo' ) . ': ' . $post->post_modified; $message .= "\r\n\r\n"; $message .= __( 'Edit the submission', 'wasmo' ) . ': ' . $edit_link . "\r\n"; $message .= __( 'Preview the submission', 'wasmo' ) . ': ' . $preview_link; $result = wp_mail( $admin_email, $subject, $message, $headers ); } elseif ( ( 'pending' === $old_status || 'future' === $old_status ) && 'publish' === $new_status && user_can( $post->post_author, 'edit_posts' ) && !user_can( $post->post_author, 'publish_posts' ) && !empty($_POST) ) { // Notify Contributor that Admin has published their post. $url = get_permalink( $post->ID ); $subject = __( 'Your submission is now live!', 'wasmo' ); $message = '"' . $post->post_title . '" ' . __( 'was just published on wasmormon.org', 'wasmo' ) . "! \r\n\r\n"; $message .= $url; $result = wp_mail( $user->user_email, $subject, $message, $headers ); } } add_action( 'transition_post_status', 'wasmo_pending_submission_notifications_send_email', 10, 3 ); // Remove admin notices for non admin users function wasmo_hide_notices(){ if ( !current_user_can('administrator') ) { remove_all_actions( 'admin_notices' ); } } add_action( 'admin_head', 'wasmo_hide_notices', 1 ); /** * Icon svg method for wasmo theme. * * @param String $icon string value. * @param Number $size number pixel value. * @param String $styles a styles attribute for any custom styles, such as `style="margin-left:20px;"`. * @return String svg element. */ function wasmo_get_icon_svg( $icon, $size = 24, $styles = '' ) { // map taxonomies to an icon switch ($icon) { case 'shelf': $icon = 'flag'; break; case 'spectrum': $icon = 'nametag'; break; case 'question': $icon = 'help'; break; } // collected from https://github.com/WordPress/dashicons/tree/master/sources/svg $arr = array( 'warning' => /* warning - dashicon */ ' ', 'help' => /* help dashicon */' ', 'flag' => /* flag dashicon */ ' ', 'nametag' => /* dashicon nametag */ ' ', 'edit-page' => /* dashicon edit-page */ ' ', 'join' => ' ', 'login' => ' ', 'link' => /* material-design – link */ ' ', 'watch' => /* material-design – watch-later */ ' ', 'archive' => /* material-design – folder */ ' ', 'tag' => /* material-design – local_offer */ ' ', 'comment' => /* material-design – comment */ ' ', 'person' => /* material-design – person */ ' ', 'edit' => /* material-design – edit */ ' ', 'chevron_left' => /* material-design – chevron_left */ ' ', 'chevron_right' => /* material-design – chevron_right */ ' ', 'check' => /* material-design – check */ ' ', ); if ( array_key_exists( $icon, $arr ) ) { $repl = sprintf( '\s*<', $svg ); // Remove whitespace between SVG tags. return $svg; } return null; } remove_filter('term_description','wpautop'); // add tags for attachments function add_tags_for_attachments() { register_taxonomy_for_object_type( 'post_tag', 'attachment' ); } add_action( 'init' , 'add_tags_for_attachments' ); // Modify the main query object function wasmo_media_in_main_query( $query ) { if ( $query->is_archive() && $query->is_main_query() ) { // only run on archive queries $query->set( 'post_type', array( 'post', 'attachment' ) ); // add attachment post types, media $query->set( 'post_status', array( 'publish', 'inherit' ) ); // add inherit post status since that is the default status of media } } // Hook my above function to the pre_get_posts action add_action( 'pre_get_posts', 'wasmo_media_in_main_query' ); /** * Update amazon links with associate tag */ function add_zon_tag($content, $tag = 'circubstu-20' ) { $all_links = wp_extract_urls( $content ); $zon_links = array_filter( $all_links, function ($link) { if ( str_contains( $link, 'amazon.' ) || str_contains( $link, 'amzn.to' ) ) { return true; } return false; } ); foreach( $zon_links as $link ) { $content = str_replace( $link, add_query_arg('tag', $tag, $link), $content ); } return $content; } add_filter( 'the_content', 'add_zon_tag' );