WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 17 months ago

Last modified 17 months ago

#22182 closed enhancement (worksforme)

Make core theme customizer section titles filterable

Reported by: dgwyer Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Customize Keywords: has-patch
Focuses: Cc:

Description

It would be very useful to be able to modify core theme customizer section titles by making them filterable, or by adding a setter class method to modify an existing section title.

At the moment you can't access a section title directly as it is set to protected.

Example user case scenario is if you needed to add sub controls to an existing section, then the title may need updating to reflect this.

Attachments (1)

update_section_titles.diff (738 bytes) - added by dgwyer 3 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 @scribu3 years ago

  • Cc scribu added

comment:2 @DrewAPicture3 years ago

  • Cc xoodrew@… added

+1 for making the labels filterable.

comment:3 @sabreuse3 years ago

  • Cc sabreuse added

comment:4 follow-up: @greenshady3 years ago

  • Cc justin@… added

Can you just use the gettext hook? Or, use remove_section() and re-add the section with add_section() with a custom title?

comment:5 in reply to: ↑ 4 @DrewAPicture3 years ago

  • Keywords close added

Replying to greenshady:

Can you just use the gettext hook? Or, use remove_section() and re-add the section with add_section() with a custom title?

I did that to re-order controls but didn't occur to me to try it for changing the section titles. This works for me:

$wp_customize->remove_section( 'colors' );
$wp_customize->add_section( 'colors', array(
	'title' => 'New Colors',
	'priority' => 40
) );

Suggest close.

comment:6 @dgwyer3 years ago

  • Keywords has-patch added

I already knew about the remove/add section approach.

If we elect to use class methods, rather than a filter, a more elegant solution would be to add a get/set method to update section title labels rather than having to remove/add sections to update each one individually.

I have uploaded a patch (update_section_titles.diff) to add a class method that accepts an array of key/value pairs of section title id's/labels to update. Using this new method you can update ANY/ALL registered section title labels at once, included user defined ones (not just core defined ones).

End usage is then simply:

$titles = array(	'title_tagline'		=> __( 'Section Title and Tagline' ),
			'colors'		=> __( 'Site Colors' ),
			'header_image'		=> __( 'Header Background Image' ),
			'nav'			=> __( 'Navigation Menu' ),
			'my_custom_title'	=> __( 'Updated Section Title' )
);
$wp_customize->update_section_titles($titles);

I have tested this locally and it seems to work well.

Version 3, edited 3 years ago by dgwyer (previous) (next) (diff)

comment:7 @dgwyer2 years ago

  • Keywords close removed

comment:8 @dgwyer2 years ago

Another reason why this is better than just removing/re-adding the whole section is that I don't necessarily know (or want to know!) how the section was added in the first place.

For example, if I remove/re-add a section and NOT match the other original section attributes exactly (such as priority, capability, theme_supports, description) then it could mess things up, which is not good.

My patch avoids this altogether allowing you to modify all section titles in one go, without affecting anything else.

comment:9 @obenland17 months ago

  • Keywords close added

IMO there really is no need for a filter here. This does it:

<?php

function prefix_customize_register( $wp_customize ) {
        $wp_customize->get_section( 'colors' )->title = __( 'Not Colors. Haha!', 'textdomain' );
}
add_action( 'customize_register', 'prefix_customize_register' );

comment:10 @dgwyer17 months ago

Thanks for the code snippet. If you can update the section title directly then that's the best solution.

Much better than removing/(re)adding an entire section just to alter the title. I don't see any reason this ticket can't be closed now.

Last edited 17 months ago by dgwyer (previous) (diff)

comment:11 @SergeyBiryukov17 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

comment:12 @SergeyBiryukov17 months ago

  • Resolution changed from invalid to worksforme
Note: See TracTickets for help on using tickets.