Advertisement
bowenac

Untitled

Jun 3rd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1.         add_settings_field(
  2.             'category_options_select',
  3.             'Category',
  4.             array( $this, 'category_options_select_callback' ),
  5.             'my-setting-admin',
  6.             'api_options',
  7.             array (
  8.                 'label_for'   => 'Categories', // makes the field name clickable,
  9.                 'name'        => 'category', // value for 'name' attribute
  10.                 'options'     => array (
  11.                     '1' => '1',
  12.                     '2' => '2',
  13.                     '3' => '3',
  14.                 ),
  15.                 'option_name' => 'test'
  16.             )
  17.         );
  18.  
  19. function category_options_select_callback( $args )
  20. {
  21.     printf(
  22.         '<select name="%1$s[%2$s]" id="%3$s">',
  23.         $args['option_name'],
  24.         $args['name'],
  25.         $args['label_for']
  26.     );
  27.  
  28.     foreach ( $args['options'] as $val => $title )
  29.         printf(
  30.             '<option value="%1$s" %2$s>%3$s</option>',
  31.             $val,
  32.             selected( $val, $this->options['categories'], FALSE ),
  33.             $title
  34.         );
  35.  
  36.     print '</select>';
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement