function ap_get_breadcrumbs() { $current_page = get_query_var('ap_page'); $title = ap_page_title(); $a = array(); $a['base'] = array('title' => ap_opt('base_page_title'), 'link' => ap_base_page_link(), 'order' => 0); if (is_question_tag()) { $a['tag'] = array('title' => __('Tags', 'ap'), 'link' => '', 'order' => 10); } elseif (is_question()) { $a['page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => get_permalink(get_question_id()), 'order' => 10); } elseif ($current_page != 'base' && $current_page != '') { if ($current_page == 'user') { $a['page'] = array('title' => __('User', 'ap'), 'link' => ap_user_link(ap_get_displayed_user_id()), 'order' => 10); $a['user_page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => ap_user_link(ap_get_displayed_user_id(), get_query_var('user_page')), 'order' => 10); } else { $a['page'] = array('title' => substr($title, 0, 30) . (strlen($title) > 30 ? __('..', 'ap') : ''), 'link' => ap_get_link_to($current_page), 'order' => 10); } } $a = apply_filters('ap_breadcrumbs', $a); return ap_sort_array_by_order($a); }
/** * Handle Ajax callback for permanent delete of post. */ public function permanent_delete_post() { $post_id = (int) $_POST['post_id']; $action = 'delete_post_' . $post_id; if (!ap_verify_nonce($action) || !ap_user_can_permanent_delete()) { $this->something_wrong(); } $post = get_post($post_id); wp_trash_post($post_id); if ($post->post_type == 'question') { do_action('ap_wp_trash_question', $post_id); } else { do_action('ap_wp_trash_answer', $post_id); } wp_delete_post($post_id, true); if ($post->post_type == 'question') { $this->send(array('action' => 'delete_question', 'do' => array('redirect' => ap_base_page_link()), 'message' => 'question_deleted_permanently')); } else { $current_ans = ap_count_published_answers($post->post_parent); $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'anspress-question-answer'), $current_ans); $remove = !$current_ans ? true : false; $this->send(array('action' => 'delete_answer', 'div_id' => '#answer_' . $post_id, 'count' => $current_ans, 'count_label' => $count_label, 'remove' => $remove, 'message' => 'answer_deleted_permanently', 'view' => array('answer_count' => $current_ans, 'answer_count_label' => $count_label))); } }
/** * Return edit link for question and answer. * * @param int| object $post_id_or_object * * @return string * * @since 2.0.1 */ function ap_post_edit_link($post_id_or_object) { if (!is_object($post_id_or_object)) { $post_id_or_object = get_post($post_id_or_object); } $post = $post_id_or_object; $nonce = wp_create_nonce('nonce_edit_post_' . $post->ID); $edit_link = add_query_arg(array('ap_page' => 'edit', 'edit_post_id' => $post->ID, '__nonce' => $nonce), ap_base_page_link()); return apply_filters('ap_post_edit_link', $edit_link); }
/** * Alter question and answer CPT permalink * @param string $link * @param object $post * @return string * @since 2.0.0-alpha2 */ public function post_type_link($link, $post) { if ($post->post_type == 'question') { $question_slug = ap_opt('question_page_slug'); if (get_option('permalink_structure')) { if (ap_opt('question_permalink_follow')) { return rtrim(ap_base_page_link(), '/') . '/' . $question_slug . '/' . $post->post_name . '/'; } else { return home_url('/' . $question_slug . '/' . $post->post_name . '/'); } } else { return add_query_arg(array('apq' => false, 'question_id' => $post->ID), ap_base_page_link()); } } elseif ($post->post_type == 'answer' && $post->post_parent != 0) { return get_permalink($post->post_parent) . "?show_answer={$post->ID}#answer_{$post->ID}"; } return $link; }
/** * Alter question and answer CPT permalink * @param string $link * @param object $post * @return string * @since 2.0.0-alpha2 */ public function post_type_link($link, $post) { if ($post->post_type == 'question') { $question_slug = ap_opt('question_page_slug'); if (empty($question_slug)) { $question_slug = 'question'; } if (get_option('permalink_structure')) { if (ap_opt('question_permalink_follow')) { $link = rtrim(ap_base_page_link(), '/') . '/' . $question_slug . '/' . $post->post_name . '/'; } else { $link = home_url('/' . $question_slug . '/' . $post->post_name . '/'); } } else { $link = add_query_arg(array('apq' => false, 'question_id' => $post->ID), ap_base_page_link()); } /** * FILTER: ap_question_post_type_link * Allow overriding of question post type permalink */ return apply_filters('ap_question_post_type_link', $link, $post); } elseif ($post->post_type == 'answer' && $post->post_parent != 0) { $link = get_permalink($post->post_parent) . "?show_answer={$post->ID}#answer_{$post->ID}"; /** * FILTER: ap_answer_post_type_link * Allow overriding of answer post type permalink */ return apply_filters('ap_answer_post_type_link', $link, $post); } return $link; }
/** * Filter category permalink. * @param string $url Default taxonomy url. * @param object $term WordPress term object. * @param string $taxonomy Current taxonomy slug. * @return string */ public function term_link_filter($url, $term, $taxonomy) { if ('question_category' == $taxonomy) { if (get_option('permalink_structure') != '') { return ap_get_link_to(array('ap_page' => ap_get_category_slug(), 'q_cat' => $term->slug)); } else { return add_query_arg(array('ap_page' => ap_get_category_slug(), 'q_cat' => $term->term_id), ap_base_page_link()); } } return $url; }