From 3f70ce4532e8c798901467544262b09318c9c4b0 Mon Sep 17 00:00:00 2001 From: stiofan Date: Thu, 12 Sep 2024 15:46:15 +0100 Subject: [PATCH] 1.2.8 --- change-log.txt | 3 +++ sd-functions.php | 32 +++++++++++++++++++++++--------- sd-plugin.php | 2 +- wp-super-duper.php | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/change-log.txt b/change-log.txt index 296b068..1daa64a 100644 --- a/change-log.txt +++ b/change-log.txt @@ -1,3 +1,6 @@ += 1.2.8 - 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 diff --git a/sd-functions.php b/sd-functions.php index 40d48b7..c43bb10 100644 --- a/sd-functions.php +++ b/sd-functions.php @@ -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; @@ -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 ) ) { diff --git a/sd-plugin.php b/sd-plugin.php index 7e49ea5..3989191 100644 --- a/sd-plugin.php +++ b/sd-plugin.php @@ -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.8 * Author: AyeCode * Author URI: https://ayecode.io * Text Domain: super-duper diff --git a/wp-super-duper.php b/wp-super-duper.php index 1cb25c8..34d9171 100644 --- a/wp-super-duper.php +++ b/wp-super-duper.php @@ -5,7 +5,7 @@ if ( ! class_exists( 'WP_Super_Duper' ) ) { - define( 'SUPER_DUPER_VER', '1.2.7' ); + define( 'SUPER_DUPER_VER', '1.2.8' ); /** * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.