Edit File by line
/home/zeestwma/ceyloniy.../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( 'removable_query_args', [ $this, 'removable_query_args' ] );
[51] Fix | Delete
add_action( 'update_option_wpforms_license', [ $this, 'reset_splash_data' ] );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Initialize splash data.
[56] Fix | Delete
*
[57] Fix | Delete
* @since 1.8.7
[58] Fix | Delete
*/
[59] Fix | Delete
public function initialize_splash_data() {
[60] Fix | Delete
[61] Fix | Delete
if ( ! $this->is_allow_splash() ) {
[62] Fix | Delete
return;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
if ( empty( $this->splash_data ) ) {
[66] Fix | Delete
$cached_data_obj = wpforms()->obj( 'splash_cache' );
[67] Fix | Delete
$cached_data = $cached_data_obj ? $cached_data_obj->get() : null;
[68] Fix | Delete
[69] Fix | Delete
if ( empty( $cached_data ) ) {
[70] Fix | Delete
return;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
$default_data = $this->get_default_data();
[74] Fix | Delete
[75] Fix | Delete
$this->splash_data = wp_parse_args( $cached_data, $default_data );
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Enqueue assets.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 1.8.7
[83] Fix | Delete
*/
[84] Fix | Delete
public function admin_enqueue_scripts() {
[85] Fix | Delete
[86] Fix | Delete
$min = wpforms_get_min_suffix();
[87] Fix | Delete
[88] Fix | Delete
// jQuery confirm.
[89] Fix | Delete
wp_register_script(
[90] Fix | Delete
'jquery-confirm',
[91] Fix | Delete
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.js',
[92] Fix | Delete
[ 'jquery' ],
[93] Fix | Delete
'1.0.0',
[94] Fix | Delete
true
[95] Fix | Delete
);
[96] Fix | Delete
[97] Fix | Delete
wp_register_style(
[98] Fix | Delete
'jquery-confirm',
[99] Fix | Delete
WPFORMS_PLUGIN_URL . 'assets/lib/jquery.confirm/jquery-confirm.min.css',
[100] Fix | Delete
[],
[101] Fix | Delete
'1.0.0'
[102] Fix | Delete
);
[103] Fix | Delete
[104] Fix | Delete
wp_register_script(
[105] Fix | Delete
'wpforms-splash-modal',
[106] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/js/admin/splash/modal{$min}.js",
[107] Fix | Delete
[ 'jquery', 'wp-util' ],
[108] Fix | Delete
WPFORMS_VERSION,
[109] Fix | Delete
true
[110] Fix | Delete
);
[111] Fix | Delete
[112] Fix | Delete
wp_register_style(
[113] Fix | Delete
'wpforms-splash-modal',
[114] Fix | Delete
WPFORMS_PLUGIN_URL . "assets/css/admin/admin-splash-modal{$min}.css",
[115] Fix | Delete
[],
[116] Fix | Delete
WPFORMS_VERSION
[117] Fix | Delete
);
[118] Fix | Delete
[119] Fix | Delete
wp_localize_script(
[120] Fix | Delete
'wpforms-splash-modal',
[121] Fix | Delete
'wpforms_splash_data',
[122] Fix | Delete
[
[123] Fix | Delete
'nonce' => wp_create_nonce( 'wpforms_dash_widget_nonce' ),
[124] Fix | Delete
'triggerForceOpen' => $this->should_open_splash(),
[125] Fix | Delete
]
[126] Fix | Delete
);
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Output splash modal.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 1.8.7
[133] Fix | Delete
*/
[134] Fix | Delete
public function admin_footer(): void {
[135] Fix | Delete
[136] Fix | Delete
if ( $this->is_splash_empty() || ! $this->is_allow_splash() ) {
[137] Fix | Delete
return;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
$this->render_modal();
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Check if splash data is empty.
[145] Fix | Delete
*
[146] Fix | Delete
* @since 1.8.7
[147] Fix | Delete
* @since 1.8.8 Changed method visibility from private to public.
[148] Fix | Delete
*
[149] Fix | Delete
* @return bool True if empty, false otherwise.
[150] Fix | Delete
*/
[151] Fix | Delete
public function is_splash_empty(): bool {
[152] Fix | Delete
[153] Fix | Delete
if ( empty( $this->splash_data ) ) {
[154] Fix | Delete
return true;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
return empty( $this->splash_data['blocks'] );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Render splash modal.
[162] Fix | Delete
*
[163] Fix | Delete
* @since 1.8.7
[164] Fix | Delete
*
[165] Fix | Delete
* @param array $data Splash modal data.
[166] Fix | Delete
*/
[167] Fix | Delete
public function render_modal( array $data = [] ) {
[168] Fix | Delete
[169] Fix | Delete
wp_enqueue_script( 'jquery-confirm' );
[170] Fix | Delete
wp_enqueue_style( 'jquery-confirm' );
[171] Fix | Delete
[172] Fix | Delete
wp_enqueue_script( 'wpforms-splash-modal' );
[173] Fix | Delete
wp_enqueue_style( 'wpforms-splash-modal' );
[174] Fix | Delete
[175] Fix | Delete
if ( $this->should_open_splash() ) {
[176] Fix | Delete
$this->update_splash_version();
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
$data = ! empty( $data ) ? $data : $this->splash_data;
[180] Fix | Delete
[181] Fix | Delete
if ( ! $this->is_plugin_version_up_to_date() ) {
[182] Fix | Delete
$data['display_notice'] = true;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[186] Fix | Delete
echo wpforms_render( 'admin/splash/modal', $data, true );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Check if the plugin version is up to date.
[191] Fix | Delete
*
[192] Fix | Delete
* @since 1.9.7
[193] Fix | Delete
*
[194] Fix | Delete
* @return bool True if up to date, false otherwise.
[195] Fix | Delete
*/
[196] Fix | Delete
private function is_plugin_version_up_to_date(): bool {
[197] Fix | Delete
[198] Fix | Delete
if ( ! empty( $this->splash_data['blocks'] ) && is_array( $this->splash_data['blocks'] ) ) {
[199] Fix | Delete
// Get the first block and check its version.
[200] Fix | Delete
$first_block = reset( $this->splash_data['blocks'] );
[201] Fix | Delete
[202] Fix | Delete
// If the first block has a version, and it's greater than the current user version, that means the splash contains features that are not available to the user.
[203] Fix | Delete
if ( ! empty( $first_block['version'] ) && version_compare( $first_block['version'], $this->get_user_version(), '>' ) ) {
[204] Fix | Delete
return false;
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
return true;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Add a splash link to footer.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 1.8.7
[215] Fix | Delete
* @deprecated 1.9.7
[216] Fix | Delete
*
[217] Fix | Delete
* @param string|mixed $content Footer content.
[218] Fix | Delete
*
[219] Fix | Delete
* @return string Footer content.
[220] Fix | Delete
*/
[221] Fix | Delete
public function add_splash_link( $content ): string {
[222] Fix | Delete
[223] Fix | Delete
return $content;
[224] Fix | Delete
}
[225] Fix | Delete
[226] Fix | Delete
/**
[227] Fix | Delete
* Check if splash modal can be displayed manually, via a link.
[228] Fix | Delete
* Used in footer and in form builder context menu.
[229] Fix | Delete
*
[230] Fix | Delete
* @since 1.8.8
[231] Fix | Delete
* @deprecated 1.9.7
[232] Fix | Delete
*
[233] Fix | Delete
* @return bool
[234] Fix | Delete
*/
[235] Fix | Delete
public function is_available_for_display(): bool {
[236] Fix | Delete
[237] Fix | Delete
return true;
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
/**
[241] Fix | Delete
* Check if splash modal is allowed.
[242] Fix | Delete
* Only allow in Form Builder, WPForms pages, and the Dashboard.
[243] Fix | Delete
*
[244] Fix | Delete
* @since 1.8.7
[245] Fix | Delete
*
[246] Fix | Delete
* @return bool True if allowed, false otherwise.
[247] Fix | Delete
*/
[248] Fix | Delete
public function is_allow_splash(): bool {
[249] Fix | Delete
[250] Fix | Delete
return wpforms_is_admin_page( 'builder' ) || wpforms_is_admin_page() || $this->is_dashboard();
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Check if the current page is the dashboard.
[255] Fix | Delete
*
[256] Fix | Delete
* @since 1.8.8
[257] Fix | Delete
*
[258] Fix | Delete
* @return bool True if it is the dashboard, false otherwise.
[259] Fix | Delete
*/
[260] Fix | Delete
private function is_dashboard(): bool {
[261] Fix | Delete
[262] Fix | Delete
global $pagenow;
[263] Fix | Delete
[264] Fix | Delete
return $pagenow === 'index.php';
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
/**
[268] Fix | Delete
* Check if splash modal should be forced open.
[269] Fix | Delete
*
[270] Fix | Delete
* @since 1.8.8
[271] Fix | Delete
*
[272] Fix | Delete
* @return bool True if it should be forced open, false otherwise.
[273] Fix | Delete
*/
[274] Fix | Delete
private function is_force_open(): bool {
[275] Fix | Delete
[276] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[277] Fix | Delete
return sanitize_key( $_GET['wpforms_action'] ?? '' ) === 'preview-splash-screen';
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Check if splash modal should be opened.
[282] Fix | Delete
*
[283] Fix | Delete
* @since 1.8.7
[284] Fix | Delete
*
[285] Fix | Delete
* @return bool True if splash should open, false otherwise.
[286] Fix | Delete
*/
[287] Fix | Delete
private function should_open_splash(): bool {
[288] Fix | Delete
[289] Fix | Delete
// Skip if announcements are hidden, or it is the dashboard page.
[290] Fix | Delete
if ( $this->is_dashboard() || $this->hide_splash_modal() ) {
[291] Fix | Delete
return false;
[292] Fix | Delete
}
[293] Fix | Delete
[294] Fix | Delete
// Allow if a splash version different from the current plugin major version, and it's not a new installation.
[295] Fix | Delete
$should_open_splash = $this->get_latest_splash_version() !== $this->get_major_version( WPFORMS_VERSION ) &&
[296] Fix | Delete
( ! $this->is_new_install() || $this->is_force_open() );
[297] Fix | Delete
[298] Fix | Delete
if ( ! $should_open_splash ) {
[299] Fix | Delete
return false;
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
// Skip if user on the builder page and the Challenge can be started.
[303] Fix | Delete
if ( wpforms_is_admin_page( 'builder' ) ) {
[304] Fix | Delete
return $this->is_allow_builder_splash();
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
return true;
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
/**
[311] Fix | Delete
* Check if splash modal should be allowed on the builder page.
[312] Fix | Delete
* If the Challenge can be started, the splash modal should not be displayed.
[313] Fix | Delete
*
[314] Fix | Delete
* @since 1.9.0
[315] Fix | Delete
*
[316] Fix | Delete
* @return bool True if allowed, false otherwise.
[317] Fix | Delete
*/
[318] Fix | Delete
private function is_allow_builder_splash(): bool {
[319] Fix | Delete
[320] Fix | Delete
$challenge = wpforms()->obj( 'challenge' );
[321] Fix | Delete
[322] Fix | Delete
return ! ( $challenge->challenge_force_start() || $challenge->challenge_can_start() );
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Check if the plugin is newly installed.
[327] Fix | Delete
*
[328] Fix | Delete
* Get all migrations that have run.
[329] Fix | Delete
* If the only migration with a timestamp is the current version, it's a new installation.
[330] Fix | Delete
*
[331] Fix | Delete
* @since 1.8.8
[332] Fix | Delete
*
[333] Fix | Delete
* @return bool True if new install, false otherwise.
[334] Fix | Delete
*/
[335] Fix | Delete
private function is_new_install(): bool {
[336] Fix | Delete
[337] Fix | Delete
if ( isset( $this->is_new_install ) ) {
[338] Fix | Delete
return $this->is_new_install;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$option_name = wpforms()->is_pro() ? 'wpforms_versions' : 'wpforms_versions_lite';
[342] Fix | Delete
[343] Fix | Delete
$migrations_run = get_option( $option_name, [] );
[344] Fix | Delete
[345] Fix | Delete
if ( empty( $migrations_run ) ) {
[346] Fix | Delete
return true;
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
unset( $migrations_run[ WPFORMS_VERSION ] );
[350] Fix | Delete
[351] Fix | Delete
$this->is_new_install = empty( end( $migrations_run ) );
[352] Fix | Delete
[353] Fix | Delete
return $this->is_new_install;
[354] Fix | Delete
}
[355] Fix | Delete
[356] Fix | Delete
/**
[357] Fix | Delete
* Determine if the current update is a minor update.
[358] Fix | Delete
*
[359] Fix | Delete
* This method checks the version history of migrations run and compares
[360] Fix | Delete
* the last recorded version with the current version to determine if
[361] Fix | Delete
* the update is minor or major.
[362] Fix | Delete
*
[363] Fix | Delete
* @since 1.9.0
[364] Fix | Delete
*
[365] Fix | Delete
* @return bool True if it's a minor update, false otherwise.
[366] Fix | Delete
*/
[367] Fix | Delete
private function is_minor_update(): bool {
[368] Fix | Delete
[369] Fix | Delete
return $this->get_major_version( $this->get_previous_plugin_version() ) === $this->get_major_version( WPFORMS_VERSION );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Check if splash modal should be hidden.
[374] Fix | Delete
*
[375] Fix | Delete
* @since 1.8.8
[376] Fix | Delete
*
[377] Fix | Delete
* @return bool True if hidden, false otherwise.
[378] Fix | Delete
*/
[379] Fix | Delete
private function hide_splash_modal(): bool {
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* Force to hide splash modal.
[383] Fix | Delete
*
[384] Fix | Delete
* @since 1.8.8
[385] Fix | Delete
*
[386] Fix | Delete
* @param bool $hide_splash_modal True to hide, false otherwise.
[387] Fix | Delete
*/
[388] Fix | Delete
return (bool) apply_filters( 'wpforms_admin_splash_screen_hide_splash_modal', wpforms_setting( 'hide-announcements' ) );
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Remove certain arguments from a query string that WordPress should always hide for users.
[393] Fix | Delete
*
[394] Fix | Delete
* @since 1.8.8
[395] Fix | Delete
*
[396] Fix | Delete
* @param array $removable_query_args An array of parameters to remove from the URL.
[397] Fix | Delete
*
[398] Fix | Delete
* @return array Extended/filtered array of parameters to remove from the URL.
[399] Fix | Delete
*/
[400] Fix | Delete
public function removable_query_args( $removable_query_args ) {
[401] Fix | Delete
[402] Fix | Delete
$removable_query_args[] = 'wpforms_action';
[403] Fix | Delete
[404] Fix | Delete
return $removable_query_args;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Reset splash data after license update.
[409] Fix | Delete
*
[410] Fix | Delete
* @since 1.9.7
[411] Fix | Delete
*/
[412] Fix | Delete
public function reset_splash_data(): void {
[413] Fix | Delete
[414] Fix | Delete
// Force update splash data cache.
[415] Fix | Delete
wpforms()->obj( 'splash_cache' )->update( true );
[416] Fix | Delete
}
[417] Fix | Delete
}
[418] Fix | Delete
[419] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function