/** * Catches a reshare to delete if js is disabled * * @package BP Reshare * @since 1.0 * * @uses bp_is_activity_component() are we in activity component * @uses bp_is_current_action() to check current action * @uses buddyreshare_get_component_slug() to get component slug * @uses bp_action_variable() to check the variables * @uses check_admin_referer() for security reasons * @uses bp_activity_get_specific() to fetch the activity to delete * @uses bp_do_404() to eventually send the user on a 404 * @uses bp_core_get_user_domain() to build user's url * @uses bp_get_activity_slug() to get activity slug * @uses buddyreshare_reset_metas() to reset some metas for the parent activity * @uses bp_core_add_message() to print a warning message * @uses bp_core_redirect() to safely redirect user * @uses bp_activity_delete() to delete the reshare */ function buddyreshare_remove_reshare() { // Not deleting a reshare if (!bp_is_activity_component() || !bp_is_current_action(buddyreshare_get_component_slug())) { return false; } // No reshare to delete if (!bp_action_variable(0) || bp_action_variable(0) != 'delete' || !bp_action_variable(1) || !is_numeric(bp_action_variable(1))) { return false; } $reshare_id = bp_action_variable(1); check_admin_referer('buddyreshare_delete'); // Get the activity details $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(1), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $reshare = $activity['activities'][0]; } // redirecting to user's profile $redirect = bp_core_get_user_domain($reshare->user_id, $reshare->user_nicename, $reshare->user_login) . bp_get_activity_slug() . '/'; $reset = buddyreshare_reset_metas($reshare->secondary_item_id, $reshare->user_id); if (empty($reset)) { bp_core_add_message(__('Unable to reset the properties of the reshared activity', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('buddyreshare_reshare_deleted', $reshare_id); bp_core_add_message(__('Reshare deleted !', 'bp-reshare')); bp_core_redirect($redirect); } else { do_action('buddyreshare_reshare_deleted_error', $reshare_id); bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } }
/** * Builds the reshare action url * * @package BP Reshare * @since 1.0 * * @global BP_Activity_Template $activities_template * @uses buddyreshare_activity_get_id_to_reshare() to get the activity id to reshare * @uses wp_nonce_url() for security reason * @uses bp_get_root_domain() to get the blog's url * @uses bp_get_activity_root_slug() to get the activity slug * @uses buddyreshare_get_component_slug() to get the component's slug * @return string the action url */ function buddyreshare_activity_get_action_url() { global $activities_template; $to_reshare = buddyreshare_activity_get_id_to_reshare(); if (empty($to_reshare)) { return false; } $action_url = wp_nonce_url(bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/' . buddyreshare_get_component_slug() . '/add/' . $to_reshare . '/', 'buddyreshare_update'); return apply_filters('buddyreshare_activity_get_action_url', $action_url); }
/** * Builds a new user sub menu for the settings component in WP Admin Bar * * @package BP Reshare * @subpackage Component * @since 1.0 * * @global $wp_admin_bar object * @uses buddyreshare_get_component_slug() to get the slug of the component * @uses bp_loggedin_user_domain() to get the loggedin user profil url * @uses bp_get_activity_slug() to get Activity slug */ public function setup_activity_wp_nav() { global $wp_admin_bar; $activity_menu = array('parent' => 'my-account-activity', 'id' => 'my-account-activity-' . buddyreshare_get_component_slug(), 'title' => $this->name, 'href' => trailingslashit(bp_loggedin_user_domain() . bp_get_activity_slug() . '/' . buddyreshare_get_component_slug())); $wp_admin_bar->add_menu($activity_menu); }
/** * Filters the reshare action url if the delete action is possible * * @package BP Reshare * @since 1.0 * * @param string $action_url * @uses buddyreshare_can_unshare() to check if the context is good to allow delete action * @uses wp_nonce_url() for security reason * @uses bp_get_root_domain() to get the blog's url * @uses bp_get_activity_root_slug() to get the activity slug * @uses buddyreshare_get_component_slug() to get the component's slug * @uses bp_get_activity_id() to get the activity id [description] * @return string $action_url */ function buddyreshare_activity_filter_action_url($action_url = '') { if (buddyreshare_can_unshare()) { $action_url = wp_nonce_url(bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/' . buddyreshare_get_component_slug() . '/delete/' . bp_get_activity_id() . '/', 'buddyreshare_delete'); } return $action_url; }
/** * Are we on a the current user's profile reshare tab * * @package BP Reshare * @since 1.0 * * @uses bp_is_activity_component() are we in activity component * @uses bp_is_user() to check we're on a user's profile * @uses bp_is_current_action() to check current action * @uses buddyreshare_get_component_slug() to get component slug * @return boolean true|false */ function buddyreshare_is_user_profile_reshares() { if (bp_is_activity_component() && bp_is_user() && bp_is_current_action(buddyreshare_get_component_slug())) { return true; } return false; }