$tests The registered tests. * * @return array */ public function tests( $tests ) { if ( ! is_array( $tests ) ) { return $tests; } $tests['direct']['sharelyai_connection'] = array( 'label' => __( 'Sharely connection', 'sharelyai' ), 'test' => array( $this, 'connection_test' ), ); return $tests; } /** * The test itself. * * Three outcomes, and the middle one matters most. Not connected is * `recommended` rather than `critical`: a plugin that has been installed * and not yet set up is not a broken site, and crying wolf on the Site * Health screen is how people learn to ignore it. Entries that failed to * sync are `recommended` too — search still works, it is just missing * pages, and the status screen names which. * * @return array */ public function connection_test(): array { $result = array( 'label' => __( 'Sharely is connected and your content is synced', 'sharelyai' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Sharely', 'sharelyai' ), 'color' => 'blue', ), 'description' => '', 'actions' => '', 'test' => 'sharelyai_connection', ); $screen = sprintf( '

%2$s

', esc_url( admin_url( 'options-general.php?page=sharelyai' ) ), esc_html__( 'Open the Sharely screen', 'sharelyai' ) ); if ( ! $this->connection->is_connected() ) { $result['status'] = 'recommended'; $result['label'] = __( 'Sharely is not connected', 'sharelyai' ); $result['description'] = '

' . esc_html__( 'Search and Ask are doing nothing until this site is connected to a Sharely workspace. WordPress search is answering on its own, exactly as it did before the plugin was installed.', 'sharelyai' ) . '

'; $result['actions'] = $screen; return $result; } $sync = new Sync( $this->connection ); $failed = count( $sync->failed_post_ids() ); if ( $failed > 0 ) { $result['status'] = 'recommended'; $result['label'] = __( 'Some pages could not be sent to Sharely', 'sharelyai' ); $result['description'] = '

' . sprintf( /* translators: %d: how many pages failed to sync. */ esc_html( _n( '%d page is missing from search because it could not be sent. Everything else is searchable.', '%d pages are missing from search because they could not be sent. Everything else is searchable.', $failed, 'sharelyai' ) ), (int) $failed ) . '

'; $result['actions'] = $screen; return $result; } $result['description'] = '

' . sprintf( /* translators: %d: how many pages are searchable. */ esc_html( _n( '%d page is searchable through Sharely.', '%d pages are searchable through Sharely.', count( $sync->synced_post_ids() ), 'sharelyai' ) ), count( $sync->synced_post_ids() ) ) . '

'; $result['actions'] = $screen; return $result; } /** * Adds the panel the Info tab shows, and support requests get pasted from. * * The workspace id is here because it is the first thing anybody helping * will ask for. The API key is not, in any form: this panel has a Copy * button next to it and people paste what it gives them into forums. * * @param array $info The registered panels. * * @return array */ public function information( $info ) { if ( ! is_array( $info ) ) { return $info; } $connected = $this->connection->is_connected(); $info['sharelyai'] = array( 'label' => __( 'Sharely', 'sharelyai' ), 'description' => __( 'How this site is connected to Sharely, and what it has sent.', 'sharelyai' ), 'fields' => array( 'connected' => array( 'label' => __( 'Connected', 'sharelyai' ), 'value' => $connected ? __( 'Yes', 'sharelyai' ) : __( 'No', 'sharelyai' ), 'debug' => $connected ? 'yes' : 'no', ), 'workspace' => array( 'label' => __( 'Workspace', 'sharelyai' ), 'value' => $connected ? $this->connection->workspace_id() : __( 'None', 'sharelyai' ), 'private' => true, ), 'api' => array( 'label' => __( 'Platform', 'sharelyai' ), 'value' => $this->connection->api_base(), ), 'credential' => array( // Whether there is a key, never the key. The question // worth answering here is "is one set", which is what // goes wrong, and that can be said without printing it. 'label' => __( 'API key', 'sharelyai' ), 'value' => '' !== $this->connection->api_key() ? __( 'Set', 'sharelyai' ) : __( 'Not set', 'sharelyai' ), 'debug' => '' !== $this->connection->api_key() ? 'set' : 'not set', ), 'synced' => array( 'label' => __( 'Pages sent', 'sharelyai' ), 'value' => (string) count( ( new Sync( $this->connection ) )->synced_post_ids() ), ), 'failed' => array( 'label' => __( 'Pages that failed', 'sharelyai' ), 'value' => (string) count( ( new Sync( $this->connection ) )->failed_post_ids() ), ), 'post_types' => array( 'label' => __( 'Post types in scope', 'sharelyai' ), 'value' => implode( ', ', $this->connection->post_types() ), ), 'queue' => array( // The difference between "runs when you edit a page" and // "runs when somebody next visits the site", which is the // answer to most "why has nothing synced" questions. 'label' => __( 'Background queue', 'sharelyai' ), 'value' => Queue::has_action_scheduler() ? __( 'Action Scheduler', 'sharelyai' ) : __( 'WP-Cron (install Action Scheduler for a quiet site)', 'sharelyai' ), ), 'abilities' => array( 'label' => __( 'Abilities API', 'sharelyai' ), 'value' => Abilities::available() ? __( 'Available — search and ask are registered', 'sharelyai' ) : __( 'Not in this WordPress (needs 6.9)', 'sharelyai' ), ), 'plugin_version' => array( 'label' => __( 'Plugin version', 'sharelyai' ), 'value' => VERSION, ), ), ); return $info; } }