Skip to content

Commit

Permalink
Merge pull request #734 from INN/727-social-links-sticky-footer
Browse files Browse the repository at this point in the history
Set defaults for new options on update
  • Loading branch information
rnagle committed Jun 5, 2015
2 parents fbe7b72 + 90fc681 commit e9519e7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
25 changes: 25 additions & 0 deletions inc/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
function largo_perform_update() {
if (largo_need_updates()) {

// this must run before any other function that makes use of of_set_option()
largo_set_new_option_defaults();

// Run when updating from pre-0.4
if (version_compare(of_get_option('largo_version'), '0.4') < 0) {
largo_home_transition();
Expand Down Expand Up @@ -88,6 +91,7 @@ function largo_need_updates() {
/** --------------------------------------------------------
* Upgrades for moving from 0.3 -> 0.4
*
>>>>>>> develop
* In which many theme options became widgets
* And homepage templates are implemented
* ------------------------------------------------------ */
Expand Down Expand Up @@ -498,6 +502,27 @@ function largo_remove_topstory_prominence_term() {
* number bumps.
* ------------------------------------------------------ */

/**
* Save default values for any newly introduced options to the database.
*
* Note: this must be called before any other update function calls `of_set_option`,
* as `of_set_uption` defaults all values to null.
*
* @since 0.5.1
*/
function largo_set_new_option_defaults() {

// Gets the unique id, returning a default if it isn't defined
$config = get_option( 'optionsframework' );
if ( isset( $config['id'] ) ) {
$options = get_option( $config['id'] ); // a list of saved options
$defaults = of_get_default_values(); // the list of default values.
$options = wp_parse_args($options,$defaults); // merge 'em.
update_option($config['id'], $options);
}

}

/**
* Make sure custom CSS is regenerated if we're using custom LESS variables
*/
Expand Down
2 changes: 1 addition & 1 deletion inc/widgets/largo-facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function form( $instance ) {
*
* @since 0.5
*/
function is_rendered() {
static function is_rendered() {
return self::$rendered;
}
}
2 changes: 1 addition & 1 deletion inc/widgets/largo-follow.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function form( $instance ) {
*
* @since 0.5
*/
function is_rendered() {
static function is_rendered() {
return self::$rendered;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/widgets/largo-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function form( $instance ) {
*
* @since 0.5
*/
function is_rendered() {
static function is_rendered() {
return self::$rendered;
}

Expand Down
15 changes: 15 additions & 0 deletions options.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,27 @@ function optionsframework_options() {
'type' => 'multicheck',
'options' => $article_utility_buttons);

/**
* Whether social icons should be shown in the sticky footer.
*
* 1 - show social icons in sticky footer.
* 0 - do not show social icons in the sticky footer.
*
* @since 0.5
*/
$options[] = array(
'desc' => __('<strong>Would you like to display share icons in the footer of single posts?</strong> By default social icons appear in the sticky footer of single posts but you can choose to not show them at all.', 'largo'),
'id' => 'single_social_icons_footer',
'std' => '1',
'type' => 'checkbox',);

/**
* Which social icons should be shown in the sticky footer.
*
* defaults: $footer_utility_buttons_defaults - facebook, twitter and email.
*
* @since 0.5
*/
$options[] = array(
'desc' => __('Select the <strong>share icons</strong> to display in the single post sticky footer.', 'largo'),
'id' => 'footer_utilities',
Expand Down
6 changes: 6 additions & 0 deletions tests/inc/test-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ function test_largo_perform_update() {
unset($widgets_backup);
}

function largo_set_new_option_defaults() {

$this->markTestIncomplete('This function relies on the real options framework');

}

function test_largo_home_transition() {
// old topstories
of_reset_options();
Expand Down

0 comments on commit e9519e7

Please sign in to comment.