Ben son birkaç gün içinde bir Wordpress tema proje üzerinde çalışıyoruz ve ben (ben öncelikle bir Tema Geliştirici değil, bir PHP scripter değilim) OOP kullanılarak düzgün çalışan bir dinamik seçenekleri sayfasını nasıl sıkışmış oldum.
<?php
$footerpage = new optionpage;
$footerpage->title = 'Footer';
$footerpage->titleprint = ' Footer Options';
$footerpage->slug = 'footer';
$footerpage->html = array(
'1' => array(
'type' => 'textarea',
'class' => 'large-text',
'name' => 'html',
'title' => 'HTML',
'description' => 'Type in whatever HTML you\'d like to see in the footer here:',
),
'2' => array(
'type' => 'input',
'class' => 'large-text',
'name' => 'background-color',
'title' => 'Background Color',
'description' => ' Choose a Background Color:'
),
);
class optionpage {
public $title;
public $titleprint;
public $slug;
public $html = array();
......
......
......
public function ab_settings() {
register_setting( $this->slug, 'ab_options');
add_settings_section('ab_section', '', array(&$this, 'ab_do_titleprint'), 'ab_' . $this->slug . '_options', 'ab_options' );
foreach ($this->html as $key => $html) {
add_settings_field( $key, $html['title'], array(&$this, 'ab_do_htmlprint' ), 'ab_' . $this->slug . '_options', 'ab_section');
}
}
public function ab_do_htmlprint() {
$html = $this->html[$key];
?>
<p><?php echo $html['description'] ?></p>
<<?php echo $html['type'] ?>
id="<?php echo $html['id'] ?>"
class="<?php echo $html['class'] ?>"
name="<?php echo $html['name'] ?>">
<?php get_option ($html['name'])?>
</<?php echo $html['type'] ?>>
<?php
}
......
......
?>
Fonksiyon foreach döngüsü gerektiği kadar birçok kez çağrılacak gidiyor çünkü bu kod örneğinde, ben, o denilen oldu foreach ifadeleri tanımak için fonksiyon ab_do_htmlprint almaya çalışıyorum.
Ben işlev adına bir değişken ekleme gibi, birkaç şey denedim, ama bu sadece farklı bir adla, aynı kodun birden fazla işlevleri gerektirir. Ben de onlar bile gerektiğinde eğer, ancak onlar da çalışma değildi, ve ben doğru olduğunu yapıyor olabilir, referans ve bu gibi çeşitli değişkenler geçen çalıştı.
Neyse verimli Bunu gerçekleştirmek için?