【发布时间】:2019-06-29 02:37:03
【问题描述】:
我是 WordPress 插件开发的新手,我在这件事上遇到了障碍。问题是使用过滤器add_filter('robots_txt', 'AddToRobotsTxt', 10, 2); 不会在我的本地主机中创建 robots.txt 文件,我不知道是什么问题。我已将目录权限设置为
<Directory />
AllowOverride All
Require all granted
</Directory>
由于我认为这可能是导致问题的原因,因此我附上了我的其余代码。
public function allRobotSettings(){
register_setting('energizer_robot_group', 'energizer_robots-name');
add_settings_section('energizer_robot_index', 'Robot Setting', array( $this->callbacks_mngr, 'robotSectionManager' )
, 'energizer_robots');
add_settings_field('robot_field_manager', 'Robot Document', array( $this->callbacks_mngr, 'robotInputboxField' ),
'energizer_robots', 'energizer_robot_index');
}
此功能用于html页面的设置。 它会调用这些函数。
public function robotSectionManager()
{
echo 'Edit your robot.txt file here.';
}
public function robotInputboxField()
{
$data=get_option('energizer_robots-name');
add_filter( 'robots_txt', 'AddToRobotsTxt',10,2);
$content=get_option('energizer_robots-name');
echo '<div ><input type="text" name="energizer_robots-name" value="'. $content.'"
style="height: 150px;
width: 100%;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8; ></div>';
}
public function AddToRobotsTxt($robotstext, $public) {
$robotsrules = get_option('energizer_robots-name');
$new_value=$robotstext . $robotsrules;
update_option( 'energizer_robots-name', $new_value);
return $robotstext . $robotsrules;
}
任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress apache phpmyadmin