| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Task_List\Application\Tasks; |
| 5 |
|
| 6 |
use Yoast\WP\SEO\Helpers\Post_Type_Helper; |
| 7 |
use Yoast\WP\SEO\Task_List\Domain\Components\Call_To_Action_Entry; |
| 8 |
use Yoast\WP\SEO\Task_List\Domain\Components\Copy_Set; |
| 9 |
use Yoast\WP\SEO\Task_List\Domain\Tasks\Abstract_Task; |
| 10 |
|
| 11 |
/** |
| 12 |
* Represents the task for creating new content. |
| 13 |
*/ |
| 14 |
class Create_New_Content extends Abstract_Task { |
| 15 |
|
| 16 |
/** |
| 17 |
* Holds the id. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
protected $id = 'create-new-content'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Holds the priority. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
protected $priority = 'medium'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Holds the duration. |
| 32 |
* |
| 33 |
* @var int |
| 34 |
*/ |
| 35 |
protected $duration = 90; |
| 36 |
|
| 37 |
/** |
| 38 |
* Holds the post type helper. |
| 39 |
* |
| 40 |
* @var Post_Type_Helper |
| 41 |
*/ |
| 42 |
private $post_type_helper; |
| 43 |
|
| 44 |
/** |
| 45 |
* Constructs the task. |
| 46 |
* |
| 47 |
* @param Post_Type_Helper $post_type_helper The post type helper. |
| 48 |
*/ |
| 49 |
public function __construct( Post_Type_Helper $post_type_helper ) { |
| 50 |
$this->post_type_helper = $post_type_helper; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Returns whether this task is completed. |
| 55 |
* |
| 56 |
* @return bool Whether this task is completed. |
| 57 |
*/ |
| 58 |
public function get_is_completed(): bool { |
| 59 |
if ( ! \in_array( 'post', $this->post_type_helper->get_public_post_types(), true ) ) { |
| 60 |
return true; |
| 61 |
} |
| 62 |
|
| 63 |
$recent_posts = \get_posts( |
| 64 |
[ |
| 65 |
'post_type' => 'post', |
| 66 |
'post_status' => 'publish', |
| 67 |
'numberposts' => 1, |
| 68 |
'date_query' => [ |
| 69 |
[ |
| 70 |
'after' => '30 days ago', |
| 71 |
], |
| 72 |
], |
| 73 |
], |
| 74 |
); |
| 75 |
|
| 76 |
return ! empty( $recent_posts ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Returns the task's link. |
| 81 |
* |
| 82 |
* @return string|null |
| 83 |
*/ |
| 84 |
public function get_link(): ?string { |
| 85 |
return \self_admin_url( 'post-new.php' ); |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Returns the task's call to action entry. |
| 90 |
* |
| 91 |
* @return Call_To_Action_Entry|null |
| 92 |
*/ |
| 93 |
public function get_call_to_action(): ?Call_To_Action_Entry { |
| 94 |
return new Call_To_Action_Entry( |
| 95 |
\__( 'Create new post', 'wordpress-seo' ), |
| 96 |
'add', |
| 97 |
$this->get_link(), |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
/** |
| 102 |
* Returns the task's copy set. |
| 103 |
* |
| 104 |
* @return string|null |
| 105 |
*/ |
| 106 |
public function get_copy_set(): Copy_Set { |
| 107 |
return new Copy_Set( |
| 108 |
\__( 'Create new content', 'wordpress-seo' ), |
| 109 |
\sprintf( |
| 110 |
/* translators: %1$s and %3$s expands to an opening p tag, %2$s and %5$s expand to a closing p tag and %4$s expands to Yoast */ |
| 111 |
\__( '%1$sLong gaps without new content slow down your traffic growth. Publishing regularly gives search engines and visitors a reason to return.%2$s%3$sPlan a topic, write your post, and use the %4$s SEO and Readability Analyses to refine it before publishing.%5$s', 'wordpress-seo' ), |
| 112 |
'<p>', |
| 113 |
'</p>', |
| 114 |
'<p>', |
| 115 |
'Yoast', |
| 116 |
'</p>', |
| 117 |
), |
| 118 |
); |
| 119 |
} |
| 120 |
} |
| 121 |
|