is_wpcom_simple() ) {
return;
}
add_filter( 'manage_users_columns', array( $this, 'add_connection_column' ) );
add_filter( 'manage_users_custom_column', array( $this, 'render_connection_column' ), 9, 3 ); // Priority 9 to run before SSO
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_print_styles-users.php', array( $this, 'add_connection_column_styles' ) );
}
/**
* Add the connection column to the users list table.
*
* @param array $columns The current columns.
* @return array Modified columns.
*/
public function add_connection_column( $columns ) {
$columns[ self::COLUMN_ID ] = sprintf(
'
%1$s
',
esc_html__( 'WordPress.com account', 'jetpack-connection' ),
esc_attr__( 'Tooltip', 'jetpack-connection' )
);
return $columns;
}
/**
* Render the connection column content.
*
* @param string $output Custom column output.
* @param string $column_name Column name.
* @param int $user_id ID of the currently-listed user.
* @return string
*/
public function render_connection_column( $output, $column_name, $user_id ) {
if ( self::COLUMN_ID !== $column_name ) {
return $output;
}
if ( ( new Manager() )->is_user_connected( $user_id ) ) {
return sprintf(
'%2$s',
esc_attr__( 'This user has connected their WordPress.com account.', 'jetpack-connection' ),
esc_html__( 'Connected', 'jetpack-connection' )
);
}
return $output;
}
/**
* Enqueue scripts and styles.
*
* @param string $hook The current admin page.
*/
public function enqueue_scripts( $hook ) {
if ( 'users.php' !== $hook ) {
return;
}
Assets::register_script(
'jetpack-users-connection',
'../dist/jetpack-users-connection.js',
__FILE__,
array(
'strategy' => 'defer',
'in_footer' => true,
'enqueue' => true,
'version' => Package_Version::PACKAGE_VERSION,
'deps' => array( 'wp-i18n' ),
)
);
wp_localize_script(
'jetpack-users-connection',
'jetpackConnectionTooltips',
array(
'columnTooltip' => esc_html__( 'Connecting a WordPress.com account unlocks Jetpackās full suite of features including secure logins.', 'jetpack-connection' ),
)
);
}
/**
* Add styles for the connection column.
*/
public function add_connection_column_styles() {
?>