Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to create a functions.php file in my child theme and put some code in it, but i can't do it because everytime i create a functions.php file and put a code in it an error occurs.

Does anybody know the way to do it?

<? php

add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{
$title = $form->getValue('iphorm_1_1');
$content = 'Content: ' . $form->getValueHtml('iphorm_1_30') . '<br />';
$content .= 'Link: ' . $form->getValueHtml('iphorm_1_11') . '<br />';
$content .= 'Creator: ' . $form->getValueHtml('iphorm_1_36') . '<br />';
$content .= 'Category: ' . $form->getValueHtml('iphorm_1_39') . '<br />';
$content .= 'Facebook: ' . $form->getValueHtml('iphorm_1_26') . '<br />';
$content .= 'Area: ' . $form->getValueHtml('iphorm_1_15') . '<br />';
$content .= 'Date: ' . $form->getValueHtml('iphorm_1_8') . '<br />';
$content .= 'Time: ' . $form->getValueHtml('iphorm_1_9') . '<br />';
$content .= 'Terms: ' . $form->getValueHtml('iphorm_1_32') . '<br />';
$content .= 'Info: ' . $form->getValueHtml('iphorm_1_35') . '<br />';

$post = array(
    'post_title' => $title,
    'post_content' => $content
    'post_status' => 'draft'
);

wp_insert_post($post);
}

?>

P.S. I use this code to automatically take the data from a submitted form (QuForm Plugin) and create a draft post. I already work it in the parent theme.

[Wed May 01 00:26:01 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 20, referer: http://www.e-win.gr/
[Wed May 01 00:26:06 2013] [warn] [client 216.52.242.14] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 20
[Wed May 01 00:26:06 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 20, referer: http://www.e-win.gr/
[Wed May 01 00:26:23 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 21, referer: http://www.e-win.gr/wp-admin/admin.php?page=options.php
[Wed May 01 00:29:12 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 21, referer: http://www.e-win.gr/wp-admin/admin.php?page=options.php
[Wed May 01 00:29:41 2013] [warn] [client 157.56.93.230] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 21
[Wed May 01 00:29:46 2013] [warn] [client 173.199.114.187] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 21
[Wed May 01 00:30:08 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 21, referer: http://www.e-win.gr/wp-admin/admin.php?page=options.php
[Wed May 01 00:37:57 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected $end in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 31, referer: http://www.e-win.gr/wp-admin/admin.php?page=options.php
[Wed May 01 00:42:05 2013] [warn] [client 188.4.45.92] mod_fcgid: stderr: PHP Parse error:  syntax error, unexpected $end in /var/www/vhosts/e-win.gr/httpdocs/wp-content/themes/e-win/functions.php on line 31, referer: http://www.e-win.gr/wp-admin/options-general.php?page=wp-viewer-log
share|improve this question

closed as too localized by toscho Apr 30 '13 at 22:57

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Add the code of your functions.php to your question please. –  toscho Apr 30 '13 at 21:15
    
You are doing it the right way. The error is being caused by the code inside your functions.php. If you show it here we may be able to tell you why. –  vancoder Apr 30 '13 at 21:18
1  
The file must start with <?php – no white space inside. –  toscho Apr 30 '13 at 21:24
    
@vancoder you mean the parent theme's functions.php or the child's? –  Charitos Apr 30 '13 at 21:25
1  
no idea if this is still relevant: the posted code in this line 'post_content' => $content is missing a comma. –  Michael Apr 30 '13 at 22:09

2 Answers 2

In addition to @vancoder's answer, you are also missing a comma in the $post array.

$post = array(
    'post_title' => $title,
    'post_content' => $content, // <-- that comma is missing in your code
    'post_status' => 'draft'
);

That causes the T_CONSTANT_ENCAPSED_STRING error when the script hits the following line.

This problem is just bad PHP. You should develop with debugging enabled and you would spot this yourself.

share|improve this answer
    
Ok you are right! –  Charitos Apr 30 '13 at 22:15

You need to remove the space between <? and php at the very start of your file.

Incorrect:

<? php

add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{

Correct:

<?php

add_action('iphorm_post_process_1', 'mytheme_create_wp_post', 10, 1);
function mytheme_create_wp_post($form)
{

This is causing a simple syntax error.

share|improve this answer
    
I did it but again it gives me an error: HTTP 500 (Internal Server Error)! –  Charitos Apr 30 '13 at 21:28
    
All you did was remove the space, and now you get the Internal Server Error, is that correct? Nothing else changed? –  vancoder Apr 30 '13 at 21:39
    
Yes! I editted as you told me above and it gives me the same error. –  Charitos Apr 30 '13 at 21:41
    
This was the error you had all along? Then, this is a different problem. –  vancoder Apr 30 '13 at 21:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.