芝麻web文件管理V1.00
编辑当前文件:/home/ezdajrnh/test.ezed.pk/wp-content/plugins/wpforms-lite/src/Lite/Admin/DashboardWidget.php
is_dashboard_page() && ! $this->is_dashboard_widget_ajax_request() ) { return; } $this->settings(); $this->hooks(); } /** * Filterable widget settings. * * @since 1.5.0 */ public function settings() { // phpcs:disable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName $this->settings = [ // Number of forms to display in the forms' list before the "Show More" button appears. 'forms_list_number_to_display' => apply_filters( 'wpforms_dash_widget_forms_list_number_to_display', 5 ), // Allow results caching to reduce a DB load. 'allow_data_caching' => apply_filters( 'wpforms_dash_widget_allow_data_caching', true ), // Transient lifetime in seconds. Defaults to the end of a current day. 'transient_lifetime' => apply_filters( 'wpforms_dash_widget_transient_lifetime', strtotime( 'tomorrow' ) - time() ), // Determine if the forms with no entries should appear in a forms' list. // Once switched, the effect applies after cache expiration. 'display_forms_list_empty_entries' => apply_filters( 'wpforms_dash_widget_display_forms_list_empty_entries', true ), ]; // phpcs:enable WPForms.Comments.PHPDocHooks.RequiredHookDocumentation, WPForms.PHP.ValidateHooks.InvalidHookName } /** * Widget hooks. * * @since 1.5.0 */ public function hooks() { $widget_slug = static::SLUG; add_action( 'admin_enqueue_scripts', [ $this, 'widget_scripts' ] ); add_action( 'wp_dashboard_setup', [ $this, 'widget_register' ] ); add_action( 'admin_init', [ $this, 'hide_widget' ] ); add_action( "wp_ajax_wpforms_{$widget_slug}_save_widget_meta", [ $this, 'save_widget_meta_ajax' ] ); } /** * Load widget-specific scripts. * * @since 1.5.0 * * @param string $hook_suffix The current admin page. */ public function widget_scripts( $hook_suffix ) { if ( $hook_suffix !== 'index.php' ) { return; } $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-dashboard-widget', WPFORMS_PLUGIN_URL . "assets/css/dashboard-widget{$min}.css", [], WPFORMS_VERSION ); wp_enqueue_script( 'wpforms-chart', WPFORMS_PLUGIN_URL . 'assets/lib/chart.min.js', [ 'moment' ], '4.4.4', true ); wp_enqueue_script( 'wpforms-dashboard-widget', WPFORMS_PLUGIN_URL . "assets/lite/js/admin/dashboard-widget{$min}.js", [ 'jquery', 'wpforms-chart' ], WPFORMS_VERSION, true ); wp_localize_script( 'wpforms-dashboard-widget', 'wpforms_dashboard_widget', [ 'nonce' => wp_create_nonce( 'wpforms_' . static::SLUG . '_nonce' ), 'slug' => static::SLUG, 'show_more_html' => esc_html__( 'Show More', 'wpforms-lite' ) . '
', 'show_less_html' => esc_html__( 'Show Less', 'wpforms-lite' ) . '
', 'i18n' => [ 'entries' => esc_html__( 'Entries', 'wpforms-lite' ), ], // Adapter for Chart.js to use Moment.js for date formatting. 'adapter_path' => WPFORMS_PLUGIN_URL . 'assets/lib/chartjs-adapter-moment.min.js?ver=1.0.1', ] ); } /** * Register the widget. * * @since 1.5.0 */ public function widget_register() { global $wp_meta_boxes; $widget_key = 'wpforms_reports_widget_lite'; wp_add_dashboard_widget( $widget_key, esc_html__( 'WPForms', 'wpforms-lite' ), [ $this, 'widget_content' ] ); // Attempt to place the widget at the top. $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; $widget_instance = [ $widget_key => $normal_dashboard[ $widget_key ] ]; unset( $normal_dashboard[ $widget_key ] ); $sorted_dashboard = array_merge( $widget_instance, $normal_dashboard ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } /** * Load widget content. * * @since 1.5.0 */ public function widget_content() { $forms = wpforms()->obj( 'form' )->get( '', [ 'fields' => 'ids' ] ); $hide_graph = (bool) $this->widget_meta( 'get', 'hide_graph' ); $no_graph_class = $hide_graph ? 'wpforms-dash-widget-no-graph' : ''; echo '
'; if ( empty( $forms ) ) { $this->widget_content_no_forms_html(); } else { $this->widget_content_html( $hide_graph ); } Links::render( [ 'docs' => [ 'medium' => 'dashboard-widget', 'content' => 'docs', ], ] ); $plugin = $this->get_recommended_plugin(); $hide_recommended = $this->widget_meta( 'get', 'hide_recommended_block' ); if ( ! empty( $plugin ) && ! empty( $forms ) && ! $hide_recommended ) { $this->recommended_plugin_block_html( $plugin ); } echo '
'; } /** * Widget content HTML if a user has no forms. * * @since 1.5.0 */ public function widget_content_no_forms_html() { $create_form_url = add_query_arg( 'page', 'wpforms-builder', admin_url( 'admin.php' ) ); $learn_more_url = 'https://wpforms.com/docs/creating-first-form/?utm_source=WordPress&utm_medium=link&utm_campaign=liteplugin&utm_content=dashboardwidget'; ?>
timespan_select_html( 0, false ); $this->widget_settings_html( false ); ?>
forms_list_block(); ?>
get_entries_count_by_form(); if ( empty( $forms ) ) { $this->forms_list_block_empty_html(); } else { $this->forms_list_block_html( $forms ); } } /** * Empty forms list block HTML. * * @since 1.5.0 */ public function forms_list_block_empty_html() { ?>
settings['forms_list_number_to_display']; ?>
$form ) : ?>
= $show_forms ? 'class="wpforms-dash-widget-forms-list-hidden-el"' : ''; ?> data-form-id="">
$show_forms ) : ?>
-
|
settings['allow_data_caching']; $transient_name = 'wpforms_dash_widget_lite_entries_by_form'; if ( $allow_caching ) { $cache = get_transient( $transient_name ); /** * Filters the cache to clear or alter its data. * * @since 1.5.0 * * @param mixed $cache The cache content. */ $cache = apply_filters( 'wpforms_dash_widget_lite_cached_data', $cache ); // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName } // is_array() detects cached empty searches. if ( $allow_caching && is_array( $cache ) ) { return $cache; } $forms = wpforms()->obj( 'form' )->get( '', [ 'fields' => 'ids' ] ); if ( empty( $forms ) || ! is_array( $forms ) ) { return []; } $result = []; foreach ( $forms as $form_id ) { $count = absint( get_post_meta( $form_id, 'wpforms_entries_count', true ) ); if ( empty( $count ) && empty( $this->settings['display_forms_list_empty_entries'] ) ) { continue; } $result[ $form_id ] = [ 'form_id' => $form_id, 'count' => $count, 'title' => get_the_title( $form_id ), ]; } if ( ! empty( $result ) ) { // Sort forms by entries count (desc). uasort( $result, static function ( $a, $b ) { return ( $a['count'] > $b['count'] ) ? -1 : 1; } ); } if ( $allow_caching ) { // Transient lifetime in seconds. Defaults to the end of a current day. $transient_lifetime = $this->settings['transient_lifetime']; set_transient( $transient_name, $result, $transient_lifetime ); } return $result; } /** * Hide dashboard widget. * Use dashboard screen options to make it visible again. * * @since 1.5.0 */ public function hide_widget() { if ( ! is_admin() || ! is_user_logged_in() ) { return; } if ( ! isset( $_GET['wpforms-nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['wpforms-nonce'] ) ), 'wpforms_hide_dash_widget' ) ) { return; } if ( ! isset( $_GET['wpforms-widget'] ) || $_GET['wpforms-widget'] !== 'hide' ) { return; } $user_id = get_current_user_id(); $metaboxhidden = get_user_meta( $user_id, 'metaboxhidden_dashboard', true ); if ( ! is_array( $metaboxhidden ) ) { update_user_meta( $user_id, 'metaboxhidden_dashboard', [ 'wpforms_reports_widget_lite' ] ); } if ( is_array( $metaboxhidden ) && ! in_array( 'wpforms_reports_widget_lite', $metaboxhidden, true ) ) { $metaboxhidden[] = 'wpforms_reports_widget_lite'; update_user_meta( $user_id, 'metaboxhidden_dashboard', $metaboxhidden ); } $redirect_url = remove_query_arg( [ 'wpforms-widget', 'wpforms-nonce' ] ); wp_safe_redirect( $redirect_url ); exit(); } /** * Clear dashboard widget cached data. * * @since 1.5.2 */ public static function clear_widget_cache() { delete_transient( 'wpforms_dash_widget_lite_entries_by_form' ); } }