如何在子主题中创建函数.php?

时间:2013-04-30 作者:Charitos

我想创建一个函数。php文件,并在其中放入一些代码,但我不能这样做,因为每次我创建一个函数。php文件,并在其中放入代码时出错。

有人知道怎么做吗?

<? 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);
}

?>
另外,我使用此代码自动从提交的表单(QuForm插件)中获取数据,并创建一个草稿帖子。我已经在父主题中使用了它。

[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

2 个回复
SO网友:vancoder

您需要删除<?php 在文件的最开始处。

不正确:

<? php

add_action(\'iphorm_post_process_1\', \'mytheme_create_wp_post\', 10, 1);
function mytheme_create_wp_post($form)
{
正确:

<?php

add_action(\'iphorm_post_process_1\', \'mytheme_create_wp_post\', 10, 1);
function mytheme_create_wp_post($form)
{
这会导致一个简单的语法错误。

SO网友:s_ha_dum

除了@vancoder的答案之外,您在$post 大堆

$post = array(
    \'post_title\' => $title,
    \'post_content\' => $content, // <-- that comma is missing in your code
    \'post_status\' => \'draft\'
);
这导致了T_CONSTANT_ENCAPSED_STRING 脚本到达下一行时出错。

这个问题就是糟糕的PHP。你应该与debugging enabled 你会自己发现的。

结束

相关推荐

如何在Functions.php中使用PHP手动修复WordPress库代码?

Wordpress为内置的gallery功能输出了一些非常糟糕的代码,这已经被谈论了很多次了。这是负责库输出的核心代码(在/wp-includes/media.php中):function gallery_shortcode($attr) { global $post; static $instance = 0; $instance++; // Allow plugins/themes to override the de