Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../includes
File: class-widget.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[2] Fix | Delete
exit;
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* WPForms widget.
[7] Fix | Delete
*
[8] Fix | Delete
* @since 1.0.2
[9] Fix | Delete
*/
[10] Fix | Delete
class WPForms_Widget extends WP_Widget {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Hold widget settings defaults, populated in constructor.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.0.2
[16] Fix | Delete
*
[17] Fix | Delete
* @var array
[18] Fix | Delete
*/
[19] Fix | Delete
protected $defaults;
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Constructor.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.0.2
[25] Fix | Delete
*/
[26] Fix | Delete
public function __construct() {
[27] Fix | Delete
[28] Fix | Delete
// Widget defaults.
[29] Fix | Delete
$this->defaults = [
[30] Fix | Delete
'title' => '',
[31] Fix | Delete
'form_id' => '',
[32] Fix | Delete
'show_title' => false,
[33] Fix | Delete
'show_desc' => false,
[34] Fix | Delete
];
[35] Fix | Delete
[36] Fix | Delete
// Widget Slug.
[37] Fix | Delete
$widget_slug = 'wpforms-widget';
[38] Fix | Delete
[39] Fix | Delete
// Widget basics.
[40] Fix | Delete
$widget_ops = [
[41] Fix | Delete
'classname' => $widget_slug,
[42] Fix | Delete
'description' => esc_html_x( 'Display a form.', 'Widget', 'wpforms-lite' ),
[43] Fix | Delete
'show_instance_in_rest' => false,
[44] Fix | Delete
];
[45] Fix | Delete
[46] Fix | Delete
// Widget controls.
[47] Fix | Delete
$control_ops = [
[48] Fix | Delete
'id_base' => $widget_slug,
[49] Fix | Delete
];
[50] Fix | Delete
[51] Fix | Delete
// Load widget.
[52] Fix | Delete
parent::__construct( $widget_slug, esc_html_x( 'WPForms', 'Widget', 'wpforms-lite' ), $widget_ops, $control_ops );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* Output the HTML for this widget.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 1.0.2
[59] Fix | Delete
*
[60] Fix | Delete
* @param array $args An array of standard parameters for widgets in this theme.
[61] Fix | Delete
* @param array $instance An array of settings for this widget instance.
[62] Fix | Delete
*/
[63] Fix | Delete
public function widget( $args, $instance ) {
[64] Fix | Delete
[65] Fix | Delete
// Merge with defaults.
[66] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults );
[67] Fix | Delete
$args = wp_parse_args(
[68] Fix | Delete
$args,
[69] Fix | Delete
[
[70] Fix | Delete
'before_widget' => '',
[71] Fix | Delete
'after_widget' => '',
[72] Fix | Delete
'before_title' => '',
[73] Fix | Delete
'after_title' => '',
[74] Fix | Delete
]
[75] Fix | Delete
);
[76] Fix | Delete
[77] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[78] Fix | Delete
echo $args['before_widget'];
[79] Fix | Delete
[80] Fix | Delete
if ( ! empty( $instance['title'] ) ) {
[81] Fix | Delete
// phpcs:ignore
[82] Fix | Delete
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title'];
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
if ( ! empty( $instance['form_id'] ) ) {
[86] Fix | Delete
wpforms()->obj( 'frontend' )->output( absint( $instance['form_id'] ), (bool) $instance['show_title'], (bool) $instance['show_desc'] );
[87] Fix | Delete
}
[88] Fix | Delete
[89] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[90] Fix | Delete
echo $args['after_widget'];
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Deal with the settings when they are saved by the admin. Here is
[95] Fix | Delete
* where any validation should be dealt with.
[96] Fix | Delete
*
[97] Fix | Delete
* @since 1.0.2
[98] Fix | Delete
*
[99] Fix | Delete
* @param array $new_instance An array of new settings as submitted by the admin.
[100] Fix | Delete
* @param array $old_instance An array of the previous settings.
[101] Fix | Delete
*
[102] Fix | Delete
* @return array The validated and (if necessary) amended settings
[103] Fix | Delete
*/
[104] Fix | Delete
public function update( $new_instance, $old_instance ) {
[105] Fix | Delete
[106] Fix | Delete
$new_instance['title'] = wp_strip_all_tags( $new_instance['title'] );
[107] Fix | Delete
$new_instance['form_id'] = ! empty( $new_instance['form_id'] ) ? (int) $new_instance['form_id'] : 0;
[108] Fix | Delete
$new_instance['show_title'] = isset( $new_instance['show_title'] ) && $new_instance['show_title'] ? '1' : false;
[109] Fix | Delete
$new_instance['show_desc'] = isset( $new_instance['show_desc'] ) && $new_instance['show_desc'] ? '1' : false;
[110] Fix | Delete
[111] Fix | Delete
return $new_instance;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
/**
[115] Fix | Delete
* Display the form for this widget on the Widgets page of the WP Admin area.
[116] Fix | Delete
*
[117] Fix | Delete
* @since 1.0.2
[118] Fix | Delete
*
[119] Fix | Delete
* @param array $instance An array of the current settings for this widget.
[120] Fix | Delete
*/
[121] Fix | Delete
public function form( $instance ) {
[122] Fix | Delete
[123] Fix | Delete
// Merge with defaults.
[124] Fix | Delete
$instance = wp_parse_args( (array) $instance, $this->defaults );
[125] Fix | Delete
?>
[126] Fix | Delete
<p>
[127] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>">
[128] Fix | Delete
<?php echo esc_html( _x( 'Title:', 'Widget', 'wpforms-lite' ) ); ?>
[129] Fix | Delete
</label>
[130] Fix | Delete
<input type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat"/>
[131] Fix | Delete
</p>
[132] Fix | Delete
<p>
[133] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>">
[134] Fix | Delete
<?php echo esc_html( _x( 'Form:', 'Widget', 'wpforms-lite' ) ); ?>
[135] Fix | Delete
</label>
[136] Fix | Delete
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'form_id' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'form_id' ) ); ?>">
[137] Fix | Delete
<?php
[138] Fix | Delete
$forms = wpforms()->obj( 'form' )->get();
[139] Fix | Delete
[140] Fix | Delete
if ( ! empty( $forms ) ) {
[141] Fix | Delete
echo '<option value="" selected disabled>' . esc_html_x( 'Select your form', 'Widget', 'wpforms-lite' ) . '</option>';
[142] Fix | Delete
[143] Fix | Delete
foreach ( $forms as $form ) {
[144] Fix | Delete
echo '<option value="' . esc_attr( $form->ID ) . '" ' . selected( $instance['form_id'], $form->ID, false ) . '>' . esc_html( $form->post_title ) . '</option>';
[145] Fix | Delete
}
[146] Fix | Delete
} else {
[147] Fix | Delete
echo '<option value="">' . esc_html_x( 'No forms', 'Widget', 'wpforms-lite' ) . '</option>';
[148] Fix | Delete
}
[149] Fix | Delete
?>
[150] Fix | Delete
</select>
[151] Fix | Delete
</p>
[152] Fix | Delete
<p>
[153] Fix | Delete
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_title' ) ); ?>" <?php checked( '1', $instance['show_title'] ); ?>>
[154] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>">
[155] Fix | Delete
<?php echo esc_html( _x( 'Display form name', 'Widget', 'wpforms-lite' ) ); ?>
[156] Fix | Delete
</label>
[157] Fix | Delete
<br>
[158] Fix | Delete
<input type="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_desc' ) ); ?>" <?php checked( '1', $instance['show_desc'] ); ?>>
[159] Fix | Delete
<label for="<?php echo esc_attr( $this->get_field_id( 'show_desc' ) ); ?>">
[160] Fix | Delete
<?php echo esc_html( _x( 'Display form description', 'Widget', 'wpforms-lite' ) ); ?>
[161] Fix | Delete
</label>
[162] Fix | Delete
</p>
[163] Fix | Delete
<?php
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Register the WPForms widget.
[169] Fix | Delete
*
[170] Fix | Delete
* @since 1.0.2
[171] Fix | Delete
*/
[172] Fix | Delete
function wpforms_register_widgets() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
[173] Fix | Delete
[174] Fix | Delete
// Hide legacy widget. This filter is available from WP 5.8.
[175] Fix | Delete
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
[176] Fix | Delete
add_filter(
[177] Fix | Delete
'widget_types_to_hide_from_legacy_widget_block',
[178] Fix | Delete
static function ( $widget_types ) {
[179] Fix | Delete
[180] Fix | Delete
$widget_types[] = 'wpforms-widget';
[181] Fix | Delete
[182] Fix | Delete
return $widget_types;
[183] Fix | Delete
}
[184] Fix | Delete
);
[185] Fix | Delete
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName, WPForms.Comments.PHPDocHooks.RequiredHookDocumentation
[186] Fix | Delete
[187] Fix | Delete
register_widget( 'WPForms_Widget' );
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
add_action( 'widgets_init', 'wpforms_register_widgets' );
[191] Fix | Delete
[192] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function