This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
footnotes/class/widgets/base.php
Ben Goldsworthy 1284544556 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 23:55:05 +01:00

87 lines
2.4 KiB
PHP

<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
/**
* Widget base.
*
* @filesource
* @package footnotes
* @since 1.5.0
*
* @since 1.6.4 Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
*/
/**
* Base Class for all Plugin Widgets. Registers each Widget to WordPress.
* The following Methods MUST be overwritten in each sub class:
* **public function widget($args, $instance)** -> echo the Widget Content
* **public function form($instance)** -> echo the Settings of the Widget
*
* @author Stefan Herndler
* @since 1.5.0
*/
abstract class Footnotes_Widget_Base extends WP_Widget {
/**
* Returns an unique ID as string used for the Widget Base ID.
*
* @since 1.5.0
* @return string
*/
abstract protected function get_id();
/**
* Returns the Public name of child Widget to be displayed in the Configuration page.
*
* @since 1.5.0
* @return string
*/
abstract protected function get_name();
/**
* Returns the Description of the child widget.
*
* @since 1.5.0
* @return string
*/
abstract protected function get_description();
/**
* Returns the width of the Widget. Default width is 250 pixel.
*
* @since 1.5.0
* @return int
*/
protected function get_widget_width() {
return 250;
}
/**
* Class Constructor. Registers the child Widget to WordPress.
*
* @since 1.5.0
*
* - Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
*
* @since 1.6.4
* @contributor @dartiss
* @link https://plugins.trac.wordpress.org/browser/footnotes/trunk/class/widgets/base.php?rev=1445720
* “The called constructor method for WP_Widget in Footnotes_Widget_ReferenceContainer is deprecated since version 4.3.0! Use __construct() instead.”
*/
public function __construct() {
$widget_options = array(
'classname' => __CLASS__,
'description' => $this->get_description(),
);
$control_options = array(
'id_base' => strtolower( $this->get_id() ),
'width' => $this->get_widget_width(),
);
// Registers the Widget.
parent::__construct(
strtolower( $this->get_id() ), // Unique ID for the widget, has to be lowercase.
$this->get_name(), // Plugin name to be displayed.
$widget_options, // Optional Widget Options.
$control_options // Optional Widget Control Options.
);
}
}