JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace WPForms\Lite\Admin;
use WPForms\Admin\Blocks\Links;
use WPForms\Admin\Dashboard\Widget;
/**
* Dashboard Widget shows a chart and the form entries stats in WP Dashboard.
*
* @since 1.5.0
*/
class DashboardWidget extends Widget {
/**
* Widget settings.
*
* @since 1.5.0
*
* @var array
*/
public $settings;
/**
* Init class.
*
* @since 1.5.5
*/
public function init() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
// phpcs:disable WPForms.PHP.ValidateHooks.InvalidHookName
/**
* Allow disabling the widget.
*
* @since 1.5.1
*
* @param bool $load Should the widget be loaded?
*/
if ( ! apply_filters( 'wpforms_admin_dashboardwidget', true ) ) {
return;
}
// phpcs:enable WPForms.PHP.ValidateHooks.InvalidHookName
add_action( 'wpforms_process_complete', [ static::class, 'clear_widget_cache' ] );
add_action( 'admin_init', [ $this, 'admin_init' ] );
}
/**
* Admin init class.
*
* @since 1.8.3
*/
public function admin_init() { // phpcs:ignore WPForms.PHP.HooksMethod.InvalidPlaceForAddingHooks
// This widget should be displayed for certain high-level users only.
if ( ! wpforms_current_user_can( 'view_forms' ) ) {
return;
}
add_action( 'wpforms_create_form', [ static::class, 'clear_widget_cache' ] );
add_action( 'wpforms_save_form', [ static::class, 'clear_widget_cache' ] );
add_action( 'wpforms_delete_form', [ static::class, 'clear_widget_cache' ] );
/**
* Clear cache after Lite plugin deactivation.
*
* Also triggered when the user upgrades the plugin to the Pro version.
* After activation of the Pro version, the cache will be cleared.
*/
add_action( 'deactivate_wpforms-lite/wpforms.php', [ static::class, 'clear_widget_cache' ] );
if ( ! $this->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.5.1',
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' ) . '<span class="dashicons dashicons-arrow-down"></span>',
'show_less_html' => esc_html__( 'Show Less', 'wpforms-lite' ) . '<span class="dashicons dashicons-arrow-up"></span>',
'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 '<div class="wpforms-dash-widget wpforms-lite ' . esc_attr( $no_graph_class ) . '">';
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 '</div><!-- .wpforms-dash-widget -->';
}
/**
* 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';
?>
<div class="wpforms-dash-widget-block wpforms-dash-widget-block-no-forms">
<img class="wpforms-dash-widget-block-sullie-logo" src="<?php echo esc_url( WPFORMS_PLUGIN_URL . 'assets/images/sullie.png' ); ?>" alt="<?php esc_attr_e( 'Sullie the WPForms mascot', 'wpforms-lite' ); ?>">
<h2><?php esc_html_e( 'Create Your First Form to Start Collecting Leads', 'wpforms-lite' ); ?></h2>
<p><?php esc_html_e( 'You can use WPForms to build contact forms, surveys, payment forms, and more with just a few clicks.', 'wpforms-lite' ); ?></p>
<?php if ( wpforms_current_user_can( 'create_forms' ) ) : ?>
<a href="<?php echo esc_url( $create_form_url ); ?>" class="button button-primary">
<?php esc_html_e( 'Create Your Form', 'wpforms-lite' ); ?>
</a>
<?php endif; ?>
<a href="<?php echo esc_url( $learn_more_url ); ?>" class="button" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Learn More', 'wpforms-lite' ); ?>
</a>
</div>
<?php
}
/**
* Widget content HTML.
*
* @since 1.5.0
* @since 1.7.4 Added hide graph parameter.
*
* @param bool $hide_graph Whether the graph is hidden.
*/
public function widget_content_html( $hide_graph = false ) {
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
/**
* Filters the content before the Dashboard Widget Chart block container (for Lite).
*
* @since 1.7.4
*
* @param string $chart_block_before Chart block before markup.
*/
echo apply_filters( 'wpforms_lite_admin_dashboard_widget_content_html_chart_block_before', '' );
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! $hide_graph ) :
?>
<div class="wpforms-dash-widget-chart-block-container">
<div class="wpforms-dash-widget-block wpforms-dash-widget-chart-block">
<canvas id="wpforms-dash-widget-chart" width="400" height="300"></canvas>
</div>
<div class="wpforms-dash-widget-block-upgrade">
<div class="wpforms-dash-widget-modal">
<a href="#" class="wpforms-dash-widget-dismiss-chart-upgrade">
<span class="dashicons dashicons-no-alt"></span>
</a>
<h2><?php esc_html_e( 'View all Form Entries inside the WordPress Dashboard', 'wpforms-lite' ); ?></h2>
<p><?php esc_html_e( 'Form entries reports are not available.', 'wpforms-lite' ); ?>
<?php esc_html_e( 'Form entries are not stored in Lite.', 'wpforms-lite' ); ?>
<?php esc_html_e( 'Upgrade to Pro and get access to the reports.', 'wpforms-lite' ); ?></p>
<p>
<a href="<?php echo esc_url( wpforms_admin_upgrade_link( 'dashboard-widget', 'upgrade-to-pro' ) ); ?>" class="wpforms-dash-widget-upgrade-btn" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'Upgrade to WPForms Pro', 'wpforms-lite' ); ?>
</a>
</p>
</div>
</div>
</div>
<?php endif; ?>
<div class="wpforms-dash-widget-block wpforms-dash-widget-block-title">
<h3><?php esc_html_e( 'Total Entries by Form', 'wpforms-lite' ); ?></h3>
<div class="wpforms-dash-widget-settings">
<?php
$this->timespan_select_html( 0, false );
$this->widget_settings_html( false );
?>
</div>
</div>
<div id="wpforms-dash-widget-forms-list-block" class="wpforms-dash-widget-block wpforms-dash-widget-forms-list-block">
<?php $this->forms_list_block(); ?>
</div>
<?php
}
/**
* Forms list block.
*
* @since 1.5.0
*/
public function forms_list_block() {
$forms = $this->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() {
?>
<p class="wpforms-error wpforms-error-no-data-forms-list">
<?php esc_html_e( 'No entries were submitted yet.', 'wpforms-lite' ); ?>
</p>
<?php
}
/**
* Forms list block HTML.
*
* @since 1.5.0
*
* @param array $forms Forms to display in the list.
*/
public function forms_list_block_html( $forms ) {
// Number of forms to display in the forms' list before the "Show More" button appears.
$show_forms = $this->settings['forms_list_number_to_display'];
?>
<table id="wpforms-dash-widget-forms-list-table" cellspacing="0">
<?php foreach ( array_values( $forms ) as $key => $form ) : ?>
<tr <?php echo $key >= $show_forms ? 'class="wpforms-dash-widget-forms-list-hidden-el"' : ''; ?> data-form-id="<?php echo absint( $form['form_id'] ); ?>">
<td><span class="wpforms-dash-widget-form-title"><?php echo esc_html( $form['title'] ); ?></span></td>
<td><?php echo absint( $form['count'] ); ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php if ( count( $forms ) > $show_forms ) : ?>
<button type="button" id="wpforms-dash-widget-forms-more" class="wpforms-dash-widget-forms-more" title="<?php esc_html_e( 'Show all forms', 'wpforms-lite' ); ?>">
<?php esc_html_e( 'Show More', 'wpforms-lite' ); ?> <span class="dashicons dashicons-arrow-down"></span>
</button>
<?php endif; ?>
<?php
}
/**
* Recommended plugin block HTML.
*
* @since 1.5.0
* @since 1.7.3 Added plugin parameter.
*
* @param array $plugin Plugin data.
*/
public function recommended_plugin_block_html( $plugin = [] ) {
if ( ! $plugin ) {
return;
}
$install_url = wp_nonce_url(
self_admin_url( 'update.php?action=install-plugin&plugin=' . rawurlencode( $plugin['slug'] ) ),
'install-plugin_' . $plugin['slug']
);
?>
<div class="wpforms-dash-widget-block wpforms-dash-widget-recommended-plugin-block">
<span class="wpforms-dash-widget-recommended-plugin">
<span class="recommended"><?php esc_html_e( 'Recommended Plugin:', 'wpforms-lite' ); ?></span>
<strong><?php echo esc_html( $plugin['name'] ); ?></strong>
<span class="sep">-</span>
<span class="action-links">
<?php if ( wpforms_can_install( 'plugin' ) ) { ?>
<a href="<?php echo esc_url( $install_url ); ?>"><?php esc_html_e( 'Install', 'wpforms-lite' ); ?></a>
<span class="sep sep-vertical">|</span>
<?php } ?>
<a href="<?php echo esc_url( $plugin['more'] ); ?>?utm_source=wpformsplugin&utm_medium=link&utm_campaign=wpformsdashboardwidget"><?php esc_html_e( 'Learn More', 'wpforms-lite' ); ?></a>
</span>
</span>
<button type="button" class="wpforms-dash-widget-dismiss-icon" title="<?php esc_html_e( 'Dismiss', 'wpforms-lite' ); ?>" data-field="hide_recommended_block">
<span class="dashicons dashicons-no-alt"></span>
</button>
</div>
<?php
}
/**
* The welcome block HTML.
*
* @since 1.8.7
* @deprecated 1.9.7
*/
public function welcome_block_html() {
return '';
}
/**
* Get entries count grouped by form.
* Main point of entry to fetch form entry count data from DB.
* Cache the result.
*
* @since 1.5.0
*
* @return array
*/
public function get_entries_count_by_form(): array {
// Allow results caching to reduce a DB load.
$allow_caching = $this->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' );
}
}