WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields - NextGEN Gallery Field add-on
[resolved] No "NextGEN Gallery" option in Field Type (26 posts)

  1. adamtomasz
    Member
    Posted 1 year ago #

    Hi!

    I'm a bit desperate. I've installed and activated the NextGEN and ACF plugins and then this add-on but the "NextGEN Gallery" option doesn't show up in Field Type as one of options. I'm not getting any error message so I can't even specify what may be the problem. All plugins are activated, obviously.
    I would really appreciate any clue.

    Regards,

    Adam

    http://wordpress.org/extend/plugins/advanced-custom-fields-nextgen-gallery-field-add-on/

  2. adamtomasz
    Member
    Posted 1 year ago #

    It's strange but reinstalling all plugins for the xth time has helped.

    Regards,
    Adam

  3. diebombe
    Member
    Posted 1 year ago #

    i've the same problem and reinstalling doesn't work for me :(

  4. adamtomasz
    Member
    Posted 1 year ago #

    I've downgraded the Advanced Custom Fields plugin to the 3.5.8.2 version. It should help :)

  5. diebombe
    Member
    Posted 1 year ago #

    ok works now but the rest does not!

    found another solution!

  6. simonseddon
    Member
    Posted 1 year ago #

    This has been marked as resolved.

    Can I confirm that the fix is to downgrade? I would consider that more a workaround than a resolution.

    (although if the root of the problem is with ACF (is it? do all other ACF add-ons fail?) then I guess there's not much you can do..)

  7. Faruk
    Member
    Posted 1 year ago #

    I have same problem!

  8. pulla
    Member
    Posted 1 year ago #

    same problem. not found it on field type.

  9. jabbo126
    Member
    Posted 1 year ago #

    Same by me, wierd

  10. eggproject
    Member
    Posted 1 year ago #

    Hello...

    this with acf v4 api
    admin area show , and save this field selected value ...
    front_end the_field and get_field do not test!

    replace code ... (plugin file head comment do not remove!)

    <?php

    class acf_field_ACF_NGGallery_Field extends acf_field
    {
    // vars
    var $settings, // will hold info such as dir / path
    $defaults; // will hold default field options
    /**
    * Base directory
    * @var string
    */
    private $base_dir;

    /**
    * Relative Uri from the WordPress ABSPATH constant
    * @var string
    */
    private $base_uri_rel;

    /**
    * Absolute Uri
    *
    * This is used to create urls to CSS and JavaScript files.
    * @var string
    */
    private $base_uri_abs;

    /**
    * WordPress Localization Text Domain
    *
    * The textdomain for the field is controlled by the helper class.
    * @var string
    */
    private $l10n_domain;

    /*
    * __construct
    *
    * Set name / label needed for actions / filters
    *
    * @since 3.6
    * @date 23/01/13
    */

    function __construct()
    {

    // settings
    $this->settings = array(
    'path' => apply_filters('acf/helpers/get_path', __FILE__),
    'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
    'version' => '1.0.0'
    );

    //Get the textdomain from the Helper class
    $this->l10n_domain ="acf-nggallery-field";

    //Base directory of this field
    $this->base_dir = rtrim( dirname( realpath( __FILE__ ) ), '/' );

    //Build the base relative uri by searching backwards until we encounter the wordpress ABSPATH
    $root = array_pop( explode( '/', rtrim( ABSPATH, '/' ) ) );
    $path_parts = explode( '/', $this->base_dir );
    $parts = array();
    while( $part = array_pop( $path_parts ) ) {
    if( $part == $root )
    break;
    array_unshift( $parts, $part );
    }
    $this->base_uri_rel = '/' . implode( '/', $parts );
    $this->base_uri_abs = get_site_url( null, $this->base_uri_rel );

    // $this->name = 'nggallery-field';

    $post_title = ( !class_exists('nggdb') ) ? '. ' . __( 'NextGEN Gallery plugin is not installed or activated!', $this->l10n_domain ) : false;
    $this->label = __( 'NextGEN Gallery'.$post_title, $this->l10n_domain );

    // vars
    $this->name = 'ACF_NGGallery_Field';
    // $this->label = __('{{field_label}}');
    $this->category = __("Basic",'acf'); // Basic, Content, Choice, etc
    $this->defaults = array(
    // add default here to merge into your field.
    // This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
    //'preview_size' => 'thumbnail'
    );

    // add_action( 'admin_print_scripts', array( &$this, 'admin_print_scripts' ), 12, 0 );
    // add_action( 'admin_print_styles', array( &$this, 'admin_print_styles' ), 12, 0 );

    // do not delete!
    parent::__construct();
    }
    /**
    * Populates the fields array with defaults for this field type
    *
    * @param array $field
    * @return array
    */
    private function set_field_defaults( &$field ) {
    //$field[ 'nggallery' ] = ( array_key_exists( 'nggallery', $field ) && isset( $field[ 'nggallery' ] ) ) ? $field[ 'nggallery' ] : 0;
    $field[ 'nggallery' ] = 0;
    $field[ 'input_type' ] = ( array_key_exists( 'input_type', $field ) && isset( $field[ 'input_type' ] ) ) ? $field[ 'input_type' ] : 'select';
    $field[ 'input_size' ] = ( array_key_exists( 'input_size', $field ) && isset( $field[ 'input_size' ] ) ) ? (int) $field[ 'input_size' ] : 5;
    $field[ 'allow_null' ] = isset($field['allow_null']) ? $field['allow_null'] : false;
    return $field;
    }

    /*
    * create_options()
    *
    * Create extra options for your field. This is rendered when editing a field.
    * The value of $field['name'] can be used (like bellow) to save extra data to the $field
    *
    * @type action
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - an array holding all the field's data
    */

    function create_options( $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */
    $this->set_field_defaults( $field );
    // key is needed in the field names to correctly save the data
    $key = $field['name'];

    ?>
    <tr class="field_option field_option_<?php echo $this->name; ?>">
    <td class="label">
    <label><?php _e("Allow Null?",'acf'); ?></label>
    </td>
    <td>
    <?php
    do_action('acf/create_field',array(
    'type' => 'radio',
    'name' => 'fields['.$key.'][allow_null]',
    'value' => $field['allow_null'],
    'choices' => array(
    '1' => 'Yes',
    '0' => 'No',
    ),
    'layout' => 'horizontal',
    ));
    ?>
    </td>
    </tr>
    <tr class="field_option field_option_<?php echo $this->name; ?>">
    <td class="label">
    <label><?php _e( 'Input Method' , $this->l10n_domain ); ?></label>
    <p class="description"><?php _e( '', $this->l10n_domain ); ?></p>
    </td>
    <td>
    <?php
    do_action('acf/create_field', array(
    'type' => 'select',
    'name' => "fields[{$key}][input_type]",
    'value' => $field[ 'input_type' ],
    'class' => "nggallery_input_type nggallery_input_type_{$key}",
    'choices' => array(
    'select' => 'Select',
    'multiselect' => 'Multi-Select',
    //'token' => 'Input Tokenizer',
    )
    ) );
    ?>
    </td>
    </tr>
    <tr id="nggallery_input_size[<?php echo $key; ?>]" class="field_option field_option_<?php echo $this->name; ?> nggallery_input_size nggallery_input_size_<?php echo $key; ?>">
    <td class="label">
    <label><?php _e( 'Multi-Select Size' , $this->l10n_domain ); ?></label>
    <p class="description"><?php _e( 'The number of rows to show at once in a multi-select.', $this->l10n_domain ); ?></p>
    </td>
    <td>
    <?php
    do_action('acf/create_field', array(
    'type' => 'select',
    'name' => "fields[{$key}][input_size]",
    'value' => $field[ 'input_size' ],
    'choices' => array_combine( range( 3, 15, 2 ), range( 3, 15, 2 ) ),
    ) );
    ?>
    </td>
    </tr>
    <script type='text/javascript'>

    jQuery(document).ready(function() {

    if ( jQuery('.nggallery_input_type_<?php echo $key; ?>').val()=='select' ) jQuery('.nggallery_input_size_<?php echo $key; ?>').hide();
    else jQuery('.nggallery_input_size_<?php echo $key; ?>').show();

    jQuery('.nggallery_input_type_<?php echo $key; ?>').change(function() {
    if ( jQuery('.nggallery_input_type_<?php echo $key; ?>').val()=='select' ) jQuery('.nggallery_input_size_<?php echo $key; ?>').hide();
    else jQuery('.nggallery_input_size_<?php echo $key; ?>').show();
    });
    });

    </script>
    <?php

    }

    /*
    * create_field()
    *
    * Create the HTML interface for your field
    *
    * @param $field - an array holding all the field's data
    *
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function create_field( $field )
    {
    global $ngg, $nggdb, $wp_query;

    $this->set_field_defaults( $field );

    $values = $field[ 'value' ];

    if ( !empty($values[0]) ):

    foreach ( $values as $form ) {

    if ( in_array ( 'gallery', $form ) )
    $values_gallery[]=$form['ngg_id'];

    if ( in_array ( 'album', $form ) )
    $values_album[]=$form['ngg_id'];

    }

    endif;

    if ( class_exists('nggdb') ) :

    // Settings of NextGEN Gallery SQL query
    $limit = 0;
    $start = 0;
    $order_by = 'title';
    $order_dir = 'ASC';

    // Seek to all NextGEN Galleries
    $gallerylist = $nggdb->find_all_galleries( $order_by, $order_dir , TRUE, $limit, $start, false);
    $albumlist = $nggdb->find_all_album( 'name', $order_dir, $limit, $start);

    $haystack = array( 'select', 'multiselect' );
    if( in_array( $field[ 'input_type' ], $haystack ) ) :
    ?>
    <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>" <?php echo ( $field[ 'input_type' ] == 'multiselect' ) ? 'multiple="multiple" size="' . $field[ 'input_size' ] . '"' : ''; ?>>
    <?php if($field['allow_null'] == '1') echo '
    <option value="null"> - Select - </option>';
    ?>

    <optgroup label="<?php _e('Galleries','nggallery'); ?>">
    <?php foreach( $gallerylist as $gallery ) : ?>
    <option value="<?php echo $gallery->gid.',gallery'; ?>"<?php if ( $values_gallery ) selected( in_array( $gallery->gid, $values_gallery ) ); ?>><?php echo $gallery->title; ?></option>
    <?php endforeach; ?>
    </optgroup>
    <optgroup label="<?php _e('Albums','nggallery'); ?>">
    <?php foreach( $albumlist as $album ) : ?>
    <option value="<?php echo $album->id.',album'; ?>"<?php if ( $values_album ) selected( in_array( $album->id, $values_album ) ); ?>><?php echo $album->name; ?></option>
    <?php endforeach; ?>
    </optgroup>
    </select>
    <?php
    endif;

    else:
    ?>
    <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>">
    <option value="0" disabled="true"><?php _e( 'NextGEN Gallery plugin is not installed or activated!', $this->l10n_domain ); ?></option>
    </select>
    <?php
    endif;

    }

    /*
    * input_admin_enqueue_scripts()
    *
    * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
    * Use this action to add css + javascript to assist your create_field() action.
    *
    * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function input_admin_enqueue_scripts()
    {
    // Note: This function can be removed if not used

    //
    // // register acf scripts
    // wp_register_script( 'acf-input-ACF_NGGallery_Field', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
    // wp_register_style( 'acf-input-ACF_NGGallery_Field', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
    //
    //
    // // scripts
    // wp_enqueue_script(array(
    // 'acf-input-ACF_NGGallery_Field',
    // ));
    //
    // // styles
    // wp_enqueue_style(array(
    // 'acf-input-ACF_NGGallery_Field',
    // ));

    }

    /*
    * input_admin_head()
    *
    * This action is called in the admin_head action on the edit screen where your field is created.
    * Use this action to add css and javascript to assist your create_field() action.
    *
    * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function input_admin_head()
    {
    // Note: This function can be removed if not used
    }

    /*
    * field_group_admin_enqueue_scripts()
    *
    * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited.
    * Use this action to add css + javascript to assist your create_field_options() action.
    *
    * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function field_group_admin_enqueue_scripts()
    {
    // Note: This function can be removed if not used
    }

    /*
    * field_group_admin_head()
    *
    * This action is called in the admin_head action on the edit screen where your field is edited.
    * Use this action to add css and javascript to assist your create_field_options() action.
    *
    * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function field_group_admin_head()
    {
    // Note: This function can be removed if not used
    }

    /*
    * load_value()
    *
    * This filter is appied to the $value after it is loaded from the db
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value found in the database
    * @param $post_id - the $post_id from which the value was loaded from
    * @param $field - the field array holding all the field options
    *
    * @return $value - the value to be saved in te database
    */

    function load_value( $value, $post_id, $field )
    {
    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * update_value()
    *
    * This filter is appied to the $value before it is updated in the db
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which will be saved in the database
    * @param $post_id - the $post_id of which the value will be saved
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function update_value( $value, $post_id, $field )
    { $this->set_field_defaults( $field );

    foreach( $value as $key=>$item ) {
    $items = explode( ',', $item );
    foreach( $items as $item ) {
    if( is_numeric( $item ) )
    $values[$key]['ngg_id'] = intval ( $item );
    else
    $values[$key]['ngg_form'] = strval( $item );
    }
    }

    // parent::update_value( $post_id, $field, $values );
    // Note: This function can be removed if not used
    return $values;
    }

    /*
    * format_value()
    *
    * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which was loaded from the database
    * @param $post_id - the $post_id from which the value was loaded
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function format_value( $value, $post_id, $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */

    // perhaps use $field['preview_size'] to alter the $value?

    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * format_value_for_api()
    *
    * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which was loaded from the database
    * @param $post_id - the $post_id from which the value was loaded
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function format_value_for_api( $value, $post_id, $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */

    // perhaps use $field['preview_size'] to alter the $value?

    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * load_field()
    *
    * This filter is appied to the $field after it is loaded from the database
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - the field array holding all the field options
    *
    * @return $field - the field array holding all the field options
    */

    function load_field( $field )
    {
    // Note: This function can be removed if not used
    return $field;
    }

    /*
    * update_field()
    *
    * This filter is appied to the $field before it is saved to the database
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - the field array holding all the field options
    * @param $post_id - the field group ID (post_type = acf)
    *
    * @return $field - the modified field
    */

    function update_field( $field, $post_id )
    {
    // Note: This function can be removed if not used
    return $field;
    }

    }

    // create field
    new acf_field_ACF_NGGallery_Field();

    ?>

  11. Thibouh
    Member
    Posted 1 year ago #

    This code doesn't work, and i have the same problem :(

  12. orangjul
    Member
    Posted 11 months ago #

    eggproject, where did you put that code? Did you replace the code in advanced-custom-fields-nextgen-gallery-field-add-on/nggallery-field.php ?

  13. eggproject
    Member
    Posted 11 months ago #

    i create v4.php => copy my new v4 api code

    and rewrite nggallery-field.php =>

    /*
    ORIGINAL PLUGIN COMMENT
    */

    add_action('acf/register_fields', 'my_register_fields');

    function my_register_fields()
    {
    require_once(rtrim( dirname( realpath( __FILE__ ) ), '/' )."/v4.php");
    }

    this work ... wp 3.5.2 lastest acf... lastest nextgen...

    sry i little speak english :(((

  14. manhngo
    Member
    Posted 11 months ago #

    eggproject, i am doing with your help and working fine :),

    many thanks.

  15. winyman
    Member
    Posted 11 months ago #

    please can you tell me (and maybe all of us) what you have done with this two code snippets from egg project? which code in which file? what should I replace, what should I append or merge? please let us know. thanks in advance

  16. eggproject
    Member
    Posted 11 months ago #

    nggallery-field.php
    <?php
    /*
    Plugin Name: Advanced Custom Fields - NextGEN Gallery Field add-on with egg BugFix migrate to acf v4 api
    Plugin URI: http://wordpress.org/extend/plugins/advanced-custom-fields-nextgen-gallery-field-add-on/
    Description: This plugin is an add-on for Advanced Custom Fields. It provides a dropdown of NextGEN Gallery and the ability to map the selected NextGEN Gallery to the post.
    Version: 1.2.1
    Requires at least: 3.0
    Tested up to: 3.4.1
    Author: Ales Loziak
    Author URI: http://www.apollo1.cz
    License: GPLv2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    *
    *
    *
    * Copyright (c) 2012, Ales Loziak
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    *
    * Redistributions of source code must retain the above copyright notice, this
    * list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
    * this list of conditions and the following disclaimer in the documentation
    * and/or other materials provided with the distribution.
    * Neither the name of Ales Loziak nor the names of its
    * contributors may be used to endorse or promote products derived from this
    * software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
    * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    * OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    add_action('acf/register_fields', 'my_register_fields');

    function my_register_fields()
    {
    require_once(rtrim( dirname( realpath( __FILE__ ) ), '/' )."/v4.php");
    }

    v4.php
    <?php

    class acf_field_ACF_NGGallery_Field extends acf_field
    {
    // vars
    var $settings, // will hold info such as dir / path
    $defaults; // will hold default field options
    /**
    * Base directory
    * @var string
    */
    private $base_dir;

    /**
    * Relative Uri from the WordPress ABSPATH constant
    * @var string
    */
    private $base_uri_rel;

    /**
    * Absolute Uri
    *
    * This is used to create urls to CSS and JavaScript files.
    * @var string
    */
    private $base_uri_abs;

    /**
    * WordPress Localization Text Domain
    *
    * The textdomain for the field is controlled by the helper class.
    * @var string
    */
    private $l10n_domain;

    /*
    * __construct
    *
    * Set name / label needed for actions / filters
    *
    * @since 3.6
    * @date 23/01/13
    */

    function __construct()
    {

    // settings
    $this->settings = array(
    'path' => apply_filters('acf/helpers/get_path', __FILE__),
    'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
    'version' => '1.0.0'
    );

    //Get the textdomain from the Helper class
    $this->l10n_domain ="acf-nggallery-field";

    //Base directory of this field
    $this->base_dir = rtrim( dirname( realpath( __FILE__ ) ), '/' );

    //Build the base relative uri by searching backwards until we encounter the wordpress ABSPATH
    $root = array_pop( explode( '/', rtrim( ABSPATH, '/' ) ) );
    $path_parts = explode( '/', $this->base_dir );
    $parts = array();
    while( $part = array_pop( $path_parts ) ) {
    if( $part == $root )
    break;
    array_unshift( $parts, $part );
    }
    $this->base_uri_rel = '/' . implode( '/', $parts );
    $this->base_uri_abs = get_site_url( null, $this->base_uri_rel );

    // $this->name = 'nggallery-field';

    $post_title = ( !class_exists('nggdb') ) ? '. ' . __( 'NextGEN Gallery plugin is not installed or activated!', $this->l10n_domain ) : false;
    $this->label = __( 'NextGEN Gallery'.$post_title, $this->l10n_domain );

    // vars
    $this->name = 'ACF_NGGallery_Field';
    // $this->label = __('{{field_label}}');
    $this->category = __("Basic",'acf'); // Basic, Content, Choice, etc
    $this->defaults = array(
    // add default here to merge into your field.
    // This makes life easy when creating the field options as you don't need to use any if( isset('') ) logic. eg:
    //'preview_size' => 'thumbnail'
    );

    // add_action( 'admin_print_scripts', array( &$this, 'admin_print_scripts' ), 12, 0 );
    // add_action( 'admin_print_styles', array( &$this, 'admin_print_styles' ), 12, 0 );

    // do not delete!
    parent::__construct();
    }
    /**
    * Populates the fields array with defaults for this field type
    *
    * @param array $field
    * @return array
    */
    private function set_field_defaults( &$field ) {
    //$field[ 'nggallery' ] = ( array_key_exists( 'nggallery', $field ) && isset( $field[ 'nggallery' ] ) ) ? $field[ 'nggallery' ] : 0;
    $field[ 'nggallery' ] = 0;
    $field[ 'input_type' ] = ( array_key_exists( 'input_type', $field ) && isset( $field[ 'input_type' ] ) ) ? $field[ 'input_type' ] : 'select';
    $field[ 'input_size' ] = ( array_key_exists( 'input_size', $field ) && isset( $field[ 'input_size' ] ) ) ? (int) $field[ 'input_size' ] : 5;
    $field[ 'allow_null' ] = isset($field['allow_null']) ? $field['allow_null'] : false;
    return $field;
    }

    /*
    * create_options()
    *
    * Create extra options for your field. This is rendered when editing a field.
    * The value of $field['name'] can be used (like bellow) to save extra data to the $field
    *
    * @type action
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - an array holding all the field's data
    */

    function create_options( $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */
    $this->set_field_defaults( $field );
    // key is needed in the field names to correctly save the data
    $key = $field['name'];

    ?>
    <tr class="field_option field_option_<?php echo $this->name; ?>">
    <td class="label">
    <label><?php _e("Allow Null?",'acf'); ?></label>
    </td>
    <td>
    <?php
    do_action('acf/create_field',array(
    'type' => 'radio',
    'name' => 'fields['.$key.'][allow_null]',
    'value' => $field['allow_null'],
    'choices' => array(
    '1' => 'Yes',
    '0' => 'No',
    ),
    'layout' => 'horizontal',
    ));
    ?>
    </td>
    </tr>
    <tr class="field_option field_option_<?php echo $this->name; ?>">
    <td class="label">
    <label><?php _e( 'Input Method' , $this->l10n_domain ); ?></label>
    <p class="description"><?php _e( '', $this->l10n_domain ); ?></p>
    </td>
    <td>
    <?php
    do_action('acf/create_field', array(
    'type' => 'select',
    'name' => "fields[{$key}][input_type]",
    'value' => $field[ 'input_type' ],
    'class' => "nggallery_input_type nggallery_input_type_{$key}",
    'choices' => array(
    'select' => 'Select',
    'multiselect' => 'Multi-Select',
    //'token' => 'Input Tokenizer',
    )
    ) );
    ?>
    </td>
    </tr>
    <tr id="nggallery_input_size[<?php echo $key; ?>]" class="field_option field_option_<?php echo $this->name; ?> nggallery_input_size nggallery_input_size_<?php echo $key; ?>">
    <td class="label">
    <label><?php _e( 'Multi-Select Size' , $this->l10n_domain ); ?></label>
    <p class="description"><?php _e( 'The number of rows to show at once in a multi-select.', $this->l10n_domain ); ?></p>
    </td>
    <td>
    <?php
    do_action('acf/create_field', array(
    'type' => 'select',
    'name' => "fields[{$key}][input_size]",
    'value' => $field[ 'input_size' ],
    'choices' => array_combine( range( 3, 15, 2 ), range( 3, 15, 2 ) ),
    ) );
    ?>
    </td>
    </tr>
    <script type='text/javascript'>

    jQuery(document).ready(function() {

    if ( jQuery('.nggallery_input_type_<?php echo $key; ?>').val()=='select' ) jQuery('.nggallery_input_size_<?php echo $key; ?>').hide();
    else jQuery('.nggallery_input_size_<?php echo $key; ?>').show();

    jQuery('.nggallery_input_type_<?php echo $key; ?>').change(function() {
    if ( jQuery('.nggallery_input_type_<?php echo $key; ?>').val()=='select' ) jQuery('.nggallery_input_size_<?php echo $key; ?>').hide();
    else jQuery('.nggallery_input_size_<?php echo $key; ?>').show();
    });
    });

    </script>
    <?php

    }

    /*
    * create_field()
    *
    * Create the HTML interface for your field
    *
    * @param $field - an array holding all the field's data
    *
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function create_field( $field )
    {
    global $ngg, $nggdb, $wp_query;

    $this->set_field_defaults( $field );

    $values = $field[ 'value' ];

    if ( !empty($values[0]) ):

    foreach ( $values as $form ) {

    if ( in_array ( 'gallery', $form ) )
    $values_gallery[]=$form['ngg_id'];

    if ( in_array ( 'album', $form ) )
    $values_album[]=$form['ngg_id'];

    }

    endif;

    if ( class_exists('nggdb') ) :

    // Settings of NextGEN Gallery SQL query
    $limit = 0;
    $start = 0;
    $order_by = 'title';
    $order_dir = 'ASC';

    // Seek to all NextGEN Galleries
    $gallerylist = $nggdb->find_all_galleries( $order_by, $order_dir , TRUE, $limit, $start, false);
    $albumlist = $nggdb->find_all_album( 'name', $order_dir, $limit, $start);

    $haystack = array( 'select', 'multiselect' );
    if( in_array( $field[ 'input_type' ], $haystack ) ) :
    ?>
    <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>" <?php echo ( $field[ 'input_type' ] == 'multiselect' ) ? 'multiple="multiple" size="' . $field[ 'input_size' ] . '"' : ''; ?>>
    <?php if($field['allow_null'] == '1') echo '
    <option value="null"> - Select - </option>';
    ?>

    <optgroup label="<?php _e('Galleries','nggallery'); ?>">
    <?php foreach( $gallerylist as $gallery ) : ?>
    <option value="<?php echo $gallery->gid.',gallery'; ?>"<?php if ( $values_gallery ) selected( in_array( $gallery->gid, $values_gallery ) ); ?>><?php echo $gallery->title; ?></option>
    <?php endforeach; ?>
    </optgroup>
    <optgroup label="<?php _e('Albums','nggallery'); ?>">
    <?php foreach( $albumlist as $album ) : ?>
    <option value="<?php echo $album->id.',album'; ?>"<?php if ( $values_album ) selected( in_array( $album->id, $values_album ) ); ?>><?php echo $album->name; ?></option>
    <?php endforeach; ?>
    </optgroup>
    </select>
    <?php
    endif;

    else:
    ?>
    <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>">
    <option value="0" disabled="true"><?php _e( 'NextGEN Gallery plugin is not installed or activated!', $this->l10n_domain ); ?></option>
    </select>
    <?php
    endif;

    }

    /*
    * input_admin_enqueue_scripts()
    *
    * This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
    * Use this action to add css + javascript to assist your create_field() action.
    *
    * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function input_admin_enqueue_scripts()
    {
    // Note: This function can be removed if not used

    //
    // // register acf scripts
    // wp_register_script( 'acf-input-ACF_NGGallery_Field', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version'] );
    // wp_register_style( 'acf-input-ACF_NGGallery_Field', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version'] );
    //
    //
    // // scripts
    // wp_enqueue_script(array(
    // 'acf-input-ACF_NGGallery_Field',
    // ));
    //
    // // styles
    // wp_enqueue_style(array(
    // 'acf-input-ACF_NGGallery_Field',
    // ));

    }

    /*
    * input_admin_head()
    *
    * This action is called in the admin_head action on the edit screen where your field is created.
    * Use this action to add css and javascript to assist your create_field() action.
    *
    * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function input_admin_head()
    {
    // Note: This function can be removed if not used
    }

    /*
    * field_group_admin_enqueue_scripts()
    *
    * This action is called in the admin_enqueue_scripts action on the edit screen where your field is edited.
    * Use this action to add css + javascript to assist your create_field_options() action.
    *
    * $info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function field_group_admin_enqueue_scripts()
    {
    // Note: This function can be removed if not used
    }

    /*
    * field_group_admin_head()
    *
    * This action is called in the admin_head action on the edit screen where your field is edited.
    * Use this action to add css and javascript to assist your create_field_options() action.
    *
    * @info http://codex.wordpress.org/Plugin_API/Action_Reference/admin_head
    * @type action
    * @since 3.6
    * @date 23/01/13
    */

    function field_group_admin_head()
    {
    // Note: This function can be removed if not used
    }

    /*
    * load_value()
    *
    * This filter is appied to the $value after it is loaded from the db
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value found in the database
    * @param $post_id - the $post_id from which the value was loaded from
    * @param $field - the field array holding all the field options
    *
    * @return $value - the value to be saved in te database
    */

    function load_value( $value, $post_id, $field )
    {
    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * update_value()
    *
    * This filter is appied to the $value before it is updated in the db
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which will be saved in the database
    * @param $post_id - the $post_id of which the value will be saved
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function update_value( $value, $post_id, $field )
    { $this->set_field_defaults( $field );

    foreach( $value as $key=>$item ) {
    $items = explode( ',', $item );
    foreach( $items as $item ) {
    if( is_numeric( $item ) )
    $values[$key]['ngg_id'] = intval ( $item );
    else
    $values[$key]['ngg_form'] = strval( $item );
    }
    }

    // parent::update_value( $post_id, $field, $values );
    // Note: This function can be removed if not used
    return $values;
    }

    /*
    * format_value()
    *
    * This filter is appied to the $value after it is loaded from the db and before it is passed to the create_field action
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which was loaded from the database
    * @param $post_id - the $post_id from which the value was loaded
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function format_value( $value, $post_id, $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */

    // perhaps use $field['preview_size'] to alter the $value?

    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * format_value_for_api()
    *
    * This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $value - the value which was loaded from the database
    * @param $post_id - the $post_id from which the value was loaded
    * @param $field - the field array holding all the field options
    *
    * @return $value - the modified value
    */

    function format_value_for_api( $value, $post_id, $field )
    {
    // defaults?
    /*
    $field = array_merge($this->defaults, $field);
    */

    // perhaps use $field['preview_size'] to alter the $value?

    // Note: This function can be removed if not used
    return $value;
    }

    /*
    * load_field()
    *
    * This filter is appied to the $field after it is loaded from the database
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - the field array holding all the field options
    *
    * @return $field - the field array holding all the field options
    */

    function load_field( $field )
    {
    // Note: This function can be removed if not used
    return $field;
    }

    /*
    * update_field()
    *
    * This filter is appied to the $field before it is saved to the database
    *
    * @type filter
    * @since 3.6
    * @date 23/01/13
    *
    * @param $field - the field array holding all the field options
    * @param $post_id - the field group ID (post_type = acf)
    *
    * @return $field - the modified field
    */

    function update_field( $field, $post_id )
    {
    // Note: This function can be removed if not used
    return $field;
    }

    }

    // create field
    new acf_field_ACF_NGGallery_Field();

    ?>

  17. DnlCY
    Member
    Posted 10 months ago #

    Thank you very much eggproject, it works well :)

  18. mary-italy
    Member
    Posted 10 months ago #

    hello guys, I follow you from Italy, please excuse my bad english.
    I installed your plugin and also I have the same problem.
    It does not appear the Field Type "Gallery".
    I use version 3.6 of WordPress.
    What should I do?
    I need to change the file "nggallery-field.php"?
    But I do not know the php code ... is there anyone who can help me?
    mary

  19. bekabug
    Member
    Posted 10 months ago #

    This works great! Thank you eggproject!

  20. zactoff
    Member
    Posted 9 months ago #

    Thank you eggproject, you're a star!

    Just in case anyone stumbles in here looking for the answer, I've put the two files up here for downloading: http://www.zaccety.com/acf-nggf/

  21. JeroenReumkens
    Member
    Posted 9 months ago #

    I've just build a script like this from scratch. Today I released this script as a WP Plugin. So anyone who's having issues with this plugin might want to check out my new script: http://wordpress.org/plugins/advanced-custom-fields-nextgen-gallery-custom-field/.

    One note, this script only works in ACF version 4 (yet)!

  22. zactoff
    Member
    Posted 9 months ago #

    Nice work, but does that mean version 4 and above, (i.e. not backwards compatible), or does that mean it will work with 4+ (i.e. the latest vresion - 4.2.2)?

  23. JeroenReumkens
    Member
    Posted 9 months ago #

    Hi Zactoff,
    It works with version 4.0.0 + :-)

    ACF has a different add-on structure for version 3 of the plugin. That's the reason that right now I only support version 4.0.0+

    Good question though!

  24. tranman79
    Member
    Posted 8 months ago #

    Am I supposed to be doing something else once the Nextgen Gallery is chosen in the ACF of the post? All I get is "Array" as the output...

  25. JeroenReumkens
    Member
    Posted 8 months ago #

    Hi Tranman79,

    It depends on what you want to achieve. I guess you've chosen for the default setting 'NGGAllery Object (in array)'. This will give you the NGGallery object which contains everything NGGallery uses to build the gallery, to give the developer the opportunity to do with it whatever he wants.

    Next to that you can choose for 'All of the images (in array)', which provides the devloper with an array with only all of the images inside. With this he can loop through the array and build their own kind of slideshow.

    The final option is 'NGGallery id', which is what you're looking for I think. With this ID you can use the default Nextgen funtionality and create the default Nextgen Gallery.

    You can do this in your template with these lines of code:

    $galleryID = get_field('nextgen_gallery_field');
    $gallery = apply_filters('the_content', '[gallery=' . $galleryID . ']' );
    echo $gallery;

    This should output the default Nextgen gallery markup based on your selected gallery in the WordPress backend.

    I hope this answers your question!

  26. tranman79
    Member
    Posted 8 months ago #

    JeroenReumkens, Thank you for the explanation, that helps me a lot!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic