Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Admin/Dashboar...
File: Widget.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Dashboard;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Class Widget.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.7.3
[7] Fix | Delete
*/
[8] Fix | Delete
abstract class Widget {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Instance slug.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 1.7.4
[14] Fix | Delete
*
[15] Fix | Delete
* @var string
[16] Fix | Delete
*/
[17] Fix | Delete
const SLUG = 'dash_widget';
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Save a widget meta for a current user using AJAX.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 1.7.4
[23] Fix | Delete
*/
[24] Fix | Delete
public function save_widget_meta_ajax() {
[25] Fix | Delete
[26] Fix | Delete
check_ajax_referer( 'wpforms_' . static::SLUG . '_nonce' );
[27] Fix | Delete
[28] Fix | Delete
$meta = ! empty( $_POST['meta'] ) ? sanitize_key( $_POST['meta'] ) : '';
[29] Fix | Delete
$value = ! empty( $_POST['value'] ) ? absint( $_POST['value'] ) : 0;
[30] Fix | Delete
[31] Fix | Delete
$this->widget_meta( 'set', $meta, $value );
[32] Fix | Delete
[33] Fix | Delete
exit();
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* Get/set a widget meta.
[38] Fix | Delete
*
[39] Fix | Delete
* @since 1.7.4
[40] Fix | Delete
*
[41] Fix | Delete
* @param string $action Possible value: 'get' or 'set'.
[42] Fix | Delete
* @param string $meta Meta name.
[43] Fix | Delete
* @param int $value Value to set.
[44] Fix | Delete
*
[45] Fix | Delete
* @return mixed
[46] Fix | Delete
*/
[47] Fix | Delete
protected function widget_meta( $action, $meta, $value = 0 ) {
[48] Fix | Delete
[49] Fix | Delete
$allowed_actions = [ 'get', 'set' ];
[50] Fix | Delete
[51] Fix | Delete
if ( ! in_array( $action, $allowed_actions, true ) ) {
[52] Fix | Delete
return false;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
$defaults = [
[56] Fix | Delete
'timespan' => $this->get_timespan_default(),
[57] Fix | Delete
'active_form_id' => 0,
[58] Fix | Delete
'hide_recommended_block' => 0,
[59] Fix | Delete
'hide_graph' => 0,
[60] Fix | Delete
'color_scheme' => 1, // 1 - wpforms, 2 - wp
[61] Fix | Delete
'graph_style' => 2, // 1 - bar, 2 - line
[62] Fix | Delete
];
[63] Fix | Delete
[64] Fix | Delete
if ( ! array_key_exists( $meta, $defaults ) ) {
[65] Fix | Delete
return false;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
$meta_key = 'wpforms_' . static::SLUG . '_' . $meta;
[69] Fix | Delete
$user_id = get_current_user_id();
[70] Fix | Delete
[71] Fix | Delete
if ( $action === 'get' ) {
[72] Fix | Delete
$meta_value = absint( get_user_meta( $user_id, $meta_key, true ) );
[73] Fix | Delete
// Return a default value from $defaults if $meta_value is empty.
[74] Fix | Delete
[75] Fix | Delete
return empty( $meta_value ) ? $defaults[ $meta ] : $meta_value;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$value = absint( $value );
[79] Fix | Delete
[80] Fix | Delete
if ( $action === 'set' && ! empty( $value ) ) {
[81] Fix | Delete
return update_user_meta( $user_id, $meta_key, $value );
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
if ( $action === 'set' && empty( $value ) ) {
[85] Fix | Delete
return delete_user_meta( $user_id, $meta_key );
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Get the default timespan option.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 1.7.4
[95] Fix | Delete
*
[96] Fix | Delete
* @return int|null
[97] Fix | Delete
*/
[98] Fix | Delete
protected function get_timespan_default() {
[99] Fix | Delete
[100] Fix | Delete
$options = $this->get_timespan_options();
[101] Fix | Delete
$default = reset( $options );
[102] Fix | Delete
[103] Fix | Delete
return is_numeric( $default ) ? $default : null;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
/**
[107] Fix | Delete
* Get timespan options (in days).
[108] Fix | Delete
*
[109] Fix | Delete
* @since 1.7.4
[110] Fix | Delete
*
[111] Fix | Delete
* @return array
[112] Fix | Delete
*/
[113] Fix | Delete
protected function get_timespan_options(): array {
[114] Fix | Delete
[115] Fix | Delete
$default = [ 7, 30 ];
[116] Fix | Delete
[117] Fix | Delete
$options = $default;
[118] Fix | Delete
[119] Fix | Delete
// Apply deprecated filters.
[120] Fix | Delete
if ( function_exists( 'apply_filters_deprecated' ) ) {
[121] Fix | Delete
// phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[122] Fix | Delete
$options = apply_filters_deprecated( 'wpforms_dash_widget_chart_timespan_options', [ $options ], '5.0', 'wpforms_dash_widget_timespan_options' );
[123] Fix | Delete
$options = apply_filters_deprecated( 'wpforms_dash_widget_forms_list_timespan_options', [ $options ], '5.0', 'wpforms_dash_widget_timespan_options' );
[124] Fix | Delete
// phpcs:enable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[125] Fix | Delete
} else {
[126] Fix | Delete
// phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[127] Fix | Delete
$options = apply_filters( 'wpforms_dash_widget_chart_timespan_options', $options );
[128] Fix | Delete
$options = apply_filters( 'wpforms_dash_widget_forms_list_timespan_options', $options );
[129] Fix | Delete
// phpcs:enable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( ! is_array( $options ) ) {
[133] Fix | Delete
$options = $default;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$widget_slug = static::SLUG;
[137] Fix | Delete
[138] Fix | Delete
// phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[139] Fix | Delete
$options = apply_filters( "wpforms_{$widget_slug}_timespan_options", $options );
[140] Fix | Delete
// phpcs:enable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName
[141] Fix | Delete
[142] Fix | Delete
if ( ! is_array( $options ) ) {
[143] Fix | Delete
return [];
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
$options = array_filter( $options, 'is_numeric' );
[147] Fix | Delete
[148] Fix | Delete
return empty( $options ) ? $default : $options;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Widget settings HTML.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 1.7.4
[155] Fix | Delete
*
[156] Fix | Delete
* @param bool $enabled Is form fields should be enabled.
[157] Fix | Delete
*/
[158] Fix | Delete
protected function widget_settings_html( $enabled = true ) {
[159] Fix | Delete
[160] Fix | Delete
$graph_style = $this->widget_meta( 'get', 'graph_style' );
[161] Fix | Delete
$color_scheme = $this->widget_meta( 'get', 'color_scheme' );
[162] Fix | Delete
[163] Fix | Delete
echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[164] Fix | Delete
'admin/dashboard/widget/settings',
[165] Fix | Delete
[
[166] Fix | Delete
'graph_style' => $graph_style,
[167] Fix | Delete
'color_scheme' => $color_scheme,
[168] Fix | Delete
'enabled' => $enabled,
[169] Fix | Delete
],
[170] Fix | Delete
true
[171] Fix | Delete
);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Return randomly chosen one of the recommended plugins.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 1.7.3
[178] Fix | Delete
*
[179] Fix | Delete
* @return array
[180] Fix | Delete
*/
[181] Fix | Delete
final protected function get_recommended_plugin(): array {
[182] Fix | Delete
[183] Fix | Delete
$plugins = [
[184] Fix | Delete
'google-analytics-for-wordpress/googleanalytics.php' => [
[185] Fix | Delete
'name' => __( 'MonsterInsights', 'wpforms-lite' ),
[186] Fix | Delete
'slug' => 'google-analytics-for-wordpress',
[187] Fix | Delete
'more' => 'https://www.monsterinsights.com/',
[188] Fix | Delete
'pro' => [
[189] Fix | Delete
'file' => 'google-analytics-premium/googleanalytics-premium.php',
[190] Fix | Delete
],
[191] Fix | Delete
],
[192] Fix | Delete
'all-in-one-seo-pack/all_in_one_seo_pack.php' => [
[193] Fix | Delete
'name' => __( 'AIOSEO', 'wpforms-lite' ),
[194] Fix | Delete
'slug' => 'all-in-one-seo-pack',
[195] Fix | Delete
'more' => 'https://aioseo.com/',
[196] Fix | Delete
'pro' => [
[197] Fix | Delete
'file' => 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php',
[198] Fix | Delete
],
[199] Fix | Delete
],
[200] Fix | Delete
'coming-soon/coming-soon.php' => [
[201] Fix | Delete
'name' => __( 'SeedProd', 'wpforms-lite' ),
[202] Fix | Delete
'slug' => 'coming-soon',
[203] Fix | Delete
'more' => 'https://www.seedprod.com/',
[204] Fix | Delete
'pro' => [
[205] Fix | Delete
'file' => 'seedprod-coming-soon-pro-5/seedprod-coming-soon-pro-5.php',
[206] Fix | Delete
],
[207] Fix | Delete
],
[208] Fix | Delete
'wp-mail-smtp/wp_mail_smtp.php' => [
[209] Fix | Delete
'name' => __( 'WP Mail SMTP', 'wpforms-lite' ),
[210] Fix | Delete
'slug' => 'wp-mail-smtp',
[211] Fix | Delete
'more' => 'https://wpmailsmtp.com/',
[212] Fix | Delete
'pro' => [
[213] Fix | Delete
'file' => 'wp-mail-smtp-pro/wp_mail_smtp.php',
[214] Fix | Delete
],
[215] Fix | Delete
],
[216] Fix | Delete
];
[217] Fix | Delete
[218] Fix | Delete
$installed = get_plugins();
[219] Fix | Delete
[220] Fix | Delete
foreach ( $plugins as $id => $plugin ) {
[221] Fix | Delete
[222] Fix | Delete
if ( isset( $installed[ $id ] ) ) {
[223] Fix | Delete
unset( $plugins[ $id ] );
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
if ( isset( $plugin['pro']['file'], $installed[ $plugin['pro']['file'] ] ) ) {
[227] Fix | Delete
unset( $plugins[ $id ] );
[228] Fix | Delete
}
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
return $plugins ? $plugins[ array_rand( $plugins ) ] : [];
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
/**
[235] Fix | Delete
* Timespan select HTML.
[236] Fix | Delete
*
[237] Fix | Delete
* @since 1.7.4
[238] Fix | Delete
*
[239] Fix | Delete
* @param int $active_form_id Currently preselected form ID.
[240] Fix | Delete
* @param bool $enabled If the select menu items should be enabled.
[241] Fix | Delete
*/
[242] Fix | Delete
protected function timespan_select_html( $active_form_id, $enabled = true ) {
[243] Fix | Delete
?>
[244] Fix | Delete
<select id="wpforms-dash-widget-timespan" class="wpforms-dash-widget-select-timespan" title="<?php esc_attr_e( 'Select timespan', 'wpforms-lite' ); ?>"
[245] Fix | Delete
<?php echo ! empty( $active_form_id ) ? 'data-active-form-id="' . absint( $active_form_id ) . '"' : ''; ?>>
[246] Fix | Delete
<?php $this->timespan_options_html( $this->get_timespan_options(), $enabled ); ?>
[247] Fix | Delete
</select>
[248] Fix | Delete
[249] Fix | Delete
<?php
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/**
[253] Fix | Delete
* Timespan select options HTML.
[254] Fix | Delete
*
[255] Fix | Delete
* @since 1.7.4
[256] Fix | Delete
*
[257] Fix | Delete
* @param array $options Timespan options (in days).
[258] Fix | Delete
* @param bool $enabled If the select menu items should be enabled.
[259] Fix | Delete
*/
[260] Fix | Delete
protected function timespan_options_html( $options, $enabled = true ) {
[261] Fix | Delete
[262] Fix | Delete
$timespan = $this->widget_meta( 'get', 'timespan' );
[263] Fix | Delete
[264] Fix | Delete
foreach ( $options as $option ) :
[265] Fix | Delete
?>
[266] Fix | Delete
<option value="<?php echo absint( $option ); ?>" <?php selected( $timespan, absint( $option ) ); ?> <?php disabled( ! $enabled ); ?>>
[267] Fix | Delete
<?php /* translators: %d - number of days. */ ?>
[268] Fix | Delete
<?php echo esc_html( sprintf( _n( 'Last %d day', 'Last %d days', absint( $option ), 'wpforms-lite' ), absint( $option ) ) ); ?>
[269] Fix | Delete
</option>
[270] Fix | Delete
<?php
[271] Fix | Delete
endforeach;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
/**
[275] Fix | Delete
* Check if the current page is a dashboard page.
[276] Fix | Delete
*
[277] Fix | Delete
* @since 1.8.3
[278] Fix | Delete
*
[279] Fix | Delete
* @return bool
[280] Fix | Delete
*/
[281] Fix | Delete
protected function is_dashboard_page(): bool {
[282] Fix | Delete
[283] Fix | Delete
global $pagenow;
[284] Fix | Delete
[285] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[286] Fix | Delete
return $pagenow === 'index.php' && empty( $_GET['page'] );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
/**
[290] Fix | Delete
* Check if is a dashboard widget ajax request.
[291] Fix | Delete
*
[292] Fix | Delete
* @since 1.8.3
[293] Fix | Delete
*
[294] Fix | Delete
* @return bool
[295] Fix | Delete
*/
[296] Fix | Delete
protected function is_dashboard_widget_ajax_request(): bool {
[297] Fix | Delete
[298] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[299] Fix | Delete
return wpforms_is_admin_ajax() && isset( $_REQUEST['action'] ) && strpos( sanitize_key( $_REQUEST['action'] ), 'wpforms_dash_widget' ) !== false;
[300] Fix | Delete
}
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function