Skip to content

Commit

Permalink
Use post type value from constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
ve3 committed Dec 11, 2024
1 parent e37fbd2 commit ad9a61a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion App/Controllers/Admin/Posts/HookNewPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions App/Controllers/Admin/Posts/ReOrderPostsAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions App/Controllers/Front/AlterPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand All @@ -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);
}
}
Expand All @@ -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';
}
}
Expand All @@ -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);
}
}
Expand Down
12 changes: 9 additions & 3 deletions App/Models/PostOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions App/Models/PostsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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[] = '<a href="' . admin_url('term.php?taxonomy=' . $taxonomy . '&amp;tag_ID=' . $term->term_id . '&amp;post_type=post') . '">' . $label . '</a>';
$outlink[] = '<a href="' . admin_url('term.php?taxonomy=' . $taxonomy . '&amp;tag_ID=' . $term->term_id . '&amp;post_type=' . \RdPostOrder\App\Models\PostOrder::POST_TYPE) . '">' . $label . '</a>';
}// endforeach;
unset($term);

Expand Down

0 comments on commit ad9a61a

Please sign in to comment.