Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wpforms-.../src/Admin/Traits
File: HasScreenOptions.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Traits;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Enables screen options for the current screen.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.8.8
[7] Fix | Delete
*/
[8] Fix | Delete
trait HasScreenOptions {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* A configuration array for the screen options.
[12] Fix | Delete
*
[13] Fix | Delete
* @var array Array of screen options.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.8.8
[16] Fix | Delete
*/
[17] Fix | Delete
private $screen_options;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Screen options ID.
[21] Fix | Delete
*
[22] Fix | Delete
* @var string Screen options ID.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.8.8
[25] Fix | Delete
*/
[26] Fix | Delete
private $screen_options_id;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Initialize the screen options.
[30] Fix | Delete
*
[31] Fix | Delete
* This method should be called during init of the class that uses this trait.
[32] Fix | Delete
* If the class itself is allowed to load, it should set $allowed to true.
[33] Fix | Delete
*
[34] Fix | Delete
* @param bool $allowed Whether to allow screen options or not.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 1.8.8
[37] Fix | Delete
*/
[38] Fix | Delete
public function init_screen_options( bool $allowed = false ) {
[39] Fix | Delete
[40] Fix | Delete
// This should always run.
[41] Fix | Delete
$this->filter_screen_options();
[42] Fix | Delete
[43] Fix | Delete
if ( ! $allowed ) {
[44] Fix | Delete
return;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
add_action( 'admin_head', [ $this, 'add_screen_options' ] );
[48] Fix | Delete
add_filter( 'screen_settings', [ $this, 'render_screen_options' ], 10, 2 );
[49] Fix | Delete
add_filter( "set_screen_option_{$this->screen_options_id}", [ $this, 'save_screen_options' ], 10, 2 );
[50] Fix | Delete
add_filter( 'screen_options_show_submit', '__return_true' );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Filter screen options.
[55] Fix | Delete
*
[56] Fix | Delete
* @since 1.8.8
[57] Fix | Delete
*/
[58] Fix | Delete
public function filter_screen_options() {
[59] Fix | Delete
[60] Fix | Delete
$options = get_user_option( $this->screen_options_id );
[61] Fix | Delete
[62] Fix | Delete
foreach ( $this->screen_options as $group => $options_group ) {
[63] Fix | Delete
foreach ( $options_group['options'] as $option ) {
[64] Fix | Delete
add_filter(
[65] Fix | Delete
"get_user_option_{$this->screen_options_id}_{$group}_{$option['option']}",
[66] Fix | Delete
function () use ( $option, $group, $options ) {
[67] Fix | Delete
$key = $group . '_' . $option['option'];
[68] Fix | Delete
[69] Fix | Delete
return $options[ $key ] ?? $option['default'];
[70] Fix | Delete
}
[71] Fix | Delete
);
[72] Fix | Delete
}
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Configure screen options.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 1.8.8
[80] Fix | Delete
*/
[81] Fix | Delete
public function add_screen_options() {
[82] Fix | Delete
[83] Fix | Delete
foreach ( $this->screen_options as $group => $options_group ) {
[84] Fix | Delete
foreach ( $options_group['options'] as $option ) {
[85] Fix | Delete
add_screen_option(
[86] Fix | Delete
$group . '_' . $option['option'],
[87] Fix | Delete
[
[88] Fix | Delete
'label' => $option['label'],
[89] Fix | Delete
'option' => $option['option'],
[90] Fix | Delete
'default' => $option['default'],
[91] Fix | Delete
]
[92] Fix | Delete
);
[93] Fix | Delete
}
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* Save screen options.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 1.8.8
[101] Fix | Delete
*
[102] Fix | Delete
* @param mixed $status Status of the screen option.
[103] Fix | Delete
* @param string $option Option name.
[104] Fix | Delete
*
[105] Fix | Delete
* @return mixed
[106] Fix | Delete
*/
[107] Fix | Delete
public function save_screen_options( $status, $option ) { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded
[108] Fix | Delete
[109] Fix | Delete
if ( $option === $this->screen_options_id ) {
[110] Fix | Delete
[111] Fix | Delete
$value = [];
[112] Fix | Delete
[113] Fix | Delete
foreach ( $this->screen_options as $group => $options_group ) {
[114] Fix | Delete
[115] Fix | Delete
$options = $options_group['options'];
[116] Fix | Delete
[117] Fix | Delete
foreach ( $options as $group_option ) {
[118] Fix | Delete
$key = $group . '_' . $group_option['option'];
[119] Fix | Delete
[120] Fix | Delete
if ( ! isset( $_POST[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
[121] Fix | Delete
$value[ $key ] = false;
[122] Fix | Delete
[123] Fix | Delete
continue;
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
$value[ $key ] = ! empty( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) : $group_option['default']; // phpcs:ignore WordPress.Security.NonceVerification.Missing
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
return $value;
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
return $status;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* Render screen options.
[138] Fix | Delete
*
[139] Fix | Delete
* @since 1.8.8
[140] Fix | Delete
*
[141] Fix | Delete
* @param string $screen_settings HTML markup of custom screen settings.
[142] Fix | Delete
*
[143] Fix | Delete
* @return string
[144] Fix | Delete
*/
[145] Fix | Delete
public function render_screen_options( $screen_settings ) { // phpcs:ignore Generic.Metrics.NestingLevel.MaxExceeded, Generic.Metrics.CyclomaticComplexity.TooHigh
[146] Fix | Delete
[147] Fix | Delete
foreach ( $this->screen_options as $group => $options_group ) {
[148] Fix | Delete
$screen_settings .= '<fieldset>';
[149] Fix | Delete
$screen_settings .= '<legend>' . esc_html( $options_group['heading'] ) . '</legend>';
[150] Fix | Delete
[151] Fix | Delete
foreach ( $options_group['options'] as $option ) {
[152] Fix | Delete
$option_value = get_user_option( "{$this->screen_options_id}_{$group}_{$option['option']}" );
[153] Fix | Delete
[154] Fix | Delete
$key = $group . '_' . $option['option'];
[155] Fix | Delete
[156] Fix | Delete
switch ( $option['type'] ) {
[157] Fix | Delete
case 'checkbox':
[158] Fix | Delete
$screen_settings .= sprintf(
[159] Fix | Delete
'<label>
[160] Fix | Delete
<input type="checkbox" id="%1$s" name="%1$s" value="1" %2$s>%3$s
[161] Fix | Delete
</label>',
[162] Fix | Delete
$key,
[163] Fix | Delete
checked( (bool) $option_value, true, false ),
[164] Fix | Delete
esc_html( $option['label'] )
[165] Fix | Delete
);
[166] Fix | Delete
break;
[167] Fix | Delete
[168] Fix | Delete
case 'number':
[169] Fix | Delete
$screen_settings .= sprintf(
[170] Fix | Delete
'<label for="%1$s">%2$s</label>
[171] Fix | Delete
<input type="number" id="%1$s" name="%1$s" value="%3$s" %4$s>',
[172] Fix | Delete
$key,
[173] Fix | Delete
esc_html( $option['label'] ),
[174] Fix | Delete
esc_attr( $option_value ),
[175] Fix | Delete
wpforms_html_attributes( '', [], [], $option['args'] ?? [] )
[176] Fix | Delete
);
[177] Fix | Delete
break;
[178] Fix | Delete
[179] Fix | Delete
case 'text':
[180] Fix | Delete
$screen_settings .= sprintf(
[181] Fix | Delete
'<label for="%1$s">%2$s</label>
[182] Fix | Delete
<input type="text" id="%1$s" name="%1$s" value="%3$s">',
[183] Fix | Delete
$key,
[184] Fix | Delete
esc_html( $option['label'] ),
[185] Fix | Delete
esc_attr( $option_value )
[186] Fix | Delete
);
[187] Fix | Delete
break;
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
$screen_settings .= sprintf(
[192] Fix | Delete
'<input name="wp_screen_options[option]" type="hidden" value="%s"><input name="wp_screen_options[value]" type="hidden" value="">',
[193] Fix | Delete
$this->screen_options_id
[194] Fix | Delete
);
[195] Fix | Delete
[196] Fix | Delete
$screen_settings .= '</fieldset>';
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
return $screen_settings;
[200] Fix | Delete
}
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function