geo-directory.php
82 lines
| 1 | <?php |
| 2 | /** |
| 3 | * GeoDirectory core integrations file |
| 4 | * |
| 5 | * @since 1.0.0 |
| 6 | * @package SureTrigger |
| 7 | */ |
| 8 | |
| 9 | namespace SureTriggers\Integrations\GeoDirectory; |
| 10 | |
| 11 | use SureTriggers\Controllers\IntegrationsController; |
| 12 | use SureTriggers\Integrations\Integrations; |
| 13 | use SureTriggers\Traits\SingletonLoader; |
| 14 | use WP_Term; |
| 15 | |
| 16 | /** |
| 17 | * Class GeoDirectory |
| 18 | * |
| 19 | * @package SureTriggers\Integrations\GeoDirectory |
| 20 | */ |
| 21 | class GeoDirectory extends Integrations { |
| 22 | |
| 23 | |
| 24 | use SingletonLoader; |
| 25 | |
| 26 | /** |
| 27 | * ID |
| 28 | * |
| 29 | * @var string |
| 30 | */ |
| 31 | protected $id = 'GeoDirectory'; |
| 32 | |
| 33 | /** |
| 34 | * Get term details |
| 35 | * |
| 36 | * @param array $gd_tags gd tags. |
| 37 | * @param string $taxonomy taxonomy. |
| 38 | * @return array |
| 39 | */ |
| 40 | public static function get_place_terms( $gd_tags, $taxonomy ) { |
| 41 | $terms = []; |
| 42 | foreach ( $gd_tags as $tag ) { |
| 43 | $term = get_term_by( 'name', $tag, $taxonomy ); |
| 44 | if ( $term instanceof WP_Term ) { |
| 45 | $term_id = $term->term_id; |
| 46 | } else { |
| 47 | $term = get_term_by( 'slug', $tag, $taxonomy ); |
| 48 | if ( $term instanceof WP_Term ) { |
| 49 | $term_id = $term->term_id; |
| 50 | } else { |
| 51 | $term = get_term_by( 'id', $tag, $taxonomy ); |
| 52 | if ( $term instanceof WP_Term ) { |
| 53 | $term_id = $term->term_id; |
| 54 | } else { |
| 55 | // If term is not found, set term_id to null or handle appropriately. |
| 56 | $term_id = null; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | // Only push term_id if it's not null. |
| 61 | if ( null !== $term_id ) { |
| 62 | $terms[] = $term_id; |
| 63 | } |
| 64 | } |
| 65 | return $terms; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * Is Plugin depended plugin is installed or not. |
| 72 | * |
| 73 | * @return bool |
| 74 | */ |
| 75 | public function is_plugin_installed() { |
| 76 | return class_exists( self::class ); |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | |
| 81 | IntegrationsController::register( GeoDirectory::class ); |
| 82 |