/** * Mark notification(s) as read * * @package WP Idea Stream * @subpackage buddypress/notifications * * @since 2.0.0 * * @uses wp_idea_stream_is_single_idea() to check if viewing the single template of an idea * @uses bp_notifications_mark_notifications_by_item_id() to mark notifications as read * @uses bp_loggedin_user_id() to get the logged in user ID * @uses wp_idea_stream_get_single_idea_id() to get the ID of the idea being viewed * @uses buddypress() to get BuddyPress instance * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier * @uses bp_is_user() to check a user's profile is displayed * @uses bp_is_current_component( 'ideastream' ) to check it's an IdeaStream part of the profile * @uses bp_notifications_mark_notifications_by_type() to mark notifications as read */ function wp_idea_stream_buddypress_comments_mark_notifications_read() { if (!empty($_GET['notif'])) { if (wp_idea_stream_is_single_idea()) { bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment'); bp_notifications_mark_notifications_by_item_id(bp_loggedin_user_id(), wp_idea_stream_get_single_idea_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate'); } if (bp_is_user() && bp_is_current_component('ideastream')) { bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_comment'); bp_notifications_mark_notifications_by_type(bp_loggedin_user_id(), buddypress()->ideastream->id, 'new_' . wp_idea_stream_get_post_type() . '_rate'); } } }
/** * Adds needed scripts to rate the idea or add tags to it * * @package WP Idea Stream * @subpackage ideas/functions * * @since 2.0.0 * * @uses wp_idea_stream_is_ideastream() to check it's plugin territory * @uses wp_idea_stream_is_single_idea() to check if a single idea is displayed * @uses wp_idea_stream_is_edit() to check if the idea is being edited * @uses wp_idea_stream_is_rating_disabled() to check if ratings are enabled * @uses wp_idea_stream_count_ratings() to get the idea rating stats * @uses wp_idea_stream_get_hint_list() to get the rating captions * @uses wp_idea_stream_users_current_user_id() to get current user ID * @uses wp_create_nonce() to create a nonce to be check when rating an idea * @uses wp_idea_stream_user_can() to check user's capability * @uses wp_enqueue_script() to add the needed scripts to WordPress queue * @uses wp_idea_stream_get_js_script() to get a specific javascript * @uses wp_idea_stream_get_version() to get plugin's version * @uses wp_localize_script() to localized script datas * @uses wp_idea_stream_is_addnew() to check the form is displayed * @uses wp_idea_stream_get_single_idea_id() to get current idea ID * @uses apply_filters() call 'wp_idea_stream_ideas_single_script' to add data to scripts used on single idea * call 'wp_idea_stream_ideas_form_script_vars' to add data to scripts used when using the form */ function wp_idea_stream_ideas_enqueue_scripts() { if (!wp_idea_stream_is_ideastream()) { return; } // Single idea > ratings if (wp_idea_stream_is_single_idea() && !wp_idea_stream_is_edit() && !wp_idea_stream_is_rating_disabled()) { $ratings = (array) wp_idea_stream_count_ratings(); $users_nb = count($ratings['users']); $hintlist = (array) wp_idea_stream_get_hint_list(); $js_vars = array('raty_loaded' => 1, 'ajaxurl' => admin_url('admin-ajax.php', 'relative'), 'wait_msg' => esc_html__('Saving your rating, please wait', 'wp-idea-stream'), 'success_msg' => esc_html__('Thanks, the average rating is now:', 'wp-idea-stream'), 'error_msg' => esc_html__('OOps, something went wrong', 'wp-idea-stream'), 'average_rate' => $ratings['average'], 'rate_nb' => $users_nb, 'one_rate' => esc_html__('One rate', 'wp-idea-stream'), 'x_rate' => esc_html__('% rates', 'wp-idea-stream'), 'readonly' => true, 'can_rate' => wp_idea_stream_user_can('rate_ideas'), 'not_rated' => esc_html__('Not rated yet', 'wp-idea-stream'), 'hints' => $hintlist, 'hints_nb' => count($hintlist), 'wpnonce' => wp_create_nonce('wp_idea_stream_rate')); $user_id = wp_idea_stream_users_current_user_id(); if (wp_idea_stream_user_can('rate_ideas')) { $js_vars['readonly'] = 0 != $users_nb ? in_array($user_id, $ratings['users']) : false; } wp_enqueue_script('wp-idea-stream-script', wp_idea_stream_get_js_script('script'), array('jquery-raty'), wp_idea_stream_get_version(), true); wp_localize_script('wp-idea-stream-script', 'wp_idea_stream_vars', apply_filters('wp_idea_stream_ideas_single_script', $js_vars)); } // Form > tags if (wp_idea_stream_is_addnew() || wp_idea_stream_is_edit()) { // Default dependencies $deps = array('tagging'); // Defaul js vars $js_vars = array('tagging_loaded' => 1, 'taginput_name' => 'wp_idea_stream[_the_tags][]', 'duplicate_tag' => __('Duplicate tag:', 'wp-idea-stream'), 'forbidden_chars' => __('Forbidden character:', 'wp-idea-stream'), 'forbidden_words' => __('Forbidden word:', 'wp-idea-stream')); // Add HeartBeat if idea is being edited if (wp_idea_stream_is_edit()) { $deps = array_merge($deps, array('heartbeat')); $js_vars = array_merge($js_vars, array('idea_id' => wp_idea_stream_get_single_idea_id(), 'pulse' => 'fast', 'warning' => esc_html__('An admin is currently editing this idea, please try to edit your idea later.', 'wp-idea-stream'))); } // Enqueue and localize script wp_enqueue_script('wp-idea-stream-script', wp_idea_stream_get_js_script('script'), $deps, wp_idea_stream_get_version(), true); wp_localize_script('wp-idea-stream-script', 'wp_idea_stream_vars', apply_filters('wp_idea_stream_ideas_form_script_vars', $js_vars)); } }