AnsPress_PostTypes::post_type_link( string $link, object $post, bool $leavename, bool $sample )
Description #
Alter question and answer CPT permalink.
Parameters #
- $linkstring (Required) Link.
- $postobject (Required) Post object.
- $leavenamebool (Required) Whether to keep the post name.
- $samplebool (Required) Is it a sample permalink.
Source #
File: includes/post-types.php
public static function post_type_link( $link, $post, $leavename, $sample ) { if ( 'question' === $post->post_type ) { $question_slug = ap_opt( 'question_page_permalink' ); if ( empty( $question_slug ) ) { $question_slug = 'question_perma_1'; } $default_lang = ''; // Support polylang permalink. if ( function_exists( 'pll_default_language' ) ) { $default_lang = pll_get_post_language( $post->ID ) ? pll_get_post_language( $post->ID ) : pll_default_language(); } if ( get_option( 'permalink_structure' ) ) { $structure = self::question_perm_structure(); $rule = str_replace( '%question_id%', $post->ID, $structure->rule ); $rule = str_replace( '%question%', ( $leavename ? '%question%' : $post->post_name ), $rule ); $link = home_url( $default_lang . '/' . $rule . '/' ); } else { $link = add_query_arg( array( 'question' => $post->ID ), ap_base_page_link() ); } /** * Allow overriding of question post type permalink * * @param string $link Question link. * @param object $post Post object. */ $link = apply_filters_deprecated( 'ap_question_post_type_link', array( $link, $post ), '4.4.0', 'ap_question_post_type_link_structure' ); /** * Allow overriding of question post type permalink * * @param string $link Question link. * @param object $post Post object. * @param bool $leavename Whether to keep the post name. * @param bool $sample Is it a sample permalink. */ $link = apply_filters( 'ap_question_post_type_link_structure', $link, $post, $leavename, $sample ); return $link; } elseif ( 'answer' === $post->post_type && 0 !== (int) $post->post_parent ) { $link = get_permalink( $post->post_parent ) . "answer/{$post->ID}/"; /** * Allow overriding of answer post type permalink. * * @param string $link Answer link. * @param object $post Post object. */ $link = apply_filters_deprecated( 'ap_answer_post_type_link', array( $link, $post ), '4.4.0', 'ap_answer_post_type_link_structure' ); /** * Allow overriding of answer post type permalink * * @param string $link Answer link. * @param object $post Post object. * @param bool $leavename Whether to keep the post name. * @param bool $sample Is it a sample permalink. */ $link = apply_filters( 'ap_answer_post_type_link_structure', $link, $post, $leavename, $sample ); return $link; } return $link; }
Expand full source code Collapse full source code View on GitHub: includes/post-types.php:231
Add your comment