/** * Checks if the user is bookmarkd to the topic. * * @since 1.0.0 * @access public * @param int $user_id * @param int $topic_id * @return bool */ function mb_is_topic_user_bookmark($user_id = 0, $topic_id = 0) { $user_id = mb_get_user_id($user_id); $topic_id = mb_get_topic_id($topic_id); $is_bookmarkd = in_array($topic_id, mb_get_user_topic_bookmarks($user_id)) ? true : false; return apply_filters('mb_is_user_bookmarkd_topic', $is_bookmarkd, $user_id, $topic_id); }
/** * Function for inserting reply data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_reply_data($post) { /* Hook for before inserting reply data. */ do_action('mb_before_insert_reply_data', $post); /* Get the reply ID. */ $reply_id = mb_get_reply_id($post->ID); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->post_parent); /* Get the forum ID. */ $forum_id = mb_get_topic_forum_id($topic_id); /* Get the user ID. */ $user_id = mb_get_user_id($post->post_author); /* Get the post date. */ $post_date = $post->post_date; $post_epoch = mysql2date('U', $post_date); /* Update user meta. */ $topic_count = mb_get_user_topic_count($user_id); update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $topic_count + 1); /* Update topic position. */ mb_set_topic_position($topic_id, $post_epoch); /* Update topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_last_reply_id($topic_id, $reply_id); $voices = mb_get_topic_voices($topic_id); if (!in_array($user_id, $voices)) { $voices[] = $user_id; mb_set_topic_voices($topic_id, $voices); mb_set_topic_voice_count($topic_id, count($voices)); } $topic_reply_count = mb_get_topic_reply_count($topic_id); mb_set_topic_reply_count($topic_id, absint($topic_reply_count) + 1); $forum_reply_count = absint(mb_get_forum_reply_count($forum_id)) + 1; /* Update forum meta. */ mb_set_forum_activity_datetime($forum_id, $post_date); mb_set_forum_activity_epoch($forum_id, $post_epoch); mb_set_forum_last_reply_id($forum_id, $reply_id); mb_set_forum_last_topic_id($forum_id, $topic_id); mb_set_forum_reply_count($forum_id, $forum_reply_count); /* Notify subscribers that there's a new reply. */ mb_notify_subscribers($post); /* Hook for after inserting reply data. */ do_action('mb_after_insert_reply_data', $post); }
/** * Function for inserting topic data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_topic_data($post) { /* Hook for before inserting topic data. */ do_action('mb_before_insert_topic_data', $post); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->ID); /* Get the forum ID. */ $forum_id = mb_get_forum_id($post->post_parent); /* Get the User ID. */ $user_id = mb_get_user_id($post->post_author); /* Get the post date. */ $post_date = $post->post_date; $post_epoch = mysql2date('U', $post_date); /* Update user meta. */ $topic_count = mb_get_user_topic_count($user_id); update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $topic_count + 1); /* Add topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_voices($topic_id, $user_id); mb_set_topic_voice_count($topic_id, 1); mb_set_topic_reply_count($topic_id, 0); /* If we have a forum ID. */ if (0 < $forum_id) { $topic_count = mb_get_forum_topic_count($forum_id); /* Update forum meta. */ mb_set_forum_activity_datetime($forum_id, $post_date); mb_set_forum_activity_epoch($forum_id, $post_epoch); mb_set_forum_last_topic_id($forum_id, $topic_id); mb_set_forum_topic_count($forum_id, absint($topic_count) + 1); } /* Notify subscribers that there's a new topic. */ mb_notify_subscribers($post); /* Hook for after inserting topic data. */ do_action('mb_after_insert_topic_data', $post); }
/** * Checks if the user is subscribed to the topic. * * @since 1.0.0 * @access public * @param int $user_id * @param int $topic_id * @return bool */ function mb_is_user_subscribed_topic($user_id = 0, $topic_id = 0) { $user_id = mb_get_user_id($user_id); $topic_id = mb_get_topic_id($topic_id); $is_subscribed = in_array($topic_id, mb_get_user_topic_subscriptions($user_id)) ? true : false; return apply_filters('mb_is_user_subscribed_topic', $is_subscribed, $user_id, $topic_id); }
/** * Overwrites the `do_trail_items()` method and creates custom trail items. * * @since 1.0.0 * @access public * @return void */ public function do_trail_items() { /* Add the network and site home links. */ $this->do_network_home_link(); $this->do_site_home_link(); $this->mb_do_board_home_link(); /* Single forum, topic, or reply. */ if (mb_is_single_forum() || mb_is_single_topic() || mb_is_single_reply()) { $this->do_singular_items(); } elseif (mb_is_forum_archive() || mb_is_topic_archive() || mb_is_reply_archive()) { $this->do_post_type_archive_items(); } elseif (mb_is_role_archive()) { $this->mb_do_user_archive_link(); if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_role_archive_url(), mb_get_role_archive_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_role_archive_title(); } } elseif (mb_is_single_role()) { $this->mb_do_user_archive_link(); $this->mb_do_role_archive_link(); if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_role_url(), mb_get_single_role_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_single_role_title(); } } elseif (mb_is_user_archive()) { if (is_paged()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_archive_url(), mb_get_user_archive_title()); } elseif ($this->args['show_title']) { $this->items[] = mb_get_user_archive_title(); } } elseif (mb_is_single_user()) { $this->mb_do_user_archive_link(); /* If single user subpage. */ if (mb_is_user_page()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_url(), get_the_author_meta('display_name', mb_get_user_id())); if (is_paged()) { if (mb_is_user_forums()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_forums_url(), mb_get_user_forums_title()); } elseif (mb_is_user_topics()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_topics_url(), mb_get_user_topics_title()); } elseif (mb_is_user_replies()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_replies_url(), mb_get_user_replies_title()); } elseif (mb_is_user_bookmarks()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_bookmarks_url(), mb_get_user_bookmarks_title()); } elseif (mb_is_user_forum_subscriptions()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_forum_subscriptions_url(), mb_get_user_forum_subscriptions_title()); } elseif (mb_is_user_topic_subscriptions()) { $this->items[] = sprintf('<a href="%s">%s</a>', mb_get_user_topic_subscriptions_url(), mb_get_user_topic_subscriptions_title()); } } elseif ($this->args['show_title']) { $this->items[] = mb_get_user_page_title(); } /* If viewing the single user page but not a subpage. */ } elseif ($this->args['show_title']) { $this->items[] = mb_get_single_user_title(); } /* Login page. */ } elseif (mb_is_forum_login()) { $this->items[] = mb_get_login_page_title(); } /* Add paged items. */ $this->do_paged_items(); /* Return the board breadcrumb trail items. */ $this->items = apply_filters('mb_get_breadcrumb_trail_items', $this->items, $this->args); }
/** * Returns a user's post count (topics + replies). * * @since 1.0.0 * @access public * @param int $user_id * @return int */ function mb_get_user_post_count($user_id = 0) { $user_id = mb_get_user_id($user_id); $topic_count = mb_get_user_topic_count($user_id); $reply_count = mb_get_user_reply_count($user_id); $count = $topic_count + $reply_count; return apply_filters('mb_get_user_post_count', $count, $user_id); }
/** * Returns the translatable forum role name for a specific user. * * @since 1.0.0 * @access public * @param int $user_id * @return string */ function mb_get_user_role_name($user_id = 0) { $user_id = mb_get_user_id($user_id); $role = mb_get_user_role($user_id); $name = !empty($role) ? mb_get_role_name($role) : ''; /* Return the role name and allow devs to filter. */ return apply_filters('mb_get_user_role_name', $name, $role, $user_id); }
/** * Callback function on the `after_delete_post` hook for when a forum is deleted. * * @todo All forum topics need to become orphans at this point. Attempt to move topics into parent if avail. * @todo Reset counts for parent forums. * @todo `wp_die()` if this is the default forum. * * @since 1.0.0 * @access public * @param int $post_id * @return void */ function mb_after_delete_forum($post_id) { global $wpdb; $mb = message_board(); if (is_object($mb->deleted_post) && $mb->deleted_post->ID === $post_id) { $forum_id = mb_get_forum_id($post_id); $user_id = mb_get_user_id($post->deleted_post->post_author); $parent_forum_id = $mb->deleted_post->post_parent; /* Get the current forum's subforum IDs. */ $subforum_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_forum_post_type(), absint($forum_id))); if (!empty($subforum_ids)) { $moved_forums = false; while (0 < $parent_forum_id) { if (mb_forum_allows_subforums($parent_forum_id)) { /* Change all of the subforums' parents to the new forum ID. */ $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", absint($parent_forum_id))); /* Reset data based on new forum. */ mb_reset_forum_data($parent_forum_id); $parent_forum_id = 0; $moved_forums = true; /* Break out of the while loop at this point. */ break; } $post = get_post($parent_forum_id); $parent_forum_id = $post->post_parent; } /* If subforums didn't get moved to a new forum, make them a top-level forum. */ if (false === $moved_forums) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $subforum_ids) . ")", 0)); } } $parent_forum_id = $mb->deleted_post->post_parent; /* Get the current forum's topic IDs. */ $topic_ids = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %s ORDER BY menu_order DESC", mb_get_topic_post_type(), absint($forum_id))); if (!empty($topic_ids)) { $moved_topics = false; while (0 < $parent_forum_id) { if (mb_forum_allows_topics($parent_forum_id)) { /* Change all of the topics' parents to the new forum ID. */ $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID IN (" . implode(',', $topic_ids) . ")", absint($parent_forum_id))); /* Reset data based on new forum. */ mb_reset_forum_data($parent_forum_id); $parent_forum_id = 0; $moved_topics = true; /* Break out of the while loop at this point. */ break; } $post = get_post($parent_forum_id); $parent_forum_id = $post->post_parent; } /* If topics didn't get moved to a new forum, set their status to "orphan". */ if (false === $moved_topics) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = %s WHERE ID IN (" . implode(',', $topic_ids) . ")", mb_get_orphan_post_status())); } } /* Reset user forum count. */ mb_set_user_forum_count($user_id); } }
?> <?php } elseif (mb_is_user_page('replies')) { ?> <?php mb_get_template_part('loop-reply'); ?> <?php } else { ?> <?php echo get_avatar(mb_get_user_id()); ?> <div class="mb-user-info"> <ul> <li><?php printf(__('Forum role: %s', 'message-board'), mb_get_role_link(mb_get_user_role())); ?> </li> <li><?php printf(__('Forums created: %s', 'message-board'), mb_get_user_forum_count()); ?> </li> <li><?php printf(__('Topics started: %s', 'message-board'), mb_get_user_topic_count());
/** * Handles the output for custom columns. * * @since 1.0.0 * @access public * @param string $column * @param string $column_name * @param int $post_id */ public function custom_column($column, $column_name, $user_id) { /* Post status column. */ if ('topics' === $column_name) { $user_id = mb_get_user_id($user_id); $topic_count = mb_get_user_topic_count($user_id); /* If the current user can create topics, link the topic count back to the edit topics screen. */ if (!empty($topic_count) && current_user_can('create_topics')) { $url = add_query_arg(array('post_type' => mb_get_topic_post_type(), 'author' => $user_id), admin_url('edit.php')); $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View topics by this user', 'message-board'), $topic_count); /* Else, display the count. */ } else { $column = !empty($topic_count) ? $topic_count : number_format_i18n(0); } /* Replies column. */ } elseif ('replies' === $column_name) { $user_id = mb_get_user_id($user_id); $reply_count = mb_get_user_reply_count($user_id); /* If the current user can create replies, link the topic count back to the edit replies screen. */ if (!empty($reply_count) && current_user_can('create_replies')) { $url = add_query_arg(array('post_type' => mb_get_reply_post_type(), 'author' => $user_id), admin_url('edit.php')); $column = sprintf('<a href="%s" title="%s">%s</a>', esc_url($url), __('View replies by this user', 'message-board'), $reply_count); /* Else, display the count. */ } else { $column = !empty($reply_count) ? $reply_count : number_format_i18n(0); } } /* Return the filtered column. */ return $column; }
/** * Function for inserting forum data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_forum_data($post) { /* Hook for before inserting forum data. */ do_action('mb_before_insert_forum_data', $post); /* Get the forum ID. */ $forum_id = mb_get_forum_id($post->ID); /* Get the User ID. */ $user_id = mb_get_user_id($post->post_author); /* Update parent's subforum count. */ if (0 < $post->post_parent) { $count = mb_get_forum_subforum_count($post->post_parent); mb_set_forum_subforum_count($post->post_parent, absint($count) + 1); } /* Update user meta. */ mb_set_user_forum_count($user_id); /* Add forum meta. */ mb_reset_forum_level($forum_id); /* Notify subscribers that there's a new forum. */ mb_notify_subscribers($post); /* Hook for after inserting forum data. */ do_action('mb_after_insert_forum_data', $post); }
function mb_handler_edit_user() { /* Verify the nonce. */ if (!mb_check_post_nonce('mb_edit_user_nonce', 'mb_edit_user_action')) { return; } /* Get the user ID. */ $user_id = mb_get_user_id($_POST['mb_user_id']); /* Make sure the current user can edit the user. */ if (!current_user_can('edit_user', $user_id)) { mb_bring_the_doom('no-permission'); } /* Get the user object. */ $user = new WP_User($user_id); $first_name = !empty($_POST['mb_first_name']) ? esc_html(strip_tags($_POST['mb_first_name'])) : ''; $last_name = !empty($_POST['mb_last_name']) ? esc_html(strip_tags($_POST['mb_last_name'])) : ''; $nickname = !empty($_POST['mb_nickname']) ? esc_html(strip_tags($_POST['mb_nickname'])) : $user->user_login; $url = !empty($_POST['mb_url']) ? esc_url_raw($_POST['mb_url']) : ''; $email = isset($_POST['mb_email']) ? sanitize_email($_POST['mb_email']) : ''; if (empty($email) || !is_email($email) || email_exists($email)) { $email = $user->user_email; } $args = array('ID' => $user->ID, 'first_name' => $first_name, 'last_name' => $last_name, 'nickname' => $nickname, 'user_email' => $email, 'user_url' => $url); if (!empty($_POST['pass1']) && !empty($_POST['pass2']) && $_POST['pass1'] === $_POST['pass2']) { $args['user_pass'] = $_POST['pass1']; } $updated = wp_update_user($args); if ($updated && !is_wp_error($updated)) { // @todo User contact methods... /* Currently-saved meta. */ $desc_meta = get_user_meta($user_id, 'description', true); /* Posted meta. */ $description = !empty($_POST['mb_description']) ? mb_filter_post_kses($_POST['mb_description']) : ''; if ($desc_meta !== $description) { update_user_meta($user_id, 'description', $description); } /* Redirect to user profile. */ wp_safe_redirect(mb_get_user_url($user_id)); } }
<?php mb_the_user(); // Set up user data. ?> <tr> <td class="mb-col-title"> <?php echo get_avatar(mb_get_user_id()); ?> <?php mb_user_link(); ?> <div class="mb-user-description"> <?php the_author_meta('description', mb_get_user_id()); ?> </div><!-- .mb-user-description --> </td> <td class="mb-col-role"><?php mb_role_link(mb_get_user_role()); ?> </td> <td class="mb-col-count"><a href="<?php mb_user_topics_url(); ?> "><?php mb_user_topic_count(); ?> </a></td> <td class="mb-col-count"><a href="<?php
_e('Username', 'message-board'); ?> </label> <input type="text" id="mb_user_login" name="mb_user_login" disabled="disabled" value="<?php echo esc_attr(get_the_author_meta('login', mb_get_user_id())); ?> " /> </p> <p> <label for="mb_email"><?php _e('Email', 'message-board'); ?> <span class="required">*</span></label> <input type="email" id="mb_email" name="mb_email" value="<?php echo esc_attr(get_the_author_meta('email', mb_get_user_id())); ?> " /> </p> <p> <label for="pass1"><?php _e('New Password', 'message-board'); ?> </label> <input type="password" id="pass1" name="pass1" value="" autocomplete="off" /> <span class="description"><?php _e('If you would like to change the password type a new one. Otherwise leave this blank.', 'message-board'); ?> </span> </p>