tag): they carry the usual «leave me alone» attributes and are added * to the exclusion lists of WP Rocket and LiteSpeed Cache below. They set no cookie, so they are marked as necessary for consent tools. * * @package Fipeo */ if ( ! defined( 'ABSPATH' ) ) { exit; } add_action( 'init', 'fipeo_register_shortcodes' ); function fipeo_register_shortcodes() { add_shortcode( 'fipeo_booking', 'fipeo_sc_booking' ); add_shortcode( 'fipeo_assistant', 'fipeo_sc_assistant' ); add_shortcode( 'fipeo_reviews', 'fipeo_sc_reviews' ); add_shortcode( 'fipeo_placement_test', 'fipeo_sc_placement_test' ); add_shortcode( 'fipeo_agents_button', 'fipeo_sc_agents_button' ); add_shortcode( 'fipeo_student_app', 'fipeo_sc_student_app' ); // version 1: [fipeo_widget key="w…"] keeps working, with or without a Fipeo key in the settings add_shortcode( 'fipeo_widget', 'fipeo_sc_widget_v1' ); } /** A note only editors see when a piece cannot be shown (visitors see nothing). */ function fipeo_note( $id ) { if ( ! current_user_can( 'edit_posts' ) ) { return ''; } $names = array( 'booking' => __( 'Prices and booking', 'fipeo' ), 'assistant' => __( 'Assistant', 'fipeo' ), 'reviews' => __( 'Reviews', 'fipeo' ), 'placement_test' => __( 'Placement test', 'fipeo' ), 'agents' => __( 'Agents button', 'fipeo' ), 'student_app' => __( 'Student app', 'fipeo' ), ); return '
' . esc_html( sprintf( /* translators: %s: the name of the piece, for example «Reviews» */ __( 'Fipeo: «%s» is not shown here. Check Settings > Fipeo (only editors see this note).', 'fipeo' ), isset( $names[ $id ] ) ? $names[ $id ] : $id ) ) . '
'; } function fipeo_enqueue_style() { wp_enqueue_style( 'fipeo', FIPEO_URL . 'assets/fipeo.css', array(), FIPEO_VERSION ); } function fipeo_enqueue_embed() { wp_enqueue_script( 'fipeo-embed', fipeo_origin() . '/w/embed.js', array(), FIPEO_VERSION, true ); } /** A button-like link. $extra: classes. */ function fipeo_button( $url, $text, $extra = '' ) { fipeo_enqueue_style(); return '' . esc_html( $text ) . ''; } /** [fipeo_booking height="640" lang="es"]: live prices, booking request and, if switched on, «Book and pay online». */ function fipeo_sc_booking( $atts ) { $a = shortcode_atts( array( 'height' => '640', 'lang' => '', 'label' => '' ), $atts, 'fipeo_booking' ); $p = fipeo_piece( 'booking' ); if ( null === $p ) { return fipeo_note( 'booking' ); } $lang = fipeo_attr_lang( $a['lang'] ); $height = max( 200, min( 4000, (int) $a['height'] ) ); fipeo_enqueue_embed(); fipeo_enqueue_style(); $o = '' . fipeo_button( $p['pay_online_url'], '' !== $a['label'] ? $a['label'] : fipeo_label( 'pay', $lang ), 'fipeo-btn-main' ) . '
'; } return $o . '' . fipeo_button( $p['url'], '' !== $a['label'] ? $a['label'] : fipeo_label( 'test', $lang ), 'fipeo-btn-main' ) . '
'; if ( '0' !== (string) $a['note'] ) { $o .= '' . esc_html( fipeo_label( 'test_note', $lang ) ) . '
'; } return $o . '' . fipeo_button( fipeo_agents_url( $p, $lang ), $text ) . '
'; } /** [fipeo_student_app]: the student app (bookings, payments, documents, messages, placement test). */ function fipeo_sc_student_app( $atts ) { $a = shortcode_atts( array( 'label' => '', 'lang' => '' ), $atts, 'fipeo_student_app' ); $p = fipeo_piece( 'student_app' ); if ( null === $p ) { return fipeo_note( 'student_app' ); } $lang = fipeo_attr_lang( $a['lang'] ); return '' . fipeo_button( $p['url'], '' !== $a['label'] ? $a['label'] : fipeo_label( 'app', $lang ) ) . '
'; } /** Version 1 of the plugin: [fipeo_widget key="w…" lang="es" height="640"]. */ function fipeo_sc_widget_v1( $atts ) { $a = shortcode_atts( array( 'key' => '', 'lang' => '', 'height' => '640' ), $atts, 'fipeo_widget' ); $key = (string) $a['key']; if ( '' === $key ) { return fipeo_sc_booking( array( 'lang' => $a['lang'], 'height' => $a['height'] ) ); } if ( ! preg_match( '/^w[A-Za-z0-9]{31}$/', $key ) ) { return current_user_can( 'edit_posts' ) ? '' . esc_html__( 'Fipeo widget: check the key in the shortcode.', 'fipeo' ) . '
' : ''; } fipeo_enqueue_embed(); return ''; } /** The language given in a shortcode (one of Fipeo's six), or the one of the page. */ function fipeo_attr_lang( $lang ) { $lang = strtolower( substr( (string) $lang, 0, 2 ) ); return in_array( $lang, array( 'en', 'es', 'fr', 'it', 'de', 'pt' ), true ) ? $lang : fipeo_lang(); } /** Without the school's own portal the link goes to the agencies' sign-up in Fipeo, in the language of the page. */ function fipeo_agents_url( $p, $lang ) { if ( ! $p['portal'] ) { return (string) preg_replace( '#/en/register$#', '/' . $lang . '/register', $p['url'] ); } return $p['url']; } /** The floating assistant: one