' . esc_html( $game['title'] ) . ''
: '';
}
/**
* Game iframe inside its sized frame, with the full screen button under it (shown by play.js where the browser
* allows full screen).
*
* With a poster the game waits for the visitor: the poster covers the frame and play.js loads the game on a click.
* Without JavaScript the copy inside noscript loads right away.
*
* @param string $src Iframe address, '' for an empty frame.
* @param string $title Accessible title.
* @param string $style Frame style from dicegem_frame_style().
* @param string $poster Poster markup from dicegem_poster(), '' to load the game at once.
* @return string HTML.
*/
function dicegem_frame( $src, $title, $style, $poster = '' ) {
$attrs = '="' . esc_url( $src ) . '" title="' . esc_attr( $title ) . '" loading="lazy" allow="fullscreen; autoplay" sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" allowfullscreen';
$inner = '' === $poster
? ''
: $poster . '';
return '
' . $inner . '
'
. '';
}
/**
* Poster shown in place of a game until the visitor presses Play.
*
* @param array $game Clean game.
* @return string HTML.
*/
function dicegem_poster( array $game ) {
return sprintf(
'',
/* translators: %s: game title. */
esc_attr( sprintf( __( 'Play %s', 'dicegem-games' ), $game['title'] ) ),
dicegem_cover( $game ),
esc_html__( 'Play', 'dicegem-games' )
);
}
/**
* Iframe address for a game, with the publisher ID when one is set.
*
* @param array $game Clean game.
* @return string URL.
*/
function dicegem_play_src( array $game ) {
$pub_id = dicegem_settings()['pub_id'];
return '' === $pub_id ? $game['play_url'] : add_query_arg( 'pub', $pub_id, $game['play_url'] );
}
/**
* Optional credit line; empty unless the site owner turned it on.
*
* @param string $href Link target on dicegem.com.
* @return string HTML.
*/
function dicegem_credit( $href ) {
if ( ! dicegem_settings()['credit'] ) {
return '';
}
return '
' . sprintf(
/* translators: %s: link to dicegem.com with the text "DiceGem". */
esc_html__( 'Play more free games on %s', 'dicegem-games' ),
'DiceGem'
) . '
' . esc_html__( 'Virtual credits only, no real money. 18+', 'dicegem-games' ) . '
';
}
/**
* A problem shown only to people who can edit posts; visitors see nothing.
*
* @param string $message Plain-text message.
* @return string HTML.
*/
function dicegem_editor_notice( $message ) {
return current_user_can( 'edit_posts' ) ? '
' . esc_html( $message ) . '
' : '';
}
/**
* Renders [dicegem game="slug"] and the dicegem/game block.
*
* @param array|string $atts Shortcode or block attributes: game, width, ratio.
* @param string $wrapper Attributes of the outer element.
* @return string HTML.
*/
function dicegem_render_game( $atts, $wrapper = 'class="dicegem-game"' ) {
$atts = shortcode_atts(
array(
'game' => '',
'width' => '',
'ratio' => '',
),
$atts,
'dicegem'
);
$slug = (string) $atts['game'];
$games = dicegem_games();
if ( ! isset( $games[ $slug ] ) ) {
$catalog = dicegem_catalog();
return dicegem_editor_notice(
isset( $catalog[ $slug ] )
? __( 'DiceGem: casino-style games are turned off in DiceGem Games > Settings.', 'dicegem-games' )
/* translators: %s: game slug. */
: sprintf( __( 'DiceGem: unknown game "%s".', 'dicegem-games' ), $slug )
);
}
$game = $games[ $slug ];
wp_enqueue_style( 'dicegem-games' );
wp_enqueue_script( 'dicegem-games-play' );
return '