get_option('formulix_servidor', 'https://api.formulix.com.br'), 'chave' => get_option('formulix_chave', ''), 'idioma' => str_replace('_', '-', get_locale()), 'nonce' => wp_create_nonce('wp_rest'), 'podeEnviar' => current_user_can('upload_files'), ], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) . ';', 'before'); }); function formulix_sanitizar_servidor($valor) { if (!is_string($valor) || trim($valor) === '') return ''; $url = esc_url_raw(trim($valor), ['https', 'http']); $partes = wp_parse_url($url); $local = $partes && in_array($partes['host'] ?? '', ['localhost', '127.0.0.1', '[::1]'], true); if (!$partes || empty($partes['host']) || isset($partes['user']) || isset($partes['pass']) || isset($partes['query']) || isset($partes['fragment']) || (($partes['scheme'] ?? '') !== 'https' && !(($partes['scheme'] ?? '') === 'http' && $local))) { add_settings_error('formulix_servidor', 'formulix_url', __('Enter an HTTPS API URL without credentials, query or fragment. HTTP is allowed only on localhost.', 'formulix')); return ''; } return untrailingslashit($url); } add_action('admin_init', function () { register_setting('formulix', 'formulix_servidor', ['type' => 'string', 'sanitize_callback' => 'formulix_sanitizar_servidor']); register_setting('formulix', 'formulix_chave', ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field']); add_settings_section('formulix_api', __('Formulix external service', 'formulix'), function () { echo '

' . esc_html__('When you use the block, data is sent to the API: previews send operations, values and expressions while you type; inserting sends the item, language, notation and public key (if any). The server also receives the IP address and the site origin. Leave the URL empty to turn sending off.', 'formulix') . '

'; echo '

' . esc_html__('The plugin is free and GPL. The API offers a free plan and paid plans; no local features are unlocked by payment. Do not send personal data in the fields.', 'formulix') . '

'; echo '

' . esc_html__('Official service: https://api.formulix.com.br. Without a key, the site uses the free plan by domain; when it reaches the limit, register the domain and choose a plan at https://painel.formulix.com.br. The key is optional.', 'formulix') . ' ' . esc_html__('Terms of use', 'formulix') . ' ยท ' . esc_html__('Privacy', 'formulix') . '

'; }, 'formulix'); add_settings_field('formulix_servidor', __('API URL', 'formulix'), 'formulix_campo_configuracao', 'formulix', 'formulix_api', ['label_for' => 'formulix_servidor', 'tipo' => 'url']); add_settings_field('formulix_chave', __('Public key', 'formulix'), 'formulix_campo_configuracao', 'formulix', 'formulix_api', ['label_for' => 'formulix_chave', 'tipo' => 'text']); }); function formulix_campo_configuracao($args) { echo ''; } add_action('admin_menu', function () { add_options_page(__('Formulix', 'formulix'), __('Formulix', 'formulix'), 'manage_options', 'formulix', function () { if (!current_user_can('manage_options')) return; echo '

' . esc_html__('Formulix', 'formulix') . '

'; settings_fields('formulix'); do_settings_sections('formulix'); submit_button(); echo '
'; }); }); add_filter('wp_kses_allowed_html', function ($tags, $context) { if ($context !== 'post') return $tags; $attributes = array_fill_keys(explode(' ', 'xmlns display data-latex data-quimica mathcolor mathbackground mathvariant displaystyle scriptlevel stretchy fence separator lspace rspace width height depth rowspacing columnspacing columnalign rowalign frame notation open close separators linethickness accent accentunder'), true); foreach (explode(' ', 'math mrow mi mn mo ms mtext mspace msub msup msubsup mfrac msqrt mroot mover munder munderover mtable mtr mtd mstyle mpadded mphantom menclose mfenced mmultiscripts mprescripts none') as $tag) $tags[$tag] = $attributes; return $tags; }, 10, 2);