| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Parsely Network Admin Site List class | |
| 3 | + * UI: Network Admin site list class | |
| 4 | 4 | * |
| 5 | 5 | * @package Parsely |
| 6 | - * @since 3.2.0 | |
| 6 | + * @since 3.2.0 | |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | declare(strict_types=1); |
| 10 | 10 | |
| @@ -10,17 +10,23 @@ | ||
| 10 | 10 | |
| 11 | 11 | namespace Parsely\UI; |
| 12 | 12 | |
| 13 | 13 | use Parsely\Parsely; |
| 14 | -use WP_Site; | |
| 15 | 14 | |
| 16 | 15 | /** |
| 17 | - * Render the additions to the WordPress Multisite Network Admin Sites List page | |
| 16 | + * Renders the additions to the WordPress Multisite Network Admin Sites List | |
| 17 | + * page. | |
| 18 | 18 | * |
| 19 | 19 | * @since 3.2.0 |
| 20 | 20 | */ |
| 21 | 21 | final class Network_Admin_Sites_List { |
| 22 | - const COLUMN_NAME = 'parsely-api-key'; | |
| 22 | + public const COLUMN_NAME = 'parsely-site-id'; | |
| 23 | + /** | |
| 24 | + * Instance of Parsely class. | |
| 25 | + * | |
| 26 | + * @var Parsely | |
| 27 | + */ | |
| 28 | + private $parsely; | |
| 23 | 29 | |
| 24 | 30 | /** |
| 25 | 31 | * Constructor. |
| 26 | 32 | * |
| @@ -30,27 +36,30 @@ | ||
| 30 | 36 | $this->parsely = $parsely; |
| 31 | 37 | } |
| 32 | 38 | |
| 33 | 39 | /** |
| 34 | - * Attach network admin page functionality to the appropriate action and filter hooks. | |
| 40 | + * Attaches network admin page functionality to the appropriate action and | |
| 41 | + * filter hooks. | |
| 35 | 42 | * |
| 36 | 43 | * @since 3.2.0 |
| 37 | - * @return void | |
| 38 | 44 | */ |
| 39 | 45 | public function run(): void { |
| 40 | - add_filter( 'manage_sites_action_links', array( __CLASS__, 'add_action_link' ), 10, 2 ); | |
| 41 | - add_filter( 'wpmu_blogs_columns', array( __CLASS__, 'add_api_key_column' ) ); | |
| 42 | - add_action( 'manage_sites_custom_column', array( $this, 'populate_api_key_column' ), 10, 2 ); | |
| 46 | + add_filter( 'manage_sites_action_links', array( self::class, 'add_action_link' ), 10, 2 ); | |
| 47 | + add_filter( 'wpmu_blogs_columns', array( self::class, 'add_site_id_column' ) ); | |
| 48 | + add_action( 'manage_sites_custom_column', array( $this, 'populate_site_id_column' ), 10, 2 ); | |
| 43 | 49 | } |
| 44 | 50 | |
| 45 | 51 | /** |
| 46 | - * Use the manage_sites_action_links filter to append a link to the settings page in the "row actions." | |
| 52 | + * Uses the manage_sites_action_links filter to append a link to the settings | |
| 53 | + * page in the "row actions". | |
| 47 | 54 | * |
| 48 | 55 | * @since 3.2.0 |
| 49 | 56 | * |
| 50 | - * @param array $actions The list of actions meant to be displayed for the current site's context in the row actions. | |
| 51 | - * @param int $_blog_id The blog ID for the current context. | |
| 52 | - * @return array The list of actions including ours. | |
| 57 | + * @param array<string, mixed> $actions The list of actions meant to be displayed for the current site's | |
| 58 | + * context in the row actions. | |
| 59 | + * @param int $_blog_id The blog ID for the current context. | |
| 60 | + * | |
| 61 | + * @return array<string, mixed> The list of actions including ours. | |
| 53 | 62 | */ |
| 54 | 63 | public static function add_action_link( array $actions, int $_blog_id ): array { |
| 55 | 64 | if ( ! current_user_can( Parsely::CAPABILITY ) ) { |
| 56 | 65 | return $actions; |
| @@ -66,9 +75,9 @@ | ||
| 66 | 75 | return $actions; |
| 67 | 76 | } |
| 68 | 77 | |
| 69 | 78 | /** |
| 70 | - * Generate ARIA label content. | |
| 79 | + * Generates ARIA label content. | |
| 71 | 80 | * |
| 72 | 81 | * @since 3.2.0 |
| 73 | 82 | * |
| 74 | 83 | * @param int $_blog_id Which sub-site to include in the ARIA label. |
| @@ -74,40 +83,42 @@ | ||
| 74 | 83 | * @param int $_blog_id Which sub-site to include in the ARIA label. |
| 75 | 84 | * @return string ARIA label content including the blogname. |
| 76 | 85 | */ |
| 77 | 86 | private static function generate_aria_label_for_blog_id( int $_blog_id ): string { |
| 78 | - $site = get_blog_details( $_blog_id ); | |
| 87 | + $site = get_blog_details( $_blog_id ); | |
| 88 | + $blogname = false === $site ? '' : $site->blogname; | |
| 79 | 89 | |
| 80 | 90 | return sprintf( |
| 81 | 91 | /* translators: blog name or blog id if empty */ |
| 82 | 92 | __( 'Go to Parse.ly stats for "%s"', 'wp-parsely' ), |
| 83 | - empty( $site->blogname ) ? $_blog_id : $site->blogname | |
| 93 | + '' === $blogname ? $_blog_id : $blogname | |
| 84 | 94 | ); |
| 85 | 95 | } |
| 86 | 96 | |
| 87 | 97 | /** |
| 88 | - * Use the wpmu_blogs_columns filter to register the column where we'll display the site's API Key (if configured). | |
| 98 | + * Uses the wpmu_blogs_columns filter to register the column where we'll | |
| 99 | + * display the site's Site ID (if configured). | |
| 89 | 100 | * |
| 90 | 101 | * @since 3.2.0 |
| 91 | 102 | * |
| 92 | - * @param array $sites_columns The list of columns meant to be displayed in the sites list table. | |
| 93 | - * @return array The list of columns to display in the network admin table including ours. | |
| 103 | + * @param array<string, mixed> $sites_columns The list of columns meant to be displayed in the sites list table. | |
| 104 | + * @return array<string, mixed> The list of columns to display in the network admin table including ours. | |
| 94 | 105 | */ |
| 95 | - public static function add_api_key_column( array $sites_columns ): array { | |
| 96 | - $sites_columns[ self::COLUMN_NAME ] = __( 'Parse.ly API Key', 'wp-parsely' ); | |
| 106 | + public static function add_site_id_column( array $sites_columns ): array { | |
| 107 | + $sites_columns[ self::COLUMN_NAME ] = __( 'Parse.ly Site ID', 'wp-parsely' ); | |
| 97 | 108 | return $sites_columns; |
| 98 | 109 | } |
| 99 | 110 | |
| 100 | 111 | /** |
| 101 | - * Use the manage_sites_custom_column action to output each site's API Key (if configured). | |
| 112 | + * Uses the manage_sites_custom_column action to output each site's Site ID | |
| 113 | + * (if configured). | |
| 102 | 114 | * |
| 103 | 115 | * @since 3.2.0 |
| 104 | 116 | * |
| 105 | 117 | * @param string $column_name The column name for the current context. |
| 106 | 118 | * @param int $_blog_id The blog ID for the current context. |
| 107 | - * @return void | |
| 108 | 119 | */ |
| 109 | - public function populate_api_key_column( string $column_name, int $_blog_id ): void { | |
| 120 | + public function populate_site_id_column( string $column_name, int $_blog_id ): void { | |
| 110 | 121 | if ( self::COLUMN_NAME !== $column_name ) { |
| 111 | 122 | return; |
| 112 | 123 | } |
| 113 | 124 | |
| @@ -112,14 +123,14 @@ | ||
| 112 | 123 | } |
| 113 | 124 | |
| 114 | 125 | // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog |
| 115 | 126 | switch_to_blog( $_blog_id ); |
| 116 | - $apikey = $this->parsely->get_api_key(); | |
| 127 | + $site_id = $this->parsely->get_site_id(); | |
| 117 | 128 | restore_current_blog(); |
| 118 | 129 | |
| 119 | - if ( strlen( $apikey ) > 0 ) { | |
| 120 | - echo esc_html( $apikey ); | |
| 130 | + if ( strlen( $site_id ) > 0 ) { | |
| 131 | + echo esc_html( $site_id ); | |
| 121 | 132 | } else { |
| 122 | - echo '<em>' . esc_html__( 'Parse.ly API key is missing', 'wp-parsely' ) . '</em>'; | |
| 133 | + echo '<em>' . esc_html__( 'Parse.ly Site ID is missing', 'wp-parsely' ) . '</em>'; | |
| 123 | 134 | } |
| 124 | 135 | } |
| 125 | 136 | } |