开发者

PHP variable doesn't work inside a conditional statement within function.php (Wordpress)?

Basically, if there's an uploaded image for the site title (logo) it will be displayed as the #header h1 a's background (this part works perfectly) and set its text to indent -9999px; (this doesn't work).

I did $text_indent = '-9999px' inside the if statement which says: "//If it is an image"

Why is $text_indent not being displayed in the final input?

header.php

#header h1 a {
        background: url(<?php echo $options['logo']; ?>) no-repeat scr开发者_Python百科oll 0 0;
        text-indent: <?php echo $text_indent; ?>
    }

function.php:

// Logo
function logo_setting() {
   echo '<input type="file" name="logo" />';
}

function validate_setting($plugin_options) {
   $keys = array_keys($_FILES);
   $i = 0;

   foreach ($_FILES as $image) {

      // if a files was upload
      if ($image['size']) {
         // if it is an image
         if (preg_match('/(jpg|jpeg|png|gif)$/', $image['type'])) {
            $override = array('test_form' => false);
            $file = wp_handle_upload($image, $override);

            $plugin_options[$keys[$i]] = $file['url'];

            // Hide site title's text
            $text_indent = '-9999px';

         } else {
            $options = get_option('plugin_options');
            $plugin_options[$keys[$i]] = $options[$logo];
            wp_die('No image was uploaded.');
         }
      }

      // else, retain the image that's already on file.
      else {
         $options = get_option('plugin_options');
         $plugin_options[$keys[$i]] = $options[$keys[$i]];
      }
      $i++;
   }

   return $plugin_options;
}

function section_cb() {}

// Add stylesheet


You are using this variable inside the function in function.php. But this variable will not accessible outside the function.

So you have to declare it as a global variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