12, 'headers' => array( 'Content-Type' => 'application/json', 'X-PressNative-Api-Key' => trim( $auth_key ), ), 'body' => wp_json_encode( array( 'site_url' => $site_url, ) ), ) ); if ( is_wp_error( $response ) ) { return null; } $code = (int) wp_remote_retrieve_response_code( $response ); if ( $code < 200 || $code >= 300 ) { return null; } $data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! is_array( $data ) || empty( $data['url'] ) || ! is_string( $data['url'] ) ) { return null; } return $data['url']; } /** * Allowed HTML and SVG elements for wp_kses() in shortcode output. * * @return array */ private static function get_allowed_html() { return array( 'div' => array( 'class' => true, 'style' => true, ), 'a' => array( 'href' => true, 'target' => true, 'rel' => true, ), 'p' => array( 'class' => true, 'style' => true, ), 'svg' => array( 'xmlns' => true, 'viewbox' => true, 'width' => true, 'height' => true, 'role' => true, 'aria-label' => true, 'focusable' => true, ), 'rect' => array( 'x' => true, 'y' => true, 'width' => true, 'height' => true, 'fill' => true, ), ); } /** * Render the shortcode output. * * @param array $atts Shortcode attributes. * @param string $content Enclosed content (ignored). * @return string */ public static function render( $atts, $content = '' ) { $atts = shortcode_atts( array( 'size' => 200, 'label' => __( 'Open in App', 'pressnative-apps' ), ), $atts, self::SHORTCODE_TAG ); $size = max( 50, min( 800, absint( $atts['size'] ) ) ); $label = sanitize_text_field( $atts['label'] ); $encoder = PRESSNATIVE_PLUGIN_DIR . 'lib/QrEncoder.php'; if ( ! class_exists( 'PressNative_QR_Encoder', false ) ) { if ( ! is_readable( $encoder ) ) { return ''; } require_once $encoder; } $deep_link = self::get_deep_link_url(); $svg = PressNative_QR_Encoder::to_svg( $deep_link, 'qrm' ); // Add width/height so SVG scales to desired size. $svg = preg_replace( '/'; $html .= $svg; $html .= ''; if ( '' !== $label ) { $html .= '

' . esc_html( $label ) . '

'; $html .= '

Tap QR code or click here to open in app

'; } $html .= ''; return wp_kses( $html, self::get_allowed_html() ); } }