0

functions.php を編集すると、なぜかいろいろなページが白くなってしまいます。たとえば、次のコードを使用します。

    <?php
    /* Add a custom field to the field editor (See editor screenshot) */
    add_action("gform_field_standard_settings", "my_standard_settings", 10, 2);
    function my_standard_settings($position, $form_id){
        // Create settings on position 25 (right after Field Label)
        if($position == 25){
?>
            <li class="admin_label_setting field_setting" style="display: list-item; ">
                <label for="field_placeholder">Placeholder Text
                    <!-- Tooltip to help users understand what this field does -->
                    <a href="javascript:void(0);" class="tooltip tooltip_form_field_placeholder" tooltip="&lt;h6&gt;Placeholder&lt;/h6&gt;Enter the placeholder/default text for this field.">(?)</a>
                </label>
                <input type="text" id="field_placeholder" class="fieldwidth-3" size="35" onkeyup="SetFieldProperty('placeholder', this.value);">
            </li>
<?php
        }
    }
    /* Now we execute some javascript technicalitites for the field to load correctly */
    add_action("gform_editor_js", "my_gform_editor_js");
    function my_gform_editor_js(){
?>
        <script>
            //binding to the load field settings event to initialize the checkbox
            $(document).bind("gform_load_field_settings", function(event, field, form){
                $("#field_placeholder").val(field["placeholder"]);
            });
        </script>

<?php
    }
    /* We use jQuery to read the placeholder value and inject it to its field */
    add_action('gform_enqueue_scripts',"my_gform_enqueue_scripts", 10, 2);
    function my_gform_enqueue_scripts($form, $is_ajax=false){
?>
        <script>
            jQuery(function(){
                <?php
                    /* Go through each one of the form fields */
                    foreach($form['fields'] as $i=>$field){
                        /* Check if the field has an assigned placeholder */
                        if(isset($field['placeholder']) && !empty($field['placeholder'])){
                            /* If a placeholder text exists, inject it as a new property to the field using jQuery */
                ?>
                jQuery('#input_<?php echo $form['id']?>_<?php echo $field['id']?>').attr('placeholder','<?php echo $field['placeholder']?>');
                <?php
                        }
                    }
                ?>
            });
        </script>
<?php
    }
?>

ページを更新すると、空白の白いページ (url: /wp-admin/post.php) が表示されます。このチュートリアルから、私が使用しようとしていた別のコード:

http://www.doitwithwp.com/pre-populate-fields-using-gravity-forms/

ログインページに空白の白いページが表示されます。WordPressの最新バージョンを実行しています。なぜこれが起こるのでしょうか?

4

1 に答える 1

2

PHP の開始タグの前にある空白を削除してみてください。時々これは大きな問題を引き起こします。通常、このファイルには後で使用する関数のみが含まれ、コンテンツは提供されないため、何もエコーしないことを確認してください。

于 2012-12-06T15:53:21.230 に答える