Piazza in Festa). * * One field only: the optional service key. The plugin does everything it can * do without it; the key just lets the service serve the widget without the * small Piazza in Festa credit line at the bottom. * * @package PiazzaInFesta */ defined( 'ABSPATH' ) || exit; /** * Reads one saved option. * * @param string $key Option key. * @return string Empty string when unset. */ function pinfesta_get_option( $key ) { $options = get_option( 'pinfesta_options', array() ); if ( ! is_array( $options ) || ! isset( $options[ $key ] ) ) { return ''; } return (string) $options[ $key ]; } /** * Registers the setting and its field. * * @return void */ function pinfesta_register_settings() { register_setting( 'pinfesta_settings', 'pinfesta_options', array( 'type' => 'array', 'sanitize_callback' => 'pinfesta_sanitize_options', 'default' => array(), ) ); add_settings_section( 'pinfesta_section', '', '__return_false', 'piazza-in-festa' ); add_settings_field( 'pinfesta_chiave', esc_html__( 'Service key', 'piazza-in-festa' ), 'pinfesta_field_chiave', 'piazza-in-festa', 'pinfesta_section' ); } add_action( 'admin_init', 'pinfesta_register_settings' ); /** * Sanitises the saved options. * * @param mixed $input Raw value coming from the form. * @return array */ function pinfesta_sanitize_options( $input ) { $out = array(); if ( is_array( $input ) && isset( $input['chiave'] ) ) { // Keys are hexadecimal strings; anything else is not a key. $chiave = preg_replace( '/[^a-zA-Z0-9]/', '', (string) $input['chiave'] ); $out['chiave'] = substr( (string) $chiave, 0, 128 ); } return $out; } /** * Prints the key field. * * @return void */ function pinfesta_field_chiave() { printf( '', esc_attr( pinfesta_get_option( 'chiave' ) ) ); echo '
' . esc_html__( 'Optional. Leave it empty and the widget works anyway, with a small credit line at the bottom.', 'piazza-in-festa' ) . '
'; } /** * Adds the menu entry. * * @return void */ function pinfesta_admin_menu() { add_options_page( esc_html__( 'Piazza in Festa', 'piazza-in-festa' ), esc_html__( 'Piazza in Festa', 'piazza-in-festa' ), 'manage_options', 'piazza-in-festa', 'pinfesta_settings_page' ); } add_action( 'admin_menu', 'pinfesta_admin_menu' ); /** * Prints the settings page. * * @return void */ function pinfesta_settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } ?>
[piazza-in-festa comuni="alba,barolo,la-morra" limite="5"]
' . esc_html( pinfesta_base_url() . '/widget' ) . '' ); ?>