Changeset 3330938
- Timestamp:
- 07/20/2025 02:04:42 PM (7 months ago)
- Location:
- shortcode-for-mobilizeamerica-api
- Files:
-
- 10 added
- 4 edited
-
tags/1.0.10/readme.txt (modified) (2 diffs)
-
tags/1.0.11 (added)
-
tags/1.0.11/css (added)
-
tags/1.0.11/css/shortcode-for-mobilizeamerica-api.css (added)
-
tags/1.0.11/includes (added)
-
tags/1.0.11/includes/elementor-widget.php (added)
-
tags/1.0.11/index.php (added)
-
tags/1.0.11/readme.txt (added)
-
tags/1.0.11/shortcode-for-mobilizeamerica-api.php (added)
-
tags/1.0.11/templates (added)
-
tags/1.0.11/templates/event-templates.php (added)
-
trunk/includes/elementor-widget.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (4 diffs)
-
trunk/shortcode-for-mobilizeamerica-api.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shortcode-for-mobilizeamerica-api/tags/1.0.10/readme.txt
r3302879 r3330938 13 13 The shortcode / elementor widget passes a specificed organization id, a start date and a variable about virtual events. 14 14 This service is provided by MobilizeAmerica - https://api.mobilize.us 15 [API Documentation](https://github.com/mobilizeamerica/api)16 [Mobilize Terms of Use](https://join.mobilize.us/terms-of-service/)17 [MobilizePrivacy Policy](https://join.mobilize.us/privacy-policy/)15 * [API Documentation](https://github.com/mobilizeamerica/api) 16 * [Mobilize Terms of Use](https://join.mobilize.us/terms-of-service/) 17 * [MobilizePrivacy Policy](https://join.mobilize.us/privacy-policy/) 18 18 19 19 ## Description … … 30 30 Attributes 31 31 The shortcode accepts the following attributes: 32 * **organization_id (required):** The ID of the organization whose events you want to display. You can find this ID on Mobilize America. https://www.mobilize.us/dashboard/YOUR-ORGANIZATION/settings/33 * timeslot_start:(optional): Suggested: gte_now which is greater than now - Unix timestamp to filter events. Only shows events withtimeslots starting after this date.34 * timeslot_end:(optional): Unix timestamp to filter events. Only shows events with timeslots starting before this date.32 * **organization_id (required):** The ID of the organization whose events you want to display. You can find this ID on Mobilize America. https://www.mobilize.us/dashboard/YOUR-ORGANIZATION/settings/ 33 * **timeslot_start:** (optional): Suggested: gte_now which is greater than now - Unix timestamp to filter events. Only shows events withtimeslots starting after this date. 34 * **timeslot_end:** (optional): Unix timestamp to filter events. Only shows events with timeslots starting before this date. 35 35 Note: For timeslot please use comparison text - The comparison operators are ≥ gte, > gt, ≤ lte, < lt 36 * event_type: (optional):Filters events by event type.37 * zipcode: (optional):Filters events by zipcode.38 * radius: (optional):Filters events by a radius around the zipcode.39 * limit: (optional):The maximum number of events to display. Default is 10.40 * template:(optional): The template to use for displaying events. Available options are:41 ** default:Displays events in a list format.42 ** card:Displays events in a card format.43 * show_description:(optional): Show or hide the event description. Default is true. Options are:44 ** true:Show the description.45 ** false:Hide the description.46 * is_virtual:(optional): Filters events by their virtual status. Options are:47 ** "":Show all events (default).48 ** "true":Show only virtual events.49 ** "false":Show only in-person events.50 * columns: (optional, only applies to the card template):The number of columns to use for the card layout. Options are 1, 2, 3, or 4. Default is 3.36 * **event_type: (optional):** Filters events by event type. 37 * **zipcode: (optional):** Filters events by zipcode. 38 * **radius: (optional):** Filters events by a radius around the zipcode. 39 * **limit: (optional):** The maximum number of events to display. Default is 10. 40 * **template:** (optional): The template to use for displaying events. Available options are: 41 * **default:** Displays events in a list format. 42 * **card:** Displays events in a card format. 43 * **show_description:** (optional): Show or hide the event description. Default is true. Options are: 44 * **true:** Show the description. 45 * **false:** Hide the description. 46 * **is_virtual:** (optional): Filters events by their virtual status. Options are: 47 * **"":** Show all events (default). 48 * **"true":** Show only virtual events. 49 * **"false":** Show only in-person events. 50 * **columns: (optional, only applies to the card template):** The number of columns to use for the card layout. Options are 1, 2, 3, or 4. Default is 3. 51 51 52 52 -
shortcode-for-mobilizeamerica-api/trunk/includes/elementor-widget.php
r3293448 r3330938 1 1 <?php 2 2 if ( ! defined( 'ABSPATH' ) ) { 3 exit; // Exit if accessed directly.3 exit; // Exit if accessed directly. 4 4 } 5 5 … … 9 9 class scfmaapi_Widget_Mobilize_America_Events extends \Elementor\Widget_Base { 10 10 11 /** 12 * Get widget name. 13 * 14 * @return string Widget name. 15 */ 16 public function get_name() { 17 return 'mobilize_america_events'; 18 } 19 20 /** 21 * Get widget title. 22 * 23 * @return string Widget title. 24 */ 25 public function get_title() { 26 return esc_html__( 'Mobilize America Events', 'shortcode-for-mobilizeamerica-api' ); 27 } 28 29 /** 30 * Get widget icon. 31 * 32 * @return string Widget icon. 33 */ 34 public function get_icon() { 35 return 'eicon-calendar'; // You can use any Elementor icon class. 36 } 37 38 /** 39 * Get widget categories. 40 * 41 * @return array List of categories the widget belongs to. 42 */ 43 public function get_categories() { 44 return [ 'basic' ]; // Or any other category you prefer. 45 } 46 47 /** 48 * Get widget keywords. 49 * 50 * @return array List of keywords the widget belongs to. 51 */ 52 public function get_keywords() { 53 return [ 'mobilize', 'events', 'america', 'shortcode' ]; 54 } 55 56 /** 57 * Register widget controls. 58 * 59 * Adds different input fields to allow the user to customize the widget settings. 60 */ 61 protected function _register_controls() { 62 $this->start_controls_section( 63 'content_section', 64 [ 65 'label' => esc_html__( 'Content', 'shortcode-for-mobilizeamerica-api' ), 66 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, 67 ] 68 ); 69 70 $this->add_control( 71 'organization_id', 72 [ 73 'label' => esc_html__( 'Organization ID', 'shortcode-for-mobilizeamerica-api' ), 74 'type' => \Elementor\Controls_Manager::TEXT, 75 'required' => true, 76 'description' => esc_html__( 'Enter your Mobilize America Organization ID.', 'shortcode-for-mobilizeamerica-api' ), 77 ] 78 ); 79 80 $this->add_control( 81 'timeslot_start', 82 [ 83 'label' => esc_html__( 'Timeslot Start', 'shortcode-for-mobilizeamerica-api' ), 84 'type' => \Elementor\Controls_Manager::TEXT, 85 'description' => esc_html__( 'Enter the start date/time for events (ISO8601 format).', 'shortcode-for-mobilizeamerica-api' ), 86 ] 87 ); 88 89 $this->add_control( 90 'timeslot_end', 91 [ 92 'label' => esc_html__( 'Timeslot End', 'shortcode-for-mobilizeamerica-api' ), 93 'type' => \Elementor\Controls_Manager::TEXT, 94 'description' => esc_html__( 'Enter the end date/time for events (ISO8601 format).', 'shortcode-for-mobilizeamerica-api' ), 95 ] 96 ); 97 98 $this->add_control( 99 'event_type', 100 [ 101 'label' => esc_html__( 'Event Type', 'shortcode-for-mobilizeamerica-api' ), 102 'type' => \Elementor\Controls_Manager::TEXT, 103 'description' => esc_html__( 'Enter the event type.', 'shortcode-for-mobilizeamerica-api' ), 104 ] 105 ); 106 107 $this->add_control( 108 'zipcode', 109 [ 110 'label' => esc_html__( 'Zipcode', 'shortcode-for-mobilizeamerica-api' ), 111 'type' => \Elementor\Controls_Manager::TEXT, 112 'description' => esc_html__( 'Enter the zipcode.', 'shortcode-for-mobilizeamerica-api' ), 113 ] 114 ); 115 116 $this->add_control( 117 'radius', 118 [ 119 'label' => esc_html__( 'Radius', 'shortcode-for-mobilizeamerica-api' ), 120 'type' => \Elementor\Controls_Manager::TEXT, 121 'description' => esc_html__( 'Enter the radius.', 'shortcode-for-mobilizeamerica-api' ), 122 ] 123 ); 124 125 $this->add_control( 126 'limit', 127 [ 128 'label' => esc_html__( 'Limit', 'shortcode-for-mobilizeamerica-api' ), 129 'type' => \Elementor\Controls_Manager::NUMBER, 130 'default' => 10, 131 'description' => esc_html__( 'Maximum number of events to display.', 'shortcode-for-mobilizeamerica-api' ), 132 ] 133 ); 134 135 $this->add_control( 136 'template', 137 [ 138 'label' => esc_html__( 'Template', 'shortcode-for-mobilizeamerica-api' ), 139 'type' => \Elementor\Controls_Manager::SELECT, 140 'default' => 'default', 141 'options' => [ 142 'default' => esc_html__( 'Default', 'shortcode-for-mobilizeamerica-api' ), 143 'card' => esc_html__( 'Card', 'shortcode-for-mobilizeamerica-api' ), 144 ], 145 'description' => esc_html__( 'Choose a template for displaying events.', 'shortcode-for-mobilizeamerica-api' ), 146 ] 147 ); 11 /** 12 * Get widget name. 13 * 14 * @return string Widget name. 15 */ 16 public function get_name() { 17 return 'mobilize_america_events'; 18 } 19 20 /** 21 * Get widget title. 22 * 23 * @return string Widget title. 24 */ 25 public function get_title() { 26 return esc_html__( 'Mobilize America Events', 'shortcode-for-mobilizeamerica-api' ); 27 } 28 29 /** 30 * Get widget icon. 31 * 32 * @return string Widget icon. 33 */ 34 public function get_icon() { 35 return 'eicon-calendar'; // You can use any Elementor icon class. 36 } 37 38 /** 39 * Get widget categories. 40 * 41 * @return array List of categories the widget belongs to. 42 */ 43 public function get_categories() { 44 return [ 'basic' ]; // Or any other category you prefer. 45 } 46 47 /** 48 * Get widget keywords. 49 * 50 * @return array List of keywords the widget belongs to. 51 */ 52 public function get_keywords() { 53 return [ 'mobilize', 'events', 'america', 'shortcode' ]; 54 } 55 56 /** 57 * Register widget controls. 58 * 59 * Adds different input fields to allow the user to customize the widget settings. 60 */ 61 protected function _register_controls() { 62 $this->start_controls_section( 63 'content_section', 64 [ 65 'label' => esc_html__( 'Content', 'shortcode-for-mobilizeamerica-api' ), 66 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, 67 ] 68 ); 69 70 $this->add_control( 71 'organization_id', 72 [ 73 'label' => esc_html__( 'Organization ID', 'shortcode-for-mobilizeamerica-api' ), 74 'type' => \Elementor\Controls_Manager::TEXT, 75 'required' => true, 76 'description' => esc_html__( 'Enter your Mobilize America Organization ID.', 'shortcode-for-mobilizeamerica-api' ), 77 ] 78 ); 79 80 // New control: organization_only 81 $this->add_control( 82 'organization_only', 83 [ 84 'label' => esc_html__( 'Organization Only', 'shortcode-for-mobilizeamerica-api' ), // Changed label 85 'type' => \Elementor\Controls_Manager::SELECT, 86 'default' => 'no', 87 'options' => [ 88 'yes' => esc_html__( 'Yes', 'shortcode-for-mobilizeamerica-api' ), // Simplified option 89 'no' => esc_html__( 'No', 'shortcode-for-mobilizeamerica-api' ), // Simplified option 90 ], 91 'description' => esc_html__( 'Only show organization events without promoted events', 'shortcode-for-mobilizeamerica-api' ), // Changed description 92 ] 93 ); 94 95 $this->add_control( 96 'timeslot_start', 97 [ 98 'label' => esc_html__( 'Timeslot Start', 'shortcode-for-mobilizeamerica-api' ), 99 'type' => \Elementor\Controls_Manager::TEXT, 100 'description' => esc_html__( 'Enter the start date/time for events (ISO8601 format).', 'shortcode-for-mobilizeamerica-api' ), 101 ] 102 ); 103 104 $this->add_control( 105 'timeslot_end', 106 [ 107 'label' => esc_html__( 'Timeslot End', 'shortcode-for-mobilizeamerica-api' ), 108 'type' => \Elementor\Controls_Manager::TEXT, 109 'description' => esc_html__( 'Enter the end date/time for events (ISO8601 format).', 'shortcode-for-mobilizeamerica-api' ), 110 ] 111 ); 112 113 $this->add_control( 114 'event_type', 115 [ 116 'label' => esc_html__( 'Event Type', 'shortcode-for-mobilizeamerica-api' ), 117 'type' => \Elementor\Controls_Manager::TEXT, 118 'description' => esc_html__( 'Enter the event type.', 'shortcode-for-mobilizeamerica-api' ), 119 ] 120 ); 121 122 $this->add_control( 123 'zipcode', 124 [ 125 'label' => esc_html__( 'Zipcode', 'shortcode-for-mobilizeamerica-api' ), 126 'type' => \Elementor\Controls_Manager::TEXT, 127 'description' => esc_html__( 'Enter the zipcode.', 'shortcode-for-mobilizeamerica-api' ), 128 ] 129 ); 130 131 $this->add_control( 132 'radius', 133 [ 134 'label' => esc_html__( 'Radius', 'shortcode-for-mobilizeamerica-api' ), 135 'type' => \Elementor\Controls_Manager::TEXT, 136 'description' => esc_html__( 'Enter the radius.', 'shortcode-for-mobilizeamerica-api' ), 137 ] 138 ); 139 140 $this->add_control( 141 'limit', 142 [ 143 'label' => esc_html__( 'Limit', 'shortcode-for-mobilizeamerica-api' ), 144 'type' => \Elementor\Controls_Manager::NUMBER, 145 'default' => 10, 146 'description' => esc_html__( 'Maximum number of events to display.', 'shortcode-for-mobilizeamerica-api' ), 147 ] 148 ); 149 150 $this->add_control( 151 'template', 152 [ 153 'label' => esc_html__( 'Template', 'shortcode-for-mobilizeamerica-api' ), 154 'type' => \Elementor\Controls_Manager::SELECT, 155 'default' => 'default', 156 'options' => [ 157 'default' => esc_html__( 'Default', 'shortcode-for-mobilizeamerica-api' ), 158 'card' => esc_html__( 'Card', 'shortcode-for-mobilizeamerica-api' ), 159 ], 160 'description' => esc_html__( 'Choose a template for displaying events.', 'shortcode-for-mobilizeamerica-api' ), 161 ] 162 ); 148 163 149 164 $this->add_control( … … 204 219 ); 205 220 206 $this->end_controls_section(); 221 $this->add_control( 222 'tag_id', 223 [ 224 'label' => esc_html__( 'Tag ID', 'shortcode-for-mobilizeamerica-api' ), 225 'type' => \Elementor\Controls_Manager::TEXT, 226 'description' => esc_html__( 'Enter a Mobilize America Tag ID to filter events.', 'shortcode-for-mobilizeamerica-api' ), 227 ] 228 ); 229 230 231 $this->end_controls_section(); 207 232 208 233 … … 277 302 ); 278 303 279 /* $this->add_group_control(304 /* $this->add_group_control( 280 305 \Elementor\Group_Control_Background::get_type(), 281 306 [ … … 289 314 );*/ 290 315 291 /* $this->add_control(316 /* $this->add_control( 292 317 'title_padding', 293 318 [ … … 406 431 407 432 $this->end_controls_section(); */ 408 }409 410 /**411 * Render widget output on the frontend.412 *413 * @return string414 */415 protected function render() {416 $settings = $this->get_settings_for_display();417 418 if ( empty( $settings['organization_id'] ) ) {419 echo '<div class="mobilize-america-error">' . esc_html__( 'Error: Organization ID is required.', 'shortcode-for-mobilizeamerica-api' ) . '</div>';420 return;421 }422 423 $shortcode_atts = [424 'organization_id' => $settings['organization_id'],425 ];433 } 434 435 /** 436 * Render widget output on the frontend. 437 * 438 * @return string 439 */ 440 protected function render() { 441 $settings = $this->get_settings_for_display(); 442 443 if ( empty( $settings['organization_id'] ) ) { 444 echo '<div class="mobilize-america-error">' . esc_html__( 'Error: Organization ID is required.', 'shortcode-for-mobilizeamerica-api' ) . '</div>'; 445 return; 446 } 447 448 $shortcode_atts = [ 449 'organization_id' => $settings['organization_id'], 450 ]; 426 451 427 452 if (!empty($settings['timeslot_start'])) { … … 459 484 $shortcode_atts['columns'] = $settings['columns']; 460 485 } 461 462 try { 463 $shortcode_str = '[mobilize_america_events '; 464 $shortcode_str .= 'organization_id="' . $settings['organization_id'] . '" '; 465 if (!empty($settings['timeslot_start'])) { 466 $shortcode_str .= ' timeslot_start="' . $settings['timeslot_start'] . '" '; 467 } 468 if (!empty($settings['timeslot_end'])) { 469 $shortcode_str .= ' timeslot_end="' . $settings['timeslot_end'] . '" '; 470 } 471 if (!empty($settings['template'])) { 472 $shortcode_str .= ' template="' . $settings['template'] . '" '; 473 } 474 if (!empty($settings['show_description'])) { 475 $shortcode_str .= ' show_description="' . $settings['show_description'] . '" '; 476 } 477 if (!empty($settings['is_virtual'])) { 478 $shortcode_str .= ' is_virtual="' . $settings['is_virtual'] . '" '; 479 } 480 if (!empty($settings['columns'])) { 481 $shortcode_str .= ' columns="' . $settings['columns'] . '" '; 486 if (!empty($settings['tag_id'])) { // Add tag_id to shortcode attributes 487 $shortcode_atts['tag_id'] = $settings['tag_id']; 488 } 489 if (!empty($settings['organization_only'])) { // Add organization_only to shortcode attributes 490 $shortcode_atts['organization_only'] = $settings['organization_only']; 491 } 492 493 try { 494 $shortcode_str = '[mobilize_america_events '; 495 foreach ($shortcode_atts as $key => $value) { 496 // Ensure boolean values are converted to 'true'/'false' strings for the shortcode 497 if (is_bool($value)) { 498 $value = $value ? 'true' : 'false'; 499 } 500 $shortcode_str .= $key . '="' . esc_attr($value) . '" '; 482 501 } 483 502 $shortcode_str .= ']'; 484 503 485 if ( ! is_string( $shortcode_str ) ) {486 $shortcode_str = '';487 }488 489 $mobilizeshortcode = do_shortcode( $shortcode_str );504 if ( ! is_string( $shortcode_str ) ) { 505 $shortcode_str = ''; 506 } 507 508 $mobilizeshortcode = do_shortcode( $shortcode_str ); 490 509 if (empty($mobilizeshortcode)) { 491 510 echo '<div class="mobilize-america-error">Shortcode output is empty. Please check your settings.</div>'; … … 494 513 { 495 514 echo wp_kses_post($mobilizeshortcode); 496 515 497 516 } 498 517 499 } catch (Exception $e) {500 echo '<div class="mobilize-america-error">' . esc_html__( 'Error: Shortcode processing failed.', 'shortcode-for-mobilizeamerica-api' ) . '</div>';501 return;502 }503 }518 } catch (Exception $e) { 519 echo '<div class="mobilize-america-error">' . esc_html__( 'Error: Shortcode processing failed.', 'shortcode-for-mobilizeamerica-api' ) . '</div>'; 520 return; 521 } 522 } 504 523 } -
shortcode-for-mobilizeamerica-api/trunk/readme.txt
r3302879 r3330938 4 4 Requires at least: 6.7 5 5 Tested up to: 6.8 6 Stable tag: 1.0.1 06 Stable tag: 1.0.11 7 7 Requires PHP: 8.0 8 8 License: GPLv2 or later … … 13 13 The shortcode / elementor widget passes a specificed organization id, a start date and a variable about virtual events. 14 14 This service is provided by MobilizeAmerica - https://api.mobilize.us 15 [API Documentation](https://github.com/mobilizeamerica/api)16 [Mobilize Terms of Use](https://join.mobilize.us/terms-of-service/)17 [MobilizePrivacy Policy](https://join.mobilize.us/privacy-policy/)15 * [API Documentation](https://github.com/mobilizeamerica/api) 16 * [Mobilize Terms of Use](https://join.mobilize.us/terms-of-service/) 17 * [MobilizePrivacy Policy](https://join.mobilize.us/privacy-policy/) 18 18 19 19 ## Description … … 30 30 Attributes 31 31 The shortcode accepts the following attributes: 32 * **organization_id (required):** The ID of the organization whose events you want to display. You can find this ID on Mobilize America. https://www.mobilize.us/dashboard/YOUR-ORGANIZATION/settings/ 33 * timeslot_start: (optional): Suggested: gte_now which is greater than now - Unix timestamp to filter events. Only shows events withtimeslots starting after this date. 34 * timeslot_end: (optional): Unix timestamp to filter events. Only shows events with timeslots starting before this date. 32 * **organization_id (required):** The ID of the organization whose events you want to display. You can find this ID on Mobilize America. https://www.mobilize.us/dashboard/YOUR-ORGANIZATION/settings/ 33 * **organization_only:** (optional): yes/no - if set to yes then only the organzation events will be shown without promoted events 34 * **timeslot_start:** (optional): Suggested: gte_now which is greater than now - Unix timestamp to filter events. Only shows events withtimeslots starting after this date. 35 * **timeslot_end:** (optional): Unix timestamp to filter events. Only shows events with timeslots starting before this date. 35 36 Note: For timeslot please use comparison text - The comparison operators are ≥ gte, > gt, ≤ lte, < lt 36 * event_type: (optional): Filters events by event type. 37 * zipcode: (optional): Filters events by zipcode. 38 * radius: (optional): Filters events by a radius around the zipcode. 39 * limit: (optional): The maximum number of events to display. Default is 10. 40 * template: (optional): The template to use for displaying events. Available options are: 41 ** default: Displays events in a list format. 42 ** card: Displays events in a card format. 43 * show_description: (optional): Show or hide the event description. Default is true. Options are: 44 ** true: Show the description. 45 ** false: Hide the description. 46 * is_virtual: (optional): Filters events by their virtual status. Options are: 47 ** "": Show all events (default). 48 ** "true": Show only virtual events. 49 ** "false": Show only in-person events. 50 * columns: (optional, only applies to the card template): The number of columns to use for the card layout. Options are 1, 2, 3, or 4. Default is 3. 37 * **event_type: (optional):** Filters events by event type. 38 * **zipcode: (optional):** Filters events by zipcode. 39 * **radius: (optional):** Filters events by a radius around the zipcode. 40 * **limit: (optional):** The maximum number of events to display. Default is 10. 41 * **template:** (optional): The template to use for displaying events. Available options are: 42 * **default:** Displays events in a list format. 43 * **card:** Displays events in a card format. 44 * **show_description:** (optional): Show or hide the event description. Default is true. Options are: 45 * **true:** Show the description. 46 * **false:** Hide the description. 47 * **is_virtual:** (optional): Filters events by their virtual status. Options are: 48 * **"":** Show all events (default). 49 * **"true":** Show only virtual events. 50 * **"false":** Show only in-person events. 51 * **columns: (optional, only applies to the card template):** The number of columns to use for the card layout. Options are 1, 2, 3, or 4. Default is 3. 52 * **tag_id:** (optional): comma separated list of tag ids to filter by 51 53 52 54 … … 88 90 89 91 ## Change Log 92 2025-07-20 v1.0.11 93 * Added support for tag_id for filtering based on tags 94 * Added support for organization only which will filter to not included promoted events 95 90 96 2025-05-29 v1.0.10 91 97 * Added default timeslot_start as gte_now so that the shortcode will show future event by default -
shortcode-for-mobilizeamerica-api/trunk/shortcode-for-mobilizeamerica-api.php
r3302846 r3330938 2 2 /** 3 3 * Plugin Name: Shortcode for MobilizeAmerica API 4 * Plugin URI: https://github.com/sflwa/shortcode-for-mobilizeamerica-api/5 4 * Description: Displays events from Mobilize America on your WordPress site. 6 * Version: 1.0.1 05 * Version: 1.0.11 7 6 * Author: South Florida Web Advisors 8 7 * Author URI: https://sflwa.net … … 10 9 * Requires at least: 6.7 11 10 * Tested up to: 6.8 12 * Stable tag: 1.0.1 011 * Stable tag: 1.0.11 13 12 * Text Domain: shortcode-for-mobilizeamerica-api 14 15 13 */ 16 14 17 15 // Prevent direct access to the plugin file. 18 16 if ( ! defined( 'ABSPATH' ) ) { 19 exit; // Exit if accessed directly.17 exit; // Exit if accessed directly. 20 18 } 21 19 … … 27 25 class Mobilize_America_API { 28 26 29 private $api_url = 'https://api.mobilize.us/v1/';27 private $api_url = 'https://api.mobilize.us/v1/'; 30 28 private $organization_id = ''; 31 29 32 /**33 * Constructor.34 */35 public function __construct($organization_id) {30 /** 31 * Constructor. 32 */ 33 public function __construct($organization_id) { 36 34 $this->organization_id = $organization_id; 37 } 38 39 /** 40 * Fetch events from the Mobilize America API. 41 * 42 * @param array $args Array of arguments for the API request. 43 * See https://www.mobilize.us/api/docs/#events-list for available parameters. 44 * @return array|WP_Error Array of events on success, WP_Error on failure. 45 */ 46 public function scfmaapi_get_events( $args = array() ) { 47 $url = $this->api_url . 'organizations/' . $this->organization_id . '/events'; // Include org ID in URL 48 49 // Build the query string from the arguments. 50 $query_args = array(); 51 if (!empty($args)) { 52 $query_args = $args; 53 } 54 55 $url = add_query_arg( $query_args, $url ); 56 57 // Make the API request. 58 $response = wp_remote_get( 59 $url, 60 array( 61 'timeout' => 15, // Set a timeout. 62 ) 63 ); 64 65 // Check for a successful response. 66 if ( is_wp_error( $response ) ) { 67 return new WP_Error( 'api_error', __( 'Error: Unable to connect to the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $response->get_error_message() ); 68 } 69 70 $body = wp_remote_retrieve_body( $response ); 71 $data = json_decode( $body, true ); 72 73 // Check the response code. 74 $response_code = wp_remote_retrieve_response_code( $response ); 35 } 36 37 /** 38 * Fetch events from the Mobilize America API. 39 * 40 * @param array $args Array of arguments for the API request. 41 * See https://www.mobilize.us/api/docs/#events-list for available parameters. 42 * @return array|WP_Error Array of events on success, WP_Error on failure. 43 */ 44 public function scfmaapi_get_events( $args = array() ) { 45 // Base URL always includes organization ID from constructor 46 $url = $this->api_url . 'organizations/' . intval($this->organization_id) . '/events'; 47 48 // Initialize query_args with only the parameters that should be in the URL 49 $query_args = array(); 50 51 // Check if 'organization_only' is set to 'yes' and add organization_id as a query parameter 52 if ( isset( $args['organization_only'] ) && $args['organization_only'] === 'yes' ) { 53 $query_args['organization_id'] = $this->organization_id; // Add organization_id as query param 54 } 55 56 // Add other relevant arguments to query_args, excluding those already handled or not API parameters 57 foreach ( $args as $key => $value ) { 58 if ( $key !== 'organization_only' && $key !== 'organization_id' ) { // Ensure organization_only and organization_id are not re-added 59 $query_args[ $key ] = $value; 60 } 61 } 62 63 // Add the filtered query arguments to the URL 64 $url = add_query_arg( $query_args, $url ); 65 66 // Make the API request. 67 $response = wp_remote_get( 68 $url, 69 array( 70 'timeout' => 15, // Set a timeout. 71 ) 72 ); 73 74 // Check for a successful response. 75 if ( is_wp_error( $response ) ) { 76 return new WP_Error( 'api_error', __( 'Error: Unable to connect to the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $response->get_error_message() ); 77 } 78 79 $body = wp_remote_retrieve_body( $response ); 80 $data = json_decode( $body, true ); 81 82 // Check the response code. 83 $response_code = wp_remote_retrieve_response_code( $response ); 75 84 if ( $response_code != 200 ) { 76 85 if (isset($data['errors']) && is_array($data['errors'])) { 77 86 $error_message = implode(", ", $data['errors']); // Combine errors into a single string 78 87 } else { 79 /* translators: 1: Error code returned from API. */88 /* translators: 1: Error code returned from API. */ 80 89 $error_message = sprintf( __( 'Mobilize America API returned an error: %d', 'shortcode-for-mobilizeamerica-api' ), $response_code ); 81 90 } 82 return new WP_Error( 'api_error', $error_message, $data );83 }84 85 // Check if the 'data' key exists and is an array.86 if ( ! isset( $data['data'] ) || ! is_array( $data['data'] ) ) {87 return new WP_Error( 'api_error', __( 'Error: Invalid data received from the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $data );88 }89 90 return $data['data'];91 }92 93 /**94 * Get a single event by its ID.95 *96 * @param int $event_id The ID of the event to retrieve.97 * @return array|WP_Error The event data on success, WP_Error on failure.98 */99 public function get_event_by_id( $event_id ) {100 $url = $this->api_url . 'events/' . intval( $event_id ) . '/';101 102 $response = wp_remote_get( $url );103 104 if ( is_wp_error( $response ) ) {105 return new WP_Error( 'api_error', __( 'Error: Unable to connect to the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $response->get_error_message() );106 }107 108 $body = wp_remote_retrieve_body( $response );109 $data = json_decode( $body, true );110 111 $response_code = wp_remote_retrieve_response_code( $response );112 if ( $response_code != 200 ) {91 return new WP_Error( 'api_error', $error_message, $data ); 92 } 93 94 // Check if the 'data' key exists and is an array. 95 if ( ! isset( $data['data'] ) || ! is_array( $data['data'] ) ) { 96 return new WP_Error( 'api_error', __( 'Error: Invalid data received from the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $data ); 97 } 98 99 return $data['data']; 100 } 101 102 /** 103 * Get a single event by its ID. 104 * 105 * @param int $event_id The ID of the event to retrieve. 106 * @return array|WP_Error The event data on success, WP_Error on failure. 107 */ 108 public function get_event_by_id( $event_id ) { 109 $url = $this->api_url . 'events/' . intval( $event_id ) . '/'; 110 111 $response = wp_remote_get( $url ); 112 113 if ( is_wp_error( $response ) ) { 114 return new WP_Error( 'api_error', __( 'Error: Unable to connect to the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $response->get_error_message() ); 115 } 116 117 $body = wp_remote_retrieve_body( $response ); 118 $data = json_decode( $body, true ); 119 120 $response_code = wp_remote_retrieve_response_code( $response ); 121 if ( $response_code != 200 ) { 113 122 if (isset($data['errors']) && is_array($data['errors'])) { 114 123 $error_message = implode(", ", $data['errors']); // Combine errors into a single string 115 124 } else { 116 125 /* translators: 1: Error code returned from API. */ 117 $error_message = sprintf( __( 'Mobilize America API returned an error: %d', 'shortcode-for-mobilizeamerica-api' ), $response_code );126 $error_message = sprintf( __( 'Mobilize America API returned an error: %d', 'shortcode-for-mobilizeamerica-api' ), $response_code ); 118 127 } 119 return new WP_Error( 'api_error', $error_message, $data );120 }121 122 if ( ! is_array( $data ) ) {123 return new WP_Error( 'api_error', __( 'Error: Invalid data received from the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $data );124 }125 return $data;126 }128 return new WP_Error( 'api_error', $error_message, $data ); 129 } 130 131 if ( ! is_array( $data ) ) { 132 return new WP_Error( 'api_error', __( 'Error: Invalid data received from the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $data ); 133 } 134 return $data; 135 } 127 136 } 128 137 … … 134 143 */ 135 144 function mobilize_america_events_shortcode( $atts ) { 136 $atts = shortcode_atts( 137 array( 138 'organization_id' => '', // Organization ID is now required. 139 'timeslot_start' => 'gte_now', // ISO8601 date-time string 140 'timeslot_end' => '', // ISO8601 date-time string 141 'event_type' => '', // event type 142 'zipcode' => '', // zipcode 143 'radius' => '', // radius 144 'limit' => 15, // Maximum number of events to display. 145 'template' => 'default', //Which template to use 146 'event_id' => '', //show a single event, 147 'show_description' => 'true', //show description 148 'is_virtual' => '', // Virtual Only - blank is all 149 'columns' => '3', // Number of columns for card template 150 ), 151 $atts, 152 'mobilize_america_events' 153 ); 145 $atts = shortcode_atts( 146 array( 147 'organization_id' => '', // Organization ID is now required. 148 'timeslot_start' => 'gte_now', // ISO8601 date-time string 149 'timeslot_end' => '', // ISO8601 date-time string 150 'event_type' => '', // event type 151 'zipcode' => '', // zipcode 152 'radius' => '', // radius 153 'limit' => 15, // Maximum number of events to display. 154 'template' => 'default', //Which template to use 155 'event_id' => '', //show a single event, 156 'show_description' => 'true', //show description 157 'is_virtual' => '', // Virtual Only - blank is all 158 'columns' => '3', // Number of columns for card template 159 'tag_id' => '', // Tag ID to filter events. 160 'organization_only' => 'no', // 'yes' to include org ID as query param, 'no' to not 161 ), 162 $atts, 163 'mobilize_america_events' 164 ); 154 165 155 166 // Organization ID is now required. Return an error if not provided. … … 158 169 } 159 170 160 $api = new Mobilize_America_API( $atts['organization_id'] ); // Pass org ID to API class.171 $api = new Mobilize_America_API( $atts['organization_id'] ); // Pass org ID to API class. 161 172 162 173 if( !empty( $atts['event_id'] ) ) { … … 170 181 // Build the arguments array for the API request. 171 182 $api_args = array( 172 //'organization_id' => $atts['organization_id'], // No longer needed in args.173 'timeslot_ start' => $atts['timeslot_start'],174 ' timeslot_end' => $atts['timeslot_end'],175 ' limit' => $atts['limit'],183 'timeslot_start' => $atts['timeslot_start'], 184 'timeslot_end' => $atts['timeslot_end'], 185 'limit' => $atts['limit'], 186 'organization_only' => $atts['organization_only'], // Pass organization_only to API class 176 187 ); 177 188 … … 181 192 182 193 if( !empty( $atts['zipcode'] ) ) { 183 $api_args['zipcode'] = $atts['zipcode'];194 $api_args['zipcode'] = $atts['zipcode']; 184 195 } 185 196 186 197 if( !empty( $atts['radius'] ) ) { 187 $api_args['radius'] = $atts['radius']; 188 } 189 198 $api_args['radius'] = $atts['radius']; 199 } 200 if( !empty( $atts['tag_id'] ) ) { 201 $api_args['tag_id'] = $atts['tag_id']; 202 } 190 203 if( !empty( $atts['is_virtual'] ) ) { 191 $api_args['is_virtual'] = $atts['is_virtual'];204 $api_args['is_virtual'] = $atts['is_virtual']; 192 205 } 193 194 206 195 207 // Remove empty arguments. 196 208 $api_args = array_filter( $api_args ); … … 204 216 205 217 206 if ( empty( $events ) ) {207 return '<div class="mobilize-america-no-events">' . esc_html__( 'No events found.', 'shortcode-for-mobilizeamerica-api' ) . '</div>';208 }209 210 $output = '<div class="mobilize-america-events-wrapper columns-' . intval($atts['columns']) . '">';218 if ( empty( $events ) ) { 219 return '<div class="mobilize-america-no-events">' . esc_html__( 'No events found.', 'shortcode-for-mobilizeamerica-api' ) . '</div>'; 220 } 221 222 $output = '<div class="mobilize-america-events-wrapper columns-' . intval($atts['columns']) . '">'; 211 223 212 224 // Include CSS file. … … 223 235 224 236 $output .= mobilize_america_get_template( $events, $atts['template'], intval($atts['columns']), $atts['show_description'] ); 225 $output .= '</div>'; // Close events-wrapper226 227 return $output;237 $output .= '</div>'; // Close events-wrapper 238 239 return $output; 228 240 229 241 } … … 232 244 // Check if Elementor is installed before hooking into it. 233 245 if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '1.0.0', '>=' ) ) { 234 add_action( 'elementor/widgets/widgets_registered', 'scfmaapi_register_mobilize_america_widget' );246 add_action( 'elementor/widgets/widgets_registered', 'scfmaapi_register_mobilize_america_widget' ); 235 247 } 236 248 … … 239 251 */ 240 252 function scfmaapi_register_mobilize_america_widget() { 241 // Include the widget class file.242 require_once( __DIR__ . '/includes/elementor-widget.php' );243 244 // Register the widget.245 \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \scfmaapi_Widget_Mobilize_America_Events() );246 } 253 // Include the widget class file. 254 require_once( __DIR__ . '/includes/elementor-widget.php' ); 255 256 // Register the widget. 257 \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \scfmaapi_Widget_Mobilize_America_Events() ); 258 }
Note: See TracChangeset
for help on using the changeset viewer.