stats4wp_visitor ) ) { $wpdb->stats4wp_visitor = DB::table( 'visitor' ); } if ( 'all' === $all_data ) { $bots = $wpdb->get_results( $wpdb->prepare( "SELECT agent, COUNT(*) AS nb FROM {$wpdb->stats4wp_visitor} where device='bot' AND last_counter BETWEEN %s AND %s GROUP BY 1 ORDER by 2 DESC", $param['from'], $param['to'] ) ); $title_local = __( 'All Bots', 'stats4wp' ); } else { $bots = $wpdb->get_results( $wpdb->prepare( "SELECT agent, COUNT(*) AS nb FROM {$wpdb->stats4wp_visitor} where device='bot' AND last_counter BETWEEN %s AND %s GROUP BY 1 ORDER by 2 DESC LIMIT 0,10", $param['from'], $param['to'] ) ); $title_local = __( 'TOP 10 Bots', 'stats4wp' ); } foreach ( $bots as $bot ) { $bot_agent[] = $bot->agent; $nb[] = $bot->nb; } $script_js = ' const dataBots= { labels:' . wp_json_encode( $bot_agent ) . ', datasets: [{ label: "' . esc_html( __( 'Bots', 'stats4wp' ) ) . '", borderColor: "#05419ad6", fill: false, cubicInterpolationMode: "monotone", tension: 0.4, backgroundColor: [ "#05419ad6" ], data:' . wp_json_encode( $nb ) . ', }] }; const optionsBots = { responsive: false, plugins: { title: { display: true, text: "' . esc_html( $title_local ) . '" }, }, legend: { display: true, position: "bottom", labels: { fontColor: "#05419ad6", fontFamily: "Circular Std Book", fontSize: 14, } }, }; const configBots = { type: "bar", data: dataBots, options: optionsBots, }; // render init block const myChartBots = new Chart( document.getElementById("chartjs_bots"), configBots ); '; wp_add_inline_script( 'chart-js', $script_js ); unset( $day, $nb ); }