[Back to Docs]

tweet-boost-pro/acf-field-group

Filters our ACF(Advanced Custom Fields) powered fields. You can use this filter to change location rules.

Here’s an simplified example of how we are using this filter to define where two of our field groups are placed:

/**
 * Class crafted to illustrate the `tweet-boost-pro/acf-field-group` filter, designed for altering ACF Field Group Arrays
 */
class Tweet_Boost_Extend_Locations_Example {

        /**
         * Initialize class
         * @return {[type]} [description]
         */
        public function __construct(){
            self::load_hooks();
        }

        /**
         * Loads hooks and filters
         * @return {[type]} [description]
         */
        public static function load_hooks(){
         
            /* adds default + extended location rules */
            add_filter('tweet-boost-pro/acf-field-group' , array( __CLASS__ , 'extend_acf_locations' ) , 10 , 1 );
        
        }

        /**
         * Alters location  of our ACF Field Groups
         */
        public static function extend_acf_locations( $field_group ) {

            /* Get white listed post types */
            $white_listed_post_types = apply_filters('tweet-boost-pro/registered-post-types' , array(
                'post' , 'page'
            ));

            /* Tweet Schedule Creation - (Where we add/manage tweets) */
            if ($field_group['key'] == 'group_5989061655cc1' ) {

                foreach ($white_listed_post_types as $type ) {
                    $field_group['location'][] =  array(
                        array(
                            'param' => 'post_type',
                            'operator' => '==',
                            'value' => $type,
                        )
                    );
                }
            }

            /* Tweet Campaign Management (Where we setup campaign behavior nature) */
            if ($field_group['key'] == 'group_59b9c1a9001b0' ) {

                foreach ($white_listed_post_types as $type ) {
                    /* adding management support for editors */
                    $field_group['location'][] =  array(
                        array(
                            'param' => 'post_type',
                            'operator' => '==',
                            'value' => $type,
                        ),
                        array(
                            'param' => 'current_user_role',
                            'operator' => '==',
                            'value' => 'editor'
                        ),
                    );

                     /* adding management support for administrators */
                    $field_group['location'][] =  array(
                        array(
                            'param' => 'post_type',
                            'operator' => '==',
                            'value' => $type,
                        ),
                        array(
                            'param' => 'current_user_role',
                            'operator' => '==',
                            'value' => 'administrator'
                        ),
                    );
                }
            }

            return $field_group;
        }
} 

/* initiate our class */
new Tweet_Boost_Extend_Locations_Example;