Plugin Directory

Changeset 3330938


Ignore:
Timestamp:
07/20/2025 02:04:42 PM (7 months ago)
Author:
sflwa
Message:
  • Added support for tag_id for filtering based on tags
  • Added support for organization only which will filter to not included promoted events
Location:
shortcode-for-mobilizeamerica-api
Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • shortcode-for-mobilizeamerica-api/tags/1.0.10/readme.txt

    r3302879 r3330938  
    1313The shortcode / elementor widget passes a specificed organization id, a start date and a variable about virtual events.
    1414This 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/)
    1818
    1919## Description
     
    3030Attributes
    3131The 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.
    3535Note: 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.
    5151
    5252
  • shortcode-for-mobilizeamerica-api/trunk/includes/elementor-widget.php

    r3293448 r3330938  
    11<?php
    22if ( ! defined( 'ABSPATH' ) ) {
    3     exit; // Exit if accessed directly.
     3    exit; // Exit if accessed directly.
    44}
    55
     
    99class scfmaapi_Widget_Mobilize_America_Events extends \Elementor\Widget_Base {
    1010
    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        );
    148163
    149164        $this->add_control(
     
    204219        );
    205220
    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();
    207232
    208233
     
    277302        );
    278303
    279        /*  $this->add_group_control(
     304       /* $this->add_group_control(
    280305            \Elementor\Group_Control_Background::get_type(),
    281306            [
     
    289314        );*/
    290315
    291       /*  $this->add_control(
     316      /* $this->add_control(
    292317            'title_padding',
    293318            [
     
    406431
    407432        $this->end_controls_section(); */
    408     }
    409 
    410     /**
    411     * Render widget output on the frontend.
    412     *
    413     * @return string
    414     */
    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        ];
    426451
    427452        if (!empty($settings['timeslot_start'])) {
     
    459484            $shortcode_atts['columns'] = $settings['columns'];
    460485        }
    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) . '" ';
    482501            }
    483502            $shortcode_str .= ']';
    484503
    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 );
    490509            if (empty($mobilizeshortcode)) {
    491510                echo '<div class="mobilize-america-error">Shortcode output is empty.  Please check your settings.</div>';
     
    494513            {
    495514                echo wp_kses_post($mobilizeshortcode);
    496                
     515               
    497516            }
    498517
    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    }
    504523}
  • shortcode-for-mobilizeamerica-api/trunk/readme.txt

    r3302879 r3330938  
    44Requires at least: 6.7
    55Tested up to: 6.8
    6 Stable tag: 1.0.10
     6Stable tag: 1.0.11
    77Requires PHP: 8.0
    88License: GPLv2 or later
     
    1313The shortcode / elementor widget passes a specificed organization id, a start date and a variable about virtual events.
    1414This 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/)
    1818
    1919## Description
     
    3030Attributes
    3131The 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.
    3536Note: 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
    5153
    5254
     
    8890
    8991## Change Log
     922025-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
    90962025-05-29 v1.0.10
    9197*   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  
    22/**
    33 * Plugin Name: Shortcode for MobilizeAmerica API
    4  * Plugin URI:  https://github.com/sflwa/shortcode-for-mobilizeamerica-api/
    54 * Description: Displays events from Mobilize America on your WordPress site.
    6  * Version:     1.0.10
     5 * Version:     1.0.11
    76 * Author:      South Florida Web Advisors
    87 * Author URI:  https://sflwa.net
     
    109 * Requires at least: 6.7
    1110 * Tested up to: 6.8
    12  * Stable tag: 1.0.10
     11 * Stable tag: 1.0.11
    1312 * Text Domain: shortcode-for-mobilizeamerica-api
    14 
    1513 */
    1614
    1715// Prevent direct access to the plugin file.
    1816if ( ! defined( 'ABSPATH' ) ) {
    19     exit; // Exit if accessed directly.
     17    exit; // Exit if accessed directly.
    2018}
    2119
     
    2725class Mobilize_America_API {
    2826
    29     private $api_url = 'https://api.mobilize.us/v1/';
     27    private $api_url = 'https://api.mobilize.us/v1/';
    3028    private $organization_id = '';
    3129
    32     /**
    33     * Constructor.
    34     */
    35     public function __construct($organization_id) {
     30    /**
     31    * Constructor.
     32    */
     33    public function __construct($organization_id) {
    3634        $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 );
    7584        if ( $response_code != 200 ) {
    7685            if (isset($data['errors']) && is_array($data['errors'])) {
    7786                $error_message = implode(", ", $data['errors']); // Combine errors into a single string
    7887            } else {
    79         /* translators: 1: Error code returned from API. */   
     88        /* translators: 1: Error code returned from API. */   
    8089                $error_message = sprintf( __( 'Mobilize America API returned an error: %d', 'shortcode-for-mobilizeamerica-api' ), $response_code );
    8190            }
    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 ) {
    113122             if (isset($data['errors']) && is_array($data['errors'])) {
    114123                $error_message = implode(", ", $data['errors']); // Combine errors into a single string
    115124            } else {
    116125                /* 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 );
    118127            }
    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    }
    127136}
    128137
     
    134143 */
    135144function 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    );
    154165
    155166    // Organization ID is now required.  Return an error if not provided.
     
    158169    }
    159170
    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.
    161172
    162173    if( !empty( $atts['event_id'] ) ) {
     
    170181        // Build the arguments array for the API request.
    171182        $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
    176187        );
    177188
     
    181192
    182193        if( !empty( $atts['zipcode'] ) ) {
    183              $api_args['zipcode'] = $atts['zipcode'];
     194            $api_args['zipcode'] = $atts['zipcode'];
    184195        }
    185196
    186197        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        }
    190203        if( !empty( $atts['is_virtual'] ) ) {
    191              $api_args['is_virtual'] = $atts['is_virtual'];
     204            $api_args['is_virtual'] = $atts['is_virtual'];
    192205        }   
    193 
    194        
     206       
    195207        // Remove empty arguments.
    196208        $api_args = array_filter( $api_args );
     
    204216
    205217
    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']) . '">';
    211223
    212224    // Include CSS file.
     
    223235
    224236    $output .= mobilize_america_get_template( $events, $atts['template'], intval($atts['columns']), $atts['show_description'] );
    225     $output .= '</div>'; // Close events-wrapper
    226 
    227     return $output;
     237    $output .= '</div>'; // Close events-wrapper
     238
     239    return $output;
    228240
    229241}
     
    232244// Check if Elementor is installed before hooking into it.
    233245if ( 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' );
    235247}
    236248
     
    239251 */
    240252function 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.