私はOOPが初めてで、クラスを持っています。このクラス内で実行しようとしています
foreach($categories as $category) {
public function beam_channels_setting.$category->name()
{
echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";
}
}
ただし、このエラーが発生し続けます: 予期しない T_FOREACH
これは関数を探しているためだと理解していますが、これを克服する方法がわかりません。すべてを別の関数に入れますか?
クラス
Class BEAM_Options {
public $options;
public $categorielist;
public function __construct()
{
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0, //<--IMPORTANT!!
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
$this->options = get_option('beam_plugin_options');
$this->register_settings_and_fields();
}
public function add_menu_page()
{
add_options_page('Ad Management', 'Ad Management', 'administrator', __FILE__, array('BEAM_Options', 'display_options_page'));
}
public function display_options_page()
{
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2> Ad Management</h2>
<form method="post" action="options.php">
<?php settings_fields('beam_plugin_options'); ?>
<?php do_settings_sections(__FILE__); ?>
<p class="submit">
<input name="submit" type="submit" class="button-primary" value="Save Changes" />
</p>
</form>
</div>
<?php
}
public function register_settings_and_fields()
{
register_setting('beam_plugin_options', 'beam_plugin_options');
add_settings_section('beam_main_section', 'Settings', array($this, 'beam_main_section_cb'), __FILE__); //id, title, section, callback, page
add_settings_field('beam_refresh_time_truth','Do you want the Advertisements to Auto-Refresh?', array($this,'beam_refresh_time_truth_setting'), __FILE__, 'beam_main_section');
add_settings_field('beam_refresh_time','Refresh Time(seconds)', array($this,'beam_refresh_time_setting'), __FILE__, 'beam_main_section');
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0, //<--IMPORTANT!!
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
foreach($categories as $category) {
add_settings_field("beam_channels.$category->name","$category->name", array($this,"beam_channels_setting.$category->name"), __FILE__, 'beam_main_section');
}
}
foreach($categories as $category) {
public function beam_channels_setting.$category->name()
{
echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";
}
}
}