0

Coming from a Javascript background and humbly jumping into WP dev I'm having some trouble with PHP (especially in a WordPress context).

Here's what I'm trying to do:
Create controls for the customizer from an array; specifically, social icon url inputs for a plethora of social sites.

Here's what I've tried (and isn't working):

$socialIcons = array (

  array( 'name' => 'behance', 'label' => 'Behance URL' ),
  array( 'name' => 'bitbucket', 'label' => 'BitBucket URL' ),
  array( 'name' => 'digg', 'label' => 'Digg URL' ),
  array( 'name' => 'dribble', 'label' => 'Dribble URL' ),
  array( 'name' => 'facebook', 'label' => 'Facebook URL' ),
  array( 'name' => 'flickr', 'label' => 'Flickr URL' ),
  array( 'name' => 'forest', 'label' => 'Forest URL' ),
  array( 'name' => 'github', 'label' => 'GitHub URL' ),
  array( 'name' => 'gplus', 'label' => 'Google Plus URL' ),
  array( 'name' => 'instagram', 'label' => 'Instagram URL' ),
  array( 'name' => 'lastfm', 'label' => 'Lastfm URL' ),
  array( 'name' => 'linkedin', 'label' => 'LinkedIn URL' ),
  array( 'name' => 'pintrest', 'label' => 'Pintrest URL' ),
  array( 'name' => 'reddit', 'label' => 'Reddit URL' ),
  array( 'name' => 'soundcloud', 'label' => 'SoundCloud URL' ),
  array( 'name' => 'stackexchange', 'label' => 'StackExchange URL' ),
  array( 'name' => 'stackoverflow', 'label' => 'StackOverflow URL' ),
  array( 'name' => 'twitter', 'label' => 'Twitter URL' ),
  array( 'name' => 'vimeo', 'label' => 'Vimeo URL' ),
  array( 'name' => 'vk', 'label' => 'VK URL' ),
  array( 'name' => 'youtube', 'label' => 'YouTube URL' ),

);

$i = 0;
foreach ($socialIcons as $icon) {
  $i = $i++
  $wp_customize->add_setting(
    'pxk_href_' . $icon['name'], // use this in twig file call to theme_mod
    array(
      'default'         => '',
      'transport'       => 'postMessage',
      'priority'        => $i
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Control(
      $wp_customize,
    'custom_href_' . $icon['name'],
      array(
        'label'          => __( $icon['label'], 'pxk' ),
        'section'        => 'social',
        'settings'       => 'pxk_href_' . $icon['name'],
        'type'           => 'url',
        'input_attrs'    => array(
          'placeholder' => 'http://your ' . $icon['name']
        ),
      )
    )
  );
};

This throws a PHP syntax parsing error, stating unexpected '$wp_customize' (T_VARIABLE)...

I suspect I need to organize this into a function or two, return or echo the $wp_ arrow functions, and perhaps call it differently in order to successfully create a setting and control for each item of the array. Ideas?

Any feedback/help is much appreciated :)

1 Answer 1

0

Please add ";" after $i = $i++ and see if that fixes your issue

foreach ($socialIcons as $icon) {
  $i = $i++;
  $wp_customize->add_setting(
    'pxk_href_' . $icon['name'], // use this in twig file call to theme_mod
    array(
      'default'         => '',
      'transport'       => 'postMessage',
      'priority'        => $i
    )
  );
2
  • Ha! Can't believe I missed that one. If only PHP were more forgiving with semi-colons. That did the trick. Many thanks! Commented May 12, 2015 at 15:53
  • Glad it helped :) Commented May 12, 2015 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.