From e0bc82b181064ffff11d3feb44148cf2a5b7dad4 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Mon, 16 Jan 2023 16:00:51 -0500 Subject: [PATCH 01/10] update conmposer config to work with PHP 8 --- composer.json | 16 ++- composer.lock | 286 ++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 219 insertions(+), 83 deletions(-) diff --git a/composer.json b/composer.json index fd1f09b..96d8c38 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,14 @@ { - "require-dev": { - "automattic/vipwpcs": "^2.0", - "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0" - } + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, + "minimum-stability": "dev", + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^1.0" + }, + "require-dev": { + "wp-coding-standards/wpcs": "dev-develop" + } } diff --git a/composer.lock b/composer.lock index 9783feb..1fa59b2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,86 +4,42 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1ea22559778ae5ee4213a463cc7f8dd6", - "packages": [], - "packages-dev": [ - { - "name": "automattic/vipwpcs", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/Automattic/VIP-Coding-Standards.git", - "reference": "fc02f491dc9f51da7c32941ac579f70b9ed300c5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/fc02f491dc9f51da7c32941ac579f70b9ed300c5", - "reference": "fc02f491dc9f51da7c32941ac579f70b9ed300c5", - "shasum": "" - }, - "require": { - "php": ">=5.6", - "squizlabs/php_codesniffer": "^3.3.1", - "wp-coding-standards/wpcs": "^2.1" - }, - "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5", - "phpcompatibility/php-compatibility": "^9", - "phpunit/phpunit": "^5 || ^6 || ^7" - }, - "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." - }, - "type": "phpcodesniffer-standard", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Contributors", - "homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors" - } - ], - "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions", - "keywords": [ - "phpcs", - "standards", - "wordpress" - ], - "time": "2019-07-12T08:47:36+00:00" - }, + "content-hash": "6cf20abad6131685a6339f5d787f0aa2", + "packages": [ { "name": "dealerdirect/phpcodesniffer-composer-installer", - "version": "v0.5.0", + "version": "v1.0.0", "source": { "type": "git", - "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", - "reference": "e749410375ff6fb7a040a68878c656c2e610b132" + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/e749410375ff6fb7a040a68878c656c2e610b132", - "reference": "e749410375ff6fb7a040a68878c656c2e610b132", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", "shasum": "" }, "require": { - "composer-plugin-api": "^1.0", - "php": "^5.3|^7", - "squizlabs/php_codesniffer": "^2|^3" + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" }, "require-dev": { "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", "phpcompatibility/php-compatibility": "^9.0", - "sensiolabs/security-checker": "^4.1.0" + "yoast/phpunit-polyfills": "^1.0" }, "type": "composer-plugin", "extra": { - "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" }, "autoload": { "psr-4": { - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -96,6 +52,10 @@ "email": "franck.nijhof@dealerdirect.com", "homepage": "http://www.frenck.nl", "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" } ], "description": "PHP_CodeSniffer Standards Composer Installer Plugin", @@ -107,6 +67,7 @@ "codesniffer", "composer", "installer", + "phpcbf", "phpcs", "plugin", "qa", @@ -117,20 +78,24 @@ "stylecheck", "tests" ], - "time": "2018-10-26T13:21:45+00:00" + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.4.2", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8" + "reference": "add95a74551c3ba8fc99ef7651ad05f553b3fbbf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", - "reference": "b8a7362af1cc1aadb5bd36c3defc4dda2cf5f0a8", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/add95a74551c3ba8fc99ef7651ad05f553b3fbbf", + "reference": "add95a74551c3ba8fc99ef7651ad05f553b3fbbf", "shasum": "" }, "require": { @@ -142,6 +107,7 @@ "require-dev": { "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, + "default-branch": true, "bin": [ "bin/phpcs", "bin/phpcbf" @@ -166,36 +132,189 @@ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2022-12-22T21:46:41+00:00" + } + ], + "packages-dev": [ + { + "name": "phpcsstandards/phpcsextra", + "version": "dev-develop", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "a077c4ad65b906768ed2f820701958b57f605be0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/a077c4ad65b906768ed2f820701958b57f605be0", + "reference": "a077c4ad65b906768ed2f820701958b57f605be0", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.5", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "default-branch": true, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "time": "2023-01-09T22:15:31+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "dev-develop", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3", + "reference": "4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.7.1 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.3", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.3", + "yoast/phpunit-polyfills": "^1.0.1" + }, + "default-branch": true, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" ], - "time": "2019-04-10T23:49:02+00:00" + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "time": "2023-01-05T12:08:37+00:00" }, { "name": "wp-coding-standards/wpcs", - "version": "2.1.1", + "version": "dev-develop", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "bd9c33152115e6741e3510ff7189605b35167908" + "reference": "546f59c67854589bb8f6b49a30e642e75ff419ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/bd9c33152115e6741e3510ff7189605b35167908", - "reference": "bd9c33152115e6741e3510ff7189605b35167908", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/546f59c67854589bb8f6b49a30e642e75ff419ad", + "reference": "546f59c67854589bb8f6b49a30e642e75ff419ad", "shasum": "" }, "require": { + "ext-filter": "*", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.3.1" + "phpcsstandards/phpcsextra": "^1.0", + "phpcsstandards/phpcsutils": "^1.0", + "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "ext-mbstring": "For improved results" }, + "default-branch": true, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", "license": [ @@ -204,23 +323,32 @@ "authors": [ { "name": "Contributors", - "homepage": "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/graphs/contributors" + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" } ], "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], - "time": "2019-05-21T02:50:00+00:00" + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "time": "2023-01-13T13:37:27+00:00" } ], "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], + "minimum-stability": "dev", + "stability-flags": { + "wp-coding-standards/wpcs": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.3.0" } From 5d227be0c22d2a02d142cb3e2fe1802583239fbf Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Mon, 16 Jan 2023 16:01:38 -0500 Subject: [PATCH 02/10] phpcs configurationc update * remove VIP Go * allow short arrays --- phpcs.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 98f6a60..bb9b421 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,10 +1,10 @@ - - - + + + From 189adefa7fa7a109061fbf51480aeb93b9eec67f Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Mon, 16 Jan 2023 16:01:55 -0500 Subject: [PATCH 03/10] update README for 1.3.12 --- README.md | 13 +++++++++---- readme.txt | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1af646c..739e23f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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). @@ -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 diff --git a/readme.txt b/readme.txt index 91d5d44..e93cf6f 100644 --- a/readme.txt +++ b/readme.txt @@ -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 == @@ -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 From 10f9e5622c6784316699e4aaf27d2047a6381604 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Mon, 16 Jan 2023 16:02:58 -0500 Subject: [PATCH 04/10] update MathJax to 2.7.9 --- class-mathjax-latex.php | 2 +- mathjax-latex.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/class-mathjax-latex.php b/class-mathjax-latex.php index 17942f0..ee86892 100644 --- a/class-mathjax-latex.php +++ b/class-mathjax-latex.php @@ -153,7 +153,7 @@ public static function add_script() { // initialise option for existing MathJax-LaTeX users if ( get_option( 'kblog_mathjax_use_cdn' ) || ! get_option( 'kblog_mathjax_custom_location' ) ) { - $mathjax_location = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js'; + $mathjax_location = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/' . MATHJAX_JS_VERSION . '/MathJax.js'; } else { $mathjax_location = get_option( 'kblog_mathjax_custom_location' ); } diff --git a/mathjax-latex.php b/mathjax-latex.php index a770636..c6e1945 100644 --- a/mathjax-latex.php +++ b/mathjax-latex.php @@ -11,5 +11,6 @@ * Newcastle University. * Paul Schreiber (paulschreiber@gmail.com) */ +define( 'MATHJAX_JS_VERSION', '2.7.9' ); require_once __DIR__ . '/class-mathjax-latex.php'; From 9063abd6b240118948e35dd91482b3eeb6322fe9 Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Mon, 16 Jan 2023 16:08:46 -0500 Subject: [PATCH 05/10] add docblock comments --- class-mathjax-latex-admin.php | 46 ++++++++++++- class-mathjax-latex.php | 117 ++++++++++++++++++++++++++++------ mathjax-latex.php | 10 ++- 3 files changed, 148 insertions(+), 25 deletions(-) diff --git a/class-mathjax-latex-admin.php b/class-mathjax-latex-admin.php index 259a82e..ad8f931 100644 --- a/class-mathjax-latex-admin.php +++ b/class-mathjax-latex-admin.php @@ -1,6 +1,11 @@ . */ +/** + * Adium UI class. + */ class MathJax_Latex_Admin { + /** + * Allow HTML tags (for use with KSES). + * + * @var array + */ public static $admin_tags = [ 'input' => [ 'type' => [], @@ -40,14 +53,23 @@ 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 @@ -55,7 +77,7 @@ public function plugin_options_menu() { $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 ) { @@ -145,6 +167,9 @@ public function plugin_options_menu() { $this->table_foot(); } + /** + * List of MathJax configuration options. + */ public function config_options() { $options = [ 'default', @@ -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' ); @@ -184,6 +212,9 @@ public function admin_save() { } } + /** + * Render configuration page header. + */ public function table_head() { ?>
@@ -195,6 +226,9 @@ public function table_head() { @@ -221,6 +255,14 @@ public function table_foot() { diff --git a/class-mathjax-latex.php b/class-mathjax-latex.php index ee86892..bfd8cd9 100644 --- a/class-mathjax-latex.php +++ b/class-mathjax-latex.php @@ -1,5 +1,11 @@ [ 'class', 'id', 'style', 'dir', 'href', 'mathbackground', 'mathcolor', 'display', 'overflow', 'xmlns' ], 'maction' => [ 'actiontype', 'class', 'id', 'style', 'href', 'mathbackground', 'mathcolor', 'selection' ], @@ -71,6 +98,9 @@ class MathJax_Latex { 'annotation-xml' => [ 'definitionURL', 'encoding', 'cd', 'name', 'src' ], ]; + /** + * Register actions and filters. + */ public static function init() { register_activation_hook( __FILE__, [ __CLASS__, 'mathjax_install' ] ); register_deactivation_hook( __FILE__, [ __CLASS__, 'mathjax_uninstall' ] ); @@ -97,7 +127,9 @@ public static function init() { add_filter( 'tiny_mce_before_init', [ __CLASS__, 'allow_mathml_tags_in_tinymce' ] ); } - // registers default options + /** + * Registers default options. + */ public static function mathjax_install() { add_option( 'kblog_mathjax_force_load', false ); add_option( 'kblog_mathjax_latex_inline', 'inline' ); @@ -107,6 +139,9 @@ public static function mathjax_install() { add_option( 'kblog_mathjax_config', 'default' ); } + /** + * Removes default options. + */ public static function mathjax_uninstall() { delete_option( 'kblog_mathjax_force_load' ); delete_option( 'kblog_mathjax_latex_inline' ); @@ -116,18 +151,36 @@ public static function mathjax_uninstall() { delete_option( 'kblog_mathjax_config' ); } - public static function mathjax_shortcode( $atts, $content ) { + /** + * Set flag to load [mathjax] shortcode. + * + * @param array $atts Shortcode attributes. + * @param string $content Shortcode content. + */ + public static function mathjax_shortcode( $atts, $content ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed self::$add_script = true; } - public static function nomathjax_shortcode( $atts, $content ) { + /** + * Set flag to load [nomathjax] shortcode. + * + * @param array $atts Shortcode attributes. + * @param string $content Shortcode content. + */ + public static function nomathjax_shortcode( $atts, $content ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed self::$block_script = true; } + /** + * Enable [latex] shortcode. + * + * @param array $atts Shortcode attributes. + * @param string $content Shortcode content. + */ public static function latex_shortcode( $atts, $content ) { self::$add_script = true; - // this gives us an optional "syntax" attribute, which defaults to "inline", but can also be "display" + // This gives us an optional "syntax" attribute, which defaults to "inline", but can also be "display". $shortcode_atts = shortcode_atts( [ 'syntax' => get_option( 'kblog_mathjax_latex_inline' ), @@ -142,6 +195,9 @@ public static function latex_shortcode( $atts, $content ) { } } + /** + * Enqueue/add the JavaScript to the tag. + */ public static function add_script() { if ( ! self::$add_script ) { return; @@ -151,7 +207,7 @@ public static function add_script() { return; } - // initialise option for existing MathJax-LaTeX users + // Initialise option for existing MathJax-LaTeX users. if ( get_option( 'kblog_mathjax_use_cdn' ) || ! get_option( 'kblog_mathjax_custom_location' ) ) { $mathjax_location = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/' . MATHJAX_JS_VERSION . '/MathJax.js'; } else { @@ -178,15 +234,20 @@ public static function add_script() { * * @return string $tag */ - public static function script_loader_tag( $tag, $handle = null, $src = null ) { + public static function script_loader_tag( $tag, $handle = null, $src = null ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed if ( 'mathjax' === $handle ) { - // replace the