| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Contact_Segmentation\Conditions; |
| 4 |
|
| 5 |
use Sellkit\Contact_Segmentation\Conditions\Condition_Base; |
| 6 |
|
| 7 |
defined( 'ABSPATH' ) || die(); |
| 8 |
|
| 9 |
/** |
| 10 |
* Class Referral Source Internal Post. |
| 11 |
* |
| 12 |
* @package Sellkit\Contact_Segmentation\Conditions |
| 13 |
* @since 1.1.0 |
| 14 |
*/ |
| 15 |
class Referral_Source_Internal_Post extends Condition_Base { |
| 16 |
|
| 17 |
/** |
| 18 |
* Condition name. |
| 19 |
* |
| 20 |
* @since 1.1.0 |
| 21 |
*/ |
| 22 |
public function get_name() { |
| 23 |
return 'referral-source-internal-post'; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Condition title. |
| 28 |
* |
| 29 |
* @since 1.1.0 |
| 30 |
*/ |
| 31 |
public function get_title() { |
| 32 |
return __( 'Referral Source (Internal Page/Post)', 'sellkit' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Condition type. |
| 37 |
* |
| 38 |
* @since 1.1.0 |
| 39 |
*/ |
| 40 |
public function get_type() { |
| 41 |
return self::SELLKIT_MULTISELECT_CONDITION_VALUE; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Get the options |
| 46 |
* |
| 47 |
* @since 1.1.0 |
| 48 |
* @return array |
| 49 |
*/ |
| 50 |
public function get_options() { |
| 51 |
$input_value = sellkit_htmlspecialchars( INPUT_GET, 'input_value' ); |
| 52 |
|
| 53 |
$posts = []; |
| 54 |
$args = [ |
| 55 |
'post_type' => [ 'post', 'page' ], |
| 56 |
'post_status' => 'any', |
| 57 |
's' => sanitize_text_field( $input_value ), |
| 58 |
]; |
| 59 |
|
| 60 |
$query = new \WP_Query( $args ); |
| 61 |
|
| 62 |
if ( $query->have_posts() ) { |
| 63 |
while ( $query->have_posts() ) { |
| 64 |
$query->the_post(); |
| 65 |
$posts[ get_the_ID() ] = htmlspecialchars_decode( get_the_title() ); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return $posts; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* It is pro feature or not. |
| 74 |
* |
| 75 |
* @since 1.1.0 |
| 76 |
*/ |
| 77 |
public function is_pro() { |
| 78 |
return true; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* All the conditions are not searchable by default. |
| 83 |
* |
| 84 |
* @return false |
| 85 |
* @since 1.1.0 |
| 86 |
*/ |
| 87 |
public function is_searchable() { |
| 88 |
return true; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Check if the condition is active or not. |
| 93 |
* |
| 94 |
* @return bool |
| 95 |
*/ |
| 96 |
public function is_active() { |
| 97 |
return false; |
| 98 |
} |
| 99 |
} |
| 100 |
|