vafour / vafpress-framework

Wordpress theme options framework, check out the demo.
http://demo.vafpress.com/vafpress-framework
Other
240 stars 98 forks source link

Add meta box to Quick Edit Form #92

Open padalec opened 9 years ago

padalec commented 9 years ago

Just like in topic, the VP_Metabox class should have an option to add some meta boxes to Quick Edit form.

Zackio commented 9 years ago

That would be cool

padalec commented 9 years ago

Hi all, I created PHP class for quick edit form but there is a little problem. After saving data, the data in meta do not changed until you refresh the page. This is my code:

/**
 * Add meta box to Quick edit form
 *
 * @author Michal Kalkowski 
 * @version $Id: quickeditform.php 1807 2014-11-03 21:03:57Z padalec $
 * @category WordPRess
 * @package SilverWP
 * @subpackage MetBox
 * @copyright 2009 - 2014-03-14 SilverSite.pl
 */
class VP_QuickEditForm extends \VP_Metabox
{
    /**
     * post type name
     * 
     * @var string
     * @access protected 
     */
    protected $post_type_name;

    /**
     * class constructor
     * 
     * @param array $attributes
     * @access public
     */
    public function __construct(array $attributes)
    {
        if (!is_array($attributes) && file_exists($attributes)) {
            $attributes = include $attributes;
        }

        $this->WPAlchemy_MetaBox($attributes);

        $this->addScripts();

        if ($this->can_output()) {
            // make sure metabox template loaded
            if (!is_array($this->template) && \file_exists($this->template)) {
                $this->template = include $this->template;
            }
            \add_action('bulk_edit_custom_box', array($this, 'addFields'), 10, 2);
            \add_action('quick_edit_custom_box', array($this, 'addFields'), 10, 2);
            \add_action('save_post', array($this, '_save'), 10, 2);

        }
        \add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
        self::$pool[ $this->id ] = $this;
    }
    /**
     * 
     * add field to quick form
     * 
     * @param string $column_name
     * @param string $post_type
     */
    public function addFields($column_name, $post_type)
    {
        if ($this->post_type_name === $post_type && $column_name == 'custom_column') {
            echo '<fieldset class="inline-edit-col-left">';
            echo '<div class="inline-edit-col">';
            $loader = \VP_WP_Loader::instance();
            $loader->add_types($this->get_field_types(), 'quickeditform');
            $this->_setup();
            echo '</div>';
            echo '</fieldset>';
        }
    }
    /**
     * add requireds css and js scripts
     * 
     * @access private
     * @return void
     */
    private function addScripts()
    {
        $loader = \VP_WP_Loader::instance();
        $loader->add_main_css('vp-metabox');
    }
    /**
     * enqueue js scripts
     * 
     * @access public
     * @return void
     */
    public function enqueueScripts()
    {
        \wp_enqueue_script('vp-quickeditform', get_template_directory_uri() . '/assets/js/silverwp-admin.js');
    }
}

In VP_WP_Loader class constructor I add to $this->types array 'quickeditform' key:

private function __construct()
    {
        $this->_dependencies = apply_filters('vp_dependencies_array', VP_Util_Config::instance()->load('dependencies'));
        $this->_types        = array(
            'option'             => array(),
            'metabox'            => array(),
            'shortcodegenerator' => array(),
            'quickeditform'      => array(),
        );
    }

In 'manage_{post_type}_posts_columns' hook I added some blank column (maybe someone has a better idea how to do this)

\add_filter('manage_{post_type}_posts_columns', array( $this, 'setColumns' ), 10, 1);
public function setColumns($columns)
{
      $columns[{post_type}.'_custom_column'] = '';
}

Regards

padalec commented 9 years ago

No body can help me? @Zackio , @vladan-me maybe you guys can help?

Zackio commented 9 years ago

Going out now, will have a look tomorrow to see if I can help

padalec commented 9 years ago

OK thanks!

Zackio commented 9 years ago

Hi, Thats really cool that you've added that. I guess it's going to need to have some ajax that's hooked into the save button. I wonder how wordpress does it internally. I'd like to have a proper play with it but I'm currently trying the get vafpress to support WPML...

padalec commented 9 years ago

Hi, thanks for your reply. OK I will try to find a solution - how to hook this. What do you mean "vafpress to support WPML"? I am asking because I did it last time so maybe I can help you. Regards

Zackio commented 9 years ago

Hi,

I did something before hooked to the save with ajax becaue i didn't like that you had to refresh the page to change the post format. Maybe something simular can be used. Will try to find the code.

It's mostly all working the only issue is that the metaboxes are not being sent the translation editor, did you get that part working?

On Thu, Nov 20, 2014 at 4:48 PM, padalec notifications@github.com wrote:

Hi, thanks for your reply. OK I will try to find a solution - how to hook this. What do you mean "vafpress to support WPML"? I am asking because I did it last time so maybe I can help you. Regards

— Reply to this email directly or view it on GitHub https://github.com/vafour/vafpress-framework/issues/92#issuecomment-63839286 .

padalec commented 9 years ago

yes I do. But I don't understand what can be problem because this is translated automatically when you create translation for post. The same post in two languages is really two diffrent posts.

Zackio commented 9 years ago

That part works, editing a post in a different language. Its the translation editor that isn't working. It's when you assign a post in the translation manager to a translator then go the the translation option to edit it.

On Thu, Nov 20, 2014 at 6:35 PM, padalec notifications@github.com wrote:

yes I do. But I don't understand what can be problem because this is translated automatically when you create translation for post. The same post in two languages is really two diffrent posts.

— Reply to this email directly or view it on GitHub https://github.com/vafour/vafpress-framework/issues/92#issuecomment-63856487 .

padalec commented 9 years ago

maybe by email can be easier?

Zackio commented 9 years ago

That would be better but is there anyway I can send you a private message to not give out my email address. Can't see a way to do it

On Thu, Nov 20, 2014 at 7:23 PM, padalec notifications@github.com wrote:

maybe by email can be easier?

— Reply to this email directly or view it on GitHub https://github.com/vafour/vafpress-framework/issues/92#issuecomment-63863793 .

padalec commented 9 years ago

Hi, Try send me a message to this email oczykrokodyla[at]gmail.com and when you do that post on this post I send you back a real email.

Zackio commented 9 years ago

I sent another email to this address because I can't for the life of me find your email. Its completely vanished

padalec commented 9 years ago

OK, I sent you back.