Skip to content
This repository has been archived by the owner on Oct 31, 2022. It is now read-only.

Commit

Permalink
Huge refactor to remove options framework
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcobb committed Jun 23, 2015
1 parent 71aff95 commit 5be69a0
Show file tree
Hide file tree
Showing 458 changed files with 1,196 additions and 60,802 deletions.
138 changes: 64 additions & 74 deletions admin/class-ccb-core-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,65 @@ public function __construct() {
}

/**
* Initialize the ReduxFramework
* Initialize the Settings Menu and Page
*
* @since 0.9.0
* @access public
* @since 0.9.0
* @return void
*/
public function initialize_redux() {
public function initialize_settings_menu() {

$redux_options = new CCB_Core_Redux_Config();
$redux_options->initialize();
$settings = new CCB_Core_Settings();
$settings_definitions = $settings->get_settings_definitions();
$settings_page = new CCB_Core_Settings_Page( $this->plugin_settings_name );

add_menu_page( $this->plugin_display_name, $this->plugin_short_display_name, 'manage_options', $this->plugin_settings_name, function(){}, 'dashicons-update', '80.9' );

if ( is_array( $settings_definitions ) && ! empty( $settings_definitions ) ) {
foreach ( $settings_definitions as $page_id => $page ) {
$settings_page = new CCB_Core_Settings_Page( $page_id, $page );
add_submenu_page( $this->plugin_settings_name, $page['page_title'], $page['page_title'], 'manage_options', $page_id, array( $settings_page, 'render_page' ) );
}
}
}

/**
* Removes the built in Redux menu so as not to confuse users
* Initialize the Settings
*
* @since 0.9.0
* @access public
* @since 0.9.0
* @return void
*/
public function remove_redux_menu() {
public function initialize_settings() {

$settings = new CCB_Core_Settings();
$settings_definitions = $settings->get_settings_definitions();

if ( is_array( $settings_definitions ) && ! empty( $settings_definitions ) ) {
foreach ( $settings_definitions as $page_id => $page ) {

remove_submenu_page('tools.php','redux-about');
register_setting( $page_id, $this->plugin_settings_name, array( $settings, 'validate_settings' ) );

if ( isset( $page['sections'] ) && ! empty( $page['sections'] ) ) {
foreach ( $page['sections'] as $section_id => $section ) {

$settings_section = new CCB_Core_Settings_Section( $section_id, $section );
add_settings_section( $section_id, $section['section_title'], array( $settings_section, 'render_section' ), $page_id );

if ( isset( $section['fields'] ) && ! empty( $section['fields'] ) ) {
foreach ( $section['fields'] as $field_id => $field ) {

$settings_field = new CCB_Core_Settings_Field( $field_id, $field );
add_settings_field( $field_id, $field['field_title'], array( $settings_field, 'render_field' ), $page_id, $section_id );

}
}

}
}

}
}

}

Expand Down Expand Up @@ -146,20 +186,6 @@ public function ajax_test_credentials() {

}

/**
* Decrypts the password and sets its plain text value
* into the field before the form is rendered
*
* @param object $redux_object
* @access public
* @since 0.9.0
* @return void
*/
public function redux_before_form_render( $redux_object ) {
$redux_object->parent->options['password']['password'] = $this->decrypt( $redux_object->parent->options['password']['password'] );
$this->refresh_test_login_wrapper( $redux_object->parent->options );
}

/**
* Create a helpful settings link on the plugin page
*
Expand All @@ -169,7 +195,7 @@ public function redux_before_form_render( $redux_object ) {
* @return array
*/
public function add_settings_link( $links ) {
$links[] = '<a href="' . esc_url( get_admin_url( null, 'options-general.php?page=' . $this->plugin_name ) ) . '">Settings</a>';
$links[] = '<a href="' . esc_url( get_admin_url( null, 'admin.php?page=' . $this->plugin_settings_name ) ) . '">Settings</a>';
return $links;
}

Expand All @@ -183,14 +209,13 @@ public function add_settings_link( $links ) {
*/
public function check_auto_refresh() {

global ${$this->plugin_options_name};
$options = ${$this->plugin_options_name};
$settings = get_option( $this->plugin_settings_name );

if ( $options['auto-sync'] == 1 ) {
if ( isset( $settings['auto-sync'] ) && $settings['auto-sync'] == 1 ) {
$latest_sync = get_option( $this->plugin_name . '-latest-sync' );

if ( ! empty( $latest_sync ) ) {
$auto_sync_timeout = $options['auto-sync-timeout'];
$auto_sync_timeout = $settings['auto-sync-timeout'];
$now = time();
$diff = $now - $latest_sync['timestamp'];

Expand Down Expand Up @@ -224,8 +249,12 @@ public function auto_sync() {
*/
public function enqueue_styles( $hook ) {

if ( $hook == "settings_page_{$this->plugin_name}" ) {
if ( stristr( $hook, $this->plugin_settings_name ) !== false ) {
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/ccb-core-admin.css', array(), $this->version, 'all' );
wp_enqueue_style( 'switchery', plugin_dir_url( __FILE__ ) . 'css/vendor/switchery.min.css', array(), $this->version, 'all' );
wp_enqueue_style( 'powerange', plugin_dir_url( __FILE__ ) . 'css/vendor/powerange.min.css', array(), $this->version, 'all' );
wp_enqueue_style( 'picker', plugin_dir_url( __FILE__ ) . 'css/vendor/default.css', array(), $this->version, 'all' );
wp_enqueue_style( 'picker-date', plugin_dir_url( __FILE__ ) . 'css/vendor/default.date.css', array(), $this->version, 'all' );
}

}
Expand All @@ -237,56 +266,17 @@ public function enqueue_styles( $hook ) {
*/
public function enqueue_scripts( $hook ) {

if ( $hook == "settings_page_{$this->plugin_name}" ) {
if ( stristr( $hook, $this->plugin_settings_name ) !== false ) {
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ccb-core-admin.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name, strtoupper( $this->plugin_options_name ), array(
wp_enqueue_script( 'switchery', plugin_dir_url( __FILE__ ) . 'js/vendor/switchery.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( 'powerange', plugin_dir_url( __FILE__ ) . 'js/vendor/powerange.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( 'picker', plugin_dir_url( __FILE__ ) . 'js/vendor/picker.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( 'picker-date', plugin_dir_url( __FILE__ ) . 'js/vendor/picker.date.js', array( 'picker' ), $this->version, false );
wp_localize_script( $this->plugin_name, strtoupper( $this->plugin_settings_name ), array(
'nextNonce' => wp_create_nonce( $this->plugin_name . '-nonce' ))
);
}

}

/**
* Handles actions we wish to run after the form is saved
*
* @param array $value
* @access public
* @since 0.9.0
* @return void
*/
public function redux_after_form_save( $value ) {
$this->refresh_test_login_wrapper( $value );
}

/**
* Checks if the credentials are at least entered
* and shows/hides the test button after save
*
* @param array $value
* @access protected
* @since 0.9.0
* @return void
*/
protected function refresh_test_login_wrapper( $value ) {

if ( empty( $value['subdomain'] ) || empty( $value['password']['password'] ) || empty( $value['password']['username'] ) ) {
echo <<<HTML
<style>
.ccb-core-test-login {
display: none;
}
</style>
HTML;
}
else {
echo <<<HTML
<style>
.ccb-core-test-login {
display: table-row;
}
</style>
HTML;
}
}

}
31 changes: 15 additions & 16 deletions admin/class-ccb-core-cpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,31 @@ public function __construct() {
*/
public function initialize() {

global ${$this->plugin_options_name};
$options = ${$this->plugin_options_name};
$settings = get_option( $this->plugin_settings_name );

if ( isset( $options['groups-enabled'] ) && $options['groups-enabled'] == 1 ) {
if ( isset( $settings['groups-enabled'] ) && $settings['groups-enabled'] == 1 ) {

$this->groups_cpt_options['name'] = ( empty( $options['groups-name'] ) ? 'Groups' : $options['groups-name'] );
$this->groups_cpt_options['slug'] = ( empty( $options['groups-slug'] ) ? 'groups' : $options['groups-slug'] );
$this->groups_cpt_options['name'] = ( empty( $settings['groups-name'] ) ? 'Groups' : $settings['groups-name'] );
$this->groups_cpt_options['slug'] = ( empty( $settings['groups-slug'] ) ? 'groups' : $settings['groups-slug'] );
$this->groups_cpt_options['singular_name'] = rtrim( $this->groups_cpt_options['name'], 's' ); // this is ghetto
$this->groups_cpt_options['exclude_from_search'] = ( $options['groups-exclude-from-search'] == '1' ? true : false );
$this->groups_cpt_options['publicly_queryable'] = ( $options['groups-publicly-queryable'] == '1' ? true : false );
$this->groups_cpt_options['show_ui'] = ( $options['groups-show-ui'] == '1' ? true : false );
$this->groups_cpt_options['show_in_nav_menus'] = ( $options['groups-show-in-nav-menus'] == '1' ? true : false );
$this->groups_cpt_options['exclude_from_search'] = ( $settings['groups-exclude-from-search'] == 'yes' ? true : false );
$this->groups_cpt_options['publicly_queryable'] = ( $settings['groups-publicly-queryable'] == 'yes' ? true : false );
$this->groups_cpt_options['show_ui'] = ( $settings['groups-show-ui'] == 'yes' ? true : false );
$this->groups_cpt_options['show_in_nav_menus'] = ( $settings['groups-show-in-nav-menus'] == 'yes' ? true : false );

$this->register_groups();

}

if ( isset( $options['calendar-enabled'] ) && $options['calendar-enabled'] == 1 ) {
if ( isset( $settings['calendar-enabled'] ) && $settings['calendar-enabled'] == 1 ) {

$this->calendar_cpt_options['name'] = ( empty( $options['calendar-name'] ) ? 'calendar' : $options['calendar-name'] );
$this->calendar_cpt_options['slug'] = ( empty( $options['calendar-slug'] ) ? 'calendar' : $options['calendar-slug'] );
$this->calendar_cpt_options['name'] = ( empty( $settings['calendar-name'] ) ? 'Events' : $settings['calendar-name'] );
$this->calendar_cpt_options['slug'] = ( empty( $settings['calendar-slug'] ) ? 'events' : $settings['calendar-slug'] );
$this->calendar_cpt_options['singular_name'] = rtrim( $this->calendar_cpt_options['name'], 's' ); // this is ghetto
$this->calendar_cpt_options['exclude_from_search'] = ( $options['calendar-exclude-from-search'] == '1' ? true : false );
$this->calendar_cpt_options['publicly_queryable'] = ( $options['calendar-publicly-queryable'] == '1' ? true : false );
$this->calendar_cpt_options['show_ui'] = ( $options['calendar-show-ui'] == '1' ? true : false );
$this->calendar_cpt_options['show_in_nav_menus'] = ( $options['calendar-show-in-nav-menus'] == '1' ? true : false );
$this->calendar_cpt_options['exclude_from_search'] = ( $settings['calendar-exclude-from-search'] == 'yes' ? true : false );
$this->calendar_cpt_options['publicly_queryable'] = ( $settings['calendar-publicly-queryable'] == 'yes' ? true : false );
$this->calendar_cpt_options['show_ui'] = ( $settings['calendar-show-ui'] == 'yes' ? true : false );
$this->calendar_cpt_options['show_in_nav_menus'] = ( $settings['calendar-show-in-nav-menus'] == 'yes' ? true : false );

$this->register_calendar();

Expand Down
Loading

0 comments on commit 5be69a0

Please sign in to comment.