ins.
*
* @since 1.6.1
*
* @return array
*/
private function get_active_plugins(): array {
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$active = is_multisite() ?
array_merge( get_option( 'active_plugins', [] ), array_flip( get_site_option( 'active_sitewide_plugins', [] ) ) ) :
get_option( 'active_plugins', [] );
$plugins = array_intersect_key( get_plugins(), array_flip( $active ) );
return array_map(
static function ( $plugin ) {
if ( isset( $plugin['Version'] ) ) {
return $plugin['Version'];
}
return 'Not Set';
},
$plugins
);
}
/**
* Installed date.
*
* @since 1.6.1
*
* @param array $activated_dates Input array with dates.
* @param string $key Input key what you want to get.
*
* @return mixed
*/
private function get_installed( array $activated_dates, string $key ) {
if ( ! empty( $activated_dates[ $key ] ) ) {
return $activated_dates[ $key ];
}
return false;
}
/**
* Number of forms with some integrations active.
*
* @since 1.6.1
*
* @param array $forms List of forms.
*
* @return array List of forms with active integrations count.
*/
private function get_forms_integrations( array $forms ): array {
$integrations = array_map(
static function ( $form ) {
if ( empty( $form->post_content['providers'] ) ) {
return false;
}
$active_integrations = [];
foreach ( $form->post_content['providers'] as $provider_slug => $connections ) {
if ( ! empty( $connections ) ) {
$active_integrations[] = $provider_slug;
}
}
return $active_integrations;
},
$forms
);
$integrations = array_filter( $integrations );
if ( count( $integrations ) > 0 ) {
$integrations = call_user_func_array( 'array_merge', array_values( $integrations ) );
}
return array_count_values( $integrations );
}
/**
* Number of forms with active payments.
*
* @since 1.6.1
*
* @param array $forms Input forms list.
*
* @return array List of forms with active payments count.
*/
private function get_payments_active( array $forms ): array {
$payments = array_map(
static function ( $form ) {
if ( empty( $form->post_content['payments'] ) ) {
return false;
}
$enabled = [];
foreach ( $form->post_content['payments'] as $key => $value ) {
if ( ! empty( $value['enable'] ) ) {
$enabled[] = $key;
}
}
return empty( $enabled ) ? false : $enabled;
},
$forms
);
$payments = array_filter( $payments );
if ( count( $payments ) > 0 ) {
$payments = call_user_func_array( 'array_merge', array_values( $payments ) );
}
return array_count_values( $payments );
}
/**
* Forms with multiple notifications.
*
* @since 1.6.1
*
* @param array $forms List of forms to check.
*
* @return array List of forms with multiple notifications.
*/
private function get_forms_with_multiple_notifications( array $forms ): array {
return array_filter(
$forms,
static function ( $form ) {
return ! empty( $form->post_content['settings']['notifications'] ) && count( $form->post_content['settings']['notifications'] ) > 1;
}
);
}
/**
* Forms with multiple confirmations.
*
* @since 1.6.1
*
* @param array $forms List of forms to check.
*
* @return array List of forms with multiple confirmations.
*/
private function get_forms_with_multiple_confirmations( array $forms ): array {
return array_filter(
$forms,
static function ( $form ) {
return ! empty( $form->post_content['settings']['confirmations'] ) && count( $form->post_content['settings']['confirmations'] ) > 1;
}
);
}
/**
* Forms with ajax submission option enabled.
*
* @since 1.6.1
*
* @param array $forms All forms.
*
* @return array
*/
private function get_ajax_form_submissions( array $forms ): array {
return array_filter(
$forms,
static function ( $form ) {
return ! empty( $form->post_content['settings']['ajax_submit'] );
}
);
}
/**
* Total number of sites.
*
* @since 1.6.1
*
* @return int
*/
private function get_sites_total(): int {
return function_exists( 'get_blog_count' ) ? (int) get_blog_count() : 1;
}
/**
* Total number of entries.
*
* @since 1.6.1
*
* @param string $period Which period should be counted? Possible values: 7days, 30days.
* Everything else will mean "all" entries.
*
* @return int
*/
private function get_entries_total( string $period = 'all' ): int {
if ( ! wpforms()->is_pro() ) {
return $this->get_entries_total_lite( $period );
}
$args = [];
// Limit results to only forms, excluding form templates.
$form_ids = wp_list_pluck( $this->get_all_forms(), 'ID' );
if ( ! empty( $form_ids ) ) {
$args['form_id'] = $form_ids;
}
switch ( $period ) {
case '7days':
$args = [
'date' => [
gmdate( 'Y-m-d', strtotime( '-7 days' ) ),
gmdate( 'Y-m-d' ),
],
];
break;
case '30days':
$args = [
'date' => [
gmdate( 'Y-m-d', strtotime( '-30 days' ) ),
gmdate( 'Y-m-d' ),
],
];
break;
}
$entry_obj = wpforms()->obj( 'entry' );
return $entry_obj ? $entry_obj->get_entries( $args, true ) : 0;
}
/**
* Total number of entries in Lite.
*
* @since 1.9.0
*
* @param string $period Which period should be counted? Possible values: 7days, 30days.
* Everything else will mean "all" entries.
*
* @return int
*/
private function get_entries_total_lite( string $period = 'all' ): int {
if ( $period === '7days' || $period === '30days' ) {
return 0;
}
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$count = $wpdb->get_var(
"SELECT SUM(meta_value)
FROM $wpdb->postmeta
WHERE meta_key = 'wpforms_entries_count';"
);
return (int) $count;
}
/**
* Forms field occurrences.
*
* @since 1.7.9
*
* @param array $forms List of forms.
*
* @return array List of field occurrences in all forms created.
*/
private function get_form_fields_count( array $forms ): array {
// Bail early, in case there are no forms created yet!
if ( empty( $forms ) ) {
return [];
}
$fields = array_map(
static function ( $form ) {
return $form->post_content['fields'] ?? [];
},
$forms
);
$fields_flatten = array_merge( [], ...$fields );
$field_types = array_column( $fields_flatten, 'type' );
return array_count_values( $field_types );
}
/**
* Determines whether the plugin is active for the entire network.
*
* This is a copy of the WP core is_plugin_active_for_network() function.
*
* @since 1.8.2
*
* @return bool
*/
private function is_active_for_network(): bool {
// Bail early, in case we are not in multisite.
if ( ! is_multisite() ) {
return false;
}
// Get all active plugins.
$plugins = get_site_option( 'active_sitewide_plugins' );
// Bail early, in case the plugin is active for the entire network.
if ( isset( $plugins[ plugin_basename( WPFORMS_PLUGIN_FILE ) ] ) ) {
return true;
}
return false;
}
/**
* Average entries count.
*
* @since 1.6.1
*
* @param int $forms Total forms count.
* @param int $entries Total entries count.
*
* @return int
*/
private function get_entries_avg( int $forms, int $entries ): int {
return $forms ? round( $entries / $forms ) : 0;
}
/**
* Get all forms.
*
* @since 1.6.1
* @since 1.8.9 Added post_type parameter.
*
* @param string|string[] $post_type Allow to sort result by post_type. By default, it's 'wpforms'.
*
* @return array
*/
private function get_all_forms( $post_type = 'wpforms' ): array {
$forms = wpforms()->obj( 'form' )->get( '', [ 'post_type' => $post_type ] );
if ( ! is_array( $forms ) ) {
return [];
}
return array_map(
static function ( $form ) {
$form->post_content = wpforms_decode( $form->post_content );
return $form;
},
$forms
);
}
/**
* Get the favorite templates.
*
* @since 1.7.7
*
* @return array
*/
private function get_favorite_templates(): array {
$settings = [];
$templates = (array) get_option( Templates::FAVORITE_TEMPLATES_OPTION, [] );
foreach ( $templates as $user_templates ) {
foreach ( $user_templates as $template => $v ) {
$name = 'fav_templates_' . str_replace( '-', '_', $template );
$settings[ $name ] = empty( $settings[ $name ] ) ? 1 : ++$settings[ $name ];
}
}
return $settings;
}
/**
* Test if the REST API is accessible.
*
* The REST API might be inaccessible due to various security measures,
* or it might be completely disabled by a plugin.
*
* @since 1.8.2.2
*
* @return bool
*/
private function is_rest_api_enabled(): bool {
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
/** This filter is documented in wp-includes/class-wp-http-streams.php */
$sslverify = apply_filters( 'https_local_ssl_verify', false );
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
$url = rest_url( 'wp/v2/types/post' );
$response = wp_remote_get(
$url,
[
'timeout' => 10,
'cookies' => is_user_logged_in() ? wp_unslash( $_COOKIE ) : [],
'sslverify' => $sslverify,
'headers' => [
'Cache-Control' => 'no-cache',
'X-WP-Nonce' => wp_create_nonce( 'wp_rest' ),
],
]
);
// When testing the REST API, an error was encountered, leave early.
if ( is_wp_error( $response ) ) {
return false;
}
// When testing the REST API, an unexpected result was returned, leave early.
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
return false;
}
// The REST API did not behave correctly, leave early.
if ( ! wpforms_is_json( wp_remote_retrieve_body( $response ) ) ) {
return false;
}
// We are all set. Confirm the connection.
return true;
}
/**
* Retrieves additional statistics.
*
* @since 1.8.8
*
* @return array
*/
private function get_additional_stats(): array {
// Initialize an empty array to store the statistics.
$stats = [];
return $this->get_admin_pointer_stats( $stats );
}
/**
* Retrieves statistics for admin pointers.
* This function retrieves statistics for admin pointers based on their engagement or dismissal status.
*
* Note: Pointers can only be engaged (interacted with) or dismissed.
*
* - If the value is 1 or true, it means the pointer is shown and interacted with (engaged).
* - If the value is 0 or false, it means the pointer is dismissed.
* - If there is no pointer ID in the stats, it means the user hasn't seen the pointer yet.
*
* @since 1.8.8
*
* @param array $stats An array containing existing statistics.
*
* @return array
*/
private function get_admin_pointer_stats( array $stats ): array {
$pointers = get_option( 'wpforms_pointers', [] );
// If there are no pointers, return empty statistics.
if ( empty( $pointers ) ) {
return $stats;
}
// Pointers can only be interacted with or dismissed.
// If there are engagement pointers, process them.
if ( isset( $pointers['engagement'] ) ) {
foreach ( $pointers['engagement'] as $pointer ) {
$stats[ sanitize_key( $pointer ) ] = true;
}
}
// If there are dismiss pointers, process them.
if ( isset( $pointers['dismiss'] ) ) {
foreach ( $pointers['dismiss'] as $pointer ) {
$stats[ sanitize_key( $pointer ) ] = false;
}
}
return $stats;
}
/**
* Retrieves form anti-spam settings statistic.
*
* @since 1.9.0
*
* @param array $forms List of forms and their settings.
*
* @return array
*/
private function get_form_antispam_stat( array $forms ): array { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.MaxExceeded
$stat = [
'antispam' => 0,
'antispam_v3' => 0,
'akismet' => 0,
'store_spam_entries' => 0,
'time_limit' => 0,
'country_filter' => 0,
'keyword_filter' => 0,
'captcha' => 0,
];
foreach ( $forms as $form ) {
$settings = $form->post_content['settings'] ?? [];
// Skip forms with disabled anti-spam settings.
if ( empty( $settings['antispam'] ) && empty( $settings['antispam_v3'] ) ) {
continue;
}
// Increment the counters for each form with enabled anti-spam settings.
$stat['antispam'] += ! empty( $settings['antispam'] ) ? 1 : 0; // Classic anti-spam enabled.
$stat['antispam_v3'] += ! empty( $settings['antispam_v3'] ) ? 1 : 0; // Modern anti-spam enabled.
$anti_spam = $settings['anti_spam'] ?? [];
// Increment the counter for each enabled anti-spam feature.
$stat['akismet'] += ! empty( $anti_spam['akismet'] ) ? 1 : 0;
$stat['store_spam_entries'] += ! empty( $settings['store_spam_entries'] ) ? 1 : 0;
$stat['time_limit'] += ! empty( $anti_spam['time_limit']['enable'] ) ? 1 : 0;
$stat['country_filter'] += ! empty( $anti_spam['country_filter']['enable'] ) ? 1 : 0;
$stat['keyword_filter'] += ! empty( $anti_spam['keyword_filter']['enable'] ) ? 1 : 0;
$stat['captcha'] += ! empty( $settings['recaptcha'] ) ? 1 : 0;
}
// Count the list of keywords for the keyword filter.
$keyword_filter = wpforms()->obj( 'antispam_keyword_filter' );
$keywords = method_exists( $keyword_filter, 'get_keywords' ) ? $keyword_filter->get_keywords() : [];
$stat['keywords'] = count( $keywords );
return $stat;
}
/**
* Count how many field have a specific setting enabled.
*
* @since 1.9.0.3
*
* @param array $forms Published forms.
* @param string $field_type Field type.
* @param string $field_setting Field setting.
*
* @return int
*/
private function count_fields_with_setting( array $forms, string $field_type, string $field_setting ): int { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$counter = 0;
// Bail early, in case there are no forms.
if ( empty( $forms ) ) {
return $counter;
}
// Go through all forms.
foreach ( $forms as $form ) {
$fields = $form->post_content['fields'] ?? [];
if ( empty( $fields ) ) {
continue;
}
// Go through all fields on the form.
foreach ( $fields as $field ) {
if ( ! empty( $field['type'] ) && $field['type'] === $field_type && ! empty( $field[ $field_setting ] ) ) {
++$counter;
}
}
}
return $counter;
}
}
compare – داروخانه دکتر سیده زهره حسینی
مقایسه محصولات در دسته شربت سرماخوردگی کودکان