michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

Bug: 'save' attribute of sections and inputs doesn't work with Page MetaBox. #275

Closed dualjack closed 6 years ago

dualjack commented 6 years ago

Steps to reproduce the issue (for Bug report)

  1. Download plugin
  2. Go to yellow settings page
  3. Click 'Submit' and see what happens.

Expected behavior and actual behavior

It shouldn't save Page MetaBox options fields, but i does. I am using AdminPageFramework to create GUI for dynamic content generation. I don't want to save data as options. I use this data in validate_ hook.

Versions

Plugin files

Download here: example_plugin.zip

example.php

<?php
/*
Plugin Name:    Example APF MetaBox plugin
Description:    Shows bugs with 'save' option.
Version:        1.0
Author:         jakubkuranda@gmail.com
*/

require_once( __DIR__ . '/lib/apf/admin-page-framework.php' );

class example extends example_AdminPageFramework {

    public function setUp() {

        //  ----------------------------------------
        //  Page definition
        //  ----------------------------------------

        $this->setRootMenuPage( sprintf( '<span style="color:yellow;">%1$s</span>', 'Example MetaBox' ) );

        $this->addSubMenuItems(
            array(
                'title'         => 'Example MetaBox',    // page title
                'page_slug'     => 'example_page',    // page slug
            )
        );

        //  ----------------------------------------
        //  Load page MetaBox
        //  ----------------------------------------

        require_once( __DIR__ . '/examplePageMetaBox.php' );

        new examplePageMetaBox(
            'example_box',
            'Look at me!',
            'example_page',
            'side',
            'default'
        );

    }

    public function content( $html ) {

        $savedOptions = get_option( 'example_option', array() );

        $html .= sprintf( '<p>Saved options: </p>' );
        $html .= sprintf( '<code>If you see some saved options below after pressing "submit" on the right, it is a bug.</code>' );
        $html .= sprintf( '<pre class="dump-array">%1$s</pre>', esc_attr( var_export( $savedOptions, true ) ) );

        return $html;

    }

}

new example( 'example_option' );

examplePageMetaBox.php

<?php

class examplePageMetaBox extends example_AdminPageFramework_PageMetaBox {

    public function setUp() {

        //  ----------------------------------------
        //  Section below and inputs should not save
        //  ----------------------------------------

        $this->addSettingSections(
            array(
                'section_id'        => 'example_section',
                'title'             => 'Example Section',
                'save'              => false        //  <===    NOT WORKING
            )
        );

        $this->addSettingFields(
            'example_section',      // target section
            array(
                'field_id'          => 'example_text',
                'type'              => 'text',
                'title'             => 'text',
                'default'           => 'hello',
                'save'              =>  false       //  <===    ALSO NOT WORKING
            ),
            array(
                'field_id'          => '__submit',
                'type'              => 'submit',
                'save'              => false,       //  <===    ALSO NOT WORKING
                'show_title_column' => false,
                'label_min_width'   => '',
                'description'       => 'Just press me.'
            )
        );

    }

}
dualjack commented 6 years ago

In addition, this way is even pointed in official documentation: http://admin-page-framework.michaeluno.jp/en/v3/package-AdminPageFramework.Factory.PageMetaBox.html

... and it's not working. Thanks for your work. I would try to fix it myself, but it's pretty complicated.

Image

michaeluno commented 6 years ago

I see. Thanks for the report.