| 1 |
<?php |
| 2 |
|
| 3 |
namespace Codemanas\InactiveLogout\Backend; |
| 4 |
|
| 5 |
use Codemanas\InactiveLogout\Helpers; |
| 6 |
use Codemanas\InactiveLogout\Modal; |
| 7 |
|
| 8 |
class Common { |
| 9 |
|
| 10 |
public function dismissNotices() { |
| 11 |
Helpers::update_option( 'ina_dismiss_like_notice', true ); |
| 12 |
} |
| 13 |
|
| 14 |
private function getPostTypeQuery() { |
| 15 |
$q = filter_input( INPUT_GET, 'q' ); |
| 16 |
|
| 17 |
$args = [ |
| 18 |
's' => $q, |
| 19 |
'post_type' => apply_filters( 'ina_free_get_custom_post_types', array( 'post', 'page' ) ), |
| 20 |
'post_status' => 'publish', |
| 21 |
]; |
| 22 |
|
| 23 |
// The Query |
| 24 |
return new \WP_Query( $args ); |
| 25 |
} |
| 26 |
|
| 27 |
public function triggerDemoToast() { |
| 28 |
$message = Helpers::getSettings( 'after_redirection_toast_message' ); |
| 29 |
$message = ! empty( $message ) ? $message : 'You have been automatically logged out due to inactivity'; |
| 30 |
$modal = Modal::instance(); |
| 31 |
$content = $modal->getToastStyle(); |
| 32 |
$content .= $modal->getToastHTML( $message ); |
| 33 |
wp_send_json( $content ); |
| 34 |
|
| 35 |
wp_die(); |
| 36 |
} |
| 37 |
|
| 38 |
public function filterPostPagesUrl() { |
| 39 |
// The Query |
| 40 |
$posts_query = $this->getPostTypeQuery(); |
| 41 |
|
| 42 |
$posts = []; |
| 43 |
if ( ! empty( $posts_query->have_posts() ) ) { |
| 44 |
foreach ( $posts_query->get_posts() as $post ) { |
| 45 |
$posts[] = [ 'text' => get_permalink( $post->ID ), 'id' => get_permalink( $post->ID ) ]; |
| 46 |
} |
| 47 |
} |
| 48 |
wp_reset_postdata(); |
| 49 |
wp_send_json( $posts ); |
| 50 |
wp_die(); |
| 51 |
} |
| 52 |
|
| 53 |
public function filterPostPagesId() { |
| 54 |
$posts_query = $this->getPostTypeQuery(); |
| 55 |
|
| 56 |
$posts = []; |
| 57 |
if ( ! empty( $posts_query->have_posts() ) ) { |
| 58 |
foreach ( $posts_query->get_posts() as $post ) { |
| 59 |
$posts[] = [ 'text' => $post->post_title, 'id' => $post->ID ]; |
| 60 |
} |
| 61 |
} |
| 62 |
wp_reset_postdata(); |
| 63 |
wp_send_json( $posts ); |
| 64 |
wp_die(); |
| 65 |
} |
| 66 |
|
| 67 |
private static ?Common $_instance = null; |
| 68 |
|
| 69 |
public static function getInstance(): ?Common { |
| 70 |
if ( is_null( self::$_instance ) ) { |
| 71 |
self::$_instance = new self(); |
| 72 |
} |
| 73 |
|
| 74 |
return self::$_instance; |
| 75 |
} |
| 76 |
} |
| 77 |
|