| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\User_Profiles_Additions\User_Interface; |
| 4 |
|
| 5 |
use WP_User; |
| 6 |
use WPSEO_Admin_Asset_Manager; |
| 7 |
use Yoast\WP\SEO\Conditionals\User_Profile_Conditional; |
| 8 |
use Yoast\WP\SEO\Helpers\Product_Helper; |
| 9 |
use Yoast\WP\SEO\Integrations\Integration_Interface; |
| 10 |
|
| 11 |
/** |
| 12 |
* Adds a new hook in the user profiles edit screen to add content. |
| 13 |
*/ |
| 14 |
class User_Profiles_Additions_Ui implements Integration_Interface { |
| 15 |
|
| 16 |
/** |
| 17 |
* Holds the Product_Helper. |
| 18 |
* |
| 19 |
* @var Product_Helper |
| 20 |
*/ |
| 21 |
private $product_helper; |
| 22 |
|
| 23 |
/** |
| 24 |
* Holds the WPSEO_Admin_Asset_Manager. |
| 25 |
* |
| 26 |
* @var WPSEO_Admin_Asset_Manager |
| 27 |
*/ |
| 28 |
private $asset_manager; |
| 29 |
|
| 30 |
/** |
| 31 |
* Constructs Academy_Integration. |
| 32 |
* |
| 33 |
* @param WPSEO_Admin_Asset_Manager $asset_manager The WPSEO_Admin_Asset_Manager. |
| 34 |
* @param Product_Helper $product_helper The Product_Helper. |
| 35 |
*/ |
| 36 |
public function __construct( WPSEO_Admin_Asset_Manager $asset_manager, Product_Helper $product_helper ) { |
| 37 |
$this->asset_manager = $asset_manager; |
| 38 |
$this->product_helper = $product_helper; |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Returns the conditionals based in which this loadable should be active. |
| 43 |
* |
| 44 |
* @return array |
| 45 |
*/ |
| 46 |
public static function get_conditionals() { |
| 47 |
return [ User_Profile_Conditional::class ]; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Initializes the integration. |
| 52 |
* |
| 53 |
* This is the place to register hooks and filters. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
public function register_hooks() { |
| 58 |
\add_action( 'show_user_profile', [ $this, 'add_hook_to_user_profile' ] ); |
| 59 |
\add_action( 'edit_user_profile', [ $this, 'add_hook_to_user_profile' ] ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Enqueues the assets needed for this integration. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public function enqueue_assets() { |
| 68 |
if ( $this->product_helper->is_premium() ) { |
| 69 |
$this->asset_manager->enqueue_style( 'introductions' ); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Add the inputs needed for SEO values to the User Profile page. |
| 75 |
* |
| 76 |
* @param WP_User $user User instance to output for. |
| 77 |
* |
| 78 |
* @return void |
| 79 |
*/ |
| 80 |
public function add_hook_to_user_profile( $user ) { |
| 81 |
$this->enqueue_assets(); |
| 82 |
echo '<div class="yoast yoast-settings">'; |
| 83 |
|
| 84 |
/** |
| 85 |
* Fires in the user profile. |
| 86 |
* |
| 87 |
* @internal |
| 88 |
* |
| 89 |
* @param WP_User $user The current WP_User object. |
| 90 |
*/ |
| 91 |
\do_action( 'wpseo_user_profile_additions', $user ); |
| 92 |
echo '</div>'; |
| 93 |
} |
| 94 |
} |
| 95 |
|