class UC_Formula_Fixer { public function __construct() { add_action('admin_menu', [$this, 'add_formula_fixer_page']); add_action('wp_ajax_fix_all_formulas', [$this, 'fix_all_formulas']); } public function add_formula_fixer_page() { add_submenu_page( 'ultimate-calculators', 'Formula Fixer', 'Formula Fixer', 'manage_options', 'uc-formula-fixer', [$this, 'render_formula_fixer_page'] ); } public function render_formula_fixer_page() { $calculators = get_posts(['post_type' => 'calculator', 'posts_per_page' => -1]); echo '
'; echo '

Formula Fixer

'; echo '

Found ' . count($calculators) . ' calculators

'; echo ''; echo '
'; echo '
'; echo ''; } public function fix_all_formulas() { if (!wp_verify_nonce($_POST['nonce'], 'fix_formulas')) { wp_die('Security check failed'); } $calculators = get_posts(['post_type' => 'calculator', 'posts_per_page' => -1]); $fixed = 0; $errors = []; foreach ($calculators as $calculator) { $data = get_post_meta($calculator->ID, '_calculator_json', true); if ($data && isset($data['formula']['expression'])) { $original = $data['formula']['expression']; $fixed_expression = $this->convert_latex_to_mathjs($original); if ($fixed_expression !== $original) { $data['formula']['expression'] = $fixed_expression; update_post_meta($calculator->ID, '_calculator_json', $data); $fixed++; } } } echo "Fixed $fixed calculator formulas!"; wp_die(); } private function convert_latex_to_mathjs($latex) { // Convert LaTeX to math.js compatible format $conversions = [ '/\\\frac{([^}]+)}{([^}]+)}/' => '($1)/($2)', '/\\\sqrt{([^}]+)}/' => 'sqrt($1)', '/\\\^\\\circ/' => '*pi/180', '/\\\times/' => '*', '/\\\cdot/' => '*', '/\\\left\(/' => '(', '/\\\right\)/' => ')', '/\\\pi/' => 'pi', '/\\\infty/' => 'Infinity', ]; $mathjs = preg_replace(array_keys($conversions), array_values($conversions), $latex); // Remove LaTeX formatting $mathjs = str_replace(['{', '}'], '', $mathjs); // Extract just the expression part (remove "BMI = " prefix) if (strpos($mathjs, '=') !== false) { $parts = explode('=', $mathjs, 2); $mathjs = trim($parts[1]); } return $mathjs; } } ESIC, पटना शिक्षण संकाय भर्ती 2025 - 33 पद - ऑफलाइन फॉर्म - SarkariResult.gen.in