| 1 |
<?php |
| 2 |
/** |
| 3 |
* Manages the display of Breadcrumbs. |
| 4 |
* |
| 5 |
* @package WP_Defender\Component |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Component; |
| 9 |
|
| 10 |
use WP_Defender\Component; |
| 11 |
|
| 12 |
/** |
| 13 |
* Use Breadcrumbs on different plugin pages. |
| 14 |
* |
| 15 |
* @since 5.2.0 |
| 16 |
*/ |
| 17 |
class Breadcrumbs extends Component { |
| 18 |
|
| 19 |
private const BREADCRUMBS_PREFIX_KEY = 'wd_'; |
| 20 |
private const BREADCRUMBS_SUFFIX_KEY = '_breadcrumbs'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Get the feature's slug. |
| 24 |
* |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
private function get_feature_slug(): string { |
| 28 |
// Update value for the next feature. |
| 29 |
return self::BREADCRUMBS_PREFIX_KEY |
| 30 |
. \WP_Defender\Component\Fake_Bot_Detection::SCENARIO_FAKE_BOT . self::BREADCRUMBS_SUFFIX_KEY; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get the previous feature's slug. |
| 35 |
* |
| 36 |
* @return string |
| 37 |
*/ |
| 38 |
private function get_previous_feature_slug(): string { |
| 39 |
return self::BREADCRUMBS_PREFIX_KEY |
| 40 |
. \WP_Defender\Component\Fake_Bot_Detection::SCENARIO_FAKE_BOT . self::BREADCRUMBS_SUFFIX_KEY; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Update the feature's meta key. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
public function update_meta_key(): void { |
| 49 |
// Add value for the next feature. |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Get the feature's meta key. |
| 54 |
* |
| 55 |
* @return bool |
| 56 |
*/ |
| 57 |
public function get_meta_key(): bool { |
| 58 |
return (bool) get_user_meta( get_current_user_id(), $this->get_feature_slug(), true ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Delete the feature's meta key. |
| 63 |
* |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function delete_meta_key(): void { |
| 67 |
global $wpdb; |
| 68 |
|
| 69 |
$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $this->get_feature_slug() ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.SlowDBQuery |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Delete the previous feature's meta key. |
| 74 |
* |
| 75 |
* @return void |
| 76 |
*/ |
| 77 |
public function delete_previous_meta() { |
| 78 |
global $wpdb; |
| 79 |
|
| 80 |
$wpdb->delete( $wpdb->usermeta, array( 'meta_key' => $this->get_previous_feature_slug() ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.SlowDBQuery |
| 81 |
} |
| 82 |
} |
| 83 |
|