Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../includes/function...
File: checks.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Helper functions to perform various checks across the core plugin and addons.
[2] Fix | Delete
*
[3] Fix | Delete
* @since 1.8.0
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
// phpcs:disable Generic.Commenting.DocComment.MissingShort
[7] Fix | Delete
/** @noinspection PhpUndefinedNamespaceInspection */
[8] Fix | Delete
/** @noinspection PhpUndefinedClassInspection */
[9] Fix | Delete
// phpcs:enable Generic.Commenting.DocComment.MissingShort
[10] Fix | Delete
[11] Fix | Delete
use WPForms\Tasks\Tasks;
[12] Fix | Delete
use WPForms\Vendor\TrueBV\Punycode;
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Check if a string is a valid URL.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 1.0.0
[18] Fix | Delete
* @since 1.5.8 Changed the pattern used to validate the URL.
[19] Fix | Delete
*
[20] Fix | Delete
* @param string $url Input URL.
[21] Fix | Delete
*
[22] Fix | Delete
* @return bool
[23] Fix | Delete
* @noinspection RegExpUnnecessaryNonCapturingGroup
[24] Fix | Delete
* @noinspection RegExpRedundantEscape
[25] Fix | Delete
*/
[26] Fix | Delete
function wpforms_is_url( $url ): bool {
[27] Fix | Delete
[28] Fix | Delete
// The pattern taken from https://gist.github.com/dperini/729294.
[29] Fix | Delete
// It is the best choice according to the https://mathiasbynens.be/demo/url-regex.
[30] Fix | Delete
$pattern = '%^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\x{00a1}-\x{ffff}][a-z0-9\x{00a1}-\x{ffff}_-]{0,62})?[a-z0-9\x{00a1}-\x{ffff}]\.)+(?:[a-z\x{00a1}-\x{ffff}]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$%iu';
[31] Fix | Delete
[32] Fix | Delete
if ( preg_match( $pattern, trim( $url ) ) ) {
[33] Fix | Delete
return true;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
return false;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Verify that an email is valid.
[41] Fix | Delete
* See the linked RFC.
[42] Fix | Delete
*
[43] Fix | Delete
* @see https://www.rfc-editor.org/rfc/inline-errata/rfc3696.html
[44] Fix | Delete
*
[45] Fix | Delete
* @since 1.7.3
[46] Fix | Delete
*
[47] Fix | Delete
* @param string $email Email address to verify.
[48] Fix | Delete
*
[49] Fix | Delete
* @return string|false Returns a valid email address on success, false on failure.
[50] Fix | Delete
*/
[51] Fix | Delete
function wpforms_is_email( $email ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
[52] Fix | Delete
[53] Fix | Delete
static $punycode;
[54] Fix | Delete
[55] Fix | Delete
// Do not allow callables, arrays, and objects.
[56] Fix | Delete
if ( ! is_scalar( $email ) ) {
[57] Fix | Delete
return false;
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
// Allow smart tags in the email address.
[61] Fix | Delete
if ( preg_match( '/{.+?}/', $email ) ) {
[62] Fix | Delete
return $email;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
// Email can't be longer than 254 octets,
[66] Fix | Delete
// otherwise it can't be used to send an email address (limitation in the MAIL and RCPT commands).
[67] Fix | Delete
// 1 octet = 8 bits = 1 byte.
[68] Fix | Delete
if ( strlen( $email ) > 254 ) {
[69] Fix | Delete
return false;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
$email_arr = explode( '@', $email );
[73] Fix | Delete
[74] Fix | Delete
if ( count( $email_arr ) !== 2 ) {
[75] Fix | Delete
return false;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
[ $local, $domain ] = $email_arr;
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* RFC requires local part to be no longer than 64 octets.
[82] Fix | Delete
* Punycode library checks for 63 octets.
[83] Fix | Delete
*
[84] Fix | Delete
* @link https://github.com/true/php-punycode/blob/master/src/Punycode.php#L182.
[85] Fix | Delete
*/
[86] Fix | Delete
if ( strlen( $local ) > 63 ) {
[87] Fix | Delete
return false;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
$domain_arr = explode( '.', $domain );
[91] Fix | Delete
[92] Fix | Delete
foreach ( $domain_arr as $domain_label ) {
[93] Fix | Delete
$domain_label = trim( $domain_label );
[94] Fix | Delete
[95] Fix | Delete
if ( ! $domain_label ) {
[96] Fix | Delete
return false;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
// The RFC says: 'A DNS label may be no more than 63 octets long'.
[100] Fix | Delete
if ( strlen( $domain_label ) > 63 ) {
[101] Fix | Delete
return false;
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
if ( ! $punycode ) {
[106] Fix | Delete
$punycode = new Punycode();
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* The wp_mail() uses phpMailer, which uses is_email() as verification callback.
[111] Fix | Delete
* For verification, phpMailer sends the email address where the domain part is punycode encoded only.
[112] Fix | Delete
* We follow here the same principle.
[113] Fix | Delete
*/
[114] Fix | Delete
$email_check = $local . '@' . $punycode->encode( $domain );
[115] Fix | Delete
[116] Fix | Delete
// Other limitations are checked by the native WordPress function is_email().
[117] Fix | Delete
return is_email( $email_check ) ? $local . '@' . $domain : false;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Check whether the string is json-encoded.
[122] Fix | Delete
*
[123] Fix | Delete
* @since 1.7.5
[124] Fix | Delete
*
[125] Fix | Delete
* @param string $value A string.
[126] Fix | Delete
*
[127] Fix | Delete
* @return bool
[128] Fix | Delete
*/
[129] Fix | Delete
function wpforms_is_json( $value ): bool {
[130] Fix | Delete
[131] Fix | Delete
return (
[132] Fix | Delete
is_string( $value ) &&
[133] Fix | Delete
is_array( json_decode( $value, true ) ) &&
[134] Fix | Delete
json_last_error() === JSON_ERROR_NONE
[135] Fix | Delete
);
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Check whether the current page is in AMP mode or not.
[140] Fix | Delete
* We need to check for specific functions, as there is no special AMP header.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 1.4.1
[143] Fix | Delete
*
[144] Fix | Delete
* @param bool $check_theme_support Whether theme support should be checked. Defaults to true.
[145] Fix | Delete
*
[146] Fix | Delete
* @return bool
[147] Fix | Delete
*/
[148] Fix | Delete
function wpforms_is_amp( $check_theme_support = true ): bool {
[149] Fix | Delete
[150] Fix | Delete
$is_amp = false;
[151] Fix | Delete
[152] Fix | Delete
// Check for AMP by AMP Project Contributors.
[153] Fix | Delete
if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
[154] Fix | Delete
$is_amp = true;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
if ( $is_amp && $check_theme_support ) {
[158] Fix | Delete
$is_amp = current_theme_supports( 'amp' );
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Filters AMP flag.
[163] Fix | Delete
*
[164] Fix | Delete
* @since 1.4.1
[165] Fix | Delete
*
[166] Fix | Delete
* @param bool $is_amp Current page AMP status.
[167] Fix | Delete
*
[168] Fix | Delete
* @return bool
[169] Fix | Delete
*/
[170] Fix | Delete
return (bool) apply_filters( 'wpforms_is_amp', $is_amp );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Helper function to determine if loading on WPForms related admin page.
[175] Fix | Delete
*
[176] Fix | Delete
* Here we determine if the current administration page is owned/created by
[177] Fix | Delete
* WPForms. This is done in compliance with WordPress best practices for
[178] Fix | Delete
* development, so that we only load required WPForms CSS and JS files on pages
[179] Fix | Delete
* we create. As a result, we do not load our assets admin wide, where they might
[180] Fix | Delete
* conflict with other plugins needlessly, also leading to a better, faster user
[181] Fix | Delete
* experience for our users.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 1.3.9
[184] Fix | Delete
*
[185] Fix | Delete
* @param string $slug Slug identifier for a specific WPForms admin page.
[186] Fix | Delete
* @param string $view Slug identifier for a specific WPForms admin page view ("subpage").
[187] Fix | Delete
*
[188] Fix | Delete
* @return bool
[189] Fix | Delete
*/
[190] Fix | Delete
function wpforms_is_admin_page( $slug = '', $view = '' ): bool {
[191] Fix | Delete
[192] Fix | Delete
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
[193] Fix | Delete
[194] Fix | Delete
// Check against basic requirements.
[195] Fix | Delete
if (
[196] Fix | Delete
empty( $_REQUEST['page'] ) ||
[197] Fix | Delete
strpos( $_REQUEST['page'], 'wpforms' ) === false ||
[198] Fix | Delete
! is_admin()
[199] Fix | Delete
) {
[200] Fix | Delete
return false;
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
// Check against page slug identifier.
[204] Fix | Delete
if (
[205] Fix | Delete
( ! empty( $slug ) && $_REQUEST['page'] !== 'wpforms-' . $slug ) ||
[206] Fix | Delete
( empty( $slug ) && $_REQUEST['page'] === 'wpforms-builder' )
[207] Fix | Delete
) {
[208] Fix | Delete
return false;
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
// Check against sub-level page view.
[212] Fix | Delete
if (
[213] Fix | Delete
! empty( $view ) &&
[214] Fix | Delete
( empty( $_REQUEST['view'] ) || $_REQUEST['view'] !== $view )
[215] Fix | Delete
) {
[216] Fix | Delete
return false;
[217] Fix | Delete
}
[218] Fix | Delete
[219] Fix | Delete
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
[220] Fix | Delete
[221] Fix | Delete
return true;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Check if a string is empty.
[226] Fix | Delete
*
[227] Fix | Delete
* @since 1.5.0
[228] Fix | Delete
*
[229] Fix | Delete
* @param string $value String to test.
[230] Fix | Delete
*
[231] Fix | Delete
* @return bool
[232] Fix | Delete
*/
[233] Fix | Delete
function wpforms_is_empty_string( $value ): bool {
[234] Fix | Delete
// phpcs:ignore WPForms.Formatting.EmptyLineBeforeReturn.RemoveEmptyLineBeforeReturnStatement
[235] Fix | Delete
return $value === '';
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Determine if the request is a rest API call.
[240] Fix | Delete
*
[241] Fix | Delete
* Case #1: After WP_REST_Request initialization
[242] Fix | Delete
* Case #2: Support "plain" permalink settings
[243] Fix | Delete
* Case #3: It can happen that WP_Rewrite is not yet initialized,
[244] Fix | Delete
* so do this (wp-settings.php)
[245] Fix | Delete
* Case #4: URL Path begins with wp-json/ (your REST prefix)
[246] Fix | Delete
* Also supports WP installations in sub folders
[247] Fix | Delete
*
[248] Fix | Delete
* @since 1.8.8
[249] Fix | Delete
*
[250] Fix | Delete
* @return bool True if the request is a REST API call, false if not.
[251] Fix | Delete
* @author matzeeable
[252] Fix | Delete
*/
[253] Fix | Delete
function wpforms_is_rest(): bool {
[254] Fix | Delete
[255] Fix | Delete
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
[256] Fix | Delete
return false;
[257] Fix | Delete
}
[258] Fix | Delete
[259] Fix | Delete
// Case #1.
[260] Fix | Delete
if ( defined( 'REST_REQUEST' ) && constant( 'REST_REQUEST' ) ) {
[261] Fix | Delete
return true;
[262] Fix | Delete
}
[263] Fix | Delete
[264] Fix | Delete
// Case #2.
[265] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[266] Fix | Delete
$rest_route = isset( $_GET['rest_route'] ) ?
[267] Fix | Delete
filter_input( INPUT_GET, 'rest_route', FILTER_SANITIZE_FULL_SPECIAL_CHARS ) :
[268] Fix | Delete
'';
[269] Fix | Delete
[270] Fix | Delete
if ( strpos( trim( $rest_route, '\\/' ), rest_get_url_prefix() ) === 0 ) {
[271] Fix | Delete
return true;
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
// Case #3.
[275] Fix | Delete
global $wp_rewrite;
[276] Fix | Delete
if ( $wp_rewrite === null ) {
[277] Fix | Delete
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
[278] Fix | Delete
$wp_rewrite = new WP_Rewrite();
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
// Case #4.
[282] Fix | Delete
$current_url = (string) wp_parse_url( add_query_arg( [] ), PHP_URL_PATH );
[283] Fix | Delete
$rest_url = wp_parse_url( trailingslashit( rest_url() ), PHP_URL_PATH );
[284] Fix | Delete
[285] Fix | Delete
return strpos( $current_url, $rest_url ) === 0;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
/**
[289] Fix | Delete
* Determine if the request is a WPForms related rest API call.
[290] Fix | Delete
*
[291] Fix | Delete
* NOTE: The function shouldn't be used before the `rest_api_init` action.
[292] Fix | Delete
*
[293] Fix | Delete
* @since 1.9.6.1
[294] Fix | Delete
*
[295] Fix | Delete
* @return bool True if the request is a WPForms related rest API call, false if not.
[296] Fix | Delete
*/
[297] Fix | Delete
function wpforms_is_wpforms_rest(): bool {
[298] Fix | Delete
[299] Fix | Delete
if ( ! wpforms_is_rest() ) {
[300] Fix | Delete
return false;
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
$rest_url = wp_parse_url( trailingslashit( rest_url() ) );
[304] Fix | Delete
$current_url = wp_parse_url( trailingslashit( wpforms_current_url() ) );
[305] Fix | Delete
$rest_url['path'] = $rest_url['path'] ?? '';
[306] Fix | Delete
[307] Fix | Delete
// phpcs:disable WordPress.Security.NonceVerification.Recommended
[308] Fix | Delete
$is_rest_plain = $rest_url['path'] === '/index.php' && ! empty( $_GET['rest_route'] );
[309] Fix | Delete
$is_rest_post_name = strpos( $rest_url['path'], '/wp-json/' ) !== false;
[310] Fix | Delete
[311] Fix | Delete
if ( $is_rest_plain ) {
[312] Fix | Delete
$rest_route = sanitize_text_field( wp_unslash( $_GET['rest_route'] ) );
[313] Fix | Delete
[314] Fix | Delete
return strpos( $rest_route, '/wpforms/' ) !== false;
[315] Fix | Delete
}
[316] Fix | Delete
// phpcs:enable WordPress.Security.NonceVerification.Recommended
[317] Fix | Delete
[318] Fix | Delete
if ( $is_rest_post_name ) {
[319] Fix | Delete
return strpos( $current_url['path'] ?? '', '/wpforms/' ) !== false;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
return false;
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
/**
[326] Fix | Delete
* Determine if the request is WPForms AJAX.
[327] Fix | Delete
*
[328] Fix | Delete
* @since 1.8.0
[329] Fix | Delete
* @since 1.9.1 Added an optional parameter to check for a specific action.
[330] Fix | Delete
*
[331] Fix | Delete
* @param string $action Certain AJAX action to check. Optional. Default is empty.
[332] Fix | Delete
*
[333] Fix | Delete
* @return bool
[334] Fix | Delete
*/
[335] Fix | Delete
function wpforms_is_ajax( string $action = '' ): bool {
[336] Fix | Delete
[337] Fix | Delete
if ( ! wp_doing_ajax() ) {
[338] Fix | Delete
return false;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
// Make sure the request target is admin-ajax.php.
[342] Fix | Delete
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
[343] Fix | Delete
if ( isset( $_SERVER['SCRIPT_FILENAME'] ) && basename( sanitize_text_field( wp_normalize_path( $_SERVER['SCRIPT_FILENAME'] ) ) ) !== 'admin-ajax.php' ) {
[344] Fix | Delete
return false;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[348] Fix | Delete
$request_action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : '';
[349] Fix | Delete
$is_wpforms_action = strpos( $request_action, 'wpforms_' ) === 0;
[350] Fix | Delete
[351] Fix | Delete
if ( empty( $action ) ) {
[352] Fix | Delete
return $is_wpforms_action;
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
return $is_wpforms_action && $action === $request_action;
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
/**
[359] Fix | Delete
* Determine if request is frontend AJAX.
[360] Fix | Delete
*
[361] Fix | Delete
* @since 1.5.8.2
[362] Fix | Delete
* @since 1.6.5 Added filterable frontend ajax actions list as a fallback to missing referer cases.
[363] Fix | Delete
* @since 1.6.7.1 Removed a requirement for an AJAX action to be a WPForms action if referer is not missing.
[364] Fix | Delete
* @since 1.8.0 Added clear separation between frontend and admin AJAX requests, see `wpforms_is_admin_ajax()`.
[365] Fix | Delete
*
[366] Fix | Delete
* @return bool
[367] Fix | Delete
*/
[368] Fix | Delete
function wpforms_is_frontend_ajax(): bool {
[369] Fix | Delete
[370] Fix | Delete
if ( wpforms_is_ajax() && ! wpforms_is_admin_ajax() ) {
[371] Fix | Delete
return true;
[372] Fix | Delete
}
[373] Fix | Delete
[374] Fix | Delete
// Try detecting a frontend AJAX call indirectly by comparing the current action
[375] Fix | Delete
// with a known frontend actions list in case there's no HTTP referer.
[376] Fix | Delete
[377] Fix | Delete
$ref = wp_get_raw_referer();
[378] Fix | Delete
[379] Fix | Delete
if ( $ref ) {
[380] Fix | Delete
return false;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
$frontend_actions = [
[384] Fix | Delete
'wpforms_submit',
[385] Fix | Delete
'wpforms_file_upload_speed_test',
[386] Fix | Delete
'wpforms_upload_chunk_init',
[387] Fix | Delete
'wpforms_upload_chunk',
[388] Fix | Delete
'wpforms_file_chunks_uploaded',
[389] Fix | Delete
'wpforms_remove_file',
[390] Fix | Delete
'wpforms_restricted_email',
[391] Fix | Delete
'wpforms_form_locker_unique_answer',
[392] Fix | Delete
'wpforms_form_abandonment',
[393] Fix | Delete
];
[394] Fix | Delete
[395] Fix | Delete
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
[396] Fix | Delete
$action = isset( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : '';
[397] Fix | Delete
[398] Fix | Delete
/**
[399] Fix | Delete
* Allow modifying the list of frontend AJAX actions.
[400] Fix | Delete
*
[401] Fix | Delete
* This filter may be running as early as `plugins_loaded` hook.
[402] Fix | Delete
* Please mind the hook order when using it.
[403] Fix | Delete
*
[404] Fix | Delete
* @since 1.6.5
[405] Fix | Delete
*
[406] Fix | Delete
* @param array $frontend_actions A list of frontend actions.
[407] Fix | Delete
*/
[408] Fix | Delete
$frontend_actions = (array) apply_filters( 'wpforms_is_frontend_ajax_frontend_actions', $frontend_actions );
[409] Fix | Delete
[410] Fix | Delete
return in_array( $action, $frontend_actions, true );
[411] Fix | Delete
}
[412] Fix | Delete
[413] Fix | Delete
/**
[414] Fix | Delete
* Determine if request is admin AJAX.
[415] Fix | Delete
*
[416] Fix | Delete
* @since 1.8.0
[417] Fix | Delete
*
[418] Fix | Delete
* @return bool
[419] Fix | Delete
*/
[420] Fix | Delete
function wpforms_is_admin_ajax(): bool {
[421] Fix | Delete
[422] Fix | Delete
if ( ! wpforms_is_ajax() ) {
[423] Fix | Delete
return false;
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
$ref = wp_get_raw_referer();
[427] Fix | Delete
[428] Fix | Delete
if ( ! $ref ) {
[429] Fix | Delete
return false;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
$path = wp_parse_url( $ref, PHP_URL_PATH );
[433] Fix | Delete
$admin_path = wp_parse_url( admin_url(), PHP_URL_PATH );
[434] Fix | Delete
[435] Fix | Delete
// Is an admin AJAX call if HTTP referer contain an admin path.
[436] Fix | Delete
return strpos( $path, $admin_path ) !== false;
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
/**
[440] Fix | Delete
* Check if Gutenberg is active.
[441] Fix | Delete
*
[442] Fix | Delete
* @since 1.6.2
[443] Fix | Delete
*
[444] Fix | Delete
* @return bool True if Gutenberg is active.
[445] Fix | Delete
* @noinspection PhpUndefinedFunctionInspection
[446] Fix | Delete
*/
[447] Fix | Delete
function wpforms_is_gutenberg_active(): bool {
[448] Fix | Delete
[449] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/plugin.php';
[450] Fix | Delete
[451] Fix | Delete
if ( is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
[452] Fix | Delete
return in_array( get_option( 'classic-editor-replace' ), [ 'no-replace', 'block' ], true );
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
if ( is_plugin_active( 'disable-gutenberg/disable-gutenberg.php' ) ) {
[456] Fix | Delete
return ! disable_gutenberg();
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
return true;
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
/**
[463] Fix | Delete
* Check if website support Divi Builder.
[464] Fix | Delete
*
[465] Fix | Delete
* @since 1.9.2.3
[466] Fix | Delete
*
[467] Fix | Delete
* @return bool True if Divi builder plugin or Divi or Extra theme is active.
[468] Fix | Delete
*/
[469] Fix | Delete
function wpforms_is_divi_active(): bool {
[470] Fix | Delete
[471] Fix | Delete
if ( function_exists( 'et_divi_builder_init_plugin' ) ) {
[472] Fix | Delete
return true;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
$allow_themes = [ 'Divi', 'Extra' ];
[476] Fix | Delete
$theme_name = get_template();
[477] Fix | Delete
[478] Fix | Delete
return in_array( $theme_name, $allow_themes, true );
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
/**
[482] Fix | Delete
* Determines whether the current request is a WP CLI request.
[483] Fix | Delete
*
[484] Fix | Delete
* @since 1.7.6
[485] Fix | Delete
*
[486] Fix | Delete
* @return bool
[487] Fix | Delete
*/
[488] Fix | Delete
function wpforms_doing_wp_cli(): bool {
[489] Fix | Delete
[490] Fix | Delete
return defined( 'WP_CLI' ) && WP_CLI;
[491] Fix | Delete
}
[492] Fix | Delete
[493] Fix | Delete
/**
[494] Fix | Delete
* Determines whether the Action Scheduler task is executing.
[495] Fix | Delete
*
[496] Fix | Delete
* @since 1.9.4
[497] Fix | Delete
*
[498] Fix | Delete
* @return bool
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function