resources
10 months ago
DonationHistoryWidget.php
10 months ago
DonationReceiptWidget.php
10 months ago
GiveDonorWallWidget.php
10 months ago
GiveFormGridWidget.php
9 months ago
GiveFormWidget.php
10 months ago
GiveGoalWidget.php
10 months ago
GiveLoginWidget.php
10 months ago
GiveMultiFormGoalWidget.php
10 months ago
GiveProfileEditorWidget.php
10 months ago
GiveRegisterWidget.php
10 months ago
GiveSubscriptionsWidget.php
10 months ago
GiveTotalsWidget.php
10 months ago
GiveMultiFormGoalWidget.php
238 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ThirdPartySupport\Elementor\Widgets\V1; |
| 4 | |
| 5 | use Give\MultiFormGoals\MultiFormGoal\Shortcode; |
| 6 | use Elementor\Widget_Base; |
| 7 | |
| 8 | /** |
| 9 | * Elementor Give Multi Form Goal Widget. |
| 10 | * |
| 11 | * Elementor widget that inserts the GiveWP [give_multi_form_goal] shortcode to output a Give Multi Form Goal. |
| 12 | * |
| 13 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 14 | */ |
| 15 | |
| 16 | class GiveMultiFormGoalWidget extends Widget_Base |
| 17 | { |
| 18 | /** |
| 19 | * GiveMultiFormGoalWidget constructor. |
| 20 | * |
| 21 | * @param array $data |
| 22 | * @param null $args |
| 23 | */ |
| 24 | /** |
| 25 | * Get widget name. |
| 26 | * |
| 27 | * Retrieve Give Multi Form Goal widget name. |
| 28 | * |
| 29 | * @access public |
| 30 | * |
| 31 | * @return string Widget name. |
| 32 | */ |
| 33 | public function get_name() |
| 34 | { |
| 35 | return 'Give Multi Form Goal'; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get widget title. |
| 40 | * |
| 41 | * Retrieve Give Multi Form Goal widget title. |
| 42 | * |
| 43 | * @access public |
| 44 | * |
| 45 | * @return string Widget title. |
| 46 | */ |
| 47 | public function get_title() |
| 48 | { |
| 49 | return __('Give Multi Form Goal (Legacy)', 'give'); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get widget icon. |
| 54 | * |
| 55 | * Retrieve Give Multi Form Goal widget icon. |
| 56 | * |
| 57 | * @access public |
| 58 | * |
| 59 | * @return string Widget icon. |
| 60 | */ |
| 61 | public function get_icon() |
| 62 | { |
| 63 | return 'give-icon'; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get widget categories. |
| 68 | * |
| 69 | * Retrieve the list of categories the Give Multi Form Goal widget belongs to. |
| 70 | * |
| 71 | * @access public |
| 72 | * |
| 73 | * @return array Widget categories. |
| 74 | */ |
| 75 | public function get_categories() |
| 76 | { |
| 77 | return ['givewp-category-legacy']; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Widget inner wrapper. |
| 82 | * |
| 83 | * Use optimized DOM structure, without the inner wrapper. |
| 84 | * |
| 85 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 86 | * @access public |
| 87 | */ |
| 88 | public function has_widget_inner_wrapper(): bool |
| 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Goal Give Multi Form Goal widget controls. |
| 95 | * |
| 96 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 97 | * |
| 98 | * @access protected |
| 99 | */ |
| 100 | protected function register_controls() |
| 101 | { |
| 102 | $this->start_controls_section( |
| 103 | 'give_multi_form_goal_settings', |
| 104 | [ |
| 105 | 'label' => esc_html__('Give Multi Form Goal Widget', 'give'), |
| 106 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 107 | ] |
| 108 | ); |
| 109 | |
| 110 | $this->add_control( |
| 111 | 'ids', |
| 112 | [ |
| 113 | 'label' => esc_html__('Donation Form IDs', 'give'), |
| 114 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 115 | 'description' => esc_html__('Choose the IDs of the forms you want to display in the multi-form goal. Display all the forms (default), a single form ID, or a comma-separated list of IDs', 'give'), |
| 116 | 'default' => '', |
| 117 | ] |
| 118 | ); |
| 119 | |
| 120 | if (give_get_option('tags') === 'enabled') { |
| 121 | $this->add_control( |
| 122 | 'tags', |
| 123 | [ |
| 124 | 'label' => esc_html__('Tags', 'give'), |
| 125 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 126 | 'description' => esc_html__('If you have tags enabled in GiveWP, you can list the category IDs that you want displayed in this grid. A comma-separated list of form tag IDs will cause the grid to include only forms with those tags.', |
| 127 | 'give'), |
| 128 | 'default' => '', |
| 129 | ] |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | if (give_get_option('categories') === 'enabled') { |
| 134 | $this->add_control( |
| 135 | 'categories', |
| 136 | [ |
| 137 | 'label' => esc_html__('Categories', 'give'), |
| 138 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 139 | 'description' => esc_html__('If you have categories enabled in GiveWP, you can list the category IDs that you want displayed in this grid. A comma-separated list of form category IDs will cause the grid to include only forms from those categories', 'give'), |
| 140 | 'default' => '', |
| 141 | ] |
| 142 | ); |
| 143 | } |
| 144 | |
| 145 | $this->add_control( |
| 146 | 'goal', |
| 147 | [ |
| 148 | 'label' => esc_html__('Goal Amount', 'give'), |
| 149 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 150 | 'description' => esc_html__('Choose the goal amount to be displayed in the multi-form goal card.', 'give'), |
| 151 | 'default' => '1000', |
| 152 | ] |
| 153 | ); |
| 154 | |
| 155 | $this->add_control( |
| 156 | 'enddate', |
| 157 | [ |
| 158 | 'label' => esc_html__('End Date', 'give'), |
| 159 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 160 | 'description' => esc_html__('Define when the multi-form goal should come to an end.', 'give'), |
| 161 | 'default' => '', |
| 162 | ] |
| 163 | ); |
| 164 | |
| 165 | $this->add_control( |
| 166 | 'color', |
| 167 | [ |
| 168 | 'label' => esc_html__('Color', 'give'), |
| 169 | 'type' => \Elementor\Controls_Manager::COLOR, |
| 170 | 'description' => esc_html__('Choose the primary color of the multi-form goal card', 'give'), |
| 171 | 'default' => '#28c77b', |
| 172 | ] |
| 173 | ); |
| 174 | |
| 175 | $this->add_control( |
| 176 | 'heading', |
| 177 | [ |
| 178 | 'label' => esc_html__('Heading Title', 'give'), |
| 179 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 180 | 'description' => esc_html__('Choose the heading to be displayed on the multi-form goal card.', 'give'), |
| 181 | 'default' => 'Example Heading', |
| 182 | ] |
| 183 | ); |
| 184 | |
| 185 | $this->add_control( |
| 186 | 'image', |
| 187 | [ |
| 188 | 'label' => esc_html__('Featured Image of the Card', 'give'), |
| 189 | 'type' => \Elementor\Controls_Manager::MEDIA, |
| 190 | 'description' => esc_html__('Choose the image URL of the multi-form goal card.', 'give'), |
| 191 | 'default' => [ |
| 192 | 'url' => GIVE_PLUGIN_URL . 'assets/dist/images/onboarding-preview-form-image.min.jpg', |
| 193 | ] |
| 194 | ] |
| 195 | ); |
| 196 | |
| 197 | $this->add_control( |
| 198 | 'summary', |
| 199 | [ |
| 200 | 'label' => esc_html__('Summary', 'give'), |
| 201 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 202 | 'description' => esc_html__('Choose the summary text placed below the heading title.', 'give'), |
| 203 | 'default' => 'This is a summary.', |
| 204 | ] |
| 205 | ); |
| 206 | |
| 207 | $this->end_controls_section(); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Render the [give_multi_form_goal] output on the frontend. |
| 212 | * |
| 213 | * Written in PHP and used to generate the final HTML. |
| 214 | * |
| 215 | * @access protected |
| 216 | */ |
| 217 | protected function render() |
| 218 | { |
| 219 | $settings = $this->get_settings_for_display(); |
| 220 | |
| 221 | $attributes = [ |
| 222 | 'ids' => isset($settings['ids']) ? esc_attr($settings['ids']) : '', |
| 223 | 'tags' => isset($settings['tags']) ? esc_attr($settings['tags']) : '', |
| 224 | 'categories' => isset($settings['categories']) ? esc_attr($settings['categories']) : '', |
| 225 | 'goal' => isset($settings['goal']) ? (int) $settings['goal'] : 1000, |
| 226 | 'color' => isset($settings['color']) ? esc_attr($settings['color']) : '#28c77b', |
| 227 | 'enddate' => isset($settings['enddate']) ? esc_attr($settings['enddate']) : '', |
| 228 | 'heading' => isset($settings['heading']) ? esc_html($settings['heading']) : '', |
| 229 | 'image' => isset($settings['image']['url']) ? esc_url($settings['image']['url']) : GIVE_PLUGIN_URL . 'assets/dist/images/onboarding-preview-form-image.min.jpg', |
| 230 | 'summary' => isset($settings['summary']) ? esc_html($settings['summary']) : 'This is a summary.', |
| 231 | ]; |
| 232 | |
| 233 | $shortcode = new Shortcode(); |
| 234 | |
| 235 | printf('<div class="givewp-elementor-widget give-multi-form-goal-wrap">%s</div>', $shortcode->renderCallback($attributes)); |
| 236 | } |
| 237 | } |
| 238 |