refactor: rename files in line with WPCS, split into public/admin/includes (a.k.a. common)
This commit is contained in:
parent
11bb8a8377
commit
ca3b283356
19 changed files with 838 additions and 670 deletions
86
src/public/widget/class-footnotes-widget-base.php
Normal file
86
src/public/widget/class-footnotes-widget-base.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* 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() {
|
||||
$l_arr_widget_options = array(
|
||||
'classname' => __CLASS__,
|
||||
'description' => $this->get_description(),
|
||||
);
|
||||
$l_arr_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.
|
||||
$l_arr_widget_options, // Optional Widget Options.
|
||||
$l_arr_control_options // Optional Widget Control Options.
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes the Plugin Widget to put the Reference Container to the Widget area.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-widget-base.php';
|
||||
|
||||
/**
|
||||
* Registers a Widget to put the Reference Container to the widget area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Widget_Reference_Container extends Footnotes_Widget_Base {
|
||||
|
||||
/**
|
||||
* Returns an unique ID as string used for the Widget Base ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_id() {
|
||||
return 'footnotes_widget';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Public name of the Widget to be displayed in the Configuration page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_name() {
|
||||
return Footnotes_Config::C_STR_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Description of the child widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
protected function get_description() {
|
||||
return __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Settings of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $instance The instance of the widget.
|
||||
* @return void
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
echo __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Content of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $args The widget's arguments.
|
||||
* @param mixed $instance The instance of the widget.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $footnotes;
|
||||
// Reference container positioning is set to "widget area".
|
||||
if ( 'widget' === Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION ) ) {
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $footnotes->a_obj_task->reference_container();
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue