codepress / admin-columns

Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel. Transform the WordPress admin screens into beautiful, clear overviews.
http://www.admincolumns.com
GNU General Public License v3.0
69 stars 26 forks source link

Inline editing does not trigger 'pre_post_update' hook #329

Closed labbitroma closed 2 years ago

labbitroma commented 3 years ago

There is an action called 'acp/editing/saved' that triggers after the column is saved. We need another action that triggers before the column is being updated.

In file admin-columns-pro/classes/Editing/Model.php

public function update( $id, $value ) {
                $this->error = null;

                /**
                 * Filter for changing the value before storing it to the DB
                 *
                 * @param mixed     $value Value send from inline edit ajax callback
                 * @param AC\Column $column
                 * @param int       $id
                 *
                 * @since 4.0
                 */
                $value = apply_filters( 'acp/editing/save_value', $value, $this->column, $id );

                // change here
                $old_value = $this->get_edit_value($id);
                do_action( 'acp/editing/before_save', $this->column, $id, $old_value, $value );

                $result = $this->save( $id, $value );

                if ( ! $this->error ) {
                        /**
                         * Fires after a inline-edit successfully saved a value
                         *
                         * @param AC\Column $column Column instance
                         * @param int       $id     Item ID
                         * @param string    $value  User submitted input
                         *
                         * @since 4.0
                         */
                        do_action( 'acp/editing/saved', $this->column, $id, $value );
                }

                return $result;
        }
DGStefan commented 3 years ago

@labbitroma can you tell me a bit more about your use case? I suspect that everything that you're asking for can be done in the filter 'acp/editing/save_value' Of course, a filter is not exactly the same as an action, but as long as you return the value or throw an exception, you can do the same things as in the hook. Unless you have a very good use case that cannot be solved with the filter.

tobiasschutter commented 2 years ago

Added: do_action( 'acp/editing/before_save', $column, $id, $request );