Reports::registerReportsScript()

Add scripts when it’s on the reports page

Description

Source

File: bp-integrations/learndash/buddypress/Reports.php

	public function registerReportsScript()
	{
		if (! bp_is_groups_component() || ! bp_is_current_action('reports')) {
			return;
		}

		wp_enqueue_script('bp-ld-reports-datatable', '//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js', ['jquery'], false, true);
		wp_enqueue_style('bp-ld-reports-datatable', '//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css', [], false);

		wp_enqueue_script(
			'bp-ld-reports',
			bp_learndash_url($filePath = '/assets/scripts/bp-learndash.js'),
			['jquery', 'bp-ld-reports-datatable'],
			filemtime(bp_learndash_path($filePath)),
			true
		);

		$per_page = bp_ld_sync('settings')->get('reports.per_page', 20);
		wp_localize_script('bp-ld-reports', 'BP_LD_REPORTS_DATA', [
			'current_group' => groups_get_current_group()->id,
			'nonce'         => wp_create_nonce('bp_ld_report'),
			'ajax_url'      => admin_url('admin-ajax.php'),
			'table_columns' => $this->getCurrentTableColumns(),
			'config' => [
				'perpage' => ( '' === $per_page ) ? 20 : $per_page
			],
			'text' => [
				'processing'     => __('Loading…', 'buddyboss'),
				'emptyTable'     => __('No result found…', 'buddyboss'),
				'paginate_first' => __('First', 'buddyboss'),
				'paginate_last'  => __('Last', 'buddyboss'),
				'paginate_next'  => __('Next', 'buddyboss'),
				'export_failed'  => __('Export failed, please refresh and try again.', 'buddyboss'),
				'export_ready'   => __('Export is ready.', 'buddyboss'),
			]
		]);

		wp_enqueue_style(
			'bp-ld-reports',
			bp_learndash_url($filePath = '/assets/styles/bp-learndash.css'),
			[],
			filemtime(bp_learndash_path($filePath))
		);
	}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.