$m[2], 'sub' => isset( $m[3] ) ? $m[3] : '', 'lang' => leaguemakerapp_normalize_language( $m[1] ), 'view' => isset( $query['view'] ) && is_string( $query['view'] ) ? $query['view'] : '', 'theme' => isset( $query['theme'] ) && is_string( $query['theme'] ) ? $query['theme'] : '', 'token' => $token, ); } /** * Builds the iframe for a LeagueMakerApp link. Explicit attributes win over * what the link carries; the language falls back to the site's. * * @param array $atts url, view, theme, height, lang. * @return string HTML, or '' (a notice for editors) if the link is not valid. */ function leaguemakerapp_render( $atts ) { $atts = wp_parse_args( $atts, array( 'url' => '', 'view' => '', 'theme' => '', 'height' => 520, 'lang' => '', ) ); $parsed = leaguemakerapp_parse_url( $atts['url'] ); if ( ! $parsed ) { if ( current_user_can( 'edit_posts' ) && '' !== trim( (string) $atts['url'] ) ) { return '

' . esc_html__( 'LeagueMakerApp: this is not a competition link. Copy it from your competition page on leaguemakerapp.com.', 'leaguemakerapp' ) . '

'; } return ''; } $lang = leaguemakerapp_normalize_language( $atts['lang'] ); if ( '' === $lang ) { $lang = '' !== $parsed['lang'] ? $parsed['lang'] : leaguemakerapp_normalize_language( determine_locale() ); } $prefix = ( '' === $lang || 'en' === $lang ) ? '' : '/' . $lang; $page = LEAGUEMAKERAPP_BASE_URL . '/competitions/' . $parsed['slug'] . $parsed['sub']; $args = array(); $view = '' !== $atts['view'] ? $atts['view'] : $parsed['view']; // Only the competition embed has views; match/team/player embeds don't. if ( '' === $parsed['sub'] && in_array( $view, leaguemakerapp_views(), true ) && 'standings' !== $view ) { $args['view'] = $view; } $theme = '' !== $atts['theme'] ? $atts['theme'] : $parsed['theme']; if ( 'light' === $theme || 'dark' === $theme ) { $args['theme'] = $theme; } if ( '' !== $parsed['token'] ) { $args['token'] = $parsed['token']; } $src = add_query_arg( $args, LEAGUEMAKERAPP_BASE_URL . $prefix . '/competitions/' . $parsed['slug'] . $parsed['sub'] . '/embed' ); $height = min( 3000, max( 200, absint( $atts['height'] ) ) ); $html = sprintf( '', esc_url( $src ), esc_attr( sprintf( /* translators: %s: competition identifier */ __( 'LeagueMakerApp: %s', 'leaguemakerapp' ), $parsed['slug'] ) ), $height ); // wordpress.org guideline 10: credit links only if the site owner opts in. if ( get_option( 'leaguemakerapp_show_credit', false ) ) { $html .= sprintf( '

%2$s

', esc_url( $page ), esc_html__( 'Powered by LeagueMakerApp', 'leaguemakerapp' ) ); } return '
' . $html . '
'; } /** * [leaguemakerapp url="https://leaguemakerapp.com/competitions/my-league" view="fixtures" theme="dark" height="600" lang="es"] * * @param array|string $atts Shortcode attributes. * @return string */ function leaguemakerapp_shortcode( $atts ) { $atts = shortcode_atts( array( 'url' => '', 'view' => '', 'theme' => '', 'height' => 520, 'lang' => '', ), $atts, 'leaguemakerapp' ); return leaguemakerapp_render( $atts ); } add_shortcode( 'leaguemakerapp', 'leaguemakerapp_shortcode' ); /** * Pasting a competition link on its own line (classic editor) or in an Embed * block turns it into the widget, like a YouTube link. */ function leaguemakerapp_register_embed_handler() { wp_embed_register_handler( 'leaguemakerapp', '#^https?://(?:www\.)?leaguemakerapp\.com/(?:[a-z]{2}(?:-[a-z]{2})?/)?competitions/[a-z0-9_-]+(?:/(?:matches|teams|players)/\d+)?(?:/embed)?/?(?:\?\S*)?$#i', 'leaguemakerapp_embed_handler' ); } add_action( 'init', 'leaguemakerapp_register_embed_handler' ); /** * Callback for wp_embed_register_handler(). * * @param array $matches Regex matches. * @param array $attr Embed attributes. * @param string $url Original URL. * @return string */ function leaguemakerapp_embed_handler( $matches, $attr, $url ) { return leaguemakerapp_render( array( 'url' => $url ) ); } /** * Block "LeagueMakerApp" (server-rendered, no build step). */ function leaguemakerapp_register_block() { register_block_type( __DIR__ . '/blocks/embed', array( 'render_callback' => 'leaguemakerapp_render_block' ) ); } add_action( 'init', 'leaguemakerapp_register_block' ); /** * Render callback of the block. * * @param array $attributes Block attributes. * @return string */ function leaguemakerapp_render_block( $attributes ) { return leaguemakerapp_render( $attributes ); } /** * Settings → LeagueMakerApp: opt-in credit link. */ function leaguemakerapp_register_settings() { register_setting( 'leaguemakerapp', 'leaguemakerapp_show_credit', array( 'type' => 'boolean', 'default' => false, 'sanitize_callback' => 'rest_sanitize_boolean', ) ); } add_action( 'admin_init', 'leaguemakerapp_register_settings' ); /** * Adds the settings page. */ function leaguemakerapp_admin_menu() { add_options_page( 'LeagueMakerApp', 'LeagueMakerApp', 'manage_options', 'leaguemakerapp', 'leaguemakerapp_settings_page' ); } add_action( 'admin_menu', 'leaguemakerapp_admin_menu' ); /** * Renders the settings page. */ function leaguemakerapp_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>

LeagueMakerApp

  1. [leaguemakerapp url="https://leaguemakerapp.com/competitions/my-league" view="fixtures" theme="light" height="600"]

' . esc_html__( 'Settings', 'leaguemakerapp' ) . '' ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'leaguemakerapp_action_links' );