• paulie22

    (@paulie22)


    This is code for:
    NGGallery Select for pages, posts, and custom
    NGGallery Select for quick edit

    make sure to get js file from:
    http://rachelcarden.com/2012/03/manage-wordpress-posts-using-bulk-edit-and-quick-edit/

    <?php
    /*
    Plugin Name: NGGallery Select Meta Box
    Plugin URI: http://wp.tutsplus.com/
    Description: Adds an example meta box to wordpress.
    Version: None
    Author: Christopher Davis
    Author URI: http://wp.tutsplus.com/
    License: Public Domain
    */
    
    add_action( 'add_meta_boxes', 'nggallery_select_meta_box_add' );
    function nggallery_select_meta_box_add()
    {
    	$types = array( 'post', 'page', 'custom' );
    
    foreach( $types as $type ) {
          add_meta_box('nggallery-select-meta-box-id', 'NGGallery Select', 'nggallery_select_meta_box_cb', $type, 'normal', 'high');
    	}
    }
    
    function nggallery_select_meta_box_cb( $post )
    {
    	$values = get_post_custom( $post->ID );
    	$selected = isset( $values['nggallery_select_meta_box_select'] ) ? esc_attr( $values['nggallery_select_meta_box_select'][0] ) : '';
    	wp_nonce_field( 'nggallery_select_meta_box_nonce', 'meta_box_nonce' );
    	?>
    	<p>
    
    		<label for="nggallery_select_meta_box_select">Select Gallery</label>
    		<select name="nggallery_select_meta_box_select" id="nggallery_select_meta_box_select">
            <?php global $nggdb; $gallerylist = $nggdb->find_all_galleries(); ?>
    		<?php foreach ($gallerylist as $objects) { ?>
    			<option value="<?php echo $objects->gid ?>" <?php selected( $selected, $objects->gid ); ?>><?php echo $objects->title ?></option>
       		<?php } ?>
    		</select>
    	</p>
    	<?php
    }
    
    add_action( 'save_post', 'nggallery_select_meta_box_save' );
    function nggallery_select_meta_box_save( $post_id )
    {
    	// Bail if we're doing an auto save
    	if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    
    	// if our nonce isn't there, or we can't verify it, bail
    	if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'nggallery_select_meta_box_nonce' ) ) return;
    
    	// if our current user can't edit this post, bail
    	if( !current_user_can( 'edit_post' ) ) return;
    
    	// now we can actually save the data
    	$allowed = array(
    		'a' => array( // on allow a tags
    		'href' => array() // and those anchords can only have href attribute
    		)
    	);
    
    	// Probably a good idea to make sure your data is set
    
    	if( isset( $_POST['nggallery_select_meta_box_select'] ) )
    		update_post_meta( $post_id, 'nggallery_select_meta_box_select', esc_attr( $_POST['nggallery_select_meta_box_select'] ) );
    
    }
    
    //NGGALLERY QUICK EDIT
    
    add_filter( 'manage_posts_columns', 'rachel_carden_managing_my_posts_columns', 10, 2 );
    function rachel_carden_managing_my_posts_columns( $columns ) {
    
             $new_columns = array();
             foreach( $columns as $key => $value ) {
                $new_columns[ $key ] = $value;
                if ( $key == 'title' )
                   $new_columns[ 'nggallery_select_meta_box_select' ] = 'Nggallery ID';
             }
             return $new_columns;
    
       return $columns;
    }
    
    add_action( 'manage_posts_custom_column', 'rachel_carden_populating_my_posts_columns', 10, 2 );
    function rachel_carden_populating_my_posts_columns( $column_name, $post_id ) {
       switch( $column_name ) {
          case 'nggallery_select_meta_box_select':
             echo '<div id="nggallery_select_meta_box_select-' . $post_id . '">' . get_post_meta( $post_id, 'nggallery_select_meta_box_select', true ) . '</div>';
             break;
       }
    }
    
    add_action( 'bulk_edit_custom_box', 'rachel_carden_add_to_bulk_quick_edit_custom_box', 10, 2 );
    add_action( 'quick_edit_custom_box', 'rachel_carden_add_to_bulk_quick_edit_custom_box', 10, 2 );
    function rachel_carden_add_to_bulk_quick_edit_custom_box( $column_name ) {
     ?><fieldset class="inline-edit-col-right">
    				  <div class="inline-edit-group">
    				    <label> <span class="title">Select Nggallery</span>
    				      <select name="nggallery_select_meta_box_select" id="nggallery_select_meta_box_select">
            <?php $selected = isset( $values['nggallery_select_meta_box_select'] ) ? esc_attr( $values['nggallery_select_meta_box_select'][0] ) : '';
            global $nggdb; $gallerylist = $nggdb->find_all_galleries(); ?>
    		<?php foreach ($gallerylist as $objects) { ?>
    			<option value="<?php echo $objects->gid ?>" <?php selected( $selected, $objects->gid ); ?>><?php echo $objects->title ?></option>
       		<?php } ?>
    		</select>
    				    </label>
    				  </div>
    				</fieldset><?php
    
    }
    
    add_action( 'admin_print_scripts-edit.php', 'rachel_carden_enqueue_edit_scripts' );
    function rachel_carden_enqueue_edit_scripts() {
       wp_enqueue_script( 'rachel-carden-admin-edit', get_bloginfo( 'stylesheet_directory' ) . '/quick_edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
    }
    
    add_action( 'save_post','rachel_carden_save_post', 10, 2 );
    function rachel_carden_save_post( $post_id, $post ) {
    
    	// don't save for autosave
       	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    		return $post_id;
    
    	// dont save for revisions
    	if ( isset( $post->post_type ) && $post->post_type == 'revision' )
    		return $post_id;
    
             		// release date
    				// Because this action is run in several places, checking for the array key keeps WordPress from editing
             		// data that wasn't in the form, i.e. if you had this post meta on your "Quick Edit" but didn't have it
             		// on the "Edit Post" screen.
    	 			if ( array_key_exists( 'nggallery_select_meta_box_select', $_POST ) )
    	    			update_post_meta( $post_id, 'nggallery_select_meta_box_select', $_POST[ 'nggallery_select_meta_box_select' ] );
    
    }
    
    add_action( 'wp_ajax_rachel_carden_save_bulk_edit', 'rachel_carden_save_bulk_edit' );
    function rachel_carden_save_bulk_edit() {
       // get our variables
       $post_ids = ( isset( $_POST[ 'post_ids' ] ) && !empty( $_POST[ 'post_ids' ] ) ) ? $_POST[ 'post_ids' ] : array();
       $nggallery_select_meta_box_select = ( isset( $_POST[ 'nggallery_select_meta_box_select' ] ) && !empty( $_POST[ 'nggallery_select_meta_box_select' ] ) ) ? $_POST[ 'nggallery_select_meta_box_select' ] : NULL;
       // if everything is in order
       if ( !empty( $post_ids ) && is_array( $post_ids ) && !empty( $nggallery_select_meta_box_select ) ) {
          foreach( $post_ids as $post_id ) {
             update_post_meta( $post_id, 'nggallery_select_meta_box_select', $nggallery_select_meta_box_select );
          }
       }
    }
    
    ?>

    http://wordpress.org/extend/plugins/nextgen-gallery/

  • The topic ‘Create a drop-down list of all galleries’ is closed to new replies.