2021-02-27 08:49:08 +00:00
|
|
|
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
2021-02-23 16:00:59 +00:00
|
|
|
/**
|
|
|
|
* Includes the Plugin settings menu.
|
|
|
|
*
|
|
|
|
* @filesource
|
2021-02-23 16:48:53 +00:00
|
|
|
* @package footnotes
|
2021-02-25 13:22:07 +00:00
|
|
|
* @since 1.5.0
|
2021-02-23 16:00:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the Settings interface of the Plugin.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
class Footnotes_Layout_Init {
|
2021-02-23 16:00:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Slug for the Plugin main menu.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
* @var string
|
|
|
|
*/
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
const MAIN_MENU_SLUG = 'footnotes';
|
2021-02-23 16:00:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin main menu name.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
* @var string
|
|
|
|
*/
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
const MAIN_MENU_TITLE = 'ManFisher';
|
2021-02-23 16:00:59 +00:00
|
|
|
|
|
|
|
/**
|
2021-04-16 02:10:03 +00:00
|
|
|
* Contains the settings layoutEngine
|
2021-02-23 16:00:59 +00:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-04-16 02:10:03 +00:00
|
|
|
private $settings_page;
|
2021-02-23 16:00:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$this->settings_page = new Footnotes_Layout_Settings();
|
2021-02-23 16:48:53 +00:00
|
|
|
|
|
|
|
// Register hooks/actions.
|
2021-04-16 02:10:03 +00:00
|
|
|
add_action( 'admin_menu', array( $this, 'register_options_submenu' ) );
|
2021-02-23 16:48:53 +00:00
|
|
|
add_action( 'admin_init', array( $this, 'initialize_settings' ) );
|
2021-02-23 22:45:01 +00:00
|
|
|
// Register AJAX callbacks for Plugin information.
|
2021-02-23 16:48:53 +00:00
|
|
|
add_action( 'wp_ajax_nopriv_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
|
|
|
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
|
2021-02-23 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-16 02:10:03 +00:00
|
|
|
* Registers the settings and initialises the settings page.
|
2021-02-23 16:00:59 +00:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
2021-02-23 16:48:53 +00:00
|
|
|
public function initialize_settings() {
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
Footnotes_Settings::instance()->register_settings();
|
2021-04-16 02:10:03 +00:00
|
|
|
$this->settings_page->register_sections();
|
2021-02-23 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-04-16 02:10:03 +00:00
|
|
|
* Registers the footnotes submenu page.
|
2021-02-23 16:00:59 +00:00
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
|
|
|
|
*/
|
2021-04-16 02:10:03 +00:00
|
|
|
public function register_options_submenu() {
|
|
|
|
add_submenu_page(
|
|
|
|
'options-general.php',
|
|
|
|
'footnotes Settings',
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
self::MAIN_MENU_SLUG,
|
2021-04-16 02:10:03 +00:00
|
|
|
'manage_options',
|
|
|
|
'footnotes',
|
|
|
|
array( $this->settings_page, 'display_content' )
|
2021-02-23 16:00:59 +00:00
|
|
|
);
|
2021-04-16 02:10:03 +00:00
|
|
|
$this->settings_page->register_sub_page();
|
2021-02-23 16:00:59 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 17:59:12 +00:00
|
|
|
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
2021-02-23 16:00:59 +00:00
|
|
|
/**
|
|
|
|
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
|
|
|
|
*
|
|
|
|
* @since 1.5.0
|
|
|
|
*/
|
2021-02-23 16:48:53 +00:00
|
|
|
public function get_plugin_meta_information() {
|
|
|
|
// TODO: add nonce verification.
|
|
|
|
|
2021-02-23 22:45:01 +00:00
|
|
|
// Get plugin internal name from POST data.
|
2021-02-23 17:59:12 +00:00
|
|
|
if ( isset( $_POST['plugin'] ) ) {
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$plugin_name = wp_unslash( $_POST['plugin'] );
|
2021-02-23 16:48:53 +00:00
|
|
|
}
|
|
|
|
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
if ( empty( $plugin_name ) ) {
|
2021-02-23 16:48:53 +00:00
|
|
|
echo wp_json_encode( array( 'error' => 'Plugin name invalid.' ) );
|
2021-02-23 16:00:59 +00:00
|
|
|
exit;
|
|
|
|
}
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$url = 'https://api.wordpress.org/plugins/info/1.0/' . $plugin_name . '.json';
|
2021-02-23 22:45:01 +00:00
|
|
|
// Call URL and collect data.
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$response = wp_remote_get( $url );
|
2021-02-23 22:45:01 +00:00
|
|
|
// Check if response is valid.
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
if ( is_wp_error( $response ) ) {
|
2021-02-23 16:48:53 +00:00
|
|
|
echo wp_json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
|
2021-02-23 16:00:59 +00:00
|
|
|
exit;
|
|
|
|
}
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
if ( ! array_key_exists( 'body', $response ) ) {
|
2021-02-23 16:48:53 +00:00
|
|
|
echo wp_json_encode( array( 'error' => 'Error reading WordPress API response message.' ) );
|
2021-02-23 16:00:59 +00:00
|
|
|
exit;
|
|
|
|
}
|
2021-02-23 22:45:01 +00:00
|
|
|
// Get the body of the response.
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$response = $response['body'];
|
2021-02-23 22:45:01 +00:00
|
|
|
// Get plugin object.
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$plugin = json_decode( $response, true );
|
|
|
|
if ( empty( $plugin ) ) {
|
|
|
|
echo wp_json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $url . '<br/>Response: ' . $response ) );
|
2021-02-23 16:00:59 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
$num_ratings = array_key_exists( 'num_ratings', $plugin ) ? intval( $plugin['num_ratings'] ) : 0;
|
|
|
|
$rating = array_key_exists( 'rating', $plugin ) ? floatval( $plugin['rating'] ) : 0.0;
|
|
|
|
$stars = round( 5 * $rating / 100.0, 1 );
|
2021-02-23 16:00:59 +00:00
|
|
|
|
2021-02-23 22:45:01 +00:00
|
|
|
// Return Plugin information as JSON encoded string.
|
2021-02-23 16:48:53 +00:00
|
|
|
echo wp_json_encode(
|
2021-02-23 16:00:59 +00:00
|
|
|
array(
|
2021-02-23 16:48:53 +00:00
|
|
|
'error' => '',
|
refactor: remove Hungarian notation and `MCI` prefixes
I had to use some RegEx-fu for this. Specifically:
```bash
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/\(p\|l\|a\)_\(str\|bool\|int\|obj\|flo\|arr\)_//g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/MCI_Footnotes/Footnotes/g' {} \;
find ./{footnotes.php,includes.php,class/} -type f -name "*.php" -exec sed -i 's/C_\(INT\|STR\|FLO\)_//g' {} \;
```
This should have covered all the bases.
In my testing I encountered one error caused by these changes.
In the `add_select_box` function in `/class/dashboard/layout.php`,
there was a function parameter called `$p_arr_options` and a variable
called `$l_str_options`. Removing the Hungarian notation caused an
error as these two variables were both now called `$options`.
This has been fixed, and I like to think that that will have been
the only naming conflict, but I think it is more likely that there
maybe others. Further testing is required before I am happy calling
this release-ready.
Close #34, progress #36
2021-04-16 22:55:05 +00:00
|
|
|
'PluginDescription' => array_key_exists( 'short_description', $plugin ) ? html_entity_decode( $plugin['short_description'] ) : 'Error reading Plugin information',
|
|
|
|
'PluginAuthor' => array_key_exists( 'author', $plugin ) ? html_entity_decode( $plugin['author'] ) : 'unknown',
|
|
|
|
'PluginRatingText' => $stars . ' ' . __( 'rating based on', 'footnotes' ) . ' ' . $num_ratings . ' ' . __( 'ratings', 'footnotes' ),
|
|
|
|
'PluginRating1' => $stars >= 0.5 ? 'star-full' : 'star-empty',
|
|
|
|
'PluginRating2' => $stars >= 1.5 ? 'star-full' : 'star-empty',
|
|
|
|
'PluginRating3' => $stars >= 2.5 ? 'star-full' : 'star-empty',
|
|
|
|
'PluginRating4' => $stars >= 3.5 ? 'star-full' : 'star-empty',
|
|
|
|
'PluginRating5' => $stars >= 4.5 ? 'star-full' : 'star-empty',
|
|
|
|
'PluginRating' => $num_ratings,
|
|
|
|
'PluginLastUpdated' => array_key_exists( 'last_updated', $plugin ) ? $plugin['last_updated'] : 'unknown',
|
|
|
|
'PluginDownloads' => array_key_exists( 'downloaded', $plugin ) ? $plugin['downloaded'] : '---',
|
2021-02-23 16:00:59 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
exit;
|
|
|
|
}
|
2021-02-27 08:49:08 +00:00
|
|
|
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
2021-02-23 16:00:59 +00:00
|
|
|
}
|