| 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 |
use FloatMenuLite\WOWP_Plugin; |
| 19 |
|
| 20 |
defined( 'ABSPATH' ) || exit; |
| 21 |
|
| 22 |
class Display { |
| 23 |
|
| 24 |
private const POST_PREFIX = 'custom_post_'; |
| 25 |
|
| 26 |
public static function init( $id, $param ): bool { |
| 27 |
if ( self::can_abort_early( $id, $param ) ) { |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! isset( $param['show'] ) ) { |
| 32 |
return false; |
| 33 |
} |
| 34 |
|
| 35 |
return self::check_shows( $param['show'], $param ); |
| 36 |
} |
| 37 |
|
| 38 |
private static function can_abort_early( $id, $param ): bool { |
| 39 |
return empty( $param ) || ! is_array( $param ) || empty( absint( $id ) ); |
| 40 |
} |
| 41 |
|
| 42 |
private static function check_shows( $showParams, $param ): bool { |
| 43 |
|
| 44 |
|
| 45 |
foreach ( $showParams as $i => $show ) { |
| 46 |
|
| 47 |
if ( self::is_match( $show, $i, $param ) ) { |
| 48 |
return true; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
private static function is_match( $show, $i, $param ): bool { |
| 56 |
|
| 57 |
$cases = [ |
| 58 |
'everywhere' => 'check_everywhere', |
| 59 |
]; |
| 60 |
|
| 61 |
$cases = apply_filters( WOWP_Plugin::PREFIX . '_pro_match_cases', $cases ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound |
| 62 |
|
| 63 |
|
| 64 |
if ( ! isset( $cases[ $show ] ) ) { |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
$function = $cases[ $show ]; |
| 69 |
|
| 70 |
if ( method_exists( __CLASS__, $function ) ) { |
| 71 |
return self::$function( $i, $param ); |
| 72 |
} |
| 73 |
|
| 74 |
return apply_filters( WOWP_Plugin::PREFIX . "_pro_match_callback_{$function}", false, $i, $param ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
private static function check_everywhere(): bool { |
| 79 |
return true; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
} |