<commit_before><?php

/**
 * Papi url functions.
 *
 * @package Papi
 * @since 1.0.0
 */

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Get the url to 'post-new.php' with query string of the page type to load.
 *
 * @param string $page_type
 * @param bool $append_admin_url
 * @param string $post_type
 * @param array $exclude
 *
 * @since 1.0.0
 *
 * @return string
 */

function papi_get_page_new_url( $page_type, $append_admin_url = true, $post_type = null, $exclude = array() ) {
	$admin_url = $append_admin_url ? get_admin_url() : '';

	$admin_url = $admin_url . 'post-new.php?page_type=' . $page_type . papi_get_page_query_strings( '&', $exclude );

	if ( ! is_null( $post_type ) && in_array( 'post_type', $exclude ) ) {
		$admin_url = str_replace( '&&', '&', $admin_url . '&post_type=' . $post_type );
	}

	return papi_append_post_type_query( $admin_url, $post_type );
}

/**
 * Get page query strings.
 *
 * @param string $first_char
 * @param array $exclude
 *
 * @since 1.0.0
 *
 * @return string
 */

function papi_get_page_query_strings( $first_char = '&', $exclude = array() ) {
	$request_uri = $_SERVER['REQUEST_URI'];
	$parsed_url  = parse_url( $request_uri );

	if ( ! isset( $parsed_url['query'] ) || empty ( $parsed_url['query'] ) ) {
		return '';
	}

	$query = $parsed_url['query'];
	$query = preg_replace( '/page\=[a-z-,]+/', '', $query );
	$query = str_replace( '?', '', $query );
	$query = explode( '&', $query );

	$query = array_filter( $query, function ( $q ) use ( $exclude ) {
		$q = explode( '=', $q );

		if ( empty( $q ) || empty( $q[0] ) ) {
			return false;
		}

		return true;
	} );

	$query = implode( '&', $query );
	$query = $first_char . $query;

	if ( in_array( 'post_type', $exclude ) ) {
		return $query;
	}

	if ( $query === $first_char ) {
		$query = '';
	}

	return papi_append_post_type_query( $query );<commit_msg>Fixed query strings for only page type<commit_after><?php

/**
 * Papi url functions.
 *
 * @package Papi
 * @since 1.0.0
 */

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
 * Get the url to 'post-new.php' with query string of the page type to load.
 *
 * @param string $page_type
 * @param bool $append_admin_url
 * @param string $post_type
 * @param array $exclude
 *
 * @since 1.0.0
 *
 * @return string
 */

function papi_get_page_new_url( $page_type, $append_admin_url = true, $post_type = null, $exclude = array() ) {
	$admin_url = $append_admin_url ? get_admin_url() : '';

	$admin_url = $admin_url . 'post-new.php?page_type=' . $page_type . papi_get_page_query_strings( '&', $exclude );

	if ( ! is_null( $post_type ) && in_array( 'post_type', $exclude ) ) {
		$admin_url = str_replace( '&&', '&', $admin_url . '&post_type=' . $post_type );
	}

	return papi_append_post_type_query( $admin_url, $post_type );
}

/**
 * Get page query strings.
 *
 * @param string $first_char
 * @param array $exclude
 *
 * @since 1.0.0
 *
 * @return string
 */

function papi_get_page_query_strings( $first_char = '&', $exclude = array() ) {
	$request_uri = $_SERVER['REQUEST_URI'];
	$parsed_url  = parse_url( $request_uri );

	if ( ! isset( $parsed_url['query'] ) || empty ( $parsed_url['query'] ) ) {
		return '';
	}

	$query = $parsed_url['query'];
	$query = preg_replace( '/page\=[a-z-,]+/', '', $query );
	$query = str_replace( '?', '', $query );
	$query = explode( '&', $query );

	$query = array_filter( $query, function ( $q ) use ( $exclude ) {
		$q = explode( '=', $q );

		if ( empty( $q ) || empty( $q[0] ) ) {
			return false;
		}

		if ( empty( $exclude ) ) {
			return true;
		}

		return ! in_array( $q[0], $exclude );
	} );

	$query = implode( '&', $query );
	$query = $first_char . $query;

	if ( in_array( 'post_type', $exclude ) ) {
		return $query;
	}

	if ( $query === $first_char ) {
		$query = '';
	}

	return papi_append_post_type_query( $query );
{'fraction_non_alphanumeric': 0.1927461139896373, 'fraction_numerical': 0.005440414507772021, 'mean_word_length': 3.6462093862815883, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1326355', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1482, 'n_words': 329}