Edit Template

Dodaj tu swój tekst nagłówka

/* Plugin Name: Font Clamp Calculator Description: Adds a Font Clamp Calculator to the WordPress admin dashboard for generating responsive font sizes with persistent data. Version: 1.2 */// Prevent direct access to the file if (!defined('ABSPATH')) { exit; }// Add menu item to the WordPress admin dashboard function font_clamp_calculator_menu() { add_menu_page( 'Font Clamp Calculator', // Page title 'Font Clamp', // Menu title 'manage_options', // Capability required 'font-clamp-calculator', // Menu slug 'font_clamp_calculator_page', // Callback function to display the page 'dashicons-editor-textcolor', // Icon (using a WordPress dashicon) 80 // Menu position ); } add_action('admin_menu', 'font_clamp_calculator_menu');// Callback function to render the Font Clamp Calculator page function font_clamp_calculator_page() { // Load saved settings $settings = get_option('font_clamp_settings', [ 'rootSize' => 16, 'minViewport' => 375, 'maxViewport' => 1100, 'unitType' => 'px', 'selectedSizeId' => 6 ]); ?>

Font Clamp Calculator

Settings

Font Size Classes

Class NameMin SizeMax Size

Preview

Selected Class CSS

Generated CSS (All Classes)

16, 'minViewport' => 375, 'maxViewport' => 1920, 'unitType' => 'px', 'selectedSizeId' => 6 ]);// Render the same UI as the admin page font_clamp_calculator_page();return ob_get_clean(); }// Enqueue Tailwind CSS when shortcode is used on the frontend add_action('wp_enqueue_scripts', 'enqueue_font_clamp_tailwind_frontend'); function enqueue_font_clamp_tailwind_frontend() { if (is_singular()) { global $post; if (has_shortcode($post->post_content, 'font_clamp_calculator')) { wp_enqueue_script('font-clamp-tailwind', 'https://cdn.tailwindcss.com', [], null, true); } } }
/* Plugin Name: Font Clamp Calculator Description: Adds a Font Clamp Calculator to the WordPress admin dashboard with Class, Tag, and Scale tabs for generating responsive font sizes with persistent data. Includes options to use custom WOFF2 fonts for previews. Version: 2.2 */// Prevent direct access to the file if (!defined('ABSPATH')) { exit; }// Add menu item to the WordPress admin dashboard function font_clamp_calculator_menu() { add_menu_page( 'Font Clamp Calculator', 'Font Clamp', 'manage_options', 'font-clamp-calculator', 'font_clamp_calculator_page', 'dashicons-editor-textcolor', 80 ); } add_action('admin_menu', 'font_clamp_calculator_menu');// Callback function to render the Font Clamp Calculator page function font_clamp_calculator_page() { // Load saved settings $settings = get_option('font_clamp_settings', [ 'rootSize' => 16, 'minViewport' => 375, 'maxViewport' => 1100, 'unitType' => 'px', 'selectedClassSizeId' => 6, 'selectedTagSizeId' => 1, 'selectedScaleSizeId' => 7, 'activeTab' => 'class', 'scalePMinFont' => 16, 'scalePMaxFont' => 16, 'scaleRatioMin' => 1.333, 'scaleRatioMax' => 1.4, 'scalePLineHeight' => 1.4, 'previewFontUrl' => '', 'previewFontUrlP' => '' ]); ?>

Font Clamp Calculator

Settings

Font Size Classes

Class NameMin SizeMax SizeLine Height

Preview

Selected Class CSS

Generated CSS (All Classes)

