Making WordPress.org

Changeset 5365


Ignore:
Timestamp:
04/19/2017 01:10:27 AM (9 years ago)
Author:
coreymckrill
Message:

WordCamp: Limit metabox_save action to WCPT post type

WCPT's metabox_save method was hooked to save_post, so it was firing
for every save, even though it's intended only for the WCPT, as
evidenced by the conditional return within the method if it's not the
right post type.

The problem is that it was throwing errors when it got called during
unrelated wp_insert_post invocations. The workaround used in
create_post_stubs was to temporarily remove the action from the hook
and then add it back. However with the recent addition of the
wcpt_configure_new_site hook, external plugins can run into the same
errors, and forcing them to also temporarily remove the action is
smelly.

The solution in this commit is to stop using the save_post hook, and
instead use save_post_{$post->post_type} to ensure that the
metabox_save method only fires on the post type for which it is
intended.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-admin.php

    r4837 r5365  
    3535        // Topic metabox actions
    3636        add_action( 'add_meta_boxes',                                 array( $this, 'metabox' ) );
    37         add_action( 'save_post',                                      array( $this, 'metabox_save' ), 10, 2 );
     37        add_action( 'save_post_' . WCPT_POST_TYPE_ID,                 array( $this, 'metabox_save' ), 10, 2 );
    3838
    3939        // Scripts and CSS
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/wcpt/wcpt-wordcamp/wordcamp-new-site.php

    r5364 r5365  
    417417
    418418        // Create actual posts from stubs
    419         remove_action( 'save_post', array( $GLOBALS['wordcamp_admin'], 'metabox_save' ) ); // prevent this callback from adding all the meta fields from the corresponding wordcamp post to new posts we create
    420 
    421419        foreach ( $stubs as $page ) {
    422420            $page_id = wp_insert_post( array(
     
    465463        }
    466464
    467         add_action( 'save_post', array( $GLOBALS['wordcamp_admin'], 'metabox_save' ) ); // restore wordcamp meta callback
    468465        Logger\log( 'finished', compact( 'assigned_sponsor_data', 'stubs', 'blog_name' ) );
    469466    }
Note: See TracChangeset for help on using the changeset viewer.