From ad9a61ad07983643e606eb82c625b07a0eea729a Mon Sep 17 00:00:00 2001 From: ve3 Date: Wed, 11 Dec 2024 13:43:32 +0700 Subject: [PATCH] Use post type value from constant. --- App/Controllers/Admin/Posts/HookNewPost.php | 2 +- App/Controllers/Admin/Posts/ReOrderPostsAjax.php | 8 ++++---- App/Controllers/Front/AlterPosts.php | 8 ++++---- App/Models/PostOrder.php | 12 +++++++++--- App/Models/PostsListTable.php | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/App/Controllers/Admin/Posts/HookNewPost.php b/App/Controllers/Admin/Posts/HookNewPost.php index 4c6e637..eb25714 100644 --- a/App/Controllers/Admin/Posts/HookNewPost.php +++ b/App/Controllers/Admin/Posts/HookNewPost.php @@ -26,7 +26,7 @@ public function hookInsertPostAction($post_id, $post, $update) && is_object($post) && isset($post->post_status) && in_array($post->post_status, $this->allowed_order_post_status) && isset($post->menu_order) && $post->menu_order == '0' - && isset($post->post_type) && $post->post_type == 'post' + && isset($post->post_type) && $post->post_type == \RdPostOrder\App\Models\PostOrder::POST_TYPE ) { // if this save is first time, whatever it status is. $PostOrder = new \RdPostOrder\App\Models\PostOrder(); diff --git a/App/Controllers/Admin/Posts/ReOrderPostsAjax.php b/App/Controllers/Admin/Posts/ReOrderPostsAjax.php index b6d657a..2f4fd2a 100644 --- a/App/Controllers/Admin/Posts/ReOrderPostsAjax.php +++ b/App/Controllers/Admin/Posts/ReOrderPostsAjax.php @@ -41,7 +41,7 @@ public function ajaxReNumberAll() // get all posts order by current menu_order (even it contain wrong order number but keep most of current order). $sql = 'SELECT `ID`, `post_status`, `menu_order`, `post_type` FROM `' . $wpdb->posts . '`' - . ' WHERE `post_type` = \'post\'' + . ' WHERE `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `menu_order` DESC'; $result = $wpdb->get_results($sql, OBJECT_K); @@ -148,7 +148,7 @@ public function ajaxReOrderPost() if ($move_to === 'up') { $sql = 'SELECT `ID`, `menu_order`, `post_type`, `post_status` FROM `' . $wpdb->posts . '`' . ' WHERE `menu_order` > \'%d\'' - . ' AND `post_type` = \'post\'' + . ' AND `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `menu_order` ASC'; $sql = $wpdb->prepare($sql, $menu_order); @@ -157,7 +157,7 @@ public function ajaxReOrderPost() } elseif ($move_to === 'down') { $sql = 'SELECT `ID`, `menu_order`, `post_type`, `post_status` FROM `' . $wpdb->posts . '`' . ' WHERE `menu_order` < \'%d\'' - . ' AND `post_type` = \'post\'' + . ' AND `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `menu_order` DESC'; $sql = $wpdb->prepare($sql, $menu_order); @@ -357,7 +357,7 @@ public function ajaxResetAllPostsOrder() // get all posts order by current menu_order (even it contain wrong order number but keep most of current order). $sql = 'SELECT `ID`, `post_date`, `post_status`, `menu_order`, `post_type` FROM `' . $wpdb->posts . '`' - . ' WHERE `post_type` = \'post\'' + . ' WHERE `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `post_date` DESC'; $result = $wpdb->get_results($sql, OBJECT_K); diff --git a/App/Controllers/Front/AlterPosts.php b/App/Controllers/Front/AlterPosts.php index d0ea265..cae0fcb 100644 --- a/App/Controllers/Front/AlterPosts.php +++ b/App/Controllers/Front/AlterPosts.php @@ -64,7 +64,7 @@ public function alterNextPostSort($order_by, $post) $is_disable_customorder = $this->isDisableCustomOrder(); if (isset($is_disable_customorder) && $is_disable_customorder !== true) { - if (isset($post->post_type) && $post->post_type == 'post') { + if (isset($post->post_type) && $post->post_type == \RdPostOrder\App\Models\PostOrder::POST_TYPE) { $orderby = 'ORDER BY p.menu_order ASC LIMIT 1'; } } @@ -91,7 +91,7 @@ public function alterNextPostWhere($where, $in_same_term, $excluded_terms, $taxo $is_disable_customorder = $this->isDisableCustomOrder(); if (isset($is_disable_customorder) && $is_disable_customorder !== true) { - if (isset($post->post_type) && $post->post_type == 'post') { + if (isset($post->post_type) && $post->post_type == \RdPostOrder\App\Models\PostOrder::POST_TYPE) { $where = str_replace('p.post_date > \''.$post->post_date.'\'', 'p.menu_order > \''.$post->menu_order.'\'', $where); } } @@ -115,7 +115,7 @@ public function alterPreviousPostSort($order_by, $post) $is_disable_customorder = $this->isDisableCustomOrder(); if (isset($is_disable_customorder) && $is_disable_customorder !== true) { - if (isset($post->post_type) && $post->post_type == 'post') { + if (isset($post->post_type) && $post->post_type == \RdPostOrder\App\Models\PostOrder::POST_TYPE) { $orderby = 'ORDER BY p.menu_order DESC LIMIT 1'; } } @@ -142,7 +142,7 @@ public function alterPreviousPostWhere($where, $in_same_term, $excluded_terms, $ $is_disable_customorder = $this->isDisableCustomOrder(); if (isset($is_disable_customorder) && $is_disable_customorder !== true) { - if (isset($post->post_type) && $post->post_type == 'post') { + if (isset($post->post_type) && $post->post_type == \RdPostOrder\App\Models\PostOrder::POST_TYPE) { $where = str_replace('p.post_date < \''.$post->post_date.'\'', 'p.menu_order < \''.$post->menu_order.'\'', $where); } } diff --git a/App/Models/PostOrder.php b/App/Models/PostOrder.php index ac250c4..5c3c1f9 100644 --- a/App/Models/PostOrder.php +++ b/App/Models/PostOrder.php @@ -15,6 +15,12 @@ class PostOrder use \RdPostOrder\App\AppTrait; + /** + * @var string Working on post type. + */ + const POST_TYPE = 'post'; + + /** * Get latest menu order number. * @@ -27,7 +33,7 @@ public function getLatestMenuOrder() // get new menu_order number (new post is latest menu_order+1). $sql = 'SELECT `post_status`, `menu_order`, `post_type` FROM `' . $wpdb->posts . '`' - . ' WHERE `post_type` = \'post\'' + . ' WHERE `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `menu_order` DESC LIMIT 0, 1'; $LastPost = $wpdb->get_row($sql); @@ -60,7 +66,7 @@ public function setMenuOrderToZero() '`post_status`, ' . '`post_type`' . ' FROM `' . $wpdb->posts . '`' . - ' WHERE `' . $wpdb->posts . '`.`post_type` = \'post\'' . + ' WHERE `' . $wpdb->posts . '`.`post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `' . $wpdb->posts . '`.`post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' ORDER BY `' . $wpdb->posts . '`.`post_date` ASC', OBJECT @@ -149,7 +155,7 @@ protected function updateScheduledPostsOrderToLatest() // get scheduled posts by order ascending (for increase from latest order +1 each). $sql = 'SELECT `ID`, `post_date`, `post_date_gmt`, `post_status`, `menu_order`, `post_type` FROM `' . $wpdb->posts . '`' - . ' WHERE `post_type` = \'post\'' + . ' WHERE `post_type` = \'' . \RdPostOrder\App\Models\PostOrder::POST_TYPE . '\'' . ' AND `post_status` IN(\'' . implode('\', \'', $this->allowed_order_post_status) . '\')' . ' AND (`post_date` > \'%s\' OR `post_date_gmt` > \'%s\')' . ' ORDER BY `menu_order` ASC'; diff --git a/App/Models/PostsListTable.php b/App/Models/PostsListTable.php index 6c950e9..62aea79 100644 --- a/App/Models/PostsListTable.php +++ b/App/Models/PostsListTable.php @@ -31,7 +31,7 @@ public function __construct($args = []) { parent::__construct($args); - $this->screen->post_type = 'post'; + $this->screen->post_type = \RdPostOrder\App\Models\PostOrder::POST_TYPE; }// __construct @@ -171,7 +171,7 @@ private function columnTaxonomyLink($taxonomy, $item) $outlink = []; foreach ($terms as $term) { $label = esc_html(sanitize_term_field('name', $term->name, $term->term_id, $taxonomy, 'display')); - $outlink[] = '' . $label . ''; + $outlink[] = '' . $label . ''; }// endforeach; unset($term);