1, 'className' => 'xxxlarge', 'min' => 48, 'max' => 64, 'lineHeight' => 1.4], ['id' => 2, 'className' => 'xxlarge', 'min' => 40, 'max' => 56, 'lineHeight' => 1.4], ['id' => 3, 'className' => 'xlarge', 'min' => 32, 'max' => 48, 'lineHeight' => 1.4], ['id' => 4, 'className' => 'large', 'min' => 24, 'max' => 40, 'lineHeight' => 1.4], ['id' => 5, 'className' => 'xmedium', 'min' => 20, 'max' => 32, 'lineHeight' => 1.4], ['id' => 6, 'className' => 'medium', 'min' => 19, 'max' => 24, 'lineHeight' => 1.4], ['id' => 7, 'className' => 'small', 'min' => 18, 'max' => 20, 'lineHeight' => 1.4], ['id' => 8, 'className' => 'xsmall', 'min' => 16, 'max' => 18, 'lineHeight' => 1.4], ['id' => 9, 'className' => 'xxsmall', 'min' => 13.2, 'max' => 15, 'lineHeight' => 1.4] ]); update_option('font_clamp_settings', array_merge(get_option('font_clamp_settings', []), [ 'selectedClassSizeId' => 6, 'previewFontUrl' => '', 'previewFontUrlP' => '' ])); } else if ($tab === 'tag') { update_option('font_clamp_tag_sizes', [ ['id' => 1, 'tagName' => 'h1', 'min' => 36, 'max' => 48, 'lineHeight' => 1.4], ['id' => 2, 'tagName' => 'h2', 'min' => 30, 'max' => 40, 'lineHeight' => 1.4], ['id' => 3, 'tagName' => 'h3', 'min' => 24, 'max' => 32, 'lineHeight' => 1.4], ['id' => 4, 'tagName' => 'h4', 'min' => 20, 'max' => 28, 'lineHeight' => 1.4], ['id' => 5, 'tagName' => 'h5', 'min' => 18, 'max' => 24, 'lineHeight' => 1.4], ['id' => 6, 'tagName' => 'h6', 'min' => 16, 'max' => 20, 'lineHeight' => 1.4], ['id' => 7, 'tagName' => 'p', 'min' => 14, 'max' => 18, 'lineHeight' => 1.4] ]); update_option('font_clamp_settings', array_merge(get_option('font_clamp_settings', []), [ 'selectedTagSizeId' => 1, 'previewFontUrl' => '', 'previewFontUrlP' => '' ])); } else if ($tab === 'scale') { update_option('font_clamp_settings', array_merge(get_option('font_clamp_settings', []), [ 'scalePMinFont' => 16, 'scalePMaxFont' => 16, 'scaleRatioMin' => 1.333, 'scaleRatioMax' => 1.4, 'scalePLineHeight' => 1.4, 'selectedScaleSizeId' => 7, 'previewFontUrl' => '', 'previewFontUrlP' => '' ])); } wp_send_json_success(); } add_action('wp_ajax_reset_font_clamp_defaults', 'reset_font_clamp_defaults');function save_font_clamp_settings() { check_ajax_referer('font_clamp_nonce', 'nonce'); if (isset($_POST['settings'])) { $settings = json_decode(stripslashes($_POST['settings']), true); if (json_last_error() === JSON_ERROR_NONE) { update_option('font_clamp_settings', $settings); wp_send_json_success(); } else { wp_send_json_error('Invalid JSON data'); } } else { wp_send_json_error('No settings provided'); } } add_action('wp_ajax_save_font_clamp_settings', 'save_font_clamp_settings');function font_clamp_push_to_customizer() { check_ajax_referer('font_clamp_nonce', 'nonce'); if (!current_user_can('edit_theme_options')) { wp_send_json_error('Permission denied'); } $new_css = stripslashes($_POST['css'] ?? ''); $existing_css = wp_get_custom_css(); $final_css = $existing_css . "\n\n/* Font Clamp Calculator Output */\n" . $new_css; $result = wp_update_custom_css_post($final_css); if ($result instanceof WP_Post) { wp_send_json_success(); } else { wp_send_json_error('Failed to update customizer CSS'); } } add_action('wp_ajax_font_clamp_push_to_customizer', 'font_clamp_push_to_customizer');function font_clamp_calculator_enqueue_assets() { if (isset($_GET['page']) && $_GET['page'] === 'font-clamp-calculator') { wp_enqueue_style('font-clamp-tailwind', 'https://cdn.tailwindcss.com', [], null); } } add_action('admin_enqueue_scripts', 'font_clamp_calculator_enqueue_assets');add_shortcode('font_clamp_calculator', 'render_font_clamp_calculator_shortcode');function render_font_clamp_calculator_shortcode() { ob_start(); $settings = get_option('font_clamp_settings', [ 'rootSize' => 16, 'minViewport' => 375, 'maxViewport' => 1100, 'unitType' => 'px', 'selectedClassSizeId' => 6, 'selectedTagSizeId' => 1, 'selectedScaleSizeId' => 7, 'scalePMinFont' => 16, 'scalePMaxFont' => 16, 'scaleRatioMin' => 1.333, 'scaleRatioMax' => 1.4, 'scalePLineHeight' => 1.4, 'previewFontUrl' => '', 'previewFontUrlP' => '', 'activeTab' => 'class' ]); font_clamp_calculator_page(); return ob_get_clean(); }add_action('wp_enqueue_scripts', 'enqueue_font_clamp_tailwind_frontend'); function enqueue_font_clamp_tailwind_frontend() { if (is_singular()) { global $post; if (has_shortcode($post->post_content, 'font_clamp_calculator')) { wp_enqueue_script('font-clamp-tailwind', 'https://cdn.tailwindcss.com', [], null, true); } } }