Skip to content

Commit

Permalink
Merge pull request #2702 from kprajapatii/master
Browse files Browse the repository at this point in the history
2.3.82
  • Loading branch information
kprajapatii authored Oct 10, 2024
2 parents b9015fe + c4f9e0b commit f475a08
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 108 deletions.
4 changes: 2 additions & 2 deletions geodirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: GeoDirectory
* Plugin URI: https://wpgeodirectory.com/
* Description: GeoDirectory - Business Directory Plugin for WordPress.
* Version: 2.3.81
* Version: 2.3.82
* Author: AyeCode - WP Business Directory Plugins
* Author URI: https://wpgeodirectory.com
* Text Domain: geodirectory
Expand All @@ -34,7 +34,7 @@ final class GeoDirectory {
*
* @var string
*/
public $version = '2.3.81';
public $version = '2.3.82';

/**
* GeoDirectory instance.
Expand Down
61 changes: 37 additions & 24 deletions includes/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,16 +1224,23 @@ function geodir_template_type_options() {
*
* @return array Template page options.
*/
function geodir_template_page_options() {
function geodir_template_page_options( $args = array() ) {
global $wpdb, $geodir_tmpl_page_options;

// Same function, lets not call it twice if we don't need to
if(function_exists('sd_template_page_options')){
return sd_template_page_options();
// Same function, lets not call it twice if we don't need to.
if ( function_exists( 'sd_template_page_options' ) ) {
return sd_template_page_options( $args );
}

global $geodir_tmpl_page_options, $wpdb;
$defaults = array(
'nocache' => false,
'with_slug' => false,
'default_label' => __( 'Select Page...', 'geodirectory' )
);

$args = wp_parse_args( $args, $defaults );

if ( ! empty( $geodir_tmpl_page_options ) ) {
if ( ! empty( $geodir_tmpl_page_options ) && empty( $args['nocache'] ) ) {
return $geodir_tmpl_page_options;
}

Expand All @@ -1248,36 +1255,42 @@ function geodir_template_page_options() {

$exclude_pages_placeholders = '';
if ( ! empty( $exclude_pages ) ) {
// Sanitize the array of excluded pages and implode it for the SQL query
$exclude_pages_placeholders = implode(',', array_fill(0, count($exclude_pages), '%d'));
// Sanitize the array of excluded pages and implode it for the SQL query.
$exclude_pages_placeholders = implode( ',', array_fill( 0, count( $exclude_pages ), '%d' ) );
}

// Prepare the base SQL query, including child_of = 0 (only root-level pages)
$sql = "
SELECT ID, post_title
FROM $wpdb->posts
WHERE post_type = 'page'
AND post_status = 'publish'
AND post_parent = 0
";
// Prepare the base SQL query.
$sql = "SELECT ID, post_title, post_name FROM " . $wpdb->posts . " WHERE post_type = 'page' AND post_status = 'publish'";

// Add the exclusion if there are pages to exclude
// Add the exclusion if there are pages to exclude.
if ( ! empty( $exclude_pages ) ) {
$sql .= " AND ID NOT IN ($exclude_pages_placeholders)";
}

// Add sorting
// Add sorting.
$sql .= " ORDER BY post_title ASC";

// Prepare the SQL query to include the excluded pages
$pages = $wpdb->get_results( $wpdb->prepare( $sql, ...$exclude_pages ) );
// Add a limit.
$limit = (int) apply_filters( 'geodir_template_page_options_limit', 500, $args );

if ( $limit > 0 ) {
$sql .= " LIMIT " . (int) $limit;
}

// Prepare the SQL query to include the excluded pages only if we have placeholders.
$pages = $exclude_pages_placeholders ? $wpdb->get_results( $wpdb->prepare( $sql, ...$exclude_pages ) ) : $wpdb->get_results( $sql );

if ( ! empty( $args['default_label'] ) ) {
$options = array( '' => $args['default_label'] );
} else {
$options = array();
}

$options = array( '' => __( 'Select Page...', 'geodirectory' ) );
if ( ! empty( $pages ) ) {
foreach ( $pages as $page ) {
if ( ! empty( $page->ID ) && ! empty( $page->post_title ) ) {
$options[ $page->ID ] = $page->post_title . ' (#' . $page->ID . ')';
}
$title = ! empty( $args['with_slug'] ) ? $page->post_title . ' (' . $page->post_name . ')' : ( $page->post_title . ' (#' . $page->ID . ')' );

$options[ $page->ID ] = $title;
}
}

Expand Down
Binary file modified languages/geodirectory-en_US.mo
Binary file not shown.
Loading

0 comments on commit f475a08

Please sign in to comment.