PHP变量在function.php(Wordpress)中的条件语句中不起作用?

时间:2010-12-23 10:39:13

标签: wordpress variables conditional-statements

基本上,如果有上传的网站标题图片(徽标),它将显示为#header h1 a的背景(此部分完美运行)并将其文本设置为缩进-9999px ; (这不起作用)。

我在if语句中写了$text_indent = '-9999px',其中说:“//If it is an image

为什么$text_indent没有显示在最终输入中?

的header.php

#header h1 a {
        background: url(<?php echo $options['logo']; ?>) no-repeat scroll 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

1 个答案:

答案 0 :(得分:1)

您在function function.php.内使用此变量但该函数外部无法访问此变量。

所以你必须将它声明为global变量。