Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Created October 4, 2023 06:56
Show Gist options
  • Save raftaar1191/12f4a3c5da81604470b9a042e362342b to your computer and use it in GitHub Desktop.
Save raftaar1191/12f4a3c5da81604470b9a042e362342b to your computer and use it in GitHub Desktop.
Do not allow activity to get posted without any Media
/**
* Add content into the post
*/
function acrosswp_nouveau_ajax_post_update_custom() {
if ( ! is_user_logged_in() || empty( $_POST['_wpnonce_post_update'] ) || ! wp_verify_nonce( $_POST['_wpnonce_post_update'], 'post_update' ) ) {
wp_send_json_error();
}
// check activity toolbar options if one of them is set, activity can be empty.
$toolbar_option = false;
if ( bp_is_active( 'media' ) && ! empty( $_POST['document'] ) ) {
$toolbar_option = true;
} elseif ( bp_is_active( 'media' ) && ! empty( $_POST['media'] ) ) {
$toolbar_option = true;
} elseif ( bp_is_activity_link_preview_active() && ! empty( $_POST['link_url'] ) ) {
$toolbar_option = true;
} elseif ( bp_is_active( 'media' ) && ! empty( $_POST['gif_data'] ) ) {
$toolbar_option = true;
} elseif ( bp_is_active( 'video' ) && ! empty( $_POST['video'] ) ) {
$toolbar_option = true;
}
if ( ! $toolbar_option ) {
wp_send_json_error(
array(
'message' => __( 'Please enter some media to post.', 'buddyboss' ),
)
);
}
}
add_action( 'wp_ajax_post_update', 'acrosswp_nouveau_ajax_post_update_custom', -1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment