tubiz / affiliatewp-mailchimp-add-on

1 stars 0 forks source link

Newsletter List #4

Open ankurpal21 opened 4 years ago

ankurpal21 commented 4 years ago

Hyy I have an issue please help how to increase newsletter list size increase up to 100 client in single list with pagination next 100 clients. public function affwp_mailchimp_get_lists() {

        $mailchimp_api_key = affiliate_wp()->settings->get( 'affwp_mailchimp_api_key' );
        $mailchimp_api_key = trim( $mailchimp_api_key );

        if ( ! empty( $mailchimp_api_key ) ) {

            $mailchimp_lists = get_transient( 'tbz_affwp_edd_mailchimp_lists' );

            if ( false === $mailchimp_lists ) {

                if ( ! class_exists( 'TbzAffWPMailChimp' ) ) {
                    require_once plugin_dir_path( __FILE__ ) . 'classes/api/MailChimp.php';
                }

                $Mailchimp = new TbzAffWPMailChimp( $mailchimp_api_key );

                $lists = $Mailchimp->get( 'lists' );

                $lists_count = $lists['total_items'];

                if ( $lists_count >= 0 ) {

                    foreach ( $lists['lists'] as $list ) {
                        $mailchimp_lists[ $list ['id'] ] = $list['name'];
                    }

                    set_transient( 'tbz_affwp_edd_mailchimp_lists', $mailchimp_lists, 15 * MINUTE_IN_SECONDS );

                }

                return false;

            }

            return $mailchimp_lists;
        }

        return false;

    }

}

}

chriscstewart commented 4 years ago

Here's the solution I got working on my site:

`//Get MailChimp lists public function affwp_mailchimp_get_lists() {

        $mailchimp_api_key = affiliate_wp()->settings->get( 'affwp_mailchimp_api_key' );
        $mailchimp_api_key = trim( $mailchimp_api_key );

        if ( ! empty( $mailchimp_api_key ) ) {

            $mailchimp_lists = get_transient( 'tbz_affwp_edd_mailchimp_lists' );

            if ( false === $mailchimp_lists ) {

                if ( ! class_exists( 'TbzAffWPMailChimp' ) ) {
                    require_once plugin_dir_path( __FILE__ ) . 'classes/api/MailChimp.php';
                }

                $Mailchimp = new TbzAffWPMailChimp( $mailchimp_api_key );
                $lists = $Mailchimp->get('lists?count=100');

                $lists_count = $lists['total_items'];

                if ( $lists_count >= 20 ) {

                    foreach ( $lists['lists'] as $list ) {
                        $mailchimp_lists[ $list ['id'] ] = $list['name'];
                    }

                    set_transient( 'tbz_affwp_edd_mailchimp_lists', $mailchimp_lists, 5 * MINUTE_IN_SECONDS );

                }

                return false;

            }

            return $mailchimp_lists;
        }

        return false;

    }`