Skip to content

Commit

Permalink
Merge pull request #58 from paulschreiber/master
Browse files Browse the repository at this point in the history
Improve documentation and configuration fallback
  • Loading branch information
paulschreiber authored Jan 16, 2023
2 parents 18c4f8e + 1887300 commit 6f65c2a
Show file tree
Hide file tree
Showing 8 changed files with 409 additions and 136 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Contributors: philliplord, sjcockell, knowledgeblog, d_swan, paulschreiber, jwenerd
Tags: mathematics, math, latex, mathml, mathjax, science, res-comms, scholar, academic
Requires at least: 3.0
Tested up to: 6.0.2
Stable tag: 1.3.11
Tested up to: 6.1.1
Stable tag: 1.3.12
Requires PHP: 7.0.0
License: GPLv2

This plugin enables mathjax (http://www.mathjax.org) functionality for
This plugin enables MathJax (http://www.mathjax.org) functionality for
WordPress (http://www.wordpress.org).

## Description
Expand All @@ -23,7 +23,7 @@ Additionally, you can use native MathJax syntax -- `$$E=mc^2$$` or `\(E=mc^2\)`.

You can use wp-latex syntax, `$latex E=mc^2$`. Parameters can be specified as with wp-latex but will be ignored. This means that MathJax-LaTeX should be a drop-in replacement for wp-latex. Because this conflicts with wp-latex, this behaviour is blocked when wp-latex is present, and must be explicitly enabled in the settings.

You can also specify `[nomathjax]` -- this will block mathjax on the current page, regardless of other tags.
You can also specify `[nomathjax]` -- this will block MathJax on the current page, regardless of other tags.

MathJax-LaTeX is developed on [GitHub](https://github.com/phillord/mathjax-latex).

Expand All @@ -34,6 +34,11 @@ MathJax-LaTeX is developed on [GitHub](https://github.com/phillord/mathjax-latex

## Changelog

### 1.3.12

1. Use version 2.7.9 of MathJax JS
1. Add code comments to all variables, functions and parameters.

### 1.3.11

1. Use version 2.7.5 of MathJax JS
Expand Down
57 changes: 45 additions & 12 deletions class-mathjax-latex-admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?php
/**
* Admin UI functions.
*
* @package MathJaxLatex
*/

/*
/**
* The contents of this file are subject to the GPL License, Version 3.0.
*
* Copyright (C) 2013, Phillip Lord, Newcastle University
Expand All @@ -19,8 +24,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* Adium UI class.
*/
class MathJax_Latex_Admin {

/**
* Allow HTML tags (for use with KSES).
*
* @var array
*/
public static $admin_tags = [
'input' => [
'type' => [],
Expand All @@ -40,22 +53,31 @@ class MathJax_Latex_Admin {
],
];

/**
* Hook for the menu item function.
*/
public function __construct() {
add_action( 'admin_menu', [ $this, 'admin_page_init' ] );
}

/**
* Add the MathJax-LaTeX menu item to the Settings menu.
*/
public function admin_page_init() {
add_options_page( 'MathJax-LaTeX', 'MathJax-LaTeX', 'manage_options', 'kblog-mathjax-latex', [ $this, 'plugin_options_menu' ] );
}

/**
* Render the settings page.
*/
public function plugin_options_menu() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

$this->table_head();

// save options if this is a valid post
// Save options if this is a valid post.
if ( isset( $_POST['kblog_mathjax_latex_save_field'] ) && // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected
wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['kblog_mathjax_latex_save_field'] ) ), 'kblog_mathjax_latex_save_action' ) // phpcs:ignore WordPress.VIP.SuperGlobalInputUsage.AccessDetected
) {
Expand Down Expand Up @@ -145,6 +167,9 @@ public function plugin_options_menu() {
$this->table_foot();
}

/**
* List of MathJax configuration options.
*/
public function config_options() {
$options = [
'default',
Expand All @@ -156,6 +181,9 @@ public function config_options() {
return $options;
}

/**
* Save configuration changes to the database.
*/
public function admin_save() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
check_ajax_referer( 'kblog_mathjax_latex_save_field', 'security' );
Expand Down Expand Up @@ -184,17 +212,23 @@ public function admin_save() {
}
}

/**
* Render configuration page header.
*/
public function table_head() {
?>
<div class='wrap' id='mathjax-latex-options'>
<h2>Mathjax-Latex by Kblog</h2>
<h2>Mathjax-Latex</h2>
<form id='mathjaxlatex' name='mathjaxlatex' action='' method='POST'>
<?php wp_nonce_field( 'kblog_mathjax_latex_save_action', 'kblog_mathjax_latex_save_field', true ); ?>
<table class='form-table'>
<caption class='screen-reader-text'>The following lists configuration options for the MathJax-LaTeX plugin.</caption>
<?php
}

/**
* Render configuration page footer.
*/
public function table_foot() {
?>
</table>
Expand All @@ -221,6 +255,14 @@ public function table_foot() {
<?php
}

/**
* Render configuration table row.
*
* @param string $head Header for the row.
* @param string $comment Description of the row.
* @param string $input The input tag (HTML).
* @param string $input_id The input ID (to associate label with input).
*/
public function admin_table_row( $head, $comment, $input, $input_id ) {
?>
<tr valign="top">
Expand All @@ -235,12 +277,3 @@ public function admin_table_row( $head, $comment, $input, $input_id ) {
<?php
}
} // class

function mathjax_latex_admin_init() {
global $mathjax_latex_admin;
$mathjax_latex_admin = new MathJax_Latex_Admin();
}

if ( is_admin() ) {
mathjax_latex_admin_init();
}
Loading

0 comments on commit 6f65c2a

Please sign in to comment.