bh_get_page_path( $p = null,  $current = false )


Description


Source

File: functions/common/resources.php

	function bh_get_page_path( &$p = null, $current = false ) {
		if ( empty( $p ) && $current ) {
			global $post, $bh_hierarchy;
			if ( ! empty( $bh_hierarchy ) ) {
				$h = $bh_hierarchy;
				$p = array_pop( $h );
				if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
					do_action( 'log', 'get_page_path: Reverting to hierarchy top', $p );
				}
			} elseif ( ! is_search() ) {
				$p = $post;
				if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
					do_action( 'log', 'get_page_path: Reverting to global post', $post );
				}
			}
		}
		if ( is_object( $p ) && ! empty( $p->_page_path ) ) {
			if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
				do_action( 'log', 'get_page_path: Stored page path', $p->_page_path );
			}
			return $p->_page_path;
		}
		if ( ! empty( $p ) && 'page' === $p->post_type ) {
			$page_id = bh_select_post_id( $p );
			$path = get_page_uri( $page_id );
			if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
				do_action( 'log', 'get_page_path: Page URI', $path );
			}
		}
		if ( empty( $path ) || is_numeric( $path ) ) {
			if ( ! empty( $p ) || ! is_search() ) {
				$permalink = get_permalink( $p );
				$path = substr( get_permalink( bh_select_post_id( $p ) ), strlen( get_option( 'home' ) ) );
				$path = trim( $path, '/' );
				if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
					do_action( 'log', 'get_page_path: Permalink', $path );
				}
			}
		}
		if ( $current && empty( $path ) ) {
			$path = $_SERVER['REQUEST_URI'];
			$path = preg_replace( '!^https?://[^/]+/!i', '', $path );
			$path = preg_replace( '!\?.*$!i', '', $path );
			$path = trim( $path, '/' );
			if ( defined( 'DEBUG_PATHS' ) && DEBUG_PATHS ) {
				do_action( 'log', 'get_page_path: Hard URI', $path );
			}
		}
		if ( is_object( $p ) ) {
			$p->_page_path = $path;
		}
		return $path;
	}


User Contributed Notes

You must log in before being able to contribute a note or feedback.