This repository has been archived on 2023-08-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
footnotes/src/admin/layout/class-engine.php

615 lines
18 KiB
PHP
Raw Normal View History

<?php // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
2021-04-15 17:03:46 +01:00
/**
2021-05-01 21:34:46 +01:00
* Admin. Layouts: Engine class
2021-04-15 17:03:46 +01:00
*
2021-05-01 21:34:46 +01:00
* The Admin. Layouts subpackage is composed of the {@see Engine}
* abstract class, which is extended by the {@see Settings}
2021-05-01 19:22:41 +01:00
* sub-class. The subpackage is initialised at runtime by the {@see
2021-05-01 21:34:46 +01:00
* Init} class.
2021-04-27 10:04:13 +01:00
*
2021-05-01 21:34:46 +01:00
* @package footnotes
2021-04-30 18:03:15 +01:00
* @since 1.5.0
* @since 2.8.0 Rename file from `layout.php` to `class-footnotes-layout-engine.php`,
2021-05-01 19:22:41 +01:00
* rename `dashboard/` sub-directory to `layout/`.
2021-04-15 17:03:46 +01:00
*/
2021-05-01 21:34:46 +01:00
namespace footnotes\admin\layout;
2021-05-01 21:38:11 +01:00
2021-05-01 21:34:46 +01:00
use footnotes\includes as Includes;
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'layout/class-init.php';
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Class to be extended by page layout sub-classes.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @abstract
2021-05-01 21:34:46 +01:00
*
* @package footnotes
2021-04-15 17:03:46 +01:00
* @since 1.5.0
*/
2021-05-01 21:34:46 +01:00
abstract class Engine {
2021-04-15 17:03:46 +01:00
2021-04-27 09:30:53 +01:00
/**
* The ID of this plugin.
*
2021-04-30 18:03:15 +01:00
* @access protected
* @var string $plugin_name The ID of this plugin.
*
* @since 2.8.0
2021-04-27 09:30:53 +01:00
*/
protected $plugin_name;
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Stores the Hook connection string for the child sub-page.
*
* @access protected
* @var null|string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
*/
protected $a_str_sub_page_hook = null;
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Stores all Sections for the child sub-page.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @access protected
* @var array
*
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
protected $a_arr_sections = array();
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Returns a Priority index. Lower numbers have a higher priority.
*
* @abstract
* @return int
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
abstract public function get_priority();
/**
2021-04-30 18:03:15 +01:00
* Returns the unique slug of the child sub-page.
*
* @abstract
* @access protected
* @return string
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
abstract protected function get_sub_page_slug();
/**
2021-04-30 18:03:15 +01:00
* Returns the title of the child sub-page.
*
* @abstract
* @access protected
* @return string
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
abstract protected function get_sub_page_title();
/**
2021-04-30 18:03:15 +01:00
* Returns an array of all registered sections for a sub-page.
*
* @abstract
* @access protected
* @return array
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
*/
abstract protected function get_sections();
/**
* Returns an array of all registered meta boxes.
*
2021-04-30 18:03:15 +01:00
* @abstract
* @access protected
* @return array
*
2021-04-15 17:03:46 +01:00
* @since 1.5.0
*/
abstract protected function get_meta_boxes();
2021-04-27 09:54:07 +01:00
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Returns an array describing a sub-page section.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_id Unique ID suffix.
* @param string $p_str_title Title of the section.
* @param int $p_int_settings_container_index Settings Container index.
* @param bool $p_bool_has_submit_button Whether a Submit button should
2021-05-02 09:26:03 +01:00
* be displayed for this section. Default `true`.
2021-04-30 18:03:15 +01:00
* @return array {
* A dashboard section.
*
* @type string $id Section ID.
* @type string $title Section title.
* @type bool $submit Whether the section has a submit button or not.
* @type int $container Settings Container index.
* }
*
* @since 1.5.0
* @todo Refactor sections into their own class?
2021-04-15 17:03:46 +01:00
*/
protected function add_section( $p_str_id, $p_str_title, $p_int_settings_container_index, $p_bool_has_submit_button = true ) {
2021-04-15 17:03:46 +01:00
return array(
2021-04-27 09:30:53 +01:00
'id' => $this->plugin_name . '-' . $p_str_id,
'title' => $p_str_title,
'submit' => $p_bool_has_submit_button,
'container' => $p_int_settings_container_index,
2021-04-15 17:03:46 +01:00
);
}
/**
* Returns an array describing a meta box.
*
2021-04-30 18:03:15 +01:00
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_section_id Parent section ID.
* @param string $p_str_id Unique ID suffix.
* @param string $p_str_title Title for the meta box.
* @param string $p_str_callback_function_name Class method name for callback.
2021-04-30 18:03:15 +01:00
* @return array {
* A dashboard meta box.
*
* @type string $parent Parent section ID.
* @type string $id Meta box ID.
* @type string $title Meta box title.
* @type string $callback Meta box callback function.
* }
*
2021-04-15 17:03:46 +01:00
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor meta boxes into their own class?
* @todo Pass actual functions rather than strings?
2021-04-15 17:03:46 +01:00
*/
protected function add_meta_box( $p_str_section_id, $p_str_id, $p_str_title, $p_str_callback_function_name ) {
2021-04-15 17:03:46 +01:00
return array(
2021-04-27 09:30:53 +01:00
'parent' => $this->plugin_name . '-' . $p_str_section_id,
'id' => $p_str_id,
'title' => $p_str_title,
'callback' => $p_str_callback_function_name,
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Registers a sub-page.
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
*/
public function register_sub_page() {
global $submenu;
2021-05-01 21:34:46 +01:00
if ( array_key_exists( plugin_basename( Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
foreach ( $submenu[ plugin_basename( Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
if ( plugin_basename( Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $l_arr_sub_menu[2] ) {
remove_submenu_page( Init::C_STR_MAIN_MENU_SLUG, Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() );
2021-04-15 17:03:46 +01:00
}
}
}
$this->a_str_sub_page_hook = add_submenu_page(
2021-05-01 21:34:46 +01:00
Init::C_STR_MAIN_MENU_SLUG,
2021-04-15 17:03:46 +01:00
$this->get_sub_page_title(),
$this->get_sub_page_title(),
'manage_options',
2021-05-01 21:34:46 +01:00
Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
2021-04-15 17:03:46 +01:00
array( $this, 'display_content' )
);
}
/**
2021-04-30 18:03:15 +01:00
* Registers all sections for a sub-page.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
public function register_sections() {
foreach ( $this->get_sections() as $l_arr_section ) {
2021-04-15 17:03:46 +01:00
// Append tab to the tab-array.
$this->a_arr_sections[ $l_arr_section['id'] ] = $l_arr_section;
2021-04-15 17:03:46 +01:00
add_settings_section(
$l_arr_section['id'],
2021-04-15 17:03:46 +01:00
'',
array( $this, 'Description' ),
$l_arr_section['id']
2021-04-15 17:03:46 +01:00
);
$this->register_meta_boxes( $l_arr_section['id'] );
2021-04-15 17:03:46 +01:00
}
}
/**
2021-04-30 18:03:15 +01:00
* Registers all Meta boxes for a sub-page.
*
* @access private
2021-05-01 19:22:41 +01:00
* @param string $p_str_parent_id Parent section unique ID.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
2021-04-15 17:03:46 +01:00
*/
private function register_meta_boxes( $p_str_parent_id ) {
2021-04-15 17:03:46 +01:00
// Iterate through each meta box.
foreach ( $this->get_meta_boxes() as $l_arr_meta_box ) {
if ( $p_str_parent_id !== $l_arr_meta_box['parent'] ) {
2021-04-15 17:03:46 +01:00
continue;
}
add_meta_box(
$p_str_parent_id . '-' . $l_arr_meta_box['id'],
$l_arr_meta_box['title'],
array( $this, $l_arr_meta_box['callback'] ),
$p_str_parent_id,
2021-04-15 17:03:46 +01:00
'main'
);
}
}
/**
2021-04-30 18:03:15 +01:00
* Append JavaScript and CSS files for specific sub-page.
*
* @access private
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-05-01 21:34:46 +01:00
* @todo Move to {@see Includes\Admin}.
2021-04-15 17:03:46 +01:00
*/
private function append_scripts() {
wp_enqueue_script( 'postbox' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
2021-04-30 18:03:15 +01:00
* Displays the content of specific sub-page.
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Review nonce verification.
2021-04-15 17:03:46 +01:00
*/
public function display_content() {
$this->append_scripts();
// Get the current section.
reset( $this->a_arr_sections );
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->a_arr_sections );
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
2021-04-15 17:03:46 +01:00
// Store settings.
$l_bool_settings_updated = false;
2021-04-15 17:03:46 +01:00
if ( array_key_exists( 'save-settings', $_POST ) ) {
if ( 'save' === $_POST['save-settings'] ) {
unset( $_POST['save-settings'] );
unset( $_POST['submit'] );
$l_bool_settings_updated = $this->save_settings();
2021-04-15 17:03:46 +01:00
}
}
// Display all sections and highlight the active section.
echo '<div class="wrap">';
echo '<h2 class="nav-tab-wrapper">';
// Iterate through all register sections.
foreach ( $this->a_arr_sections as $l_str_id => $l_arr_description ) {
$l_str_tab_active = ( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '';
2021-04-15 17:03:46 +01:00
echo sprintf(
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '',
2021-05-01 21:34:46 +01:00
Init::C_STR_MAIN_MENU_SLUG,
$l_str_id,
$l_arr_description['title']
2021-04-15 17:03:46 +01:00
);
}
echo '</h2><br/>';
if ( $l_bool_settings_updated ) {
2021-04-15 17:03:46 +01:00
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
}
// Form to submit the active section.
echo '<!--suppress HtmlUnknownTarget --><form method="post" action="">';
echo '<input type="hidden" name="save-settings" value="save" />';
// Outputs the settings field of the active section.
do_settings_sections( $l_arr_active_section['id'] );
do_meta_boxes( $l_arr_active_section['id'], 'main', null );
2021-04-15 17:03:46 +01:00
// Add submit button to active section if defined.
if ( $l_arr_active_section['submit'] ) {
2021-04-15 17:03:46 +01:00
submit_button();
}
echo '</form>';
echo '</div>';
// Echo JavaScript for the expand/collapse function of the meta boxes.
echo '<script type="text/javascript">';
echo 'jQuery(document).ready(function ($) {';
2021-04-16 21:50:02 +01:00
echo 'jQuery(".footnotes-color-picker").wpColorPicker();';
2021-04-15 17:03:46 +01:00
echo "jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');";
echo "postboxes.add_postbox_toggles('" . $this->a_str_sub_page_hook . "');";
2021-04-15 17:03:46 +01:00
echo '});';
echo '</script>';
}
2021-04-30 18:03:15 +01:00
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
2021-04-15 17:03:46 +01:00
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
2021-04-30 18:03:15 +01:00
* Save all plugin settings.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @access private
* @return bool `true` on save success, else `false`.
*
* @since 1.5.0
* @todo Review nonce verification.
2021-04-15 17:03:46 +01:00
*/
private function save_settings() {
$l_arr_new_settings = array();
2021-04-15 17:03:46 +01:00
// TODO: add nonce verification.
// Get current section.
reset( $this->a_arr_sections );
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->a_arr_sections );
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
2021-04-15 17:03:46 +01:00
2021-05-01 21:34:46 +01:00
foreach ( Includes\Settings::instance()->get_defaults( $l_arr_active_section['container'] ) as $l_str_key => $l_mixed_value ) {
if ( array_key_exists( $l_str_key, $_POST ) ) {
$l_arr_new_settings[ $l_str_key ] = wp_unslash( $_POST[ $l_str_key ] );
2021-04-15 17:03:46 +01:00
} else {
// Setting is not defined in the POST array, define it to avoid the Default value.
$l_arr_new_settings[ $l_str_key ] = '';
2021-04-15 17:03:46 +01:00
}
}
// Update settings.
2021-05-01 21:34:46 +01:00
return Includes\Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_new_settings );
2021-04-15 17:03:46 +01:00
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
2021-04-30 18:03:15 +01:00
* Output the description of a section. May be overwritten in any section.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
* @todo Required? Should be `abstract`?
2021-04-15 17:03:46 +01:00
*/
public function description() {
// Default no description will be displayed.
}
/**
2021-04-30 18:03:15 +01:00
* Loads a specified setting.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_key_name Setting key.
2021-04-30 18:03:15 +01:00
* @return array {
* A configurable setting.
*
* @type string $id Setting key.
* @type string $name Setting name.
* @type string $value Setting value.
* }
*
* @since 1.5.0
* @since 2.5.11 Broken due to accidental removal of `esc_attr()` call.
* @since 2.6.1 Restore `esc_attr()` call.
2021-04-15 17:03:46 +01:00
*/
protected function load_setting( $p_str_setting_key_name ) {
2021-04-15 17:03:46 +01:00
// Get current section.
reset( $this->a_arr_sections );
$p_arr_return = array();
$p_arr_return['id'] = sprintf( '%s', $p_str_setting_key_name );
$p_arr_return['name'] = sprintf( '%s', $p_str_setting_key_name );
2021-05-01 21:34:46 +01:00
$p_arr_return['value'] = esc_attr( Includes\Settings::instance()->get( $p_str_setting_key_name ) );
return $p_arr_return;
2021-04-15 17:03:46 +01:00
}
2021-05-01 19:22:41 +01:00
2021-04-15 17:03:46 +01:00
/**
2021-04-30 18:03:15 +01:00
* Returns a simple text inside HTML `<span>` element.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_text Message to be surrounded with `<span>` tags.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_text( $p_str_text ) {
return sprintf( '<span>%s</span>', $p_str_text );
2021-04-15 17:03:46 +01:00
}
/**
2021-04-30 18:03:15 +01:00
* Returns the HTML tag for an `<input>`/`<select>` label.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Settings key.
* @param string $p_str_caption Label caption.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_label( $p_str_setting_name, $p_str_caption ) {
if ( empty( $p_str_caption ) ) {
2021-04-15 17:03:46 +01:00
return '';
}
/*
* Remove the colon causing localization issues with French, and with
* languages not using punctuation at all, and with languages using other
* punctuation marks instead of colon, e.g. Greek using a raised dot.
* In French, colon is preceded by a space, forcibly non-breaking, and
* narrow per new school.
* Add colon to label strings for inclusion in localization. Colon after
* label is widely preferred best practice, mandatory per
2021-04-30 18:03:15 +01:00
* {@link https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui
* style guides}.
2021-04-15 17:03:46 +01:00
*/
return sprintf( '<label for="%s">%s</label>', $p_str_setting_name, $p_str_caption );
2021-04-15 17:03:46 +01:00
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for a text `<input>` element.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
* @param int $p_str_max_length Maximum length of the input. Default length 999 chars.
* @param bool $p_bool_readonly Set the input to be read only. Default `false`.
* @param bool $p_bool_hidden Set the input to be hidden. Default `false`.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_text_box( $p_str_setting_name, $p_str_max_length = 999, $p_bool_readonly = false, $p_bool_hidden = false ) {
$l_str_style = '';
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
if ( $p_bool_hidden ) {
$l_str_style .= 'display:none;';
2021-04-15 17:03:46 +01:00
}
return sprintf(
'<input type="text" name="%s" id="%s" maxlength="%d" style="%s" value="%s" %s/>',
$l_arr_data['name'],
$l_arr_data['id'],
$p_str_max_length,
$l_str_style,
$l_arr_data['value'],
$p_bool_readonly ? 'readonly="readonly"' : ''
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for a checkbox `<input>` element.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_checkbox( $p_str_setting_name ) {
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
2021-04-15 17:03:46 +01:00
return sprintf(
'<input type="checkbox" name="%s" id="%s" %s/>',
$l_arr_data['name'],
$l_arr_data['id'],
2021-05-01 21:34:46 +01:00
Includes\Convert::to_bool( $l_arr_data['value'] ) ? 'checked="checked"' : ''
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for a `<select>` element.
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
2021-04-30 18:03:15 +01:00
* @param array $p_arr_options Possible options.
* @return string
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_select_box( $p_str_setting_name, $p_arr_options ) {
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
$l_str_options = '';
2021-04-15 17:03:46 +01:00
// Loop through all array keys.
foreach ( $p_arr_options as $l_str_value => $l_str_caption ) {
$l_str_options .= sprintf(
2021-04-15 17:03:46 +01:00
'<option value="%s" %s>%s</option>',
$l_str_value,
2021-04-15 17:03:46 +01:00
// Only check for equality, not identity, WRT backlink symbol arrows.
2021-04-26 17:15:48 +01:00
// phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
$l_str_value == $l_arr_data['value'] ? 'selected' : '',
2021-04-26 17:15:48 +01:00
// phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
$l_str_caption
2021-04-15 17:03:46 +01:00
);
}
return sprintf(
'<select name="%s" id="%s">%s</select>',
$l_arr_data['name'],
$l_arr_data['id'],
$l_str_options
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for a `<textarea>` element.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
2021-04-30 18:03:15 +01:00
* @since 1.5.0
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_textarea( $p_str_setting_name ) {
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
2021-04-15 17:03:46 +01:00
return sprintf(
'<textarea name="%s" id="%s">%s</textarea>',
$l_arr_data['name'],
$l_arr_data['id'],
$l_arr_data['value']
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for a text `<input>` element with the colour selection
* class.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.6
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
* @todo Use proper colorpicker element.
2021-04-15 17:03:46 +01:00
*/
protected function add_color_selection( $p_str_setting_name ) {
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
2021-04-15 17:03:46 +01:00
return sprintf(
2021-04-16 21:50:02 +01:00
'<input type="text" name="%s" id="%s" class="footnotes-color-picker" value="%s"/>',
$l_arr_data['name'],
$l_arr_data['id'],
$l_arr_data['value']
2021-04-15 17:03:46 +01:00
);
}
/**
2021-04-30 18:03:15 +01:00
* Constructs the HTML for numeric `<input>` element.
*
* @access protected
2021-05-01 19:22:41 +01:00
* @param string $p_str_setting_name Setting key.
* @param int $p_in_min Minimum value.
* @param int $p_int_max Maximum value.
* @param bool $p_bool_deci `true` if float, `false` if integer. Default `false`.
2021-04-30 18:03:15 +01:00
* @return string
2021-04-15 17:03:46 +01:00
*
* @since 1.5.0
2021-04-30 18:03:15 +01:00
* @todo Refactor HTML generation.
2021-04-15 17:03:46 +01:00
*/
protected function add_num_box( $p_str_setting_name, $p_in_min, $p_int_max, $p_bool_deci = false ) {
2021-04-15 17:03:46 +01:00
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
2021-04-15 17:03:46 +01:00
if ( $p_bool_deci ) {
$l_str_value = number_format( floatval( $l_arr_data['value'] ), 1 );
2021-04-15 17:03:46 +01:00
return sprintf(
'<input type="number" name="%s" id="%s" value="%s" step="0.1" min="%d" max="%d"/>',
$l_arr_data['name'],
$l_arr_data['id'],
$l_str_value,
2021-04-15 17:03:46 +01:00
$p_in_min,
$p_int_max
2021-04-15 17:03:46 +01:00
);
} else {
return sprintf(
'<input type="number" name="%s" id="%s" value="%d" min="%d" max="%d"/>',
$l_arr_data['name'],
$l_arr_data['id'],
$l_arr_data['value'],
2021-04-15 17:03:46 +01:00
$p_in_min,
$p_int_max
2021-04-15 17:03:46 +01:00
);
}
}
}