• Resolved tlongren

    (@tlongren)


    Not sure if this is the proper place for this, but I’ll give it a shot anyway.

    I’m adding some theme options to my HTML5Press theme.

    Options it has that work:
    1. Enable/Disable “back to top” floating button.
    2. Featured Image size
    3. Featured Posts Category

    Now, there’s an option that goes along with #3, it’s “# Featured Posts to Show”.

    No matter what, I can’t get that value to update in the database, it always stays at the default value. All the other options work fine.

    I’ve looked at the code numerous times for an hour or more at a time, and can’t figure out what the issue is.

    The theme options page can be found here:
    https://github.com/tlongren/html5press/blob/master/theme-options.php

    The problem resides in that file, that’s the only file that deals with theme options, functions.php just checks which options are set and grabs the values for those options.

    $html5press_num_featured_options is the array that stores the available choices for “# Featured Posts to Show”. That array gets looped through and produces the select form field for choosing how many posts to show.

    num_featured is the name of the option in the array of HTML5Press options that gets stored in the wordpress options table.

    Can anyone shed any light as to why this one option never updates?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter tlongren

    (@tlongren)

    Well, I’ve narrowed it down to the part of the validation function that validates the input from the “# Featured Posts to Show” option.

    Lines 178 to 181 here:
    https://gist.github.com/959698

    Any ideas why that validation fails but works above and below those lines?

    Not sure about this as I use a different array method, I may be off base.

    // Default options values
    $html5press_options = array(
             'back_to_top' => true,
    	'featured_image_size' => 'large',
    	'featured_cat' => '',
    	'num_featured' => '5'
    );

    If it is not returning the array key as ‘5’ then is not the array key ‘five’?

    'five' => array( 'value' => '5', 'label' => '5' ),

    I would use something like this to store the key value of ‘5’:

    $html5press_num_featured_options = array(
    	array( 'value' => '5', 'label' => 'Five' ),
    	array( 'value' => '10', 'label' => 'Ten' ),
    	array( 'value' => '15', 'label' => 'Fifteen' ),
    	array( 'value' => '20', 'label' => 'Twenty' )
    );

    HTH

    David

    Thread Starter tlongren

    (@tlongren)

    Hi David,

    Thanks for the tip! Same results though using your array method.

    When I unserialize the data stored in the database to see what it looks like, this is what I see:

    Array
    (
        [back_to_top] => 1
        [featured_image_size] => large
        [featured_cat] => 3
        [num_featured] => 5
    )

    Hi,
    This does Work and is tested!

    Default:

    // Default options values
    $html5press_options = array(
    	'back_to_top' => true,
    	'featured_image_size' => 'large',
    	'featured_cat' => '',
    	'num_featured' => '5'
    );

    Array:

    // Store number of featured posts to show options
    $html5press_num_featured_options = array(
    	'5' => array(
    		'value' => '5',
    		'label' => 'Five'
    	),
    	'10' => array(
    		'value' => '10',
    		'label' => 'Ten'
    	),
    	'15' => array(
    		'value' => '15',
    		'label' => 'Fifteen'
    	),
    	'20' => array(
    		'value' => '20',
    		'label' => 'Twenty'
    	)
    );

    Tested: ‘Twenty’ selected ’20’ stored in last array element in option serial

    a:4:{s:11:"back_to_top";i:1;s:19:"featured_image_size";s:5:"large";
    s:12:"featured_cat";s:1:"1";s:12:"num_featured";s:2:"20";}

    It was as expected the array ‘key’ was ‘five’ and not ‘5’, here is the changed array.
    var_dump( $html5press_num_featured_options);

    array
      5 =>
        array
          'value' => string '5' (length=1)
          'label' => string 'Five' (length=4)
      10 =>
        array
          'value' => string '10' (length=2)
          'label' => string 'Ten' (length=3)
      15 =>
        array
          'value' => string '15' (length=2)
          'label' => string 'Fifteen' (length=7)
      20 =>
        array
          'value' => string '20' (length=2)
          'label' => string 'Twenty' (length=6)

    HTH

    David

    Thread Starter tlongren

    (@tlongren)

    David, that worked like a charm. Thanks for digging into that a bit more.

    Meant to do it yesterday, but I was a little under the weather. My wife turned 21 earlier in the week, so you can imagine how that’s been.

    I haven’t drank this much in at least 5 years.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Theme options working, except for one’ is closed to new replies.