Skip to content

Commit

Permalink
geodir_template_page_options() function updated to use custom query f…
Browse files Browse the repository at this point in the history
…or better memory usage - CHANGED
  • Loading branch information
Stiofan committed Sep 12, 2024
1 parent 127d579 commit 4fcde76
Show file tree
Hide file tree
Showing 10 changed files with 505 additions and 465 deletions.
864 changes: 432 additions & 432 deletions geodirectory.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/admin/class-geodir-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?

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

$pages = get_pages( $parsed_args );
$page_options = array();

if ( ! empty( $pages ) ) {
Expand All @@ -836,6 +835,7 @@ class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?
$page_options[ $id ] = $title;
}
}
$page_options = geodir_template_page_options();

if ( isset( $parsed_args['show_option_none'] ) ) {
$parsed_args['show_option_none'] = trim( $parsed_args['show_option_none'] );
Expand Down
40 changes: 31 additions & 9 deletions includes/template-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1225,30 +1225,52 @@ function geodir_template_type_options() {
* @return array Template page options.
*/
function geodir_template_page_options() {
global $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();
}

global $geodir_tmpl_page_options, $wpdb;

if ( ! empty( $geodir_tmpl_page_options ) ) {
return $geodir_tmpl_page_options;
}

$args = array(
'child_of' => 0,
'sort_column' => 'post_title',
'sort_order' => 'ASC'
);

$exclude_pages = array();
if ( $page_on_front = get_option( 'page_on_front' ) ) {
$exclude_pages[] = $page_on_front;
}

if ( $page_for_posts = get_option( 'page_for_posts' ) ) {
$exclude_pages[] = $page_for_posts;
}

$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'));
}

// 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
";

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

$pages = get_pages( $args );
// 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 ) );

$options = array( '' => __( 'Select Page...', 'geodirectory' ) );
if ( ! empty( $pages ) ) {
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s

= GeoDirectory v2.3.78 - TBD =
* GD > Post Content read more link don't scrolls to tab content when tab is not placed at first - FIXED
* geodir_template_page_options() function updated to use custom query for better memory usage - CHANGED

= GeoDirectory v2.3.77 - 2024-09-06 =
* Theme customize AyeCode UI colors settings not working after update - FIXED
Expand Down
3 changes: 3 additions & 0 deletions vendor/ayecode/wp-super-duper/change-log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
= 1.2.9 - 2024-09-12 =
* Template get_pages call changed to custom query for better memory management - CHANGED

= 1.2.7 - 2024-08-29 =
* Fix conflicts with UpSolution Core plugin - FIXED

Expand Down
32 changes: 23 additions & 9 deletions vendor/ayecode/wp-super-duper/sd-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3165,18 +3165,12 @@ function sd_visibility_output_options() {
* @return array Template page options.
*/
function sd_template_page_options( $args = array() ) {
global $sd_tmpl_page_options;
global $sd_tmpl_page_options,$wpdb;

if ( ! empty( $sd_tmpl_page_options ) ) {
return $sd_tmpl_page_options;
}

$args = wp_parse_args( $args, array(
'child_of' => 0,
'sort_column' => 'post_title',
'sort_order' => 'ASC'
) );

$exclude_pages = array();
if ( $page_on_front = get_option( 'page_on_front' ) ) {
$exclude_pages[] = $page_on_front;
Expand All @@ -3186,11 +3180,31 @@ function sd_template_page_options( $args = array() ) {
$exclude_pages[] = $page_for_posts;
}

$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'));
}

// 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
";

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

$pages = get_pages( $args );
// 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 ) );

$options = array( '' => __( 'Select Page...', 'ayecode-connect' ) );
if ( ! empty( $pages ) ) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/ayecode/wp-super-duper/sd-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @wordpress-plugin
* Plugin Name: Super Duper - Examples
* Description: This is a Hello World test plugin for WP Super Duper Class.
* Version: 1.2.7
* Version: 1.2.9
* Author: AyeCode
* Author URI: https://ayecode.io
* Text Domain: super-duper
Expand Down
2 changes: 1 addition & 1 deletion vendor/ayecode/wp-super-duper/wp-super-duper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

if ( ! class_exists( 'WP_Super_Duper' ) ) {

define( 'SUPER_DUPER_VER', '1.2.7' );
define( 'SUPER_DUPER_VER', '1.2.9' );

/**
* A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
Expand Down
14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,24 +246,24 @@
},
{
"name": "ayecode/wp-super-duper",
"version": "1.2.7",
"version_normalized": "1.2.7.0",
"version": "1.2.9",
"version_normalized": "1.2.9.0",
"source": {
"type": "git",
"url": "https://github.com/AyeCode/wp-super-duper.git",
"reference": "077bbe648ab7b3a9cc77068d2e0c326dfe1a6849"
"reference": "0b832085e97956a9f783ca018a5d04f27566b4a2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/AyeCode/wp-super-duper/zipball/077bbe648ab7b3a9cc77068d2e0c326dfe1a6849",
"reference": "077bbe648ab7b3a9cc77068d2e0c326dfe1a6849",
"url": "https://api.github.com/repos/AyeCode/wp-super-duper/zipball/0b832085e97956a9f783ca018a5d04f27566b4a2",
"reference": "0b832085e97956a9f783ca018a5d04f27566b4a2",
"shasum": ""
},
"require": {
"composer/installers": "~1.0",
"php": ">=5.4.0"
},
"time": "2024-08-29T16:44:21+00:00",
"time": "2024-09-12T14:50:31+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down Expand Up @@ -295,7 +295,7 @@
],
"support": {
"issues": "https://github.com/AyeCode/wp-super-duper/issues",
"source": "https://github.com/AyeCode/wp-super-duper/tree/1.2.7"
"source": "https://github.com/AyeCode/wp-super-duper/tree/1.2.9"
},
"install-path": "../ayecode/wp-super-duper"
},
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'ayecode/geodirectory',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'd5266abf17ab19e599928af50ea6b22edaf67bfd',
'reference' => '127d579bcf7f3621270a57031687df175a905578',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -22,7 +22,7 @@
'ayecode/geodirectory' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'd5266abf17ab19e599928af50ea6b22edaf67bfd',
'reference' => '127d579bcf7f3621270a57031687df175a905578',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down Expand Up @@ -65,9 +65,9 @@
'dev_requirement' => false,
),
'ayecode/wp-super-duper' => array(
'pretty_version' => '1.2.7',
'version' => '1.2.7.0',
'reference' => '077bbe648ab7b3a9cc77068d2e0c326dfe1a6849',
'pretty_version' => '1.2.9',
'version' => '1.2.9.0',
'reference' => '0b832085e97956a9f783ca018a5d04f27566b4a2',
'type' => 'library',
'install_path' => __DIR__ . '/../ayecode/wp-super-duper',
'aliases' => array(),
Expand Down

0 comments on commit 4fcde76

Please sign in to comment.