Skip to content

Commit

Permalink
Register AJAX actions for BP 12+.
Browse files Browse the repository at this point in the history
BP 12 requires that AJAX actions be explicitly registered if they
need access to the current BP context, such as BP groups.

See #748.
  • Loading branch information
boonebgorges committed Mar 6, 2024
1 parent d0f26d5 commit ee8da7b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bp-docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ function __construct() {
// Set up doc taxonomy, etc
add_action( 'bp_docs_init', array( $this, 'load_doc_extras' ), 8 );

// Register AJAX actions.
add_action( 'bp_docs_init', array( $this, 'register_ajax_actions' ) );

// Add rewrite rules
add_action( 'generate_rewrite_rules', array( &$this, 'generate_rewrite_rules' ) );

Expand Down Expand Up @@ -461,6 +464,32 @@ function load_doc_extras() {
do_action( 'bp_docs_load_doc_extras' );
}

/**
* Registers AJAX actions for BP 12+.
*
* @since 2.2.2
*
* @return void
*/
public function register_ajax_actions() {
if ( ! function_exists( 'bp_ajax_register_action' ) ) {
return;
}

$ajax_actions = array(
'add_edit_lock',
'bp_docs_create_dummy_doc',
'doc_attachment_item_markup',
'refresh_access_settings',
'refresh_associated_group',
'remove_edit_lock',
);

foreach ( $ajax_actions as $action ) {
bp_ajax_register_action( $action );
}
}

/**
* Add rewrite tags
*
Expand Down
31 changes: 31 additions & 0 deletions includes/addon-folders.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class BP_Docs_Folders {
* @since 1.9
*/
public function __construct() {
$this->register_ajax_actions();

if ( ! bp_docs_enable_folders() ) {
return;
}
Expand Down Expand Up @@ -195,6 +197,35 @@ public function enqueue_assets() {
'force_metabox' => $force_folders_metabox,
) );
}

/**
* Register AJAX actions.
*
* Required by BuddyPress 12+, so that context information like "current group"
* is available during our AJAX callbacks.
*
* @since 2.2.2
*
* @return void
*/
public function register_ajax_actions() {
if ( ! function_exists( 'bp_ajax_register_action' ) ) {
return;
}

$ajax_actions = array(
'bp_docs_update_folders',
'bp_docs_update_parent_folders',
'bp_docs_update_folder_type',
'bp_docs_update_folder_type_for_group',
'bp_docs_process_folder_drop',
'bp_docs_get_folder_content',
);

foreach ( $ajax_actions as $action ) {
bp_ajax_register_action( $action );
}
}
}

/** Utility functions ********************************************************/
Expand Down

0 comments on commit ee8da7b

Please sign in to comment.