plugin = $plugin; } /** * Renders the page. */ public function render(): void { if ( ! current_user_can( Plugin::CAPABILITY ) ) { return; } $settings = $this->plugin->settings(); $values = $settings->all(); $channels = $this->plugin->channels()->all(); $label = $this->plugin->channel()->label(); ?>

plugin ); ?>

render_status( $settings, $channels ); ?> plugin->job_monitor() ); ?>

button( Actions::TOGGLE_PAUSE, $settings->is_paused() ? __( 'Resume', 'tidelist' ) : __( 'Pause everything', 'tidelist' ), $settings->is_paused() ? 'button button-primary' : 'button' ); foreach ( $channels as $channel ) { $this->render_connection_buttons( $channel ); } ?>

render_paste_card( $channel ); ?>

label() ) ); ?>

label() ) ); ?>

settings_schema() ) as $heading => $fields ) : ?>

id() ); ?>

label(); if ( $channel->is_connected() ) { $this->button( Actions::OAUTH_START, Text::channel( __( 'Reconnect {channel} account', 'tidelist' ), $label ), 'button', $channel ); $this->button( Actions::DISCONNECT, Text::channel( __( 'Disconnect {channel}', 'tidelist' ), $label ), 'button', $channel ); } else { $this->button( Actions::OAUTH_START, Text::channel( __( 'Connect {channel} account', 'tidelist' ), $label ), 'button button-primary', $channel ); } $this->button( Actions::TEST, Text::channel( __( 'Test {channel} connection (read-only)', 'tidelist' ), $label ), 'button', $channel ); } /** * The "paste the address" card for a site the marketplace cannot return to (a local copy). * * @param ChannelInterface $channel Channel. */ private function render_paste_card( ChannelInterface $channel ): void { if ( ! Actions::needs_paste( $channel->redirect_uri() ) || ( $channel->is_connected() && ! Actions::connect_pending() ) ) { return; } ?>

label() ) ); ?>

label() ) ); ?>

$channels Channels. */ private function render_status( Settings $settings, array $channels ): void { $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); $label = $this->plugin->channel()->label(); $rows = array( __( 'Mode', 'tidelist' ) => $settings->is_dry_run() ? $this->badge( Text::channel( __( 'DRY-RUN – nothing that changes {channel} is sent', 'tidelist' ), $label ), '#00a32a' ) : $this->badge( __( 'LIVE – adverts can be published', 'tidelist' ), '#d63638' ), __( 'Pause switch', 'tidelist' ) => $settings->is_paused() ? $this->badge( Text::channel( __( 'PAUSED – no calls to {channel}', 'tidelist' ), $label ), '#dba617' ) : esc_html__( 'Running', 'tidelist' ), ); foreach ( $channels as $channel ) { $name = $channel->label(); $connection = $channel->connection(); if ( $connection->secret_unreadable ) { $credentials = __( 'cannot be decrypted – please enter it again', 'tidelist' ); } elseif ( $connection->has_credentials ) { $credentials = __( 'saved (encrypted)', 'tidelist' ); } else { $credentials = __( 'missing', 'tidelist' ); } $rows[ Text::channel( __( '{channel} application', 'tidelist' ), $name ) ] = esc_html( $credentials ); $rows[ Text::channel( __( '{channel} account', 'tidelist' ), $name ) ] = $connection->connected ? esc_html( sprintf( /* translators: 1: account name, 2: date */ __( 'Connected as %1$s (since %2$s)', 'tidelist' ), '' !== $connection->account_name ? $connection->account_name : '?', $connection->connected_at ? wp_date( $format, $connection->connected_at ) : '?' ) ) : esc_html__( 'Not connected', 'tidelist' ); if ( $connection->connected && $connection->expires_at ) { $rows[ Text::channel( __( '{channel} connection valid until', 'tidelist' ), $name ) ] = esc_html( wp_date( $format, $connection->expires_at ) . ' ' . __( '(renewed automatically every day)', 'tidelist' ) ); } $rows[ Text::channel( __( '{channel} API cooldown', 'tidelist' ), $name ) ] = $connection->cooldown_until > time() ? esc_html( sprintf( /* translators: %s: time */ Text::channel( __( 'Paused by {channel} throttling until %s', 'tidelist' ), $name ), wp_date( $format, $connection->cooldown_until ) ) ) : esc_html__( 'None', 'tidelist' ); } ?> $html ) : ?>
%2$s', esc_attr( $color ), esc_html( $text ) ); } /** * A one-button POST form with a nonce. * * @param string $action Action name (also the nonce action). * @param string $label Button label. * @param string $css_class CSS classes. * @param ChannelInterface|null $channel Channel the button acts on (none for a global button). */ private function button( string $action, string $label, string $css_class = 'button', ?ChannelInterface $channel = null ): void { ?>