admin
1 year ago
models
1 year ago
query-views
1 year ago
rest-endpoints
1 year ago
tab-handlers
1 year ago
module.php
1 year ago
tools.php
1 year ago
user-journey-rest-controller.php
1 year ago
tools.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\User_Journey; |
| 5 | |
| 6 | // If this file is called directly, abort. |
| 7 | if ( ! defined( 'WPINC' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | /** |
| 12 | * Tools for User Journey Module |
| 13 | * |
| 14 | * This file provides utility functions for the User Journey module. |
| 15 | */ |
| 16 | class Tools { |
| 17 | /** |
| 18 | * Retrieves WordPress page data by URL. |
| 19 | * |
| 20 | * @param string $url The URL to retrieve data for. |
| 21 | * |
| 22 | * @return array|false An array of page data or false if not found. |
| 23 | */ |
| 24 | public static function get_wp_page_data_by_url( string $url ) { |
| 25 | if ( function_exists( 'wc_get_page_id' ) && function_exists( 'get_permalink' ) ) { |
| 26 | $shop_page_id = wc_get_page_id( 'shop' ); |
| 27 | $shop_url = get_permalink( $shop_page_id ); |
| 28 | $shop_url_path = wp_parse_url( $shop_url, PHP_URL_PATH ); |
| 29 | |
| 30 | if ( $shop_url_path === $url ) { |
| 31 | return array( |
| 32 | 'ID' => $shop_page_id, |
| 33 | 'title' => get_the_title( $shop_page_id ), |
| 34 | 'permalink' => $shop_url, |
| 35 | ); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if ( '/' === $url ) { |
| 40 | $post_id = get_option( 'page_on_front' ); |
| 41 | } else { |
| 42 | $post_id = url_to_postid( $url ); |
| 43 | } |
| 44 | |
| 45 | if ( ! $post_id ) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | $title = get_the_title( $post_id ); |
| 50 | $permalink = get_permalink( $post_id ); |
| 51 | |
| 52 | return array( |
| 53 | 'ID' => $post_id, |
| 54 | 'title' => $title, |
| 55 | 'permalink' => $permalink, |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 |