Skip to content

Commit

Permalink
updated to work with the new rbhn re-factored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Fletcher committed Jul 1, 2014
1 parent 79eae6a commit 878bdff
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 352 deletions.
4 changes: 2 additions & 2 deletions includes/class-rbhn-capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
* Tabbed_Settings class.
* RBHN_Capabilities class.
*/
class RBHN_Capabilities {

Expand Down Expand Up @@ -256,4 +256,4 @@ public function rbhn_map_meta_cap( $caps, $cap, $user_id, $args ) {

new RBHN_Capabilities();

?>
?>
127 changes: 81 additions & 46 deletions includes/class-tabbed-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public function __call($method, $arguments) {
*/
class Tabbed_Settings extends Extendible_Tabbed_Settings {

public static $instance;
public $settings = array();
// public static $instance;
public static $settings = array();
// public static $config = array();


// the following are configurable externally
public $menu = '';
Expand All @@ -49,7 +51,7 @@ class Tabbed_Settings extends Extendible_Tabbed_Settings {
*/
function __construct() {

self::$instance = $this;
// self::$instance = $this;

// hook priority = 9 to load settings before the class-tgm-plugin-activation.php runs with the same init hook at priority level 10
add_action( 'init', array( $this, 'init' ), 9 );
Expand All @@ -68,7 +70,7 @@ function __construct() {
*/
public function init() {

do_action( 'ticktock_settings_register' );
do_action( 'tabbed_settings_register' );
// After this point, the settings should be registered and the configuration set.

}
Expand All @@ -80,6 +82,7 @@ public function init() {
* @return void
*/
public function add_admin_menus() {

add_options_page( __( 'Notes', 'role-based-help-notes-text-domain' ), __( 'Help Notes', 'role-based-help-notes-text-domain' ), 'manage_options', $this->menu, array( &$this, 'plugin_options_page' ) );
}

Expand All @@ -96,15 +99,18 @@ public function add_admin_menus() {
public function register_tabbed_settings( $settings ) {

foreach ( $settings as $tab_name => $registered_setting_page ) {
$this->settings[$tab_name] = $registered_setting_page;
// $this->settings[$tab_name] = $registered_setting_page;
self::$settings[$tab_name] = $registered_setting_page;
}
}

/**
* Amend default configuration.
* Amend default configuration. This function strips out the config array elements and stores them
* as a variable within the current Class object $this->"config-element" will be the means to return the
* current configuration stored.
*
* @param array $config Array of config options to pass as class properties.
* @return - sets up the CLASS object values $this->config-setting.
* @return - sets up the CLASS object values $this->config.
*/
public function register_config( $config ) {

Expand All @@ -117,7 +123,7 @@ public function register_config( $config ) {
if ( isset( $config[$key] ) ) {
if ( is_array( $config[$key] ) ) {
foreach ( $config[$key] as $subkey => $value ) {
$this->{$key}[$subkey] = $value;
$this->{$key}[$subkey] = $value;
}
} else {
$this->$key = $config[$key];
Expand All @@ -134,7 +140,7 @@ public function register_config( $config ) {
*/
public function render_setting_page(){

foreach ( $this->settings as $options_group => $section ) {
foreach ( self::$settings as $options_group => $section ) {

foreach ( $section['settings'] as $option ) {
$this->current_section = $section;
Expand Down Expand Up @@ -163,9 +169,11 @@ public function plugin_options_page() {
global $role_based_help_notes;
$tab = isset( $_GET['tab'] ) ? sanitize_key($_GET['tab'] ) : $this->default_tab_key;
if ( ! empty( $_GET['settings-updated'] )) {
flush_rewrite_rules();
do_action( 'tabbed_settings_after_update' );
////////// >>>>>> to do next 2 lines >>>>>> using the above hook
$role_based_help_notes->help_do_on_activation(); // add the active capabilities
RBHN_Capabilities::rbhn_clean_inactive_capabilties(); // remove the inactive role capabilities
flush_rewrite_rules();
}
?>
<div class="wrap">
Expand All @@ -189,9 +197,9 @@ public function plugin_options_page() {
* @return void
*/
public function hooks_section_callback( $section_passed ){
foreach ( $this->settings as $options_group => $section ) {
if (( $section_passed['id'] == $options_group) && ( ! empty( $section['description'] ))) {
echo esc_html( $this->settings[$options_group]['description'] );
foreach ( self::$settings as $options_group => $section ) {
if (( $section_passed['id'] == $options_group) && ( ! empty( $section['description'] ))) {
echo esc_html( self::$settings[$options_group]['description'] );
}
}
}
Expand Down Expand Up @@ -337,59 +345,86 @@ public function field_default_option( array $args ) {
* @return void
*/
public function plugin_options_tabs() {

$current_tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : $this->default_tab_key;

screen_icon();
echo '<h2 class="nav-tab-wrapper">';
foreach ( $this->tabbed_settings as $tab_key => $tab_caption ) {
foreach ( self::$settings as $tab_key => $tab_options_array ) {
$active = $current_tab == $tab_key ? 'nav-tab-active' : '';
echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->menu . '&tab=' . $tab_key . '">' . $tab_caption . '</a>';
echo '<a class="nav-tab ' . $active . '" href="?page=' . $this->menu . '&tab=' . $tab_key . '">' . $tab_options_array['title'] . '</a>';
}
echo '</h2>';
}




/**
* selected_plugins function.
*
* @access public
* @return array of plugins selected within the settings page for installation via the TGM_Plugin_Activation class
*/
public STATIC function selected_plugins() {

$plugins = array();

if ( Tabbed_Settings::$settings ) {


/**
* Returns the singleton instance of the class.
* @return object The Tabbed_Settings object.
*/
public static function get_instance() {
$plugin_array = Tabbed_Settings::$settings['plugin_extension']['settings'];

if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Tabbed_Settings ) ) {
self::$instance = new Tabbed_Settings();
}

return self::$instance;
foreach ( $plugin_array as $plugin ) {

}
if ( get_option( $plugin['name'] ) ) {
// change the array element key name from 'label' to 'name' for use by TGM Activation
$plugin['option-name'] = $plugin['name'];
$plugin['name'] = $plugin['label'];
unset($plugin['label']);
$plugins[] = $plugin;
}
}
}

return $plugins;
}



/**
* Returns the *Singleton* instance of this class.
*
* @return Singleton The *Tabbed_Settings* instance.
*/
public static function get_instance()
{
static $instance = null;
if (null === $instance) {
$instance = new static();
}

return $instance;
}

}

// Ensure only one instance of the class is ever invoked.
$ticktock_settings = Tabbed_Settings::get_instance();
Tabbed_Settings::get_instance();
}


if ( ! function_exists( 'ticktock_settings' ) ) {
/**
* Helper function to register a collection of required plugins.
*
* @since 2.0.0
* @api
*
* @param array $settings An array of tab page settings arrays.
* @param array $config Optional. An array of configuration values.
*/
function ticktock_settings( $settings, $config = array() ) {

if ( $settings ) {
Tabbed_Settings::$instance->register_tabbed_settings( $settings );
}
if ( ! class_exists( 'Tabbed_Settings_Child' ) ) {

if ( $config ) {
Tabbed_Settings::$instance->register_config( $config );
}
}
/**
* Tabbed_Settings class.
*/
class Tabbed_Settings_Child extends Tabbed_Settings {

}
}




?>
14 changes: 6 additions & 8 deletions includes/plugin-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@ function rbhn_bp_enable_root_profiles($val, $user_id ) {
if ( !function_exists('help_notes_available') ) {
function help_notes_available() {

global $role_based_help_notes;

// check if no help notes are selected.
$help_note_post_types = get_option('rbhn_post_types');

if ( ! array_filter( (array) $help_note_post_types ) && ! get_option('rbhn_general_enabled') )
return false;


global $role_based_help_notes;
// option collection
$post_types_array = get_option('rbhn_post_types');


//if the current user has the role of an active Help Note.
if ( array_filter( (array) $post_types_array )) {
foreach( $post_types_array as $array) {
if ( array_filter( (array) $help_note_post_types )) {
foreach( $help_note_post_types as $array) {
foreach( $array as $active_role=>$active_posttype) {
if ($role_based_help_notes->help_notes_current_user_has_role( $active_role )) {
return true;
Expand Down
95 changes: 34 additions & 61 deletions includes/plugin-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,47 @@

add_action( 'tgmpa_register', 'rbhn_tgmpa_register' );

function rbhn_tgmpa_register() {

$plugins = selected_plugins();

$theme_text_domain = 'role-based-help-notes-text-domain';

$config = array(
'default_path' => '', // Default absolute path to pre-packaged plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'tgmpa' ),
'menu_title' => __( 'Install Plugins', 'tgmpa' ),
'installing' => __( 'Installing Plugin: %s', 'tgmpa' ), // %s = plugin name.
'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'tgmpa' ), // %1$s = plugin name(s).
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'tgmpa' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'tgmpa' ),
'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ),
'complete' => __( 'All plugins installed and activated successfully. %s', 'tgmpa' ), // %s = dashboard link.
'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
)
);

tgmpa( $plugins, $config );

}

function rbhn_tgmpa_register( ) {

/**
* selected_plugins function.
*
* @access public
* @return array of plugins selected within the settings page for installation via the TGM_Plugin_Activation class
*/
function selected_plugins() {
$plugins = Tabbed_Settings::selected_plugins();

$plugins = array();
$theme_text_domain = 'role-based-help-notes-text-domain';

if ( Tabbed_Settings::$instance->settings ) {
$config = array(
'default_path' => '', // Default absolute path to pre-packaged plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '', // Message to output right before the plugins table.
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'tgmpa' ),
'menu_title' => __( 'Install Plugins', 'tgmpa' ),
'installing' => __( 'Installing Plugin: %s', 'tgmpa' ), // %s = plugin name.
'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'tgmpa' ), // %1$s = plugin name(s).
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'tgmpa' ), // %1$s = plugin name(s).
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'tgmpa' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'tgmpa' ),
'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ),
'complete' => __( 'All plugins installed and activated successfully. %s', 'tgmpa' ), // %s = dashboard link.
'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
)
);

$plugin_array = Tabbed_Settings::$instance->settings['rbhn_plugin_extension']['settings'];

foreach ( $plugin_array as $plugin ) {
tgmpa( $plugins, $config );

if ( get_option( $plugin['name'] ) ) {
// change the array element key name from 'label' to 'name' for use by TGM Activation
$plugin['option-name'] = $plugin['name'];
$plugin['name'] = $plugin['label'];
unset($plugin['label']);
$plugins[] = $plugin;
}
}
}

return $plugins;
}


?>
Loading

0 comments on commit 878bdff

Please sign in to comment.