request ) ) );
}
if ( ! empty( $query_arg ) ) {
return add_query_arg( $queryArgs, home_url( $wp->request ) );
}
return home_url( $wp->request );
}
/**
* Method adqs_get_base_page_url
*
* @param string $url [explicite description]
*
* @return void
*/
function adqs_get_base_page_url( $url = '' ) {
// Parse the URL
$parsed_url = parse_url( $url );
// Get the path part of the URL
$path = $parsed_url['path'] ?? '';
// Remove the pagination part if it exists
$base_path = preg_replace( '#/page/[^/]+/?$#', '', $path );
// Rebuild the URL without the pagination part
$base_url = ( $parsed_url['scheme'] ?? '' ) . '://' . ( $parsed_url['host'] ?? '' ) . $base_path;
// Append the query string if it exists
if ( isset( $parsed_url['query'] ) ) {
$base_url .= '?' . $parsed_url['query'];
}
return trailingslashit( $base_url );
}
/**
* Method adqs_single_file_upload
*
* @param $file
*
* @return string
*/
function adqs_single_file_upload( $file ) {
$filename = sanitize_file_name( $file['name'] );
$filenameWithoutExtension = pathinfo( $filename, PATHINFO_FILENAME );
$trimfilename = ucwords( preg_replace( '/[-_]/', ' ', $filenameWithoutExtension ) );
$uniquename = wp_unique_filename( wp_upload_dir()['path'], $filename );
$uploads = move_uploaded_file( $file['tmp_name'], wp_upload_dir()['path'] . '/' . $uniquename );
if ( $uploads ) {
$file_url = wp_upload_dir()['url'] . '/' . $uniquename;
return $file_url;
}
return false;
}
/**
* Method adqs_get_setting_option
*
* @param $option_name
* @param $default
*
* @return string|boolean|array
*/
function adqs_get_setting_option( $option_name = null, $default = '' ) {
if ( empty( $option_name ) ) {
return $default;
}
$getSetting = Setting::get_single_setting( $option_name ) ?? false;
return ! empty( $getSetting ) ? $getSetting : $default;
}
/**
* Method adqs_get_setting_currency
*
* @param $type
*
* @return string
*/
function adqs_get_setting_currency( $type = 'code' ) {
$getCurrency = adqs_get_setting_option( 'select_currency' );
if ( empty( $getCurrency ) || strpos( $getCurrency, '__' ) === false ) {
return '';
}
list($c_code, $c_symbol, $c_postion) = explode( '__', $getCurrency );
if ( $type === 'symbol' ) {
$c_symbol = ! empty( $c_symbol ?? '' ) ? $c_symbol : '$';
return apply_filters( 'adqs_currency_symbol', $c_symbol ?? '' );
}
if ( $type === 'postion' ) {
return apply_filters( 'adqs_currency_postion', $c_postion ?? '' );
}
return apply_filters( 'adqs_currency_code', $c_code ?? '' );
}
/**
* Method adqs_get_price_ws
*
* @param $price
*
* @return string
*/
function adqs_get_price_ws( $price = '' ) {
if ( empty( $price ) ) {
return '';
}
if ( ! empty( $price ) ) {
$price = number_format( floatval( $price ), 2 );
}
$symbol = adqs_get_setting_currency( 'symbol' );
if ( adqs_get_setting_currency( 'postion' ) == 'after' ) {
return "{$price}{$symbol}";
}
return "{$symbol}{$price}";
}
/**
* Method get_default_preview_image
*
* @param $list_id
* @param $size
*
* @return string
*/
function get_default_preview_image( $list_id = 0, $size = 'post-thumbnail' ) {
$preview_image = get_the_post_thumbnail_url( $list_id, $size );
if ( ! empty( $preview_image ) ) {
return $preview_image;
}
return AD()->Helper->get_setting( 'default_preview_image' );
}
/**
* Method adqs_get_permalink_by_key
*
* @param $pagekey $pagekey [explicite description]
*
* @return string
*/
function adqs_get_permalink_by_key( $pagekey ) {
$pages = get_option( 'adqs_onboarding_pages', [] );
$permalink = get_permalink( $pages[ $pagekey ] ?? '' );
return $permalink ?? '#';
}
/**
* Method adqs_remove_http_protocol_from_url
*
* @param $url
*
* @return string
*/
function adqs_remove_http_protocol_from_url( $url = '' ) {
$url = trim( (string) $url );
if ( empty( $url ) ) {
return '';
}
return untrailingslashit(
preg_replace( '#^https?://#i', '', $url )
);
}
/**
* Method g rchacha
*
* @return void
*/
function add_grecaptcha_input_field() {
?>
0 ) {
return false;
}
if ( in_array( 'ad-pricing-package/ad-pricing-package.php', $plugins ) || in_array( 'ad-wc-pricing-package/ad-wc-pricing-package.php', $plugins ) ) {
return true;
}
return false;
}
// convert slug terms id
if ( ! function_exists( 'adqs_covertTerm_slug_to_id' ) ) {
function adqs_covertTerm_slug_to_id( $terms = '', $taxonomy = 'adqs_tags' ) {
if ( empty( $terms ) ) {
return $terms;
}
$terms_array = explode( ',', $terms );
$are_terms_numeric = array_reduce(
$terms_array,
function ( $carry, $tag ) {
return $carry && ctype_digit( trim( $tag ) );
},
true
);
if ( ! $are_terms_numeric ) {
$converted_terms = [];
foreach ( $terms_array as $t ) {
$t = trim( $t );
$term = get_term_by( 'slug', $t, $taxonomy );
if ( $term && ! is_wp_error( $term ) ) {
$converted_terms[] = $term->term_id;
}
}
$terms = implode( ',', array_filter( $converted_terms ) );
}
return $terms;
}
}
// render tax lists
function adqs_render_tax_lists( $args = [], $options = [] ) {
$has_input = $options['has_input'] ?? false;
$has_name = $options['has_name'] ?? true;
$has_directory = $options['has_directory'] ?? false;
$directory_id = isset( $options['directory_id'] ) ? absint( $options['directory_id'] ) : 0;
$has_children = $options['has_children'] ?? true;
$saved_data = $options['saved_data'] ?? [];
$display_count = $options['display_count'] ?? true;
$default_args = [
'taxonomy' => '',
'hide_empty' => false,
'hierarchical' => true,
'parent' => 0,
];
$args = array_merge( $default_args, $args );
// Check if taxonomy exists before trying to get terms
$taxonomy = $args['taxonomy'] ?? '';
if ( empty( $taxonomy ) ) {
// Get the category taxonomy for the current post type
$current_post_type = get_post_type();
$taxonomy = adqs_get_taxonomy_for_post_type( $current_post_type, 'categories' );
if ( empty( $taxonomy ) ) {
return ''; // Fallback
}
}
// Check if the taxonomy exists, if not return empty
if ( ! taxonomy_exists( $taxonomy ) ) {
return '';
}
$terms = get_terms( $args );
if ( $terms && ! is_wp_error( $terms ) ) {
// Filter terms by post types if filter_by_post_types is provided
if ( ! empty( $options['filter_by_post_types'] ) && is_array( $options['filter_by_post_types'] ) ) {
// Query posts to find which terms are actually used
$posts_query = new WP_Query(
[
'post_type' => $options['filter_by_post_types'],
'posts_per_page' => -1,
'fields' => 'ids',
'post_status' => 'publish',
]
);
if ( $posts_query->have_posts() ) {
// Get term IDs used by these posts
$used_term_ids = [];
foreach ( $posts_query->posts as $post_id ) {
$post_terms = wp_get_post_terms( $post_id, $taxonomy, [ 'fields' => 'ids' ] );
if ( ! is_wp_error( $post_terms ) && ! empty( $post_terms ) ) {
$used_term_ids = array_merge( $used_term_ids, $post_terms );
}
}
$used_term_ids = array_unique( $used_term_ids );
// Filter terms to only those used by the posts
$terms = array_filter(
$terms,
function ( $term ) use ( $used_term_ids ) {
return in_array( $term->term_id, $used_term_ids, true );
}
);
} else {
// No posts found, return empty terms
$terms = [];
}
wp_reset_postdata();
}
// Filter terms by directory if has_directory is enabled
if ( $has_directory && ! empty( $directory_id ) ) {
$terms = array_filter(
$terms,
function ( $term ) use ( $directory_id ) {
$term_directories = adqs_get_term_directories( $term->term_id );
// If term has no directory assignments, show it (backward compatibility)
if ( empty( $term_directories ) ) {
return true;
}
// Otherwise, only show if it's assigned to the current directory
return in_array( $directory_id, $term_directories, true );
}
);
}
foreach ( $terms as $term ) {
// Ensure $term is a valid WP_Term object
if ( ! is_object( $term ) || ! isset( $term->term_id ) || ! isset( $term->name ) ) {
continue;
}
$value_type = ( ( $options['value_type'] ?? '' ) == 'slug' ) ? $term->slug : $term->term_id;
$checked = in_array( $value_type, $saved_data ) ? 'checked' : '';
$child_terms = get_term_children( $term->term_id, $taxonomy );
?>
name ); ?>
(count ) ? esc_html( $term->count ) : '0'; ?>)
$taxonomy,
'hide_empty' => $args['hide_empty'] ?? false,
'parent' => $term->term_id,
],
$options
);
?>
$post_id,
'parent' => 0, // Only parent comments (no replies)
'status' => 'approve',
'count' => true,
]
);
return $parent_reviews;
}
/**
* Get svg icon.
*
* @since 3.1.0
*
* @param string $icon
*/
function adqs_get_icon_template( $icon = '' ) {
if ( empty( $icon ) ) {
return;
}
adqs_get_template_part( "icons/{$icon}" );
}
/**
* Method add_preset_fields_lists
*
* @return array
*/
function add_preset_fields_lists() {
$presetField_list = apply_filters( 'add_preset_fields_lists', [ 'address', 'businesshour', 'fax', 'map', 'phone', 'pricing', 'tagline', 'video', 'view_count', 'website', 'zip', 'badges' ] );
return array_unique( $presetField_list );
}