start_controls_section( 'give_totals_settings', [ 'label' => __('GiveWP Totals Widget', 'give'), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'forms', [ 'label' => __('Forms', 'give'), 'type' => \Elementor\Controls_Manager::SELECT2, 'description' => __('Choose the forms you want to combine in this total.', 'give'), 'separator' => 'after', 'options' => $this->getDonationForms(), 'multiple' => true, 'default' => '', ] ); $this->add_control( 'total_goal', [ 'label' => __('Goal Amount', 'give'), 'type' => \Elementor\Controls_Manager::TEXT, 'description' => __('Designate a goal amount.', 'give'), 'default' => '10000' ] ); $this->add_control( 'message', [ 'label' => __('Message:', 'give'), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'description' => __('(Optional) The total goal you want to reflect in your message.', 'give'), 'default' => __('Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give'), ] ); $this->add_control( 'link', [ 'label' => __('Link', 'give'), 'type' => \Elementor\Controls_Manager::URL, 'description' => __('The url of where you want to link donors to encourage them to donate toward the goal.', 'give'), 'show_external' => false, 'default' => [ 'url' => 'https://example.org', 'is_external' => false, 'nofollow' => false, ], ] ); $this->add_control( 'link_text', [ 'label' => __('Link Text', 'give'), 'type' => \Elementor\Controls_Manager::TEXTAREA, 'description' => __('The text you want to hyperlink with your link.', 'give'), 'default' => __('Donate Now', 'give'), ] ); $this->add_control( 'show_progress', [ 'label' => __('Show Progress', 'give'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'description' => __('Show or hide a the progress bar.', 'give'), 'label_on' => __('Show', 'give'), 'label_off' => __('Hide', 'give'), 'default' => 'yes' ] ); $this->add_control( 'cats', [ 'label' => __('Categories', 'give'), 'type' => \Elementor\Controls_Manager::TEXT, 'description' => __('Comma separated list of GiveWP category IDs you want to combine into this total.', 'give'), ] ); $this->add_control( 'tags', [ 'label' => __('Tags', 'give'), 'type' => \Elementor\Controls_Manager::TEXT, 'description' => __('Comma separated list of GiveWP tag IDs you want to combine into this total.', 'give'), ] ); $this->add_control( 'give_totals_info', [ 'label' => '', 'type' => \Elementor\Controls_Manager::RAW_HTML, 'content_classes' => 'give-info', 'raw' => '

' . __('GIVEWP TOTALS WIDGET', 'give') . '

' . __('This is the GiveWP Totals widget. Use this to display a total of one or many forms.', 'give') . '

' ] ); $this->end_controls_section(); } /** * Render the [give_totals] output on the frontend. * * Written in PHP and used to generate the final HTML. * * @since 4.7.0 migrated from givewp-elementor-widgets * @access protected */ protected function render() { $settings = $this->get_settings_for_display(); $goal = esc_html($settings['total_goal']); $message = esc_html($settings['message']); $link = esc_url($settings['link']['url']); $linkText = esc_html($settings['link_text']); $showProgress = ('yes' === $settings['show_progress'] ? 'progress_bar="true"' : 'progress_bar="false"'); $cats = esc_html($settings['cats']); $tags = esc_html($settings['tags']); $html = do_shortcode(' [give_totals ids="' . implode(',', $settings['forms']) . '" total_goal="' . $goal . '" message="' . $message . '" link_text="' . $linkText . '" link="' . $link . '" ' . $showProgress . ' cats="' . $cats . '" tags="' . $tags . '"]' ); echo '
'; echo $html; echo '
'; } /** * Get donation forms * * @since 4.7.0 migrated from givewp-elementor-widgets * * @return array */ private function getDonationForms() { $options = []; $forms = DB::table('posts') ->select('ID', 'post_title') ->where('post_type', 'give_forms') ->where('post_status', 'publish') ->getAll(); foreach ($forms as $form) { $options[$form->ID] = $form->post_title; } return $options; } }