'--alpl-bg',
'textColor' => '--alpl-text',
'accentColor' => '--alpl-accent',
'barBgColor' => '--alpl-bar-bg',
'borderColor' => '--alpl-border',
) as $alpl_attr => $alpl_var ) {
$alpl_color = ALPL_Poll\Block::color( $attributes[ $alpl_attr ] ?? '' );
if ( $alpl_color ) {
$alpl_style .= $alpl_var . ':' . $alpl_color . ';';
}
}
$alpl_config = array(
'id' => $alpl['id'],
'api' => rest_url( ALPL_Poll\Rest::NS . '/' ),
// only logged-in visitors get a nonce, page caches skip their pages
'nonce' => is_user_logged_in() ? wp_create_nonce( 'wp_rest' ) : '',
// view.js adds the page the visitor is on, the poll may be in a template shown on many pages
'login' => wp_login_url(),
'multiple' => $alpl['multiple'],
'max' => $alpl['max'],
'showResults' => $alpl['showResults'],
'format' => $alpl['format'],
'showTotal' => $alpl['showTotal'],
);
$alpl_class = 'alpl_poll' . ( $alpl['animate'] ? ' alpl_animate' : '' ) . ( ALPL_Poll\Block::color( $attributes['accentColor'] ?? '' ) ? ' alpl_has_accent' : '' );
$alpl_qid = wp_unique_id( 'alpl_q_' );
$alpl_hid = wp_unique_id( 'alpl_h_' );
$alpl_has_q = '' !== trim( wp_strip_all_tags( $alpl['question'] ) );
if ( $alpl['multiple'] ) {
$alpl_hint = $alpl['max'] < count( $alpl['options'] )
/* translators: %d: how many answers a visitor may pick */
? sprintf( _n( 'Choose up to %d answer.', 'Choose up to %d answers.', $alpl['max'], 'softicon-poll' ), $alpl['max'] )
: __( 'Choose one or more answers.', 'softicon-poll' );
}
$alpl_meta = '';
if ( ! ALPL_Poll\Block::is_open( $alpl ) ) {
$alpl_meta = __( 'This poll is closed.', 'softicon-poll' );
} elseif ( $alpl['endDate'] ) {
/* translators: %s: the date and time the poll closes */
$alpl_meta = sprintf( __( 'Voting ends on %s.', 'softicon-poll' ), wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $alpl['endDate']->getTimestamp() ) );
}
$alpl_wrapper = get_block_wrapper_attributes(
array(
'class' => $alpl_class,
'style' => $alpl_style,
// hex flags keep quotes and ampersands from breaking the attribute or JSON.parse
'data-alpl' => wp_json_encode( $alpl_config, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ),
)
);
$alpl_label = function ( $option, $index ) {
$image = ALPL_Poll\Block::image( $option['image'] );
if ( $image ) {
echo '';
}
// an image without text or alt still gives screen readers a name for the answer
if ( '' === trim( wp_strip_all_tags( $option['text'] ) ) && ( ! $image || '' === $image['alt'] ) ) {
/* translators: %d: the answer's position, like 1 */
echo '' . esc_html( sprintf( __( 'Answer %d', 'softicon-poll' ), $index + 1 ) ) . '';
return;
}
echo '' . wp_kses(
$option['text'],
array(
'strong' => array(),
'em' => array(),
'b' => array(),
'i' => array(),
)
) . '';
};
?>