/** * Plugin bootstrap file * * Plugin Name: FNT Fantogame Classifica * Plugin URI: https://www.fantogame.it * Description: Classifica ajax - Supporta Polylang e Classifica Generale * Version: 1.1 * Author: Fantogame * Author URI: https://www.fantogame.it * Text Domain: classifica_ajax */ function create_classifica_shortcode($atts) { // --- 1. Handle Attributes & Defaults --- $atts = shortcode_atts( array( 'gioco' => '', // Optional: Game slug/ID passed directly 'classifica' => '', // Defaults to General view ("") 'posizione' => '0', // Default position/container ID 'posizione_di_classifica' => '0', // Default page position ID ), $atts, 'classifica' ); $gioco = $atts['gioco']; $classifica = $atts['classifica']; $posizione = $atts['posizione']; $posizione_di_pagina_classifica = $atts['posizione_di_classifica']; // --- 2. Polylang & Game ID Retrieval --- // Get current language code (assuming Polylang function is available) $current_language = function_exists('pll_current_language') ? pll_current_language() : 'it'; // Get Game ID from current post meta, if not provided in attributes $game_id_meta = get_post_meta(get_the_ID(), '_gioco_id', true); // Determine the final game identifier: prioritize attribute, fallback to meta $final_gioco = !empty($gioco) ? esc_attr($gioco) : (int)$game_id_meta; // --- 3. Initial Display Logic Check --- // Check if the request parameter is missing or not one of the recognized types $request_classifica = isset($_REQUEST["classifica"]) ? $_REQUEST["classifica"] : ''; // If the shortcode is used on a page that shouldn't show the widget (and no specific view is requested) if (empty($request_classifica) && $posizione_di_pagina_classifica == 1) { return ""; } // Handle cases where a specific view IS requested, but the default general view (empty string) was passed to the shortcode. if ($request_classifica != "1" && $request_classifica != "1a" && empty($classifica) && $posizione_di_pagina_classifica == 1) { // If the shortcode itself is empty, but the request is for something else, show the general view. } // --- 4. HTML & JavaScript Generation (Heredoc) --- $html = <<< aaa

Classifica {$current_language}

aaa; return $html; } add_shortcode( 'classifica', 'create_classifica_shortcode' );