| @@ -523,12 +523,29 @@ | ||
| 523 | 523 | $validation['valid'] = false; |
| 524 | 524 | } |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | + // The default Open Graph and Twitter images are checked in the field | |
| 528 | + // details above only while their feature is switched on, but they are | |
| 529 | + // stored (and shown in the admin preview's src) either way. | |
| 530 | + $flagged = []; | |
| 531 | + foreach ($field_details as $field) { | |
| 532 | + if ('error' === ($field['status'] ?? '')) { | |
| 533 | + $flagged[] = $field['field'] ?? ''; | |
| 534 | + } | |
| 535 | + } | |
| 536 | + foreach (['default_og_image' => 'Default Open Graph image', 'default_twitter_image' => 'Default Twitter Card image'] as $key => $label) { | |
| 537 | + if (!empty($settings[$key]) && !in_array($key, $flagged, true) | |
| 538 | + && !\ThinkRank\Core\Url_Validator::is_http_url($settings[$key])) { | |
| 539 | + $validation['errors'][] = $label . ' must be an http or https URL.'; | |
| 540 | + $validation['valid'] = false; | |
| 541 | + } | |
| 542 | + } | |
| 543 | + | |
| 527 | 544 | // Validate default image |
| 528 | 545 | if (isset($settings['default_image']) && !empty($settings['default_image'])) { |
| 529 | - if (!filter_var($settings['default_image'], FILTER_VALIDATE_URL)) { | |
| 530 | - $validation['errors'][] = 'default_image must be a valid URL'; | |
| 546 | + if (!\ThinkRank\Core\Url_Validator::is_http_url($settings['default_image'])) { | |
| 547 | + $validation['errors'][] = 'default_image must be an http or https URL'; | |
| 531 | 548 | $validation['valid'] = false; |
| 532 | 549 | } else { |
| 533 | 550 | // Check image dimensions and format |
| 534 | 551 | $image_validation = $this->validate_social_image($settings['default_image']); |
| @@ -766,9 +783,12 @@ | ||
| 766 | 783 | } |
| 767 | 784 | |
| 768 | 785 | // Default Image validation |
| 769 | 786 | if (!empty($settings['default_og_image'])) { |
| 770 | - if (filter_var($settings['default_og_image'], FILTER_VALIDATE_URL)) { | |
| 787 | + // http(s) only, and refused rather than warned about: the | |
| 788 | + // value becomes og:image and the admin preview's src, and a | |
| 789 | + // javascript: URL passed is_valid(). | |
| 790 | + if (\ThinkRank\Core\Url_Validator::is_http_url($settings['default_og_image'])) { | |
| 771 | 791 | $field_details[] = [ |
| 772 | 792 | 'field' => 'default_og_image', |
| 773 | 793 | 'label' => 'Default Open Graph image is configured.', |
| 774 | 794 | 'status' => 'valid', |
| @@ -776,11 +796,11 @@ | ||
| 776 | 796 | ]; |
| 777 | 797 | } else { |
| 778 | 798 | $field_details[] = [ |
| 779 | 799 | 'field' => 'default_og_image', |
| 780 | - 'label' => 'Default Open Graph image URL appears invalid.', | |
| 781 | - 'status' => 'warning', | |
| 782 | - 'icon' => '⚠' | |
| 800 | + 'label' => 'Default Open Graph image must be an http or https URL.', | |
| 801 | + 'status' => 'error', | |
| 802 | + 'icon' => '✗' | |
| 783 | 803 | ]; |
| 784 | 804 | } |
| 785 | 805 | } else { |
| 786 | 806 | $field_details[] = [ |
| @@ -900,9 +920,9 @@ | ||
| 900 | 920 | } |
| 901 | 921 | |
| 902 | 922 | // Default Twitter Image validation |
| 903 | 923 | if (!empty($settings['default_twitter_image'])) { |
| 904 | - if (filter_var($settings['default_twitter_image'], FILTER_VALIDATE_URL)) { | |
| 924 | + if (\ThinkRank\Core\Url_Validator::is_http_url($settings['default_twitter_image'])) { | |
| 905 | 925 | $field_details[] = [ |
| 906 | 926 | 'field' => 'default_twitter_image', |
| 907 | 927 | 'label' => 'Default Twitter Card image is configured.', |
| 908 | 928 | 'status' => 'valid', |
| @@ -910,11 +930,11 @@ | ||
| 910 | 930 | ]; |
| 911 | 931 | } else { |
| 912 | 932 | $field_details[] = [ |
| 913 | 933 | 'field' => 'default_twitter_image', |
| 914 | - 'label' => 'Default Twitter Card image URL appears invalid.', | |
| 915 | - 'status' => 'warning', | |
| 916 | - 'icon' => '⚠' | |
| 934 | + 'label' => 'Default Twitter Card image must be an http or https URL.', | |
| 935 | + 'status' => 'error', | |
| 936 | + 'icon' => '✗' | |
| 917 | 937 | ]; |
| 918 | 938 | } |
| 919 | 939 | } else { |
| 920 | 940 | $field_details[] = [ |
| @@ -1533,9 +1553,21 @@ | ||
| 1533 | 1553 | $data['title'] = $fallback_title; |
| 1534 | 1554 | } else { |
| 1535 | 1555 | $data['title'] = $blogname; |
| 1536 | 1556 | } |
| 1537 | - $data['description'] = $settings['og_description'] ?? get_bloginfo('description'); | |
| 1557 | + // Same rule as the title above: the shipped default (the tagline) | |
| 1558 | + // is not a choice, so the homepage's meta description wins over | |
| 1559 | + // it. Without this an imported or hand-set homepage description | |
| 1560 | + // printed as the meta description while og:/twitter:description | |
| 1561 | + // kept the tagline (#897). | |
| 1562 | + $og_description = (string) ($settings['og_description'] ?? ''); | |
| 1563 | + if ($og_description !== '' && $og_description !== get_bloginfo('description')) { | |
| 1564 | + $data['description'] = $og_description; | |
| 1565 | + } elseif ($fallback_description !== null && $fallback_description !== '') { | |
| 1566 | + $data['description'] = $fallback_description; | |
| 1567 | + } else { | |
| 1568 | + $data['description'] = get_bloginfo('description'); | |
| 1569 | + } | |
| 1538 | 1570 | // Use home_url('/') so og:url matches the homepage canonical |
| 1539 | 1571 | // (class-seo-manager.php) and the WebSite schema, which both include |
| 1540 | 1572 | // the trailing slash. A bare home_url() would key a different URL in |
| 1541 | 1573 | // social caches than the canonical. |
| @@ -3023,9 +3055,9 @@ | ||
| 3023 | 3055 | return $validation; |
| 3024 | 3056 | } |
| 3025 | 3057 | |
| 3026 | 3058 | // Check if URL is valid |
| 3027 | - if (!filter_var($image_url, FILTER_VALIDATE_URL)) { | |
| 3059 | + if (!\ThinkRank\Core\Url_Validator::is_http_url($image_url)) { | |
| 3028 | 3060 | $validation['warnings'][] = 'Invalid image URL'; |
| 3029 | 3061 | return $validation; |
| 3030 | 3062 | } |
| 3031 | 3063 | |