/** * settings_screen() is the catch-all method for displaying the content * of the edit, create, and Dashboard admin panels */ function settings_screen($group_id = NULL) { $categories = CMA_Category::getCategoriesTree(null, 0, $onlyVisible = false); $currentCategory = $this->getRelatedCategory(); $options = '<option value="">-- none --</option>'; foreach ($categories as $categoryId => $categoryName) { $options .= sprintf('<option value="%s"%s>%s</option>', esc_attr($categoryId), selected($categoryId, $currentCategory, false), esc_html($categoryName)); } printf('<p><label for="cma-category">%s</label> <select name="cma-category" id="cma-category">%s</select></p>', CMA::__('Related CM Answers category'), $options); }
protected static function replaceCommentSystem() { $currentPostId = null; $category = null; add_filter('comments_array', function ($comments, $postId) use(&$category) { $category = CMA_Category::getPostCommentsCategory($postId); if (is_main_query() and get_post_type() != CMA_Thread::POST_TYPE and !empty($category) and !empty($category->term_id)) { $posts = get_posts(array('category' => $category->term_id, 'post_type' => CMA_Thread::POST_TYPE)); return $posts; } else { return $comments; } }, 10, 2); add_filter('comments_template', function ($theme_template) use(&$category) { if (is_main_query() and get_post_type() != CMA_Thread::POST_TYPE and !empty($category) and !empty($category->term_id)) { return CMA_PATH . '/views/frontend/comment/comments.phtml'; } else { return $theme_template; } }); add_action('post_comment_status_meta_box-options', function ($post) { // Add select box with CMA categories $categories = CMA_Category::getCategoriesTree(null, 0, $onlyVisible = false); $currentCategory = CMA_Category::getPostCommentsCategory($post->ID); echo CMA_BaseController::_loadView('../backend/hooks/post_comment_status_meta_box', compact('categories', 'post', 'currentCategory')); }); add_action('save_post', function ($postId) { // Save CMA category ID for post/page if (isset($_POST['cma_category'])) { if (empty($_POST['cma_category'])) { wp_set_post_terms($postId, array(), CMA_Category::TAXONOMY); } else { if ($_POST['cma_category'] == 'new') { if (!empty($_POST['cma_category_name'])) { $category = (object) wp_insert_term($_POST['cma_category_name'], CMA_Category::TAXONOMY); clean_term_cache(array(), CMA_Category::TAXONOMY); } } else { $category = get_term($_POST['cma_category'], CMA_Category::TAXONOMY, OBJECT); } } if (!empty($category) and !empty($category->term_id)) { CMA_Category::setPostCommentsCategoryId($postId, $category->term_id); } } }, 10); add_action('save_page', function ($postId) { // Save CMA category ID for post/page if (isset($_POST['cma_category'])) { if (empty($_POST['cma_category'])) { wp_set_post_terms($postId, array(), CMA_Category::TAXONOMY); } else { if ($_POST['cma_category'] == 'new') { if (!empty($_POST['cma_category_name'])) { $category = (object) wp_insert_term($_POST['cma_category_name'], CMA_Category::TAXONOMY); clean_term_cache(array(), CMA_Category::TAXONOMY); } } else { $category = get_term($_POST['cma_category'], CMA_Category::TAXONOMY, ARRAY_A); } } if (!empty($category) and !empty($category->term_id)) { CMA_Category::setPostCommentsCategoryId($postId, $category->term_id); } } }, 10); }