From 3c7f2aebe4139a97eab3b51f91285464b970e196 Mon Sep 17 00:00:00 2001 From: Paul van Buuren Date: Thu, 20 May 2021 13:08:14 +0200 Subject: [PATCH] Remove hardcode table references https://github.com/InternetSocietyChapters/isoc2017-wp/issues/21 --- od/includes/hooks-setup.php | 2 +- od/includes/utils.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/od/includes/hooks-setup.php b/od/includes/hooks-setup.php index 0bb2406..4312635 100644 --- a/od/includes/hooks-setup.php +++ b/od/includes/hooks-setup.php @@ -66,7 +66,7 @@ function od_create_page( $sPageTitle, $iMenuOrder = NULL, $sPageContent = NULL ) // early exit - slug exists if( od_slug_exists($sPageSlug) ) { global $wpdb; - $oPost = $wpdb->get_row("SELECT post_name FROM od_posts WHERE post_name = '".$sPageSlug."'"); + $oPost = $wpdb->get_row( "SELECT post_name FROM $wpdb->posts WHERE post_name = '" . sanitize_title( $sPageSlug ) . "'" ); // we've got ourselves a page if( $oPost->post_type == 'page' ) { return $oPost->ID; } // not a page, better create one then diff --git a/od/includes/utils.php b/od/includes/utils.php index 7c343e1..ffae714 100644 --- a/od/includes/utils.php +++ b/od/includes/utils.php @@ -79,6 +79,9 @@ function od_get_id_by_slug( $object_slug ) { */ function od_slug_exists( $slug ) { global $wpdb; - if( $wpdb->get_row("SELECT post_name FROM od_posts WHERE post_name = '".$slug."'", 'ARRAY_A') ) { return TRUE; } - else { return FALSE; } + if ( $wpdb->get_row( "SELECT post_name FROM $wpdb->posts WHERE post_name = '" . sanitize_title( $slug ) . "'", 'ARRAY_A' ) ) { + return true; + } else { + return false; + } }