Skip to content

Commit

Permalink
Move admin gallery save compatibility function to post helper also fi…
Browse files Browse the repository at this point in the history
…x the admin gallery update issue that caused galleries to be reassigned to the admin from user
  • Loading branch information
sbrajesh committed Jul 28, 2015
1 parent 23969d4 commit 952a167
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 57 deletions.
86 changes: 85 additions & 1 deletion admin/class-mpp-post-helper.php
Expand Up @@ -17,6 +17,8 @@ private function __construct () {
add_action( 'admin_enqueue_scripts', array( $this, 'load_js' ) );

add_action( 'admin_enqueue_scripts', array( $this, 'load_css' ) );

add_action( 'save_post_' . mpp_get_gallery_post_type(), array( $this, 'update_gallery_details' ), 1, 3 );
}

/**
Expand Down Expand Up @@ -65,6 +67,24 @@ public function is_gallery_edit () {
return false;
}

private function get_component_id( $post_id ) {
//if it is not gallery edit page, let us not worry
if( ! $this->is_gallery_edit() ) {
return mpp_get_current_component_id();
}
//we are on edit page,
//it can be either add new or edit gallery
//we do not want to modify the component_id(associated component id)

$component_id = mpp_get_gallery_meta( $post_id, '_mpp_component_id', true );

if( ! $component_id ) {
$component_id = get_current_user_id();//
}

return $component_id;

}
public function init () {
//we need to take these actions only on gallery post type
//or should we do it at add_metboxes
Expand Down Expand Up @@ -182,7 +202,7 @@ public function generate_meta_box ( $post ) {
<?php endforeach; ?>

</ul>
<input type='hidden' name="mpp-gallery-component-id" value="<?php echo mpp_get_current_component_id(); ?>" />
<input type='hidden' name="mpp-gallery-component-id" value="<?php echo $this->get_component_id( $post->ID );?>" />
</div>


Expand Down Expand Up @@ -291,7 +311,71 @@ public function load_css () {
//wp_enqueue_style( 'mpp-upload-css', MPP_PLUGIN_URL . 'admin/assets/css/mpp-admin.css' );
wp_enqueue_style( 'mpp-core-css', mediapress()->get_url() . 'assets/css/mpp-core.css' );
}
/**
* When a gallery is created/edit from dashboard, simulate the same behaviour as front end created galleries
*
* @param type $post_id
* @param type $post
* @param type $update
* @return type
*/
public function update_gallery_details( $post_id, $post, $update ) {

if( defined( 'DOING_AJAX' ) && DOING_AJAX || ! is_admin() ) {
return;
}
/**
* On the front end, we are using the taxonomy term slugs as the value while on the backend we are using the term_id as the value
*
* So, we are attaching this function only for the Dashboar created gallery
*
* We do need to make it uniform in the futuer
*
*/
//we need to set the object terms

//we need to update the media count?

//do we need to do anything else?
//gallery-type
//gallery-component
//gallery status

if( ! empty( $_POST['mpp-gallery-type'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-type'] ), mpp_get_type_taxname() );
}

if( ! empty( $_POST['mpp-gallery-component'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-component'] ), mpp_get_component_taxname() );

}

if( ! empty( $_POST['mpp-gallery-status'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-status'] ), mpp_get_status_taxname() );

}

//update media cout or recount?
if( ! empty( $_POST['mpp-gallery-component-id'] ) ) {

mpp_update_gallery_meta( $post_id, '_mpp_component_id', absint( $_POST['mpp-gallery-component-id'] ) );

} else {
//if component id is not given, check if it is members gallery, if so,

}

if( ! $update ) {

do_action( 'mpp_gallery_created', $post_id );
}

}

}

//instantiate
Expand Down
56 changes: 0 additions & 56 deletions core/gallery/actions.php
Expand Up @@ -683,62 +683,6 @@ function mpp_action_hide_unpublished_media() {
*/


function mpp_update_gallery_details_on_save( $post_id, $post, $update ) {

if( defined( 'DOING_AJAX' ) && DOING_AJAX || ! is_admin() ) {
return;
}
/**
* On the front end, we are using the taxonomy term slugs as the value while on the backend we are using the term_id as the value
*
* So, we are attaching this function only for the Dashboar created gallery
*
* We do need to make it uniform in the futuer
*
*/
//we need to set the object terms

//we need to update the media count?

//do we need to do anything else?
//gallery-type
//gallery-component
//gallery status

if( ! empty( $_POST['mpp-gallery-type'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-type'] ), mpp_get_type_taxname() );
}

if( ! empty( $_POST['mpp-gallery-component'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-component'] ), mpp_get_component_taxname() );

}

if( ! empty( $_POST['mpp-gallery-status'] ) ) {

wp_set_object_terms( $post_id, absint( $_POST['mpp-gallery-status'] ), mpp_get_status_taxname() );

}

//update media cout or recount?
if( ! empty( $_POST['mpp-gallery-component-id'] ) ) {

mpp_update_gallery_meta( $post_id, '_mpp_component_id', absint( $_POST['mpp-gallery-component-id'] ) );

}

if( is_admin() && ! $update ) {

do_action( 'mpp_gallery_created', $post_id );
}

}
add_action( 'save_post_' . mpp_get_gallery_post_type(), 'mpp_update_gallery_details_on_save', 1, 3 );


/** Clanup actions*/
function mpp_clean_gallery_cache( $gallery ) {

Expand Down

0 comments on commit 952a167

Please sign in to comment.