| @@ -9,14 +9,14 @@ | ||
| 9 | 9 | declare(strict_types=1); |
| 10 | 10 | |
| 11 | 11 | namespace Parsely; |
| 12 | 12 | |
| 13 | +use Parsely\Content_Helper\Suggestion_Defaults; | |
| 13 | 14 | use Parsely\REST_API\REST_API_Controller; |
| 14 | 15 | use Parsely\Services\Content_API\Content_API_Service; |
| 15 | 16 | use Parsely\Services\Suggestions_API\Suggestions_API_Service; |
| 16 | 17 | use Parsely\UI\Metadata_Renderer; |
| 17 | 18 | use Parsely\UI\Settings_Page; |
| 18 | -use Parsely\Utils\Utils; | |
| 19 | 19 | use WP_Post; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Holds most of the logic for the plugin. |
| @@ -59,8 +59,11 @@ | ||
| 59 | 59 | * |
| 60 | 60 | * @phpstan-type Parsely_Options_Content_Helper_Feature array{ |
| 61 | 61 | * enabled: bool, |
| 62 | 62 | * allowed_user_roles: string[], |
| 63 | + * default_length?: int, | |
| 64 | + * default_tone?: string, | |
| 65 | + * default_persona?: string, | |
| 63 | 66 | * } |
| 64 | 67 | * |
| 65 | 68 | * @phpstan-type Parsely_Options_Headline_Testing array{ |
| 66 | 69 | * enabled: bool, |
| @@ -135,12 +138,17 @@ | ||
| 135 | 138 | ), |
| 136 | 139 | 'title_suggestions' => array( |
| 137 | 140 | 'enabled' => true, |
| 138 | 141 | 'allowed_user_roles' => array( 'administrator' ), |
| 142 | + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, | |
| 143 | + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, | |
| 139 | 144 | ), |
| 140 | 145 | 'excerpt_suggestions' => array( |
| 141 | 146 | 'enabled' => true, |
| 142 | 147 | 'allowed_user_roles' => array( 'administrator' ), |
| 148 | + 'default_length' => Suggestion_Defaults::DEFAULT_LENGTH, | |
| 149 | + 'default_tone' => Suggestion_Defaults::DEFAULT_TONE, | |
| 150 | + 'default_persona' => Suggestion_Defaults::DEFAULT_PERSONA, | |
| 143 | 151 | ), |
| 144 | 152 | 'traffic_boost' => array( |
| 145 | 153 | 'enabled' => true, |
| 146 | 154 | 'allowed_user_roles' => array( 'administrator' ), |
| @@ -1193,8 +1201,9 @@ | ||
| 1193 | 1201 | * |
| 1194 | 1202 | * This is needed for environments, such as wp-now, that block remote requests. |
| 1195 | 1203 | * |
| 1196 | 1204 | * @since 3.13.0 |
| 1205 | + * @since 3.24.2 Matches the Parse.ly hosts exactly, over HTTPS. | |
| 1197 | 1206 | * @access private |
| 1198 | 1207 | */ |
| 1199 | 1208 | private function allow_parsely_remote_requests(): void { |
| 1200 | 1209 | $allowed_urls = array( |
| @@ -1205,14 +1214,20 @@ | ||
| 1205 | 1214 | |
| 1206 | 1215 | add_filter( |
| 1207 | 1216 | 'http_request_host_is_external', |
| 1208 | 1217 | function ( bool $external, string $host, string $url ) use ( $allowed_urls ) { |
| 1209 | - // Check if the URL matches any URLs on the allowed list. | |
| 1210 | - foreach ( $allowed_urls as $allowed_url ) { | |
| 1211 | - if ( Utils::str_starts_with( $url, $allowed_url ) ) { | |
| 1212 | - return true; | |
| 1213 | - } | |
| 1218 | + $scheme = strtolower( (string) wp_parse_url( $url, PHP_URL_SCHEME ) ); | |
| 1219 | + $allowed_hosts = array_map( | |
| 1220 | + static function ( string $allowed_url ): string { | |
| 1221 | + return (string) wp_parse_url( $allowed_url, PHP_URL_HOST ); | |
| 1222 | + }, | |
| 1223 | + $allowed_urls | |
| 1224 | + ); | |
| 1225 | + | |
| 1226 | + if ( 'https' === $scheme && in_array( strtolower( $host ), $allowed_hosts, true ) ) { | |
| 1227 | + return true; | |
| 1214 | 1228 | } |
| 1229 | + | |
| 1215 | 1230 | return $external; |
| 1216 | 1231 | }, |
| 1217 | 1232 | 10, |
| 1218 | 1233 | 3 |