Plugin Directory

Changeset 3397379


Ignore:
Timestamp:
11/17/2025 04:05:57 PM (5 months ago)
Author:
sflwa
Message:

Fix for Single Event display, WP Coding Standards and other code cleanup

Location:
shortcode-for-mobilizeamerica-api
Files:
11 added
3 edited

Legend:

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

    r3383176 r3397379  
    44Requires at least: 6.7
    55Tested up to: 6.8
    6 Stable tag: 1.0.14
     6Stable tag: 1.0.15
    77Requires PHP: 8.0
    88License: GPLv2 or later
     
    9090
    9191## Change Log
     922025-11-17 v1.0.15
     93* Fixed Single Event Filtering
     94* Updated Using Plugin Notice - Option vs Transient
     95* Cleanup WordPress Coding Standards / Debug Code
     96
    92972025-10-22 v1.0.14
    9398* Fixed Sort to be in date order regardless of how it is in the API results
  • shortcode-for-mobilizeamerica-api/trunk/sflwa-notice-handler.php

    r3340482 r3397379  
    3030 * Registers the admin notice if it hasn't been permanently dismissed.
    3131 *
    32  * This function checks for a transient set when the user dismisses the notice.
    33  * If the transient doesn't exist, it means the notice should be displayed.
     32 * This function checks for a persistent option set when the user dismisses the notice.
     33 * If the option is not set or not equal to '1', it means the notice should be displayed.
    3434 */
    3535function sflwa_register_admin_notice() {
    36     // Construct a unique transient name based on the plugin name.
    37     // sanitize_title() ensures the name is safe for a transient key.
    38     $transient_name = 'sflwa_notice_dismissed_' . sanitize_title( SFLWA_PLUGIN_NAME );
    39 
    40     // Check if the transient exists. If not, add the action to display the notice.
    41     if ( ! get_transient( $transient_name ) ) {
     36    // Construct a unique option name based on the plugin name.
     37    // sanitize_title() ensures the name is safe for an option key.
     38    $option_name = 'sflwa_notice_dismissed_' . sanitize_title( SFLWA_PLUGIN_NAME );
     39
     40    // Check if the permanent option is set to '1'. If not, add the action to display the notice.
     41    if ( get_option( $option_name ) !== '1' ) {
    4242        add_action( 'admin_notices', 'sflwa_display_admin_notice' );
    4343    }
     
    273273 *
    274274 * This function is hooked to 'wp_ajax_sflwa_dismiss_admin_notice'.
    275  * It sets a transient to prevent the notice from showing again for this plugin.
     275 * It sets an option to prevent the notice from showing again for this plugin.
    276276 */
    277277add_action( 'wp_ajax_sflwa_dismiss_admin_notice', 'sflwa_dismiss_admin_notice_callback' );
     
    283283    $plugin_name = isset( $_POST['plugin_name'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_name'] ) ) : '';
    284284
    285     // Construct the unique transient name.
    286     $transient_name = 'sflwa_notice_dismissed_' . sanitize_title( $plugin_name );
    287 
    288     // Set a transient that never expires (0 seconds lifetime) to permanently hide the notice.
    289     set_transient( $transient_name, '1', 0 );
     285    // Construct the unique option name.
     286    $option_name = 'sflwa_notice_dismissed_' . sanitize_title( $plugin_name );
     287
     288    // Set a permanent option to '1' to permanently hide the notice.
     289    // The 'true' flag tells WordPress to autoload the option if it's new (which is good for a quick check).
     290    update_option( $option_name, '1', true );
    290291
    291292    wp_send_json_success( 'Notice dismissed permanently.' );
  • shortcode-for-mobilizeamerica-api/trunk/shortcode-for-mobilizeamerica-api.php

    r3382969 r3397379  
    33 * Plugin Name: Shortcode for MobilizeAmerica API
    44 * Description: Displays events from Mobilize America on your WordPress site.
    5  * Version:     1.0.14
     5 * Version:     1.0.15
    66 * Author:      South Florida Web Advisors
    77 * Author URI:  https://sflwa.net
     
    99 * Requires at least: 6.7
    1010 * Tested up to: 6.8
    11  * Stable tag: 1.0.14
     11 * Stable tag: 1.0.15
    1212 * Text Domain: shortcode-for-mobilizeamerica-api
    1313 */
     
    101101    }
    102102
    103     /**
     103/**
    104104     * Get a single event by its ID.
    105105     *
     
    108108     */
    109109    public function get_event_by_id( $event_id ) {
    110         $url = $this->api_url . 'events/' . intval( $event_id ) . '/';
     110        // CORRECTED API ENDPOINT: Must include both organization ID and event ID in the path.
     111        // Format: /v1/organizations/:organization_id/events/:event_id
     112        $url = $this->api_url . 'organizations/' . intval( $this->organization_id ) . '/events/' . intval( $event_id );
    111113
    112114        $response = wp_remote_get( $url );
     
    130132        }
    131133
    132         if ( ! is_array( $data ) ) {
     134        // FIX: The single event object is wrapped in a 'data' key in the response.
     135        if ( ! isset( $data['data'] ) || ! is_array( $data['data'] ) ) {
    133136            return new WP_Error( 'api_error', __( 'Error: Invalid data received from the Mobilize America API.', 'shortcode-for-mobilizeamerica-api' ), $data );
    134137        }
    135         return $data;
     138       
     139        return $data['data'];
    136140    }
    137141}
     
    143147 * @return string HTML output for the events.
    144148 */
    145 function mobilize_america_events_shortcode( $atts ) {
     149function scfmaapi_mobilize_america_events_shortcode( $atts ) {
    146150    $atts = shortcode_atts(
    147151        array(
     
    267271
    268272}
    269 add_shortcode( 'mobilize_america_events', 'mobilize_america_events_shortcode' );
     273add_shortcode( 'mobilize_america_events', 'scfmaapi_mobilize_america_events_shortcode' );
    270274
    271275// Check if Elementor is installed before hooking into it.
     
    281285    require_once( __DIR__ . '/includes/elementor-widget.php' );
    282286
    283     // Register the widget.
    284     \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new \scfmaapi_Widget_Mobilize_America_Events() );
    285 }
     287    // Register the widget using the correct class name without leading namespace indicator.
     288    \Elementor\Plugin::instance()->widgets_manager->register_widget_type( new scfmaapi_Widget_Mobilize_America_Events() );
     289}
Note: See TracChangeset for help on using the changeset viewer.