WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 7 weeks ago

#26661 closed enhancement (fixed)

Add before/after hooks to override output of wp_widget_control()

Reported by: westonruter Owned by: SergeyBiryukov
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: Widgets Keywords: has-patch docs-feedback
Focuses: Cc:

Description

As part of the widgets improvements being worked on for core, we need to override the default output of wp_widget_control(). One way to do this is to add a before/after actions around the output generated by the function:

  • src/wp-admin/includes/widgets.php

     
    188188        $widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) ); 
    189189        $has_form = 'noform'; 
    190190 
     191        do_action( 'temp_wp_widget_control_before', $sidebar_args ); 
    191192        echo $sidebar_args['before_widget']; ?> 
    192193        <div class="widget-top"> 
    193194        <div class="widget-title-action"> 
     
    237238        </div> 
    238239<?php 
    239240        echo $sidebar_args['after_widget']; 
     241        do_action( 'temp_wp_widget_control_after', $sidebar_args, $has_form !== 'noform' ); 
    240242        return $sidebar_args; 
    241243} 

Such hooks seem useful on a permanent basis as well, so perhaps the temp_ prefix can be dropped to begin with.

See related discussion on IRC (up until the end of the day): https://irclogs.wordpress.org/chanlog.php?channel=wordpress-ui&day=2013-12-16&sort=asc#m144514

Related to #25368

Attachments (4)

widgets.php.patch (692 bytes) - added by westonruter 4 months ago.
widgets.php.2.patch (669 bytes) - added by westonruter 4 months ago.
Pass $has_form variable into action as-is, and remove temp_ prefix
widgets.php.3.patch (1.7 KB) - added by westonruter 4 months ago.
Remove temp_ prefixes and add docs to new action hooks wp_widget_control_before and wp_widget_control_after
widgets.php.4.patch (2.4 KB) - added by westonruter 4 months ago.
Applying some more hook docs improvements gleaned from DrewAPicture in #25368

Download all attachments as: .zip

Change History (16)

westonruter4 months ago

comment:1 westonruter4 months ago

  • Keywords has-patch added

comment:2 SergeyBiryukov4 months ago

  • Milestone changed from Awaiting Review to 3.9

comment:3 ircbot4 months ago

This ticket was mentioned in IRC in #wordpress-dev by westonruter. View the logs.

comment:4 SergeyBiryukov4 months ago

Can we just pass $has_form rather than $has_form !== 'noform' as the last argument to wp_widget_control_after?

westonruter4 months ago

Pass $has_form variable into action as-is, and remove temp_ prefix

comment:5 SergeyBiryukov4 months ago

In 26865:

Add temporary hooks for the widgets feature team to wp_widget_control().

props westonruter.
see #26661.

comment:6 SergeyBiryukov4 months ago

In 26866:

Add comments for temporary hooks. see #26661.

comment:7 SergeyBiryukov4 months ago

On second thought, 'noform' !== $has_form seems to make sense, so I decided to leave it as is.

We'd need to document the new hooks if they are going to stay.

westonruter4 months ago

Remove temp_ prefixes and add docs to new action hooks wp_widget_control_before and wp_widget_control_after

comment:8 SergeyBiryukov4 months ago

  • Keywords docs-feedback added

westonruter4 months ago

Applying some more hook docs improvements gleaned from DrewAPicture in #25368

comment:9 westonruter7 weeks ago

  • Resolution set to maybelater
  • Status changed from new to closed

It turns out that we actually didn't need this, since the widget icons are being supplied via CSS as dashicons instead of as inline image elements.

comment:10 follow-up: SergeyBiryukov7 weeks ago

  • Resolution maybelater deleted
  • Status changed from closed to reopened

Do we still need temporary hooks added in [26865]? If not, let's remove them.

comment:11 in reply to: ↑ 10 westonruter7 weeks ago

Replying to SergeyBiryukov:

Do we still need temporary hooks added in [26865]? If not, let's remove them.

They can be removed, yes, unless @shaunandrews objects.

comment:12 SergeyBiryukov7 weeks ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from reopened to closed

In 27324:

Remove temporary hooks added in [26865].

fixes #26661.

Note: See TracTickets for help on using tickets.