/** * Custom row actions below the post title. * * @since 1.0.0 * @access public * @param array $actions * @param object $post * @return array */ function row_actions($actions, $post) { $topic_id = mb_get_topic_id($post->ID); /* Remove quick edit. */ if (isset($actions['inline hide-if-no-js'])) { unset($actions['inline hide-if-no-js']); } /* Add delete link for spam and orphan replies. */ if ((mb_is_topic_spam($topic_id) || mb_is_topic_orphan($topic_id)) && current_user_can('delete_post', $topic_id) && EMPTY_TRASH_DAYS) { $actions['delete'] = sprintf('<a class="submitdelete" href="%s">%s</a>', get_delete_post_link($topic_id, '', true), __('Delete Permanently', 'message-board')); } /* Add spam toggle link if user has permission. */ if (current_user_can('spam_topic', $topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $spam_object = get_post_status_object(mb_get_spam_post_status()); /* Get spam link text. */ $spam_text = mb_is_topic_spam($topic_id) ? __('Not Spam', 'message-board') : $spam_object->mb_label_verb; /* Build spam toggle URL. */ $spam_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $spam_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'spam'), $spam_url); $spam_url = wp_nonce_url($spam_url, "spam_topic_{$topic_id}"); /* Add toggle spam action link. */ $actions['mb_toggle_spam'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($spam_url), mb_is_topic_spam() ? 'restore' : 'spam', $spam_text); } /* Add open/close toggle link if user has permission and topic is not spam. */ if (current_user_can('open_topic', $topic_id) && !mb_is_topic_open($topic_id) && !mb_is_topic_spam($topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $open_object = get_post_status_object(mb_get_open_post_status()); /* Build open/close toggle URL. */ $open_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $open_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'open'), $open_url); $open_url = wp_nonce_url($open_url, "open_topic_{$topic_id}"); /* Add toggle open/close action link. */ $actions['mb_toggle_open'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($open_url), 'open', $open_object->mb_label_verb); } /* Add open/close toggle link if user has permission and topic is not spam. */ if (current_user_can('close_topic', $topic_id) && !mb_is_topic_closed($topic_id) && !mb_is_topic_spam($topic_id) && !mb_is_topic_orphan($topic_id)) { /* Get post status objects. */ $close_object = get_post_status_object(mb_get_close_post_status()); /* Build open/close toggle URL. */ $close_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); $close_url = add_query_arg(array('topic_id' => $topic_id, 'mb_toggle_status' => 'close'), $close_url); $close_url = wp_nonce_url($close_url, "close_topic_{$topic_id}"); /* Add toggle open/close action link. */ $actions['mb_toggle_close'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($close_url), 'close', $close_object->mb_label_verb); } /* Don't allow stickies for these topic statuses. */ $icky_sticky = array(mb_get_orphan_post_status(), mb_get_spam_post_status(), mb_get_trash_post_status()); $topic_status = mb_get_topic_status($topic_id); /* Add super toggle link if user has permission and topic has a public status. */ if (current_user_can('super_topic', $topic_id) && !in_array($topic_status, $icky_sticky)) { $current_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); /* Build sticky text. */ $super_text = mb_is_topic_super($topic_id) ? __('Unsuper', 'message-board') : __('Super', 'message-board'); /* Build super toggle URL. */ $super_url = add_query_arg(array('topic_id' => $topic_id, 'action' => 'mb_toggle_super'), $current_url); $super_url = wp_nonce_url($super_url, "super_topic_{$topic_id}"); $actions['mb_toggle_super'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($super_url), 'super', $super_text); } /* Add sticky toggle link if user has permission and topic has a public status. */ if (current_user_can('stick_topic', $topic_id) && !in_array($topic_status, $icky_sticky)) { $current_url = remove_query_arg(array('topic_id', 'mb_topic_notice')); /* Build sticky text. */ $sticky_text = mb_is_topic_sticky($topic_id) ? __('Unstick', 'message-board') : __('Stick', 'message-board'); /* Build sticky toggle URL. */ $sticky_url = add_query_arg(array('topic_id' => $topic_id, 'action' => 'mb_toggle_sticky'), $current_url); $sticky_url = wp_nonce_url($sticky_url, "sticky_topic_{$topic_id}"); $actions['mb_toggle_sticky'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($sticky_url), 'sticky', $sticky_text); } /* Move view action to the end. */ if (isset($actions['view'])) { $view_action = $actions['view']; unset($actions['view']); if (mb_get_spam_post_status() !== get_query_var('post_status')) { $actions['view'] = $view_action; } } return $actions; }
/** * 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); } }
/** * Conditional check to see whether a reply has the "orphan" post status. * * @since 1.0.0 * @access public * @return bool */ function mb_is_reply_orphan($reply_id = 0) { $reply_id = mb_get_reply_id($reply_id); $status = mb_get_reply_status($reply_id); return apply_filters('mb_is_reply_orphan', mb_get_orphan_post_status() === $status ? true : false, $reply_id); }