', __( 'Settings saved', 'footnotes' ) );
}
// Form to submit the active section.
echo '';
echo '
';
// Echo JavaScript for the expand/collapse function of the meta boxes.
echo '';
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Save all Plugin settings.
*
* @since 1.5.0
* @return bool
*/
private function save_settings() {
$new_settings = array();
// TODO: add nonce verification.
// Get current section.
reset( $this->sections );
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->sections );
$active_section = $this->sections[ $active_section_id ];
foreach ( Footnotes_Settings::instance()->get_defaults( $active_section['container'] ) as $key => $l_mixed_value ) {
if ( array_key_exists( $key, $_POST ) ) {
$new_settings[ $key ] = wp_unslash( $_POST[ $key ] );
} else {
// Setting is not defined in the POST array, define it to avoid the Default value.
$new_settings[ $key ] = '';
}
}
// Update settings.
return Footnotes_Settings::instance()->save_options( $active_section['container'], $new_settings );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Output the Description of a section. May be overwritten in any section.
*
* @since 1.5.0
*/
public function description() {
// Default no description will be displayed.
}
/**
* Loads specific setting and returns an array with the keys [id, name, value].
*
* @since 1.5.0
* @param string $setting_key_name Settings Array key name.
* @return array Contains Settings ID, Settings Name and Settings Value.
*
* @since 2.5.11 Remove escapement function.
* When refactoring the codebase after 2.5.8, all and every output was escaped.
* After noticing that the plugin was broken, all escapement functions were removed.
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5
* @link https://github.com/markcheret/footnotes/pull/50#issuecomment-787624123
* In that process, this instance of esc_attr() was removed too, so the plugin was
* broken again.
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5#diff-a8ed6e859c32a18fc10bbbad3b4dd8ce7f43f2378d29471c7638e314ab30f1bdL349-L354
*
* @since 2.5.15 To fix it, the data was escaped in add_select_box() instead.
* @since 2.6.1 Restore esc_attr() in load_setting().
* @see add_select_box()
* This is the only instance of esc_|kses|sanitize in the pre-2.5.11 codebase.
* Removing this did not fix the quotation mark backslash escapement bug.
*/
protected function load_setting( $setting_key_name ) {
// Get current section.
reset( $this->sections );
$return = array();
$return['id'] = sprintf( '%s', $setting_key_name );
$return['name'] = sprintf( '%s', $setting_key_name );
$return['value'] = esc_attr( Footnotes_Settings::instance()->get( $setting_key_name ) );
return $return;
}
/**
* Returns a line break to start a new line.
*
* @since 1.5.0
* @return string
*/
protected function add_newline() {
return ' ';
}
/**
* Returns a line break to have a space between two lines.
*
* @since 1.5.0
* @return string
*/
protected function add_line_space() {
return '
';
}
/**
* Returns a simple text inside html text.
*
* @since 1.5.0
* @param string $text Message to be surrounded with simple html tag (span).
* @return string
*/
protected function add_text( $text ) {
return sprintf( '%s', $text );
}
/**
* Returns the html tag for an input/select label.
*
* @since 1.5.0
* @param string $setting_name Name of the Settings key to connect the Label with the input/select field.
* @param string $caption Label caption.
* @return string
*/
protected function add_label( $setting_name, $caption ) {
if ( empty( $caption ) ) {
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
* [style guides](https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui).
*/
return sprintf( '', $setting_name, $caption );
}
/**
* Returns the html tag for an input [type = text].
*
* @since 1.5.0
* @param string $setting_name Name of the Settings key to pre load the input field.
* @param int $max_length Maximum length of the input, default 999 characters.
* @param bool $readonly Set the input to be read only, default false.
* @param bool $hidden Set the input to be hidden, default false.
* @return string
*/
protected function add_text_box( $setting_name, $max_length = 999, $readonly = false, $hidden = false ) {
$style = '';
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
if ( $hidden ) {
$style .= 'display:none;';
}
return sprintf(
'',
$data['name'],
$data['id'],
$max_length,
$style,
$data['value'],
$readonly ? 'readonly="readonly"' : ''
);
}
/**
* Returns the html tag for an input [type = checkbox].
*
* @since 1.5.0
* @param string $setting_name Name of the Settings key to pre load the input field.
* @return string
*/
protected function add_checkbox( $setting_name ) {
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
return sprintf(
'',
$data['name'],
$data['id'],
Footnotes_Convert::to_bool( $data['value'] ) ? 'checked="checked"' : ''
);
}
/**
* Returns the html tag for a select box.
*
* @since 1.5.0
*
* - Bugfix: Dashboard: Referrers and tooltips: Backlink symbol: debug select box by reverting identity check to equality check, thanks to @lolzim bug report.
*
* @reporter @lolzim
*
* @since 2.5.13
* @param string $setting_name Name of the Settings key to pre select the current value.
* @param array $options Possible options to be selected.
* @return string
*
* @since 2.5.15 Bugfix: Dashboard: General settings: Footnote start and end short codes: debug select box for shortcodes with pointy brackets.
* @since 2.6.1 Restore esc_attr() in load_setting(), remove htmlspecialchars() here.
*/
protected function add_select_box( $setting_name, $options ) {
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
$select_options = '';
// Loop through all array keys.
foreach ( $options as $value => $caption ) {
$select_options .= sprintf(
'',
$value,
// Only check for equality, not identity, WRT backlink symbol arrows.
$value == $data['value'] ? 'selected' : '',
$caption
);
}
return sprintf(
'',
$data['name'],
$data['id'],
$select_options
);
}
/**
* Returns the html tag for a text area.
*
* @since 1.5.0
* @param string $setting_name Name of the Settings key to pre fill the text area.
* @return string
*/
protected function add_textarea( $setting_name ) {
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
return sprintf(
'',
$data['name'],
$data['id'],
$data['value']
);
}
/**
* Returns the html tag for an input [type = text] with color selection class.
*
* @since 1.5.6
* @param string $setting_name Name of the Settings key to pre load the input field.
* @return string
*/
protected function add_color_selection( $setting_name ) {
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
return sprintf(
'',
$data['name'],
$data['id'],
$data['value']
);
}
/**
* Returns the html tag for an input [type = num].
*
* @since 1.5.0
* @param string $setting_name Name of the Settings key to pre load the input field.
* @param int $p_in_min Minimum value.
* @param int $max Maximum value.
* @param bool $deci true if 0.1 steps and floating to string, false if integer (default).
* @return string
*
* Edited:
* @since 2.1.4 step argument and number_format() to allow decimals ..
*/
protected function add_num_box( $setting_name, $p_in_min, $max, $deci = false ) {
// Collect data for given settings field.
$data = $this->load_setting( $setting_name );
if ( $deci ) {
$value = number_format( floatval( $data['value'] ), 1 );
return sprintf(
'',
$data['name'],
$data['id'],
$value,
$p_in_min,
$max
);
} else {
return sprintf(
'',
$data['name'],
$data['id'],
$data['value'],
$p_in_min,
$max
);
}
}
}