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/Splash
File: SplashScreen.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Splash;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* What's New class.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.8.7
[7] Fix | Delete
*/
[8] Fix | Delete
class SplashScreen {
[9] Fix | Delete
[10] Fix | Delete
use SplashTrait;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Splash data.
[14] Fix | Delete
*
[15] Fix | Delete
* @since 1.8.7
[16] Fix | Delete
*
[17] Fix | Delete
* @var array
[18] Fix | Delete
*/
[19] Fix | Delete
private $splash_data = [];
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Whether it is a new WPForms installation.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.8.8
[25] Fix | Delete
*
[26] Fix | Delete
* @var bool
[27] Fix | Delete
*/
[28] Fix | Delete
private $is_new_install;
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Initialize class.
[32] Fix | Delete
*
[33] Fix | Delete
* @since 1.8.7
[34] Fix | Delete
*/
[35] Fix | Delete
public function init() {
[36] Fix | Delete
[37] Fix | Delete
$this->hooks();
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Hooks.
[42] Fix | Delete
*
[43] Fix | Delete
* @since 1.8.7
[44] Fix | Delete
*/
[45] Fix | Delete
private function hooks() {
[46] Fix | Delete
[47] Fix | Delete
add_action( 'admin_init', [ $this, 'initialize_splash_data' ], 15 );
[48] Fix | Delete
add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
[49] Fix | Delete
add_action( 'admin_footer', [ $this, 'admin_footer' ] );
[50] Fix | Delete
add_filter( 'wpforms_pro_admin_dashboard_widget_welcome_block_html_message', [ $this, 'add_splash_link' ] );
[51] Fix | Delete
add_filter( 'wpforms_lite_admin_dashboard_widget_welcome_block_html_message', [ $this, 'add_splash_link' ] );
[52] Fix | Delete
add_filter( 'update_footer', [ $this, 'add_splash_link' ], PHP_INT_MAX );
[53] Fix | Delete
add_filter( 'removable_query_args', [ $this, 'removable_query_args' ] );
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Initialize splash data.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 1.8.7
[60] Fix | Delete
*/
[61] Fix | Delete
public function initialize_splash_data() {
[62] Fix | Delete
[63] Fix | Delete
if ( ! $this->is_allow_splash() ) {
[64] Fix | Delete
return;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
if ( empty( $this->splash_data ) ) {
[68] Fix | Delete
$cached_data_obj = wpforms()->get( 'splash_cache' );
[69] Fix | Delete
$cached_data = $cached_data_obj ? $cached_data_obj->get() : null;
[70] Fix | Delete
[71] Fix | Delete
if ( empty( $cached_data ) ) {
[72] Fix | Delete
return;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
$default_data = $this->get_default_data();
[76] Fix | Delete
[77] Fix | Delete
$this->splash_data = wp_parse_args( $cached_data, $default_data );
[78] Fix | Delete
[79] Fix | Delete
$version = $this->get_major_version( WPFORMS_VERSION );
[80] Fix | Delete
[81] Fix | Delete
$this->update_splash_data_version( $version );
[82] Fix | Delete
}
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
/**
[86] Fix | Delete
* Enqueue assets.
[87] Fix | Delete
*
[88] Fix | Delete
* @since 1.8.7
[89] Fix | Delete
*/
[90] Fix | Delete
public function admin_enqueue_scripts() {
[91] Fix | Delete
[92] Fix | Delete
$min = wpforms_get_min_suffix();
[93] Fix | Delete
[94] Fix | Delete
// jQuery confirm.
[95] Fix | Delete
wp_register_script(
[96] Fix | Delete
'jquery-confirm',
[97] Fix | Delete
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.js',
[98] Fix | Delete
[ 'jquery' ],
[99] Fix | Delete
'1.0.0',
[100] Fix | Delete
true
[101] Fix | Delete
);
[102] Fix | Delete
[103] Fix | Delete
wp_register_style(
[104] Fix | Delete
'jquery-confirm',
[105] Fix | Delete
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.css',
[106] Fix | Delete
[],
[107] Fix | Delete
'1.0.0'
[108] Fix | Delete
);
[109] Fix | Delete
[110] Fix | Delete
wp_register_script(
[111] Fix | Delete
'wpforms-splash-modal',
[112] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/admin/splash/modal{$min}.js",
[113] Fix | Delete
[ 'jquery' ],
[114] Fix | Delete
WPFORMS_VERSION,
[115] Fix | Delete
true
[116] Fix | Delete
);
[117] Fix | Delete
[118] Fix | Delete
wp_register_style(
[119] Fix | Delete
'wpforms-splash-modal',
[120] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/css/admin/admin-splash-modal{$min}.css",
[121] Fix | Delete
[],
[122] Fix | Delete
WPFORMS_VERSION
[123] Fix | Delete
);
[124] Fix | Delete
[125] Fix | Delete
wp_localize_script(
[126] Fix | Delete
'wpforms-splash-modal',
[127] Fix | Delete
'wpforms_splash_data',
[128] Fix | Delete
[
[129] Fix | Delete
'triggerForceOpen' => $this->should_open_splash(),
[130] Fix | Delete
]
[131] Fix | Delete
);
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Output splash modal.
[136] Fix | Delete
*
[137] Fix | Delete
* @since 1.8.7
[138] Fix | Delete
*/
[139] Fix | Delete
public function admin_footer() {
[140] Fix | Delete
[141] Fix | Delete
if ( $this->is_splash_empty() || ! $this->is_allow_splash() ) {
[142] Fix | Delete
return;
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
$this->render_modal();
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Check if splash data is empty.
[150] Fix | Delete
*
[151] Fix | Delete
* @since 1.8.7
[152] Fix | Delete
* @since 1.8.8 Changed method visibility from private to public.
[153] Fix | Delete
*
[154] Fix | Delete
* @return bool True if empty, false otherwise.
[155] Fix | Delete
*/
[156] Fix | Delete
public function is_splash_empty(): bool {
[157] Fix | Delete
[158] Fix | Delete
if ( empty( $this->splash_data ) ) {
[159] Fix | Delete
return true;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
return empty( $this->retrieve_blocks_for_user( $this->splash_data['blocks'] ?? [] ) );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Retrieve blocks for user.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 1.8.7
[169] Fix | Delete
*
[170] Fix | Delete
* @param array $blocks Splash modal blocks.
[171] Fix | Delete
*/
[172] Fix | Delete
private function retrieve_blocks_for_user( array $blocks ): array {
[173] Fix | Delete
[174] Fix | Delete
$user_license = $this->get_user_license();
[175] Fix | Delete
[176] Fix | Delete
if ( ! $user_license ) {
[177] Fix | Delete
$user_license = 'lite';
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
return array_filter(
[181] Fix | Delete
$blocks,
[182] Fix | Delete
static function ( $block ) use ( $user_license ) { //phpcs:ignore WPForms.PHP.UseStatement.UnusedUseStatement
[183] Fix | Delete
[184] Fix | Delete
return in_array( $user_license, $block['type'] ?? [], true );
[185] Fix | Delete
}
[186] Fix | Delete
);
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Render splash modal.
[191] Fix | Delete
*
[192] Fix | Delete
* @since 1.8.7
[193] Fix | Delete
*
[194] Fix | Delete
* @param array $data Splash modal data.
[195] Fix | Delete
*/
[196] Fix | Delete
public function render_modal( array $data = [] ) {
[197] Fix | Delete
[198] Fix | Delete
wp_enqueue_script( 'jquery-confirm' );
[199] Fix | Delete
wp_enqueue_style( 'jquery-confirm' );
[200] Fix | Delete
[201] Fix | Delete
wp_enqueue_script( 'wpforms-splash-modal' );
[202] Fix | Delete
wp_enqueue_style( 'wpforms-splash-modal' );
[203] Fix | Delete
[204] Fix | Delete
if ( $this->should_open_splash() ) {
[205] Fix | Delete
$this->update_splash_version();
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
if ( empty( $data ) ) {
[209] Fix | Delete
$data = $this->splash_data ?? [];
[210] Fix | Delete
[211] Fix | Delete
$data['blocks'] = $this->retrieve_blocks_for_user( $data['blocks'] ?? [] );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[215] Fix | Delete
echo wpforms_render( 'admin/splash/modal', $data, true );
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Add a splash link to footer.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 1.8.7
[222] Fix | Delete
*
[223] Fix | Delete
* @param string|mixed $content Footer content.
[224] Fix | Delete
*
[225] Fix | Delete
* @return string Footer content.
[226] Fix | Delete
*/
[227] Fix | Delete
public function add_splash_link( $content ): string {
[228] Fix | Delete
[229] Fix | Delete
$content = (string) $content;
[230] Fix | Delete
[231] Fix | Delete
if ( ! $this->is_available_for_display() ) {
[232] Fix | Delete
return $content;
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
// Allow only on WPForms pages and the Dashboard.
[236] Fix | Delete
if ( ! $this->is_allow_splash() || $this->is_new_install() ) {
[237] Fix | Delete
return $content;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
// Do not output the link in the footer on the dashboard.
[241] Fix | Delete
if ( $this->is_dashboard() && current_filter() === 'update_footer' ) {
[242] Fix | Delete
return $content;
[243] Fix | Delete
}
[244] Fix | Delete
[245] Fix | Delete
$content .= sprintf(
[246] Fix | Delete
' <span>-</span> <a href="#" class="wpforms-splash-modal-open">%s</a>',
[247] Fix | Delete
__( 'See the new features!', 'wpforms-lite' )
[248] Fix | Delete
);
[249] Fix | Delete
[250] Fix | Delete
return $content;
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Check if splash modal can be displayed manually, via a link.
[255] Fix | Delete
* Used in footer and in form builder context menu.
[256] Fix | Delete
*
[257] Fix | Delete
* @since 1.8.8
[258] Fix | Delete
*
[259] Fix | Delete
* @return bool
[260] Fix | Delete
*/
[261] Fix | Delete
public function is_available_for_display(): bool {
[262] Fix | Delete
[263] Fix | Delete
// Return if splash data is empty.
[264] Fix | Delete
if ( $this->is_splash_empty() ) {
[265] Fix | Delete
return false;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
// Return if a splash data version is different from the current plugin major version.
[269] Fix | Delete
if ( $this->get_splash_data_version() !== $this->get_major_version( WPFORMS_VERSION ) ) {
[270] Fix | Delete
return false;
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return true;
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Check if splash modal is allowed.
[278] Fix | Delete
* Only allow in Form Builder, WPForms pages, and the Dashboard.
[279] Fix | Delete
* And only if it's not a new installation.
[280] Fix | Delete
*
[281] Fix | Delete
* @since 1.8.7
[282] Fix | Delete
*
[283] Fix | Delete
* @return bool True if allowed, false otherwise.
[284] Fix | Delete
*/
[285] Fix | Delete
public function is_allow_splash(): bool {
[286] Fix | Delete
[287] Fix | Delete
if ( ! $this->is_force_open() && $this->is_new_install() ) {
[288] Fix | Delete
return false;
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
// Only show on WPForms pages OR dashboard.
[292] Fix | Delete
return wpforms_is_admin_page( 'builder' ) || wpforms_is_admin_page() || $this->is_dashboard();
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
/**
[296] Fix | Delete
* Check if the current page is the dashboard.
[297] Fix | Delete
*
[298] Fix | Delete
* @since 1.8.8
[299] Fix | Delete
*
[300] Fix | Delete
* @return bool True if it is the dashboard, false otherwise.
[301] Fix | Delete
*/
[302] Fix | Delete
private function is_dashboard(): bool {
[303] Fix | Delete
[304] Fix | Delete
global $pagenow;
[305] Fix | Delete
[306] Fix | Delete
return $pagenow === 'index.php';
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
/**
[310] Fix | Delete
* Check if splash modal should be forced open.
[311] Fix | Delete
*
[312] Fix | Delete
* @since 1.8.8
[313] Fix | Delete
*
[314] Fix | Delete
* @return bool True if it should be forced open, false otherwise.
[315] Fix | Delete
*/
[316] Fix | Delete
private function is_force_open(): bool {
[317] Fix | Delete
[318] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[319] Fix | Delete
return sanitize_key( $_GET['wpforms_action'] ?? '' ) === 'preview-splash-screen';
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* Check if splash modal should be opened.
[324] Fix | Delete
*
[325] Fix | Delete
* @since 1.8.7
[326] Fix | Delete
*
[327] Fix | Delete
* @return bool True if splash should open, false otherwise.
[328] Fix | Delete
*/
[329] Fix | Delete
private function should_open_splash(): bool {
[330] Fix | Delete
[331] Fix | Delete
// Skip if announcements are hidden, or it is the dashboard page.
[332] Fix | Delete
if ( $this->is_dashboard() || $this->hide_splash_modal() ) {
[333] Fix | Delete
return false;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
$splash_version = $this->get_latest_splash_version();
[337] Fix | Delete
[338] Fix | Delete
// Allow if a splash version different from the current plugin major version, and it's not a new installation.
[339] Fix | Delete
return $splash_version !== $this->get_major_version( WPFORMS_VERSION ) &&
[340] Fix | Delete
( ! $this->is_new_install() || $this->is_force_open() );
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* Check if the plugin is newly installed.
[345] Fix | Delete
*
[346] Fix | Delete
* Get all migrations that have run.
[347] Fix | Delete
* If the only migration with a timestamp is the current version, it's a new installation.
[348] Fix | Delete
*
[349] Fix | Delete
* @since 1.8.8
[350] Fix | Delete
*
[351] Fix | Delete
* @return bool True if new install, false otherwise.
[352] Fix | Delete
*/
[353] Fix | Delete
private function is_new_install(): bool {
[354] Fix | Delete
[355] Fix | Delete
if ( isset( $this->is_new_install ) ) {
[356] Fix | Delete
return $this->is_new_install;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
$option_name = wpforms()->is_pro() ? 'wpforms_versions' : 'wpforms_versions_lite';
[360] Fix | Delete
[361] Fix | Delete
$migrations_run = get_option( $option_name, [] );
[362] Fix | Delete
[363] Fix | Delete
if ( empty( $migrations_run ) ) {
[364] Fix | Delete
return true;
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
unset( $migrations_run[ WPFORMS_VERSION ] );
[368] Fix | Delete
[369] Fix | Delete
$this->is_new_install = empty( end( $migrations_run ) );
[370] Fix | Delete
[371] Fix | Delete
return $this->is_new_install;
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
/**
[375] Fix | Delete
* Check if splash modal should be hidden.
[376] Fix | Delete
*
[377] Fix | Delete
* @since 1.8.8
[378] Fix | Delete
*
[379] Fix | Delete
* @return bool True if hidden, false otherwise.
[380] Fix | Delete
*/
[381] Fix | Delete
private function hide_splash_modal(): bool {
[382] Fix | Delete
[383] Fix | Delete
/**
[384] Fix | Delete
* Force to hide splash modal.
[385] Fix | Delete
*
[386] Fix | Delete
* @since 1.8.8
[387] Fix | Delete
*
[388] Fix | Delete
* @param bool $hide_splash_modal True to hide, false otherwise.
[389] Fix | Delete
*/
[390] Fix | Delete
return (bool) apply_filters( 'wpforms_admin_splash_screen_hide_splash_modal', wpforms_setting( 'hide-announcements' ) );
[391] Fix | Delete
}
[392] Fix | Delete
[393] Fix | Delete
/**
[394] Fix | Delete
* Remove certain arguments from a query string that WordPress should always hide for users.
[395] Fix | Delete
*
[396] Fix | Delete
* @since 1.8.8
[397] Fix | Delete
*
[398] Fix | Delete
* @param array $removable_query_args An array of parameters to remove from the URL.
[399] Fix | Delete
*
[400] Fix | Delete
* @return array Extended/filtered array of parameters to remove from the URL.
[401] Fix | Delete
*/
[402] Fix | Delete
public function removable_query_args( $removable_query_args ) {
[403] Fix | Delete
[404] Fix | Delete
$removable_query_args[] = 'wpforms_action';
[405] Fix | Delete
[406] Fix | Delete
return $removable_query_args;
[407] Fix | Delete
}
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function