| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Display |
| 5 |
* |
| 6 |
* This class is responsible for displaying the item based on specific conditions. |
| 7 |
* |
| 8 |
* @package WowPlugin |
| 9 |
* @subpackage Publish |
| 10 |
* @author Dmytro Lobov <dev@wow-company.com>, Wow-Company |
| 11 |
* @copyright 2024 Dmytro Lobov |
| 12 |
* @license GPL-2.0+ |
| 13 |
* |
| 14 |
*/ |
| 15 |
|
| 16 |
namespace FloatMenuLite\Publish; |
| 17 |
|
| 18 |
defined( 'ABSPATH' ) || exit; |
| 19 |
|
| 20 |
class Display { |
| 21 |
|
| 22 |
private const POST_PREFIX = 'custom_post_'; |
| 23 |
|
| 24 |
public static function init( $id, $param ): bool { |
| 25 |
if ( self::can_abort_early( $id, $param ) ) { |
| 26 |
return false; |
| 27 |
} |
| 28 |
|
| 29 |
return self::check_shows( $param['show'], $param ); |
| 30 |
} |
| 31 |
|
| 32 |
private static function can_abort_early( $id, $param ): bool { |
| 33 |
return empty( $param ) || ! is_array( $param ) || empty( absint( $id ) ); |
| 34 |
} |
| 35 |
|
| 36 |
private static function check_shows( $showParams, $param ): bool { |
| 37 |
|
| 38 |
foreach ( $showParams as $i => $show ) { |
| 39 |
|
| 40 |
if ( self::is_match( $show, $i, $param ) ) { |
| 41 |
return true; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return false; |
| 46 |
} |
| 47 |
|
| 48 |
private static function is_match( $show, $i, $param ): bool { |
| 49 |
|
| 50 |
$cases = [ |
| 51 |
'everywhere' => 'check_everywhere', |
| 52 |
]; |
| 53 |
|
| 54 |
if ( ! isset( $cases[ $show ] ) ) { |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
$function = $cases[ $show ]; |
| 59 |
|
| 60 |
return self::$function( $i, $param ); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
private static function check_everywhere(): bool { |
| 65 |
return true; |
| 66 |
} |
| 67 |
|
| 68 |
} |