/** * Start the rewrites * * @package WP Idea Stream * @subpackage core/classes * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance */ public static function start() { $wp_idea_stream = wp_idea_stream(); if (empty($wp_idea_stream->rewrites)) { $wp_idea_stream->rewrites = new self(); } return $wp_idea_stream->rewrites; }
/** * Starts the class * * @package WP Idea Stream * @subpackage comments/classes * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance */ public static function start() { $wp_idea_stream = wp_idea_stream(); if (empty($wp_idea_stream->comments)) { $wp_idea_stream->comments = new self(); } return $wp_idea_stream->comments; }
public function tearDown() { parent::tearDown(); $_POST = $this->reset_post; $_REQUEST = $this->reset_request; $_SERVER = $this->reset_server; $_COOKIE = $this->reset_cookie; wp_idea_stream()->feedback = array(); remove_filter('wp_redirect', '__return_false'); }
/** * Let's start the class * * @package WP Idea Stream * @subpackage admin/sticky * * @since 2.0.0 * * @uses is_admin() to check for WordPress Administration * @uses wp_idea_stream() to get plugin's main instance */ public static function start() { if (!is_admin()) { return; } $wp_idea_stream_admin = wp_idea_stream()->admin; if (empty($wp_idea_stream_admin->sticky)) { $wp_idea_stream_admin->sticky = new self(); } return $wp_idea_stream_admin->sticky; }
/** * Finally Loads the component into BuddyPress instance * * @package WP Idea Stream * @subpackage buddypress/loader * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance * @uses buddypress() to get BuddyPress main instance * @uses get_option() to check for BuddyPress integration setting * @uses is_admin() to check for the Administration context * @uses wp_idea_stream_get_includes_dir() to get plugin's include dir * @uses wp_idea_stream_set_idea_var() to globalize a value for a later use * @uses add_query_arg(), admin_url() to build an url * @uses WP_Idea_Stream_BuddyPress to launch the IdeaStream BuddyPress component */ function wp_idea_stream_buddypress() { // Init a dummy BuddyPress version $bp_version = 0; // Set the required version $required_buddypress_version = '2.4.0'; // Get main plugin instance $wp_idea_stream = wp_idea_stream(); // Try to get buddypress() if (function_exists('buddypress')) { $bp_version = buddypress()->version; } // Should we load ? Yes, try by default! if (!get_option('_ideastream_buddypress_integration', 1)) { // Include at least BuddyPress filters & settings in order to extend // WP Idea Stream Settings and let the Admin deactivate/activate BuddyPress // integration. if (is_admin()) { require wp_idea_stream_get_includes_dir() . 'buddypress/settings.php'; } // Prevent BuddyPress Integration load return; } // If BuddyPress required version does not match, provide a feedback // Does not fire if BuddyPress integration is disabled. if (!version_compare($bp_version, $required_buddypress_version, '>=')) { if (is_admin()) { wp_idea_stream_set_idea_var('feedback', array('admin_notices' => array(sprintf(esc_html__('To benefit of WP Idea Stream in BuddyPress, version %s of BuddyPress is required. Please upgrade or deactivate %s.', 'wp-idea-stream'), $required_buddypress_version, '<a href="' . esc_url(add_query_arg(array('page' => 'ideastream'), admin_url('options-general.php'))) . '#buddypress">"BuddyPress integration"</a>')))); require wp_idea_stream_get_includes_dir() . 'buddypress/settings.php'; } // Prevent BuddyPress Integration load. return; } buddypress()->ideastream = new WP_Idea_Stream_BuddyPress(); }
/** * Displays the form submit/reset buttons * * @package WP Idea Stream * @subpackage ideas/tags * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's instance * @uses wp_nonce_field() to add a security token to check upon once submitted * @uses do_action() call 'wp_idea_stream_ideas_the_form_submit' to add custom actions before buttons * @uses wp_idea_stream_is_addnew() to check if using the add new form * @uses wp_idea_stream_is_edit() to check if using the edit form * @return string output for submit/reset buttons */ function wp_idea_stream_ideas_the_form_submit() { $wp_idea_stream = wp_idea_stream(); wp_nonce_field('wp_idea_stream_save'); do_action('wp_idea_stream_ideas_the_form_submit'); ?> <?php if (wp_idea_stream_is_addnew()) { ?> <input type="reset" value="<?php esc_attr_e('Reset', 'wp-idea-stream'); ?> "/> <input type="submit" value="<?php esc_attr_e('Submit', 'wp-idea-stream'); ?> " name="wp_idea_stream[save]"/> <?php } elseif (wp_idea_stream_is_edit() && !empty($wp_idea_stream->query_loop->idea->ID)) { ?> <input type="hidden" value="<?php echo esc_attr($wp_idea_stream->query_loop->idea->ID); ?> " name="wp_idea_stream[_the_id]"/> <input type="submit" value="<?php esc_attr_e('Update', 'wp-idea-stream'); ?> " name="wp_idea_stream[save]"/> <?php } ?> <?php }
public static function start($context, $template_args) { $wp_idea_stream = wp_idea_stream(); if (empty($wp_idea_stream->screens)) { $wp_idea_stream->screens = new self($template_args); } return $wp_idea_stream->screens; }
/** * Checks if an idea is sticky * * @package WP Idea Stream * @subpackage ideas/functions * * @since 2.0.0 * * @param int $id The idea ID * @param array $stickies the list of IDs of the sticky ideas * @uses wp_idea_stream() to get plugin's main instance * @uses wp_idea_stream_ideas_get_stickies() to get the sticky ideas * @return bool true if it's a sticky idea, false otherwise */ function wp_idea_stream_ideas_is_sticky($id = 0, $stickies = array()) { $id = absint($id); if (empty($id)) { if (!wp_idea_stream()->query_loop->idea->ID) { return false; } else { $id = wp_idea_stream()->query_loop->idea->ID; } } if (empty($stickies)) { $stickies = wp_idea_stream_ideas_get_stickies(); } if (!is_array($stickies)) { return false; } if (in_array($id, $stickies)) { return true; } return false; }
/** * Setups some globals * * @package WP Idea Stream * @subpackage admin/admin * * @since 2.0.0 * * @uses wp_idea_stream_get_post_type() to get the ideas post type identifier * @uses wp_idea_stream() to get WP Idea Stream instance */ private function setup_globals() { $this->post_type = wp_idea_stream_get_post_type(); $this->includes_dir = trailingslashit(wp_idea_stream()->includes_dir . 'admin'); $this->parent_slug = false; $this->metaboxes = array(); $this->is_plugin_settings = false; $this->downloading_csv = false; }
/** * Displays metas for form/single display * * @package WP Idea Stream * @subpackage ideas/classes * * @since 2.0.0 * * @param string $context the context (single/form) * @uses wp_idea_stream() to get plugin's instance * @uses WP_Idea_Stream_Idea_Metas->display_meta() to display the meta output * @return string HTML Output */ public function front_output($context = '') { if (empty($this->metas)) { return; } if (empty($context)) { $context = 'form'; } $wp_idea_stream = wp_idea_stream(); $idea_id = 0; if (!empty($wp_idea_stream->query_loop->idea->ID)) { $idea_id = $wp_idea_stream->query_loop->idea->ID; } foreach ($this->metas as $meta_object) { $this->display_meta($idea_id, $meta_object, $context); } }
/** * Count rating stats for a specific idea or gets the rating of a specific user for a given idea * * @package WP Idea Stream * @subpackage core/functions * * @since 2.0.0 * * @param integer $id the ID of the idea object * @param integer $user_id the user id * @param boolean $details whether to include detailed stats * @uses wp_idea_stream() to get plugin's main instance * @uses get_post_meta() to get the idea rates * @uses apply_filters() call 'wp_idea_stream_get_user_ratings' to cheat on user's rating * @uses number_format_i18n() to format the average * @uses apply_filters() call 'wp_idea_stream_count_ratings' to cheat on idea's rating stats * @return mixed int|array the rate of the user or the stats */ function wp_idea_stream_count_ratings($id = 0, $user_id = 0, $details = false) { // Init a default array $retarray = array('average' => 0, 'users' => array()); // Init a default user rating $user_rating = 0; // No idea, try to find it in the query loop if (empty($id)) { if (!wp_idea_stream()->query_loop->idea->ID) { return $retarray; } else { $id = wp_idea_stream()->query_loop->idea->ID; } } // Get all the rates for the idea $rates = get_post_meta($id, '_ideastream_rates', true); // Build the stats if (!empty($rates) && is_array($rates)) { foreach ($rates as $rate => $users) { // We need the user's rating if (!empty($user_id) && in_array($user_id, (array) $users['user_ids'])) { $user_rating = $rate; // We need average rating } else { $retarray['users'] = array_merge($retarray['users'], (array) $users['user_ids']); $retarray['average'] += $rate * count((array) $users['user_ids']); if (!empty($details)) { $retarray['details'][$rate] = (array) $users['user_ids']; } } } } // Return the user rating if (!empty($user_id)) { /** * @param int $user_rating the rate given by the user to the idea * @param int $id the ID of the idea * @param int $user_id the user id who rated the idea */ return apply_filters('wp_idea_stream_get_user_ratings', $user_rating, $id, $user_id); } if (!empty($retarray['users'])) { $retarray['average'] = number_format($retarray['average'] / count($retarray['users']), 1); } else { $retarray['average'] = 0; } /** * @param array $retarray the idea rating stats * @param int $id the ID of the idea * @param array $rates all idea rates organized in an array */ return apply_filters('wp_idea_stream_count_ratings', $retarray, $id, $rates); }
/** * Return the footer of the comment currently being iterated on. * * @package WP Idea Stream * @subpackage comments/tags * * @since 2.0.0 * * @uses wp_idea_stream() to get plugin's main instance * @uses get_comment_date() to get the date the comment was posted * @uses apply_filters() call 'wp_idea_stream_comments_get_comment_footer' to override the output * @return string the footer. */ function wp_idea_stream_comments_get_comment_footer() { $posted_on = sprintf(esc_html__('This comment was posted on %s', 'wp-idea-stream'), get_comment_date('', wp_idea_stream()->comment_query_loop->comment->comment_ID)); /** * @param string $posted_on the comment footer * @param object the comment object */ return apply_filters('wp_idea_stream_comments_get_comment_footer', $posted_on, wp_idea_stream()->comment_query_loop->comment); }
/** * Checks for rewrite conflicts, displays a warning if any * * @package WP Idea Stream * @subpackage admin/settings * * @since 2.0.0 * * @param string $slug the plugin's root slug * @uses wp_idea_stream() to get plugin's main instance * @uses get_posts() to look for a posts or a page having a post name like root slug * @uses esc_url() to sanitize an url * @uses get_edit_post_link() to get the edit link of the found post or page * @uses bbp_get_root_slug() to get bbPress forums root slug * @uses add_query_arg() to add query vars to an url * @uses admin_url() to build a link inside the current blog's Administration * @uses is_multisite() to check the WordPress config * @uses get_id_from_blogname() to check if a blog exists having the same slug than the plugin's root slug * @uses get_current_blog_id() to get the current blog ID * @uses get_home_url() to get the blog's home page * @uses is_super_admin() to check if the current user is a Super Administrator * @uses network_admin_url() to build a link inside the network Administration * @uses apply_filters() call 'wp_idea_stream_root_slug_conflict_check' to let plugins add their own warning messages * @return string HTML output */ function wp_idea_stream_root_slug_conflict_check($slug = 'ideastream') { // Initialize attention $attention = array(); /** * For pages and posts, problem can occur if the permalink setting is set to * '/%postname%/' In that case a post will be listed in post archive pages but the * single post may arrive on the IdeaStream Archive page. */ if ('/%postname%/' == wp_idea_stream()->pretty_links) { // Check for posts having a post name == root IdeaStream slug $post = get_posts(array('name' => $slug, 'post_type' => array('post', 'page'))); if (!empty($post)) { $post = $post[0]; $conflict = sprintf(_x('this %s', 'ideastream settings root slug conflict', 'wp-idea-stream'), $post->post_type); $attention[] = '<strong><a href="' . esc_url(get_edit_post_link($post->ID)) . '">' . $conflict . '</strong>'; } } /** * We need to check for bbPress forum's root prefix, if called the same way than * the root prefix of ideastream, then forums archive won't be reachable. */ if (function_exists('bbp_get_root_slug') && $slug == bbp_get_root_slug()) { $conflict = _x('bbPress forum root slug', 'bbPress possible conflict', 'wp-idea-stream'); $attention[] = '<strong><a href="' . esc_url(add_query_arg(array('page' => 'bbpress'), admin_url('options-general.php'))) . '">' . $conflict . '</strong>'; } /** * Finally, in case of a multisite config, we need to check if a child blog is called * the same way than the ideastream root slug */ if (is_multisite()) { $blog_id = (int) get_id_from_blogname($slug); $current_blog_id = (int) get_current_blog_id(); $current_site = get_current_site(); if (!empty($blog_id) && $blog_id != $current_blog_id && $current_site->blog_id == $current_blog_id) { $conflict = _x('child blog slug', 'Child blog possible conflict', 'wp-idea-stream'); $blog_url = get_home_url($blog_id, '/'); if (is_super_admin()) { $blog_url = add_query_arg(array('id' => $blog_id), network_admin_url('site-info.php')); } $attention[] = '<strong><a href="' . esc_url($blog_url) . '">' . $conflict . '</strong>'; } } /** * Other plugins can come in there to draw attention ;) * * @param array $attention list of slug conflicts * @param string $slug the plugin's root slug */ $attention = apply_filters('wp_idea_stream_root_slug_conflict_check', $attention, $slug); // Display warnings if needed if (!empty($attention)) { ?> <span class="attention"><?php printf(esc_html__('Possible conflict with: %s', 'wp-idea-stream'), join(', ', $attention)); ?> </span> <?php } }
function wp_idea_stream_users_the_signup_submit() { $wp_idea_stream = wp_idea_stream(); wp_nonce_field('wp_idea_stream_signup'); do_action('wp_idea_stream_users_the_signup_submit'); ?> <input type="reset" value="<?php esc_attr_e('Reset', 'wp-idea-stream'); ?> "/> <input type="submit" value="<?php esc_attr_e('Sign-up', 'wp-idea-stream'); ?> " name="wp_idea_stream_signup[signup]"/> <?php }
/** * Set a role on the site of the network if needed * * @package WP Idea Stream * @subpackage users/functions * * @since 2.2.0 */ function wp_idea_stream_maybe_set_current_user_role() { if (!is_multisite() || is_super_admin()) { return; } $current_user = wp_idea_stream()->current_user; if (empty($current_user->ID) || !empty($current_user->roles) || !wp_idea_stream_user_new_idea_set_role()) { return; } $current_user->set_role(wp_idea_stream_users_get_default_role()); }
/** * Creates a comments submenu to the IdeaStream menu * * @package WP Idea Stream * @subpackage admin/comments * * @since 2.0.0 * * @param array $menus list of menu items to add * @uses wp_idea_stream_get_idea_var() to get a globalized value * @uses wp_idea_stream_comments_count_comments() to build stats about idea comments * @uses WP_Idea_Stream_Admin_Comments->bubbled_menu() to build the pending count bubble * @uses add_query_arg() to build the parent slug * @return array the new menu items */ public function comments_menu($menus = array()) { // Comments menu title $comments_menu_title = esc_html__('Comments', 'wp-idea-stream'); $this->idea_comment_count = wp_idea_stream_get_idea_var('idea_comment_count'); if (empty($this->idea_comment_count)) { $this->idea_comment_count = wp_idea_stream_comments_count_comments(); } $comments_menu_title = $this->bubbled_menu($comments_menu_title . ' ', $this->idea_comment_count->moderated); $menus[0] = array('type' => 'comments', 'parent_slug' => wp_idea_stream()->admin->parent_slug, 'page_title' => esc_html__('Comments', 'wp-idea-stream'), 'menu_title' => $comments_menu_title, 'capability' => 'edit_ideas', 'slug' => add_query_arg('post_type', $this->post_type, 'edit-comments.php'), 'function' => '', 'alt_screen_id' => 'edit-comments.php', 'actions' => array('admin_head-%page%' => array($this, 'comments_menu_highlight'))); return $menus; }