settings(); $this->hooks(); } /** * Filterable widget settings. * * @since 1.5.0 */ public function settings() { $this->settings = array( // Number of forms to display in the forms list before "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 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 ), ); } /** * Widget hooks. * * @since 1.5.0 */ public function hooks() { \add_action( 'admin_enqueue_scripts', array( $this, 'widget_scripts' ) ); \add_action( 'wp_dashboard_setup', array( $this, 'widget_register' ) ); \add_action( 'admin_init', array( $this, 'hide_widget' ) ); \add_action( 'wpforms_create_form', __CLASS__ . '::clear_widget_cache' ); \add_action( 'wpforms_save_form', __CLASS__ . '::clear_widget_cache' ); \add_action( 'wpforms_delete_form', __CLASS__ . '::clear_widget_cache' ); } /** * Load widget-specific scripts. * * @since 1.5.0 */ public function widget_scripts() { $screen = \get_current_screen(); if ( ! isset( $screen->id ) || 'dashboard' !== $screen->id ) { return; } $min = \wpforms_get_min_suffix(); \wp_enqueue_style( 'wpforms-dashboard-widget', \WPFORMS_PLUGIN_URL . "assets/css/dashboard-widget{$min}.css", array(), \WPFORMS_VERSION ); \wp_enqueue_script( 'wpforms-moment', \WPFORMS_PLUGIN_URL . 'assets/js/moment.min.js', array(), '2.22.2', true ); \wp_enqueue_script( 'wpforms-chart', \WPFORMS_PLUGIN_URL . 'assets/js/chart.min.js', array( 'wpforms-moment' ), '2.7.2', true ); \wp_enqueue_script( 'wpforms-dashboard-widget', \WPFORMS_PLUGIN_URL . "lite/assets/js/admin/dashboard-widget{$min}.js", array( 'jquery', 'wpforms-chart' ), \WPFORMS_VERSION, true ); \wp_localize_script( 'wpforms-dashboard-widget', 'wpforms_dashboard_widget', array( 'show_more_html' => \esc_html__( 'Show More', 'wpforms-lite' ) . '', 'show_less_html' => \esc_html__( 'Show Less', 'wpforms-lite' ) . '', 'i18n' => array( 'entries' => \esc_html__( 'Entries', 'wpforms-lite' ), ), ) ); } /** * 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' ), array( $this, 'widget_content' ) ); // Attempt to place the widget at the top. $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; $widget_instance = array( $widget_key => $normal_dashboard[ $widget_key ] ); unset( $normal_dashboard[ $widget_key ] ); $sorted_dashboard = \array_merge( $widget_instance, $normal_dashboard ); $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; } /** * Load widget content. * * @since 1.5.0 */ public function widget_content() { $forms = \wpforms()->form->get( '', array( 'fields' => 'ids' ) ); 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'; ?> 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']; ?>