. */ /** * Setting constants * * @since 1.0 * @version 1.1 */ /** Plugin directory */ define( 'BBPABA_PLUGIN_DIR', dirname( __FILE__ ) ); /** Plugin base directory */ define( 'BBPABA_PLUGIN_BASEDIR', dirname( plugin_basename( __FILE__ ) ) ); /** Various link/content related helper constants */ define( 'BBPABA_VTUTORIALS_INSTALL', apply_filters( 'bbpaba_filter_video_installation', 'http://www.youtube.com/watch?v=EDAp8M7CuPk&hd=1' ) ); define( 'BBPABA_VTUTORIALS_THEMING', apply_filters( 'bbpaba_filter_video_theming', 'http://www.youtube.com/watch?v=lB2Oodx2GJw&hd=1' ) ); define( 'BBPABA_TUTORIALS_STARTING', apply_filters( 'bbpaba_filter_tutorial_starting', 'http://wp.smashingmagazine.com/2011/11/15/getting-started-with-bbpress/' ) ); add_action( 'init', 'ddw_bbpress_aba_init' ); /** * Load the text domain for translation of the plugin. * Load admin helper functions - only within 'wp-admin'. * * @since 1.0 * @version 1.2 */ function ddw_bbpress_aba_init() { /** First look in WordPress' "languages" folder = custom & update-secure! */ load_plugin_textdomain( 'bbpaba', false, BBPABA_PLUGIN_BASEDIR . '/../../languages/bbpress-admin-bar-addition/' ); /** Then look in plugin's "languages" folder = default */ load_plugin_textdomain( 'bbpaba', false, BBPABA_PLUGIN_BASEDIR . '/languages/' ); /** If 'wp-admin' include admin helper functions */ if ( is_admin() ) { require_once( BBPABA_PLUGIN_DIR . '/includes/bbpaba-admin.php' ); } /** Add "Settings Page" link to plugin page - only within 'wp-admin' */ if ( is_admin() && current_user_can( 'manage_options' ) ) { add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ) , 'ddw_bbpaba_settings_page_link' ); } /** Define constants and set defaults for removing all or certain sections */ if ( ! defined( 'BBPABA_DISPLAY' ) ) { define( 'BBPABA_DISPLAY', TRUE ); } if ( ! defined( 'BBPABA_EXTENSIONS_DISPLAY' ) ) { define( 'BBPABA_EXTENSIONS_DISPLAY', TRUE ); } if ( ! defined( 'BBPABA_THEMES_DISPLAY' ) ) { define( 'BBPABA_THEMES_DISPLAY', TRUE ); } if ( ! defined( 'BBPABA_RESOURCES_DISPLAY' ) ) { define( 'BBPABA_RESOURCES_DISPLAY', TRUE ); } if ( ! defined( 'BBPABA_DE_DISPLAY' ) ) { define( 'BBPABA_DE_DISPLAY', TRUE ); } if ( ! defined( 'BBPABA_REMOVE_GDBBPRESSTOOLS_TOOLBAR' ) ) { define( 'BBPABA_REMOVE_GDBBPRESSTOOLS_TOOLBAR', FALSE ); } } // end of function ddw_bbpress_aba_init add_action( 'admin_bar_menu', 'ddw_bbpress_aba_admin_bar_menu', 98 ); /** * Add new menu items to the WordPress Toolbar / Admin Bar. * * @since 1.0 * @version 1.3 * * @global mixed $wp_admin_bar */ function ddw_bbpress_aba_admin_bar_menu() { global $wp_admin_bar; /** * Allows for filtering the general user role/capability to see main & sub-level items * * Default role: 'moderate' (set by bbPress 2.x itself!) * * @since 1.5 */ $bbpaba_filter_capability = apply_filters( 'bbpaba_filter_capability_all', 'moderate' ); /** * Required bbPress/ WordPress cabability to display new admin bar entry * Only showing items if toolbar / admin bar is activated and user is logged in! * * @since 1.0 * @version 1.1 */ if ( ! is_user_logged_in() || ! is_admin_bar_showing() || ! current_user_can( $bbpaba_filter_capability ) || // allows for custom filtering the required role/capability ! BBPABA_DISPLAY // allows for custom disabling ) return; /** Set unique prefix */ $prefix = 'ddw-bbpress-'; /** Create parent menu item references/prefixes */ $bbpressbar = $prefix . 'admin-bar'; // root level $bbpsupport = $prefix . 'bbpsupport'; // sub level: bbp support $bbpdocumentation = $prefix . 'bbpdocumentation'; // sub level: bbp documentation $bbpknowledgebase = $prefix . 'bbpknowledgebase'; // sub level: bbp knowledgebase $bbpsites = $prefix . 'bbpsites'; // sub level: bbp sites $bbpsettings = $prefix . 'bbpsettings'; // sub level: bbp settings $forums = $prefix . 'forums'; // sub level: forums $forumsfrontbase = $prefix . 'forumsfrontbase'; // third level: forums frontend view $f_gdtools = $prefix . 'f_gdtools'; // third level plugin extension: gd bbpress tools $f_gdtoolbox = $prefix . 'f_gdtoolbox'; // third level plugin extension: gd bbpress toolbox $topics = $prefix . 'topics'; // sub level: topics $replies = $prefix . 'replies'; // sub level: replies $users = $prefix . 'users'; // sub level: users $userswangguard = $prefix . 'userswangguard'; // third level plugin extension: wangguard $extensions = $prefix . 'extensions'; // sub level: support $extgdtools = $prefix . 'extgdtools'; // third level plugin extension: gd bbpress tools $extgdtoolbox = $prefix . 'extgdtoolbox'; // third level plugin extension: gd bbpress toolbox $extwangguard = $prefix . 'extwangguard'; // third level plugin extension: wangguard $extcptprivacy = $prefix . 'extcptprivacy'; // third level plugin extension: custom post type privacy $extbbpconvert = $prefix . 'extbbpconvert'; // third level plugin extension: bbconverter $exts2member = $prefix . 'exts2member'; // third level plugin extension: s2member $bbpgroup = $prefix . 'bbpgroup'; // sub level: bbp group (resources) /** Make the "bbPress" name filterable within menu items */ $bbpaba_bbpress_name = apply_filters( 'bbpaba_filter_bbpress_name', __( 'bbPress', 'bbpaba' ) ); /** Make the "bbPress" name's tooltip filterable within menu items */ $bbpaba_bbpress_name_tooltip = apply_filters( 'bbpaba_filter_bbpress_name_tooltip', _x( 'bbPress', 'Translators: For the tooltip', 'bbpaba' ) ); /** * Check for WordPress version to add parent ids for resource links group * Check against WP 3.3+ only function "wp_editor" - if true use "$bbpgroup" as parent (WP 3.3+ style) * otherwise use "$bbpressbar" as parent (WP 3.1/3.2 style) * * @since 1.4 * * @param $bbpgroup_check_item */ if ( function_exists( 'wp_editor' ) ) { $bbpgroup_check_item = $bbpgroup; } else { $bbpgroup_check_item = $bbpressbar; } /** Display these items also when bbPress plugin is not installed */ if ( BBPABA_RESOURCES_DISPLAY ) { /** Include plugin file with resources links */ require_once( BBPABA_PLUGIN_DIR . '/includes/bbpaba-resources.php' ); } // end-if constant check for displaying resources /** Display the following links only for these locales: de_DE, de_AT, de_CH, de_LU */ if ( BBPABA_DE_DISPLAY && ( get_locale() == 'de_DE' || get_locale() == 'de_AT' || get_locale() == 'de_CH' || get_locale() == 'de_LU' ) ) { /** German public community support forum */ $menu_items['bbp-forum-de'] = array( 'parent' => $bbpgroup_check_item, 'title' => __( 'German Support Forum', 'bbpaba' ), 'href' => 'http://forum.wpde.org/bbpress/', 'meta' => array( 'title' => _x( 'Public German Community Support Forum', 'Translators: For the tooltip', 'bbpaba' ) ) ); /** German language packs */ $menu_items['bbp-languages-de'] = array( 'parent' => $bbpgroup_check_item, 'title' => __( 'German language files', 'bbpaba' ), 'href' => 'http://deckerweb.de/material/sprachdateien/bbpress-forum/', 'meta' => array( 'title' => _x( 'German language files for bbPress 2.x plus some extensions', 'Translators: For the tooltip', 'bbpaba' ) ) ); } // end-if german locales /** Show these items only if bbPress plugin is actually installed */ if ( class_exists( 'bbPress' ) ) { /** Main settings link */ $bbp_aurl_main = admin_url( 'options-general.php?page=bbpress' ); /** Main settings section */ if ( current_user_can( 'manage_options' ) ) { $menu_items['bbpsettings'] = array( 'parent' => $bbpressbar, 'title' => esc_attr__( $bbpaba_bbpress_name ) . ' ' . __( 'Main Settings', 'bbpaba' ), 'href' => admin_url( 'options-general.php?page=bbpress' ), 'meta' => array( 'target' => '', 'title' => esc_attr__( $bbpaba_bbpress_name_tooltip ) . ' ' . _x( 'Main Settings', 'Translators: For the tooltip', 'bbpaba' ) ) ); } // end-if cap check /** Settings: Widgets & Menus */ if ( current_user_can( 'edit_theme_options' ) ) { $menu_items['s-widgets'] = array( 'parent' => $bbpsettings, 'title' => esc_attr__( $bbpaba_bbpress_name ) . ' ' . __( 'Widgets', 'bbpaba' ), 'href' => admin_url( 'widgets.php' ), 'meta' => array( 'target' => '', 'title' => esc_attr__( $bbpaba_bbpress_name_tooltip ) . ' ' . __( 'Widgets', 'bbpaba' ) ) ); $menu_items['s-menus'] = array( 'parent' => $bbpsettings, 'title' => esc_attr__( $bbpaba_bbpress_name ) . ' ' . __( 'Menus', 'bbpaba' ), 'href' => admin_url( 'nav-menus.php' ), 'meta' => array( 'target' => '', 'title' => esc_attr__( $bbpaba_bbpress_name_tooltip ) . ' ' . __( 'Menus', 'bbpaba' ) ) ); } // end-if cap check /** Settings: Repair/Import/Reset Forums (former: Recount) */ if ( is_super_admin() && current_user_can( 'manage_options' ) ) { /** Set "Repair" admin URL */ if ( function_exists( 'bbp_current_user_can_see' ) ) { $bbp_aurl_repair = admin_url( 'tools.php?page=bbp-repair' ); } else { $bbp_aurl_repair = admin_url( 'tools.php?page=bbp-recount' ); } $menu_items['s-repairforums'] = array( 'parent' => $bbpsettings, 'title' => __( 'Repair Forums', 'bbpaba' ), 'href' => $bbp_aurl_repair, 'meta' => array( 'target' => '', 'title' => _x( 'Repair Forum Relationships for Topics, Replies, Voices etc.', 'Translators: For the tooltip', 'bbpaba' ) ) ); } // end-if cap check /** Settings: Update Forums in Multisite - only for super admins */ if ( current_user_can( 'manage_network' ) ) { $menu_items['s-msupdate'] = array( 'parent' => $bbpsettings, 'title' => __( 'Update Forums', 'bbpaba' ), 'href' => network_admin_url( 'update-core.php?page=bbpress-update' ), 'meta' => array( 'target' => '', 'title' => sprintf( _x( 'Update all %s Forums in Multisite', 'Translators: For the tooltip', 'bbpaba' ), esc_attr__( $bbpaba_bbpress_name_tooltip ) ) ) ); } // end-if multisite check /** Settings: Import Forums (Converter) */ if ( class_exists( 'BBP_Converter' ) && current_user_can( 'manage_options' ) && ( function_exists( 'bbp_current_user_can_see' ) && bbp_current_user_can_see( 'bbp_tools_import_page' ) ) ) { $menu_items['s-importforums'] = array( 'parent' => $bbpsettings, 'title' => __( 'Import Forums', 'bbpaba' ), 'href' => admin_url( 'tools.php?page=bbp-converter' ), 'meta' => array( 'target' => '', 'title' => sprintf( _x( 'bbPress Converter: Convert other forum systems to %s', 'Translators: For the tooltip', 'bbpaba' ), esc_attr__( $bbpaba_bbpress_name_tooltip ) ) ) ); } // end-if cap check /** Settings: Reset Forums */ if ( current_user_can( 'manage_options' ) && ( function_exists( 'bbp_current_user_can_see' ) && bbp_current_user_can_see( 'bbp_tools_reset_page' ) ) ) { $menu_items['s-resetforums'] = array( 'parent' => $bbpsettings, 'title' => __( 'Reset Forums', 'bbpaba' ), 'href' => admin_url( 'tools.php?page=bbp-reset' ), 'meta' => array( 'target' => '', 'title' => sprintf( _x( 'Reset Forums to brand new %s install', 'Translators: For the tooltip', 'bbpaba' ), esc_attr__( $bbpaba_bbpress_name_tooltip ) ) ) ); } // end-if cap check /** Forums section */ if ( current_user_can( 'publish_forums' ) || current_user_can( 'edit_forum' ) ) { $menu_items['forums'] = array( 'parent' => $bbpressbar, 'title' => __( 'Forums', 'bbpaba' ), 'href' => admin_url( 'edit.php?post_type=forum' ), 'meta' => array( 'target' => '', 'title' => __( 'Forums', 'bbpaba' ) ) ); /** Forums helper code */ $bbpaba_query = $bbpaba_forums_query = array( 'post_parent' => 0, 'post_status' => 'publish', 'posts_per_page' => 20, 'orderby' => 'menu_order', 'order' => 'ASC' ); $bbpaba_forums = bbp_get_forums_for_current_user( $bbpaba_query ); /** If Forums are available, display their links */ if ( is_array( $bbpaba_forums ) && count( $bbpaba_forums ) > 0 ) { /** Forums Front Base = Forums Archive */ $menu_items['forumsfrontbase'] = array( 'parent' => $forums, 'title' => __( 'View Forums', 'bbpaba' ), 'href' => get_post_type_archive_link( 'forum' ), 'meta' => array( 'target' => '', 'title' => __( 'View Forums', 'bbpaba' ) ) ); /** Dynamically add all active Forums */ foreach ( $bbpaba_forums as $bbpaba_forum ) { $menu_items['forums-frontend-' . $bbpaba_forum->ID] = array( 'parent' => $forumsfrontbase, 'title' => apply_filters( 'the_title', $bbpaba_forum->post_title, $bbpaba_forum->ID ), 'href' => esc_url_raw( get_permalink( $bbpaba_forum->ID ) ), 'meta' => array( 'target' => '', 'title' => _x( 'View Forum', 'Translators: For the tooltip', 'bbpaba' ) . ': ' . apply_filters( 'the_title', $bbpaba_forum->post_title, $bbpaba_forum->ID ) ) ); } // end foreach } // end-if available forums check /** * Action Hook 'bbpaba_custom_forum_items' * allows for hooking other custom forum items in * * @since 1.5 */ do_action( 'bbpaba_custom_forum_items' ); /** Add new forum */ $menu_items['f-add-forum'] = array( 'parent' => $forums, 'title' => __( 'Add new Forum', 'bbpaba' ), 'href' => admin_url( 'post-new.php?post_type=forum' ), 'meta' => array( 'target' => '', 'title' => __( 'Add new Forum', 'bbpaba' ) ) ); } // end-if cap check / forum section /** Topics section */ if ( current_user_can( 'publish_topics' ) || current_user_can( 'edit_topic' ) ) { $menu_items['topics'] = array( 'parent' => $bbpressbar, 'title' => __( 'Topics', 'bbpaba' ), 'href' => admin_url( 'edit.php?post_type=topic' ), 'meta' => array( 'target' => '', 'title' => __( 'Topics', 'bbpaba' ) ) ); $menu_items['t-add-topic'] = array( 'parent' => $topics, 'title' => __( 'Add new Topic', 'bbpaba' ), 'href' => admin_url( 'post-new.php?post_type=topic' ), 'meta' => array( 'target' => '', 'title' => __( 'Add new Topic', 'bbpaba' ) ) ); $menu_items['t-topic-tags'] = array( 'parent' => $topics, 'title' => __( 'Topic Tags', 'bbpaba' ), 'href' => admin_url( 'edit-tags.php?taxonomy=topic-tag&post_type=topic' ), 'meta' => array( 'target' => '', 'title' => __( 'Topic Tags', 'bbpaba' ) ) ); } // end-if cap check /** Replies section */ if ( current_user_can( 'publish_replies' ) || current_user_can( 'edit_reply' ) ) { $menu_items['replies'] = array( 'parent' => $bbpressbar, 'title' => __( 'Replies', 'bbpaba' ), 'href' => admin_url( 'edit.php?post_type=reply' ), 'meta' => array( 'target' => '', 'title' => _x( 'Replies', 'Translators: For the tooltip', 'bbpaba' ) ) ); $menu_items['r-add-reply'] = array( 'parent' => $replies, 'title' => __( 'Add new Reply', 'bbpaba' ), 'href' => admin_url( 'post-new.php?post_type=reply' ), 'meta' => array( 'target' => '', 'title' => __( 'Add new Reply', 'bbpaba' ) ) ); } // end-if cap check /** Users section */ if ( current_user_can( 'edit_users' ) ) { $menu_items['users'] = array( 'parent' => $bbpressbar, 'title' => __( 'Users', 'bbpaba' ), 'href' => is_network_admin() ? network_admin_url( 'users.php' ) : admin_url( 'users.php' ), 'meta' => array( 'target' => '', 'title' => __( 'Users', 'bbpaba' ) ) ); } // end-if can edit_users if ( current_user_can( 'add_users' ) ) { $menu_items['u-add-user'] = array( 'parent' => $users, 'title' => __( 'Add new User', 'bbpaba' ), 'href' => is_network_admin() ? network_admin_url( 'user-new.php' ) : admin_url( 'user-new.php' ), 'meta' => array( 'target' => '', 'title' => __( 'Add new User', 'bbpaba' ) ) ); } // end-if can add_users /** * Display last main item in the menu for active extensions/plugins * ATTENTION: This is where plugins/extensions hook in on the sub-level hierarchy * * @since 1.0 * @version 1.1 */ if ( BBPABA_EXTENSIONS_DISPLAY && current_user_can( 'activate_plugins' ) ) { $menu_items['extensions'] = array( 'parent' => $bbpressbar, 'title' => __( 'Active Extensions', 'bbpaba' ), 'href' => is_network_admin() ? network_admin_url( 'plugins.php' ) : admin_url( 'plugins.php' ), 'meta' => array( 'target' => '', 'title' => _x( 'Active Extensions', 'Translators: For the tooltip', 'bbpaba' ) ) ); /** * Action Hook 'bbpaba_custom_extension_items' * allows for hooking other extension-related items in * * @since 1.5 */ do_action( 'bbpaba_custom_extension_items' ); } // end-if constant & cap check for displaying extensions } else { /** If bbPress is not active "void" main settings link */ $bbp_aurl_main = false; } // end-if bbPress conditional /** * Display links to active bbPress 2.x plugins/extensions settings' pages * * @since 1.0 * @version 1.2 */ /** Include plugin file with plugin support links */ require_once( BBPABA_PLUGIN_DIR . '/includes/bbpaba-plugins.php' ); /** * Display links to active bbPress 2.x compatible/specific themes settings' pages * * @since 1.5 */ /** Include plugin file with theme support links */ if ( BBPABA_THEMES_DISPLAY ) { require_once( BBPABA_PLUGIN_DIR . '/includes/bbpaba-themes.php' ); /** * Action Hook 'bbpaba_custom_theme_items' * allows for hooking other theme-related items in * * @since 1.5 */ do_action( 'bbpaba_custom_theme_items' ); } // end-if constant check /** Allow menu items to be filtered, but pass in parent menu item IDs */ $menu_items = (array) apply_filters( 'ddw_bbpress_aba_menu_items', $menu_items, $prefix, $bbpressbar, $bbpsupport, $bbpdocumentation, $bbpknowledgebase, $bbpsites, $bbpsettings, $forums, $forumsfrontbase, $f_gdtools, $f_gdtoolbox, $topics, $replies, $users, $userswangguard, $extensions, $extgdtools, $extgdtoolbox, $extwangguard, $extcptprivacy, $extbbpconvert, $exts2member, $bbpgroup ); // end of array /** * Add the bbPress top-level menu item * * @since 1.0 * @version 1.1 * * @param $bbpaba_main_item_title * @param $bbpaba_main_item_title_tooltip * @param $bbpaba_main_item_icon_display */ /** Filter the main item name */ $bbpaba_main_item_title = apply_filters( 'bbpaba_filter_main_item', __( 'bbPress', 'bbpaba' ) ); /** Filter the main item name's tooltip */ $bbpaba_main_item_title_tooltip = apply_filters( 'bbpaba_filter_main_item_tooltip', _x( 'bbPress Forums', 'Translators: For the tooltip', 'bbpaba' ) ); /** Filter the main item icon's class/display */ $bbpaba_main_item_icon_display = apply_filters( 'bbpaba_filter_main_item_icon_display', 'icon-bbpress' ); $wp_admin_bar->add_menu( array( 'id' => $bbpressbar, 'title' => esc_attr__( $bbpaba_main_item_title ), 'href' => $bbp_aurl_main, 'meta' => array( 'class' => esc_attr( $bbpaba_main_item_icon_display ), 'title' => esc_attr__( $bbpaba_main_item_title_tooltip ) ) ) ); /** Loop through the menu items */ foreach ( $menu_items as $id => $menu_item ) { /** Add in the item ID */ $menu_item['id'] = $prefix . $id; /** Add meta target to each item where it's not already set, so links open in new window/tab */ if ( ! isset( $menu_item['meta']['target'] ) ) $menu_item['meta']['target'] = '_blank'; /** Add class to links that open up in a new window/tab */ if ( '_blank' === $menu_item['meta']['target'] ) { if ( ! isset( $menu_item['meta']['class'] ) ) $menu_item['meta']['class'] = ''; $menu_item['meta']['class'] .= $prefix . 'bbpaba-new-tab'; } /** Add menu items */ $wp_admin_bar->add_menu( $menu_item ); } // end foreach /** * Action Hook 'bbpaba_custom_main_items' * allows for hooking other main items in * * @since 1.5 */ do_action( 'bbpaba_custom_main_items' ); /** * Check for WordPress version to add resource links group * Check against WP 3.3+ only function "wp_editor" - if true display group styling * otherwise display links in WP 3.1/3.2 style * * @since 1.4 */ if ( function_exists( 'wp_editor' ) ) { $wp_admin_bar->add_group( array( 'parent' => $bbpressbar, 'id' => $bbpgroup, 'meta' => array( 'class' => 'ab-sub-secondary' ) ) ); } else { $wp_admin_bar->add_menu( array( 'parent' => $bbpressbar, 'id' => $bbpgroup ) ); } // end-if wp version check /** * Action Hook 'bbpaba_custom_group_items' * allows for hooking other bbPress Group items in * * @since 1.5 */ do_action( 'bbpaba_custom_group_items' ); } // end of main function add_action( 'wp_head', 'ddw_bbpress_aba_admin_style' ); add_action( 'admin_head', 'ddw_bbpress_aba_admin_style' ); /** * Add the styles for new WordPress Toolbar / Admin Bar entry * * @since 1.0 * @version 1.3 * * @param $bbpaba_main_icon */ function ddw_bbpress_aba_admin_style() { /** No styles if admin bar is disabled or user is not logged in or items are disabled via constant */ if ( ! is_admin_bar_showing() || ! is_user_logged_in() || ! BBPABA_DISPLAY ) return; /** * Add CSS styles to wp_head/admin_head * Check against WP 3.3+ only function "wp_editor" */ /** Add filter for main icon */ $bbpaba_main_icon = apply_filters( 'bbpaba_filter_main_icon', plugins_url( 'bbpress-admin-bar-addition/images/bbpress-icon2.png', dirname( __FILE__ ) ) ); /** Styles for WordPress 3.3 or higher */ if ( function_exists( 'wp_editor' ) ) { ?>