xprofile_add_admin_js()

Enqueue the jQuery libraries for handling drag/drop/sort.


Description Description


Source Source

File: bp-xprofile/bp-xprofile-cssjs.php

function xprofile_add_admin_js() {
	if ( !empty( $_GET['page'] ) && strpos( $_GET['page'], 'bp-profile-setup' ) !== false ) {
		wp_enqueue_script( 'jquery-ui-core'      );
		wp_enqueue_script( 'jquery-ui-tabs'      );
		wp_enqueue_script( 'jquery-ui-mouse'     );
		wp_enqueue_script( 'jquery-ui-draggable' );
		wp_enqueue_script( 'jquery-ui-droppable' );
		wp_enqueue_script( 'jquery-ui-sortable'  );

		$min = bp_core_get_minified_asset_suffix();
		wp_enqueue_script( 'xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array( 'jquery', 'jquery-ui-sortable' ), bp_get_version() );

		// Localize strings.
		// supports_options_field_types is a dynamic list of field
		// types that support options, for use in showing/hiding the
		// "please enter options for this field" section.
		$strings = array(
			'do_settings_section_field_types' => array(),
			'do_autolink' => '',
		);

		foreach ( bp_xprofile_get_field_types() as $field_type => $field_type_class ) {
			$field = new $field_type_class();
			if ( $field->do_settings_section() ) {
				$strings['do_settings_section_field_types'][] = $field_type;
			}
		}

		// Load 'autolink' setting into JS so that we can provide smart defaults when switching field type.
		if ( ! empty( $_GET['field_id'] ) ) {
			$field_id = intval( $_GET['field_id'] );

			// Pull the raw data from the DB so we can tell whether the admin has saved a value yet.
			$strings['do_autolink'] = bp_xprofile_get_meta( $field_id, 'field', 'do_autolink' );
		}

		wp_localize_script( 'xprofile-admin-js', 'XProfileAdmin', $strings );
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.