Make WordPress Core

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#22182 closed enhancement (worksforme)

Make core theme customizer section titles filterable

Reported by: dgwyer's profile 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 12 years ago.

Download all attachments as: .zip

Change History (13)

#1 @scribu
12 years ago

  • Cc scribu added

#2 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

+1 for making the labels filterable.

#3 @sabreuse
12 years ago

  • Cc sabreuse added

#4 follow-up: @greenshady
12 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?

#5 in reply to: ↑ 4 @DrewAPicture
12 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.

#6 @dgwyer
12 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 in ONE go, including user defined ones (not just core defined ones).

Usage is 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 and it works well. Very easy to update one or more section titles simultaneously.

Last edited 12 years ago by dgwyer (previous) (diff)

#7 @dgwyer
12 years ago

  • Keywords close removed

#8 @dgwyer
11 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.

#9 @obenland
11 years 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' );

#10 @dgwyer
11 years 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 11 years ago by dgwyer (previous) (diff)

#11 @SergeyBiryukov
11 years ago

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

#12 @SergeyBiryukov
11 years ago

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