cyberhobo / wordpress-geo-mashup

Official repository for Geo Mashup, the plugin that makes WordPress into a GeoCMS. Documentation:
https://github.com/cyberhobo/wordpress-geo-mashup/wiki/Getting-Started
63 stars 15 forks source link

geomashup\widgets\search #868

Closed netzgestaltung closed 3 years ago

netzgestaltung commented 4 years ago

Hi there,

after an update (dont know which) this year the Geomashup search widget was gone from my page. While recreating it with a new widget i found that the classname has changed to geomashup\widgets\search-2 which i believe should be geomashup-widgets-search-2 and the className of the previous widget (thanks to the css i wrote on it) was geomashupsearchwidget.

So i think the old widget has gone due to renaming the widget base. but the new className(and the widget ID is also geomashup\widgets\search-x) contains a bug.

Visible page: https://www.alphabetisierung.at/kurssuche/

kind regards, tom

netzgestaltung commented 4 years ago

as a workaround i noted my CSS selector like so .widget_geomashup\\widgets\\search{...}

cyberhobo commented 4 years ago

The workaround may need to be permanent. Renaming the widget PHP class isn't practical, but that's what WordPress uses to generate that CSS class and ID. This isn't likely to change again soon, but changing it back isn't a good option.

We do have control over the class on the form tag, geo-mashup-search-form, which did not change.

netzgestaltung commented 4 years ago

Hi,

you allready renamed it (yes that wasnt practical, the old widget was gone without notice ;-) ). I dont think that class selectors HTML are valid this way.

Your constructor method is missing informations, when i compare it with a slider, i did once:

class sandbox_social_widget extends WP_Widget {
  public function __construct() {
    /* Widget settings. */
    $widget_ops = array(
      'classname' => 'social', 
      'description' => __('Display social share icons without automatic user tracking', 'sandbox')
    );
    /* Widget control settings. */
    $control_ops = array('width' => 300, 'height' => 350, 'id_base' => 'social');
    /* Create the widget. */
    parent::__construct('social', 'Social share', $widget_ops, $control_ops );
  }

Your constructor:

class Search extends WP_Widget {

    // Construct Widget
    public function __construct() {
        $default_options = array(
            'description' => __( 'Search content by Geo Mashup location.', 'GeoMashup' )
        );
        parent::__construct( false, __( 'Geo Mashup Search', 'GeoMashup' ), $default_options );
    }

So you are missing the "classname" and "id_base" property and so WP is taking "something" while you give the first argument of the parent constructor a "false".

that seems more a bug to me.

i looked in the WP source code at https://core.trac.wordpress.org/browser/tags/5.5/src/wp-includes/class-wp-widget.php#L163

if the first argument $id_base of the constructor is missing, this is what happens:

$this->id_base  = empty( $id_base ) ? preg_replace( '/(wp_)?widget_/', '', strtolower( get_class( $this ) ) ) : strtolower( $id_base );
cyberhobo commented 4 years ago

Apologies, my response was overly hasty and I should have reviewed the Widget API more closely. You're right, I can and should fix this.

netzgestaltung commented 3 years ago

thank you for the reaction and fixiing!