shortcode_name, [$this, 'shortcode'] ); add_action( 'wp_enqueue_scripts', [$this, 'scripts'] ); add_action('admin_menu', [$this, 'admin']); } public function admin(){ add_menu_page( 'Agenda in Cloud', 'Agenda in Cloud', 'manage_options', 'agenda-in-cloud', [$this,'admin_init'] ); } public function admin_init(){ $html = "

Agenda in Cloud

"; $html .= "

Agenda in Cloud wordpress plugin v".$this->version."

"; $html .= "

Hai installato correttamente il plugin di Agenda in Cloud per wordpress.
Collegati alla tua Agenda in Cloud per trovare le istruzioni di utilizzo e per creare i tuoi shortcodes da inserire nel sito.

vai ad Agenda in Cloud

"; echo $html; } public function shortcode( $atts ) { extract(shortcode_atts(array( "organization" => "agendaincloud", "mode" => "workweek", "day" => date('Y-m-d'), "booking" => "false", "showoperator" => "false", "showstructure" => "false" ), $atts)); $response = wp_remote_get( "https://www.agendaincloud.it/api/v1/0/public/agenda/courses/".$atts['organization']."/".$atts['mode']."/".$atts['day'] ); $body = wp_remote_retrieve_body( $response ); $groups = json_decode($body); function cmp($a, $b) { return strcmp($a->from, $b->from); } $result = "
"; foreach($groups as $group => $bookings){ $result .= "
".$group."
"; $sorted = usort($bookings, function($a, $b) {return strcmp($a->from, $b->from);}); foreach($bookings as $booking){ if($atts["booking"] === "true"){ $result .= ""; }else{ $result .= ""; } } $result .= "
"; } $result .= "
"; $result .= ""; return $result; } public function scripts() { global $post; // Only enqueue scripts if we're displaying a post that contains the shortcode if( has_shortcode( $post->post_content, $this->shortcode_name ) ) { wp_enqueue_style( 'agenda-in-cloud', plugin_dir_url( __FILE__ ) . 'css/agenda-in-cloud.css', [], '0.1' ); } } } (new AgendaInCloud())->register(); } ?>