Skip to content

Commit 63a36c0

Browse files
committed
Main Theme: Fix PHP warnings when the queried object or post is not available.
git-svn-id: https://meta.svn.wordpress.org/sites/trunk@14772 74240141-8908-4e6f-9713-ba540dce6ec7
1 parent 411a0ab commit 63a36c0

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • wordpress.org/public_html/wp-content/themes/pub/wporg-main

wordpress.org/public_html/wp-content/themes/pub/wporg-main/functions.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ function scripts() {
126126
wp_enqueue_style( 'page-40-percent', get_theme_file_uri( '/css/page-40-percent-style.css' ), [], '20210527a' );
127127
}
128128

129-
if ( is_page() && get_queried_object()->post_parent ) {
129+
$queried_object = get_queried_object();
130+
if ( is_page() && $queried_object && $queried_object->post_parent ) {
130131
wp_enqueue_script( 'wporg-navigation', get_theme_file_uri( "/js/navigation$suffix.js" ), [], '20151215', true );
131132
}
132133
}
@@ -195,7 +196,7 @@ function body_class( $classes ) {
195196
function child_page_templates( $templates ) {
196197
$page = get_queried_object();
197198

198-
if ( $page->post_parent ) {
199+
if ( $page && $page->post_parent ) {
199200
$parent = get_post( $page->post_parent );
200201

201202
// We want it before page-{page_name}.php but after {Page Template}.php.
@@ -302,14 +303,16 @@ function old_page_redirects() {
302303
* - It's not a rosetta page owned by anyone other than wordpressdotorg (These are the globally synced pages).
303304
*/
304305
function maybe_remove_hreflang_tags() {
306+
$post = get_post();
307+
305308
if (
306309
! is_page() ||
307310
is_page( 'hosting' ) ||
308311
// Exclude custom localised pages.
309312
// Only include posts authored by `wordPressdotorg` which are using a page template.
310313
(
311314
defined( 'IS_ROSETTA_NETWORK' ) && IS_ROSETTA_NETWORK &&
312-
get_user_by( 'slug', 'wordpressdotorg' )->ID != get_post()->post_author
315+
( ! $post || get_user_by( 'slug', 'wordpressdotorg' )->ID != $post->post_author )
313316
)
314317
) {
315318
remove_action( 'wp_head', 'WordPressdotorg\Theme\hreflang_link_attributes' );

0 commit comments

Comments
 (0)