| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Internals |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Represents the health check for the postname in the permalink. |
| 10 |
*/ |
| 11 |
class WPSEO_Health_Check_Postname_Permalink extends WPSEO_Health_Check { |
| 12 |
|
| 13 |
/** |
| 14 |
* The name of the test. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $test = 'yoast-health-check-postname-permalink'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Runs the test. |
| 22 |
*/ |
| 23 |
public function run() { |
| 24 |
if ( $this->has_postname_in_permalink() ) { |
| 25 |
$this->label = esc_html__( 'Your permalink structure includes the post name', 'wordpress-seo' ); |
| 26 |
$this->status = self::STATUS_GOOD; |
| 27 |
$this->badge['color'] = 'blue'; |
| 28 |
$this->description = esc_html__( 'You do have your postname in the URL of your posts and pages.', 'wordpress-seo' ); |
| 29 |
|
| 30 |
return; |
| 31 |
} |
| 32 |
|
| 33 |
$this->label = esc_html__( 'You do not have your postname in the URL of your posts and pages', 'wordpress-seo' ); |
| 34 |
$this->status = self::STATUS_RECOMMENDED; |
| 35 |
$this->badge['color'] = 'red'; |
| 36 |
|
| 37 |
$this->description = sprintf( |
| 38 |
/* translators: %s expands to '/%postname%/' */ |
| 39 |
__( 'It\'s highly recommended to have your postname in the URL of your posts and pages. Consider setting your permalink structure to %s.', 'wordpress-seo' ), |
| 40 |
'<strong>/%postname%/</strong>' |
| 41 |
); |
| 42 |
|
| 43 |
$this->actions = sprintf( |
| 44 |
/* translators: %1$s is a link start tag to the permalink settings page, %2$s is the link closing tag. */ |
| 45 |
__( 'You can fix this on the %1$sPermalink settings page%2$s.', 'wordpress-seo' ), |
| 46 |
'<a href="' . admin_url( 'options-permalink.php' ) . '">', |
| 47 |
'</a>' |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Check if the permalink uses %postname%. |
| 53 |
* |
| 54 |
* @return bool |
| 55 |
*/ |
| 56 |
private function has_postname_in_permalink() { |
| 57 |
return ( strpos( get_option( 'permalink_structure' ), '%postname%' ) !== false ); |
| 58 |
} |
| 59 |
} |
| 60 |
|