resources
11 months ago
DonationHistoryWidget.php
1 year ago
DonationReceiptWidget.php
1 year ago
GiveDonorWallWidget.php
1 year ago
GiveFormGridWidget.php
11 months ago
GiveFormWidget.php
11 months ago
GiveGoalWidget.php
1 year ago
GiveLoginWidget.php
1 year ago
GiveMultiFormGoalWidget.php
1 year ago
GiveProfileEditorWidget.php
1 year ago
GiveRegisterWidget.php
1 year ago
GiveSubscriptionsWidget.php
1 year ago
GiveTotalsWidget.php
1 year ago
GiveFormGridWidget.php
485 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ThirdPartySupport\Elementor\Widgets\V1; |
| 4 | |
| 5 | use Elementor\Widget_Base; |
| 6 | |
| 7 | /** |
| 8 | * Elementor Give Form Grid Widget. |
| 9 | * |
| 10 | * Elementor widget that inserts the GiveWP [give_form_grid] shortcode to output a form total with options. |
| 11 | * |
| 12 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 13 | */ |
| 14 | |
| 15 | class GiveFormGridWidget extends Widget_Base |
| 16 | { |
| 17 | /** |
| 18 | * Get widget name. |
| 19 | * |
| 20 | * Retrieve Give Form Grid widget name. |
| 21 | * |
| 22 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 23 | * @access public |
| 24 | * |
| 25 | * @return string Widget name. |
| 26 | */ |
| 27 | public function get_name() |
| 28 | { |
| 29 | return 'GiveWP_Form_Grid'; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Get widget title. |
| 34 | * |
| 35 | * Retrieve Give Form Grid widget title. |
| 36 | * |
| 37 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 38 | * @access public |
| 39 | * |
| 40 | * @return string Widget title. |
| 41 | */ |
| 42 | public function get_title() |
| 43 | { |
| 44 | return __('Give Form Grid (Legacy)', 'give'); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get widget icon. |
| 49 | * |
| 50 | * Retrieve Give Form Grid widget icon. |
| 51 | * |
| 52 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 53 | * @access public |
| 54 | * |
| 55 | * @return string Widget icon. |
| 56 | */ |
| 57 | public function get_icon() |
| 58 | { |
| 59 | return 'give-icon'; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Get widget categories. |
| 64 | * |
| 65 | * Retrieve the list of categories the Give Form Grid widget belongs to. |
| 66 | * |
| 67 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 68 | * @access public |
| 69 | * |
| 70 | * @return array Widget categories. |
| 71 | */ |
| 72 | public function get_categories() |
| 73 | { |
| 74 | return ['givewp-category-legacy']; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Widget inner wrapper. |
| 79 | * |
| 80 | * Use optimized DOM structure, without the inner wrapper. |
| 81 | * |
| 82 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 83 | * @access public |
| 84 | */ |
| 85 | public function has_widget_inner_wrapper(): bool |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Register Give Form Grid widget controls. |
| 92 | * |
| 93 | * Adds different input fields to allow the user to change and customize the widget settings. |
| 94 | * |
| 95 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 96 | * @access protected |
| 97 | */ |
| 98 | protected function register_controls() |
| 99 | { |
| 100 | $this->start_controls_section( |
| 101 | 'give_form_grid_settings', |
| 102 | [ |
| 103 | 'label' => __('GiveWP Form Grid Widget', 'give'), |
| 104 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 105 | ] |
| 106 | ); |
| 107 | |
| 108 | $this->add_control( |
| 109 | 'forms_cats_tags', |
| 110 | [ |
| 111 | 'label' => __('Collection Method', 'give'), |
| 112 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 113 | 'description' => __('Would you like to show forms by ID, by their Categories, or by their Tags?', 'give'), |
| 114 | 'options' => [ |
| 115 | 'forms' => __('Forms', 'give'), |
| 116 | 'cats' => __('Categories', 'give'), |
| 117 | 'tags' => __('Tags', 'give'), |
| 118 | ], |
| 119 | 'default' => 'forms', |
| 120 | ] |
| 121 | ); |
| 122 | |
| 123 | $this->add_control( |
| 124 | 'all_forms', |
| 125 | [ |
| 126 | 'label' => __('Show All Forms?', 'give'), |
| 127 | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 128 | 'description' => __('Do you want to show all forms in your grid?', 'give'), |
| 129 | 'options' => [ |
| 130 | 'yes' => [ |
| 131 | 'title' => __('Yes', 'give'), |
| 132 | 'icon' => 'fa fa-check', |
| 133 | ], |
| 134 | 'no' => [ |
| 135 | 'title' => __('No', 'give'), |
| 136 | 'icon' => 'fa fa-times-circle', |
| 137 | ], |
| 138 | ], |
| 139 | 'default' => 'yes', |
| 140 | 'toggle' => true, |
| 141 | 'condition' => [ |
| 142 | 'forms_cats_tags' => 'forms' |
| 143 | ] |
| 144 | ] |
| 145 | ); |
| 146 | |
| 147 | $this->add_control( |
| 148 | 'form_ids', |
| 149 | [ |
| 150 | 'label' => __('Show by Form IDs', 'give'), |
| 151 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 152 | 'description' => __('Place the form IDs you\'d like to show in your grid here, separated by commas.', 'give'), |
| 153 | 'condition' => [ |
| 154 | 'all_forms' => 'no', |
| 155 | 'forms_cats_tags' => 'forms' |
| 156 | ] |
| 157 | ] |
| 158 | ); |
| 159 | |
| 160 | $this->add_control( |
| 161 | 'cats', |
| 162 | [ |
| 163 | 'label' => __('Show by Form Categories', 'give'), |
| 164 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 165 | 'description' => __('Place the form category IDs you\'d like to show in your grid here, separated by commas.', 'give'), |
| 166 | 'condition' => [ |
| 167 | 'forms_cats_tags' => 'cats' |
| 168 | ] |
| 169 | ] |
| 170 | ); |
| 171 | |
| 172 | $this->add_control( |
| 173 | 'tags', |
| 174 | [ |
| 175 | 'label' => __('Show by Form Tags', 'give'), |
| 176 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 177 | 'description' => __('Place the form category IDs you\'d like to show in your grid here, separated by commas.', 'give'), |
| 178 | 'condition' => [ |
| 179 | 'forms_cats_tags' => 'tags' |
| 180 | ] |
| 181 | ] |
| 182 | ); |
| 183 | |
| 184 | $this->add_control( |
| 185 | 'exclude', |
| 186 | [ |
| 187 | 'label' => __('Exclude Forms', 'give'), |
| 188 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 189 | 'description' => __('List the form IDs that you want excluded from this Form Grid.', 'give'), |
| 190 | ] |
| 191 | ); |
| 192 | |
| 193 | $this->add_control( |
| 194 | 'forms_per_page', |
| 195 | [ |
| 196 | 'label' => __('Forms Per Page', 'give'), |
| 197 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 198 | 'description' => __('The number of forms to show in the grid before the "Load More" button appears.', 'give'), |
| 199 | 'options' => [ |
| 200 | '1' => '1', |
| 201 | '2' => '2', |
| 202 | '3' => '3', |
| 203 | '4' => '4', |
| 204 | '5' => '5', |
| 205 | '6' => '6', |
| 206 | '7' => '7', |
| 207 | '8' => '8', |
| 208 | '9' => '9', |
| 209 | '10' => '10', |
| 210 | '11' => '11', |
| 211 | '12' => '12', |
| 212 | ], |
| 213 | 'default' => '12' |
| 214 | ] |
| 215 | ); |
| 216 | |
| 217 | $this->add_control( |
| 218 | 'paged', |
| 219 | [ |
| 220 | 'label' => __('Show Pagination', 'give'), |
| 221 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 222 | 'label_on' => __('Show', 'give'), |
| 223 | 'label_off' => __('Hide', 'give'), |
| 224 | 'default' => 'yes', |
| 225 | ] |
| 226 | ); |
| 227 | |
| 228 | $this->add_control( |
| 229 | 'orderby', |
| 230 | [ |
| 231 | 'label' => __('Order By', 'give'), |
| 232 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 233 | 'description' => __('The element which the order will be determined by.', 'give'), |
| 234 | 'options' => [ |
| 235 | 'date' => __('Date Created', 'give'), |
| 236 | 'title' => __('Form Name', 'give'), |
| 237 | 'amount_donated' => __('Amount Donated', 'give'), |
| 238 | 'number_donations' => __('Number of Donations', 'give'), |
| 239 | 'menu_order' => __('Menu Order', 'give'), |
| 240 | 'post__in' => __('Form ID', 'give'), |
| 241 | 'closest_to_goal' => __('Closest to Goal', 'give'), |
| 242 | ], |
| 243 | 'default' => 'date' |
| 244 | ] |
| 245 | ); |
| 246 | |
| 247 | $this->add_control( |
| 248 | 'order', |
| 249 | [ |
| 250 | 'label' => __('Order By', 'give'), |
| 251 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 252 | 'description' => __('The order the donors will be displayed in according to the "Order By" field chosen.', 'give'), |
| 253 | 'options' => [ |
| 254 | 'desc' => __('Descending', 'give'), |
| 255 | 'asc' => __('Ascending', 'give') |
| 256 | ], |
| 257 | 'default' => 'desc' |
| 258 | ] |
| 259 | ); |
| 260 | |
| 261 | $this->add_control( |
| 262 | 'columns', |
| 263 | [ |
| 264 | 'label' => __('Number of Columns', 'give'), |
| 265 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 266 | 'description' => __('The number of columns to display. Note that "Best Fit" will always stretch to fill the available width that the donor wall is placed within.', 'give'), |
| 267 | 'options' => [ |
| 268 | 'best-fit' => __('Best Fit', 'give'), |
| 269 | '1' => '1', |
| 270 | '2' => '2', |
| 271 | '3' => '3', |
| 272 | '4' => '4', |
| 273 | ], |
| 274 | 'default' => 'best-fit' |
| 275 | ] |
| 276 | ); |
| 277 | |
| 278 | $this->add_control( |
| 279 | 'show_title', |
| 280 | [ |
| 281 | 'label' => __('Show Form Title', 'give'), |
| 282 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 283 | 'description' => __('Show/Hide the form title.', 'give'), |
| 284 | 'label_on' => __('Show', 'give'), |
| 285 | 'label_off' => __('Hide', 'give'), |
| 286 | 'default' => 'yes', |
| 287 | ] |
| 288 | ); |
| 289 | |
| 290 | $this->add_control( |
| 291 | 'show_excerpt', |
| 292 | [ |
| 293 | 'label' => __('Show Form Excerpt', 'give'), |
| 294 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 295 | 'description' => __('Show/Hide the form excerpt.', 'give'), |
| 296 | 'label_on' => __('Show', 'give'), |
| 297 | 'label_off' => __('Hide', 'give'), |
| 298 | 'default' => 'yes', |
| 299 | ] |
| 300 | ); |
| 301 | |
| 302 | $this->add_control( |
| 303 | 'excerpt_length', |
| 304 | [ |
| 305 | 'label' => __('Excerpt Length', 'give'), |
| 306 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 307 | 'description' => __('Excerpt Length.', 'give'), |
| 308 | 'condition' => [ |
| 309 | 'show_excerpt' => 'yes' |
| 310 | ] |
| 311 | ] |
| 312 | ); |
| 313 | |
| 314 | $this->add_control( |
| 315 | 'show_goal', |
| 316 | [ |
| 317 | 'label' => __('Show Form Goal', 'give'), |
| 318 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 319 | 'description' => __('Show/Hide the form goal.', 'give'), |
| 320 | 'label_on' => __('Show', 'give'), |
| 321 | 'label_off' => __('Hide', 'give'), |
| 322 | 'default' => 'yes', |
| 323 | ] |
| 324 | ); |
| 325 | |
| 326 | $this->add_control( |
| 327 | 'show_featured_image', |
| 328 | [ |
| 329 | 'label' => __('Show Form Featured Image', 'give'), |
| 330 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 331 | 'description' => __('Show/Hide the form featured image.', 'give'), |
| 332 | 'label_on' => __('Show', 'give'), |
| 333 | 'label_off' => __('Hide', 'give'), |
| 334 | 'default' => 'yes', |
| 335 | ] |
| 336 | ); |
| 337 | |
| 338 | $this->add_control( |
| 339 | 'image_size', |
| 340 | [ |
| 341 | 'label' => __('Image Size', 'give'), |
| 342 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 343 | 'description' => __('Featured image size. Default "medium". Accepts WordPress image sizes.', 'give'), |
| 344 | 'condition' => [ |
| 345 | 'show_featured_image' => 'yes' |
| 346 | ] |
| 347 | ] |
| 348 | ); |
| 349 | |
| 350 | $this->add_control( |
| 351 | 'image_height', |
| 352 | [ |
| 353 | 'label' => __('Image Height', 'give'), |
| 354 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 355 | 'description' => __('Featured image height. Default "auto". Accepts valid CSS heights', 'give'), |
| 356 | 'condition' => [ |
| 357 | 'show_featured_image' => 'yes' |
| 358 | ] |
| 359 | ] |
| 360 | ); |
| 361 | |
| 362 | $this->add_control( |
| 363 | 'show_donate_button', |
| 364 | [ |
| 365 | 'label' => __('Show Donate Button', 'give'), |
| 366 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 367 | 'label_on' => __('Show', 'give'), |
| 368 | 'label_off' => __('Hide', 'give'), |
| 369 | 'default' => 'yes', |
| 370 | ] |
| 371 | ); |
| 372 | |
| 373 | $this->add_control( |
| 374 | 'donate_button_text_color', |
| 375 | [ |
| 376 | 'label' => __('Donate Button Text Color', 'give'), |
| 377 | 'type' => \Elementor\Controls_Manager::COLOR, |
| 378 | 'default' => '#69B86B', |
| 379 | 'condition' => [ |
| 380 | 'show_donate_button' => 'yes' |
| 381 | ], |
| 382 | ] |
| 383 | ); |
| 384 | |
| 385 | $this->add_control( |
| 386 | 'display_style', |
| 387 | [ |
| 388 | 'label' => __('Display Type', 'give'), |
| 389 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 390 | 'description' => __('Choose the behavior when a form is clicked on within the grid.', 'give'), |
| 391 | 'options' => [ |
| 392 | 'redirect' => __('Redirect to the single Form Page.', 'give'), |
| 393 | 'modal_reveal' => __('Open the form in a modal window.', 'give'), |
| 394 | ], |
| 395 | 'default' => 'redirect' |
| 396 | ] |
| 397 | ); |
| 398 | |
| 399 | $this->add_control( |
| 400 | 'give_form_grid_info', |
| 401 | [ |
| 402 | 'label' => '', |
| 403 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 404 | 'content_classes' => 'give-info', |
| 405 | 'raw' => ' |
| 406 | <div class="give"> |
| 407 | <p class="info-head"> |
| 408 | ' . __('GIVEWP FORM GRID WIDGET', 'give') . '</p> |
| 409 | <p class="info-message">' . __('This is the GiveWP Form Grid widget. Choose the elements you want to see appear in the form grid.', 'give') . '</p> |
| 410 | <p class="give-docs-links"> |
| 411 | <a href="https://givewp.com/documentation/core/shortcodes/give_form_grid/?utm_source=plugin_settings&utm_medium=referral&utm_campaign=Free_Addons&utm_content=givelementor" rel="noopener noreferrer" target="_blank"><i class="fa fa-book" aria-hidden="true"></i>' . __('Visit the GiveWP Docs for more info on the GiveWP Form Grid.', 'give') . '</a> |
| 412 | </p> |
| 413 | </div>' |
| 414 | ] |
| 415 | ); |
| 416 | |
| 417 | $this->end_controls_section(); |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Render the [give_form_grid] output on the frontend. |
| 422 | * |
| 423 | * Written in PHP and used to generate the final HTML. |
| 424 | * |
| 425 | * @since 4.7.0 migrated from givewp-elementor-widgets |
| 426 | * @access protected |
| 427 | */ |
| 428 | protected function render() |
| 429 | { |
| 430 | global $give_receipt_args, $donation; |
| 431 | |
| 432 | $settings = $this->get_settings_for_display(); |
| 433 | |
| 434 | $forms = ('yes' === $settings['all_forms'] ? '' : $settings['form_ids']); |
| 435 | $formsPerPage = esc_html($settings['forms_per_page']); |
| 436 | $paged = esc_html($settings['paged']); |
| 437 | $columns = esc_html($settings['columns']); |
| 438 | $orderby = esc_html($settings['orderby']); |
| 439 | $order = esc_html($settings['order']); |
| 440 | $exclude = esc_html($settings['exclude']); |
| 441 | $cats = esc_html($settings['cats']); |
| 442 | $tags = esc_html($settings['tags']); |
| 443 | $showTitle = esc_html($settings['show_title']); |
| 444 | $showGoal = esc_html($settings['show_goal']); |
| 445 | $showExcerpt = esc_html($settings['show_excerpt']); |
| 446 | $excerptLength = esc_html($settings['excerpt_length']); |
| 447 | $showFeaturedImage = esc_html($settings['show_featured_image']); |
| 448 | $displayStyle = esc_html($settings['display_style']); |
| 449 | $imageSize = esc_html($settings['image_size']); |
| 450 | $imageHeight = esc_html($settings['image_height']); |
| 451 | $showDonateButton = esc_html($settings['show_donate_button']); |
| 452 | $buttonTextColor = esc_html($settings['donate_button_text_color']); |
| 453 | |
| 454 | $html = do_shortcode(' |
| 455 | [give_form_grid |
| 456 | forms_per_page="' . $formsPerPage . '" |
| 457 | paged="' . $paged . '" |
| 458 | ids="' . $forms . '" |
| 459 | columns="' . $columns . '" |
| 460 | order="' . $order . '" |
| 461 | exclude="' . $exclude . '" |
| 462 | cats="' . $cats . '" |
| 463 | tags="' . $tags . '" |
| 464 | show_title="' . $showTitle . '" |
| 465 | show_goal="' . $showGoal . '" |
| 466 | show_excerpt="' . $showExcerpt . '" |
| 467 | excerpt_length="' . $excerptLength . '" |
| 468 | show_featured_image="' . $showFeaturedImage . '" |
| 469 | image_size="' . $imageSize . '" |
| 470 | image_height="' . $imageHeight . '" |
| 471 | show_donate_button="' . $showDonateButton . '" |
| 472 | donate_button_text_color="' . $buttonTextColor . '" |
| 473 | display_style="' . $displayStyle . '" |
| 474 | orderby="' . $orderby . |
| 475 | '"]' |
| 476 | ); |
| 477 | |
| 478 | echo '<div class="givewp-elementor-widget give-form-grid-shortcode-wrap">'; |
| 479 | |
| 480 | echo $html; |
| 481 | |
| 482 | echo '</div>'; |
| 483 | } |
| 484 | } |
| 485 |