plugin = $plugin;
}
/**
* Renders the page for the channel in the "channel" query argument (default: the default channel).
*/
public function render(): void {
if ( ! current_user_can( Plugin::CAPABILITY ) ) {
return;
}
$channels = $this->plugin->channels();
$channel = $this->plugin->requested_channel();
$label = $channel->label();
$steps = $channel->connect_steps();
$current = $this->current_step( $steps );
wp_register_script( 'tidelist-connect', '', array(), TIDELIST_VERSION, true );
wp_enqueue_script( 'tidelist-connect' );
wp_add_inline_script( 'tidelist-connect', self::copy_script() );
?>
all() ) > 1 ) : ?>
all() as $id => $other ) : ?>
label() ); ?>
$step ) : ?>
open_step( $index + 1, (string) $step['title'], $index < $current ? 'done' : ( $index === $current ? 'current' : 'todo' ) ); ?>
render_step( $channel, $step ); ?>
close_step(); ?>
$step ) {
if ( empty( $step['done'] ) ) {
return $index;
}
}
return count( $steps );
}
/**
* Draws the body of one step.
*
* @param ChannelInterface $channel Channel.
* @param array $step Step.
*/
private function render_step( ChannelInterface $channel, array $step ): void {
switch ( (string) $step['type'] ) {
case 'choice':
$this->render_choice( $channel, $step );
break;
case 'guide':
$this->render_guide( $step );
break;
case 'fields':
$this->render_fields( $channel, $step );
break;
case 'oauth':
$this->render_oauth( $channel, $step );
break;
case 'status':
$this->render_status( $channel, $step );
break;
}
}
/**
* A select over the channel's countries (or another set of options) saved on its own.
*
* @param ChannelInterface $channel Channel.
* @param array $step Step.
*/
private function render_choice( ChannelInterface $channel, array $step ): void {
$field = ChannelFields::fields( $channel, array( (string) $step['field'] ) );
?>
$item ) : ?>
-
' . esc_html( (string) $item['link']['label'] ) . '';
echo wp_kses(
sprintf( esc_html( (string) $item['text'] ), $link ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
);
} else {
echo esc_html( (string) $item['text'] );
}
if ( ! empty( $item['copy'] ) ) :
$id = 'tidelist-copy-' . $step['id'] . '-' . $n;
?>
connection();
?>
button( $channel, Actions::OAUTH_START, $connection->connected ? (string) $step['reconnect_label'] : (string) $step['connect_label'], $connection->connected ? 'button' : 'button button-primary', $connection->has_credentials ); ?>
redirect_uri() ) ) : ?>
label() ) ); ?>
connection();
if ( ! $connection->connected ) {
echo '' . esc_html__( 'Not connected yet.', 'tidelist' ) . '
';
return;
}
?>
account_name ? $connection->account_name : '?' ); ?>
is_business ) {
echo ' · ' . esc_html( $connection->is_business ? __( 'Business account', 'tidelist' ) : __( 'Private account', 'tidelist' ) );
}
?>
is_business && ! empty( $step['business_note'] ) ) : ?>
button( $channel, Actions::TEST, __( 'Test connection (read-only)', 'tidelist' ) ); ?>
button( $channel, Actions::DISCONNECT, __( 'Disconnect', 'tidelist' ) ); ?>
'✓',
'current' => '→',
'todo' => '',
);
?>
';
}
/**
* A one-button POST form with a nonce.
*
* @param ChannelInterface $channel Channel the button acts on.
* @param string $action Action (also the nonce action).
* @param string $label Label.
* @param string $css_class CSS classes.
* @param bool $enabled Whether the button can be pressed.
*/
private function button( ChannelInterface $channel, string $action, string $label, string $css_class = 'button', bool $enabled = true ): void {
?>