Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#24478 closed defect (bug) (fixed)

The `theme_action_links` filter passes different arguments in different places.

Reported by: georgestephanis's profile georgestephanis Owned by: ryan's profile ryan
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.1
Component: Themes Keywords: needs-codex has-patch commit
Focuses: Cc:

Description

Since r20029 at least, there has been an inconsistency in how core uses the theme_action_links filter.

Ordinarily, it's used like this:

http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/class-wp-themes-list-table.php#L151
$actions = apply_filters( 'theme_action_links', $actions, $theme );

with $theme being a WP_Theme object.

However, in the Multi Site theme admin panel, it's used like this:

http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/class-wp-ms-themes-list-table.php#L287
$actions = apply_filters( 'theme_action_links', array_filter( $actions ), $stylesheet, $theme, $context );

which means that for any module to successfully function in both contexts, it needs to do the following:

function theme_action_links_filter( $actions, $theme, $ms_theme = null ) {
    if ( is_a( $ms_theme, 'WP_Theme' ) ) {
        $theme = $ms_theme;
    }
    // stuff with $theme
    return $actions;
}

as can be seen in this changeset for a practical implementation: http://plugins.trac.wordpress.org/changeset/721178

If we're using a filter in core, I feel that we should be consistent with what sequence parameters are being passed to it, or at least leave a comment to devs giving them a heads up that they need to account for the other sequence.

Attachments (1)

24478.diff (1.9 KB) - added by georgestephanis 11 years ago.
Potentially breaking ms-themes table by dropping the $stylesheet argument as per nacin.

Download all attachments as: .zip

Change History (9)

#1 @DrewAPicture
11 years ago

  • Keywords needs-codex added

#2 @SergeyBiryukov
11 years ago

  • Version changed from 3.5.1 to 3.1

Introduced in [10713] for single site screen and [16113] for network admin.

#3 @georgestephanis
11 years ago

The $context currently passed to the ms one is whether you're searching or filtering by active or inactive.

It looks, from the initial commit, like the options are 'all', 'enabled', 'disabled', 'upgrade', 'search'

http://core.trac.wordpress.org/browser/trunk/wp-admin/includes/list-table-ms-themes.php?rev=16113#L17

Not really necessary for the non-multi-site implementation, I don't believe.

@georgestephanis
11 years ago

Potentially breaking ms-themes table by dropping the $stylesheet argument as per nacin.

#4 @georgestephanis
11 years ago

Here's an ack of all the .org plugins that use the filter:

~/code/plugins/plugins $ ack theme_action_links
bangla-press/system/views/admin_themes_available_themes.php
45:	$actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);

child-themify/child-themify.php
178:		add_filter( 'theme_action_links', array( 'CTF_Babymaker', 'moodLighting' ), 10, 2 );

custom-content-type-manager/loader.php
83:		// add_filter('theme_action_links', 'CCTM::highlight_cctm_compatible_themes');

dp-excerpt/lib/panel.php
345:	function theme_action_links($links) {

iammobiled-mobile/iammobiled-mobile.php
755:	$actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);

ktai-style/config/panel.php
287:	$actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);

minimum-version/hooks-3.json
1:["add_meta_boxes","add_meta_boxes_comment","add_meta_boxes_link","add_meta_boxes_{$post_type}","add_option_{$option}","add_signup_meta","add_site_option","add_site_option_{$option}","add_tag_form_fields","add_user_to_blog","admin_color_scheme_picker","admin_memory_limit","admin_user_info_links","after-{$taxonomy}-table","after_mu_upgrade","after_setup_theme","after_signup_form","allowed_themes","allow_subdirectory_install","all_plugins","app_entry","app_head","app_ns","archive_blog","author_template","before_signup_form","blog_details","blog_option_{$setting}","blog_redirect_404","clean_attachment_cache","comment_duplicate_trigger","comment_form_after","comment_form_after_fields","comment_form_before","comment_form_before_fields","comment_form_comments_closed","comment_form_defaults","comment_form_default_fields","comment_form_field_comment","comment_form_field_{$name}","comment_form_logged_in","comment_form_logged_in_after","comment_form_must_log_in_after","comment_form_top","comment_id_fields","comment_max_links_url","comment_on_password_protected","current_screen","deactivate_blog","deleted_site_transient","deleted_transient","delete_blog","delete_option_{$option}","delete_site_email_content","delete_site_option","delete_site_option_{$option}","delete_site_transient_{$transient}","delete_transient_{$transient}","deprecated_argument_run","deprecated_argument_trigger_error","do_mu_upgrade","dynamic_sidebar","edit_{$taxonomy}_per_page","enable_edit_any_user_configuration","enable_post_by_email_configuration","enable_update_services_configuration","front_page_template","getimagesize_mimes_to_exts","get_avatar_comment_types","get_blogs_of_user","get_calendar","get_shortlink","get_template_part_{$slug}","get_the_date","global_terms_enabled","graceful_fail","graceful_fail_template","granted_super_admin","grant_super_admin","home_url","in_admin_header","kses_allowed_protocols","lang_codes","login_form_bottom","login_form_defaults","login_form_middle","login_form_top","lostpassword_redirect","make_ham_blog","make_ham_user","make_spam_blog","make_spam_user","manage_blogs_custom_column","manage_{$post_type}_posts_columns","manage_{$screen->id}_columns","ms_sites_per_page","ms_site_check","ms_users_per_page","mu_activity_box_end","mu_dropdown_languages","mu_menu_items","mu_rightnow_end","myblogs_allblogs_options","myblogs_blog_actions","myblogs_options","nav_menu_attr_title","nav_menu_css_class","nav_menu_description","nav_menu_meta_box_object","network_admin_url","network_home_url","network_site_url","newblogname","newblog_notify_siteadmin","newuser_notify_siteadmin","new_admin_email_content","new_user_email_content","opml_head","option_{$option}","override_unload_textdomain","paginate_links","parent_file","plugin_locale","posts_search","post_edit_form_tag","post_type_link","post_updated","post_updated_messages","preprocess_signup_form","pre_add_site_option_{$option}","pre_current_active_plugins","pre_delete_site_option_{$option}","pre_get_shortlink","pre_insert_term","pre_option_{$option}","pre_post_link","pre_set_site_transient_{$transient}","pre_set_transient_{$transient}","pre_site_option_{$option}","pre_update_option_{$option}","pre_update_site_option_{$option}","pre_user_search","privacy_on_link_text","privacy_on_link_title","random_password","register_sidebar","registration_redirect","remove_user_from_blog","revoked_super_admin","revoke_super_admin","right_now_content_table_end","right_now_discussion_table_end","robots_txt","sanitize_key","screen_settings","search_link","setted_site_transient","setted_transient","set_site_transient_{$transient}","set_transient_{$transient}","shake_error_codes","show_adduser_fields","show_advanced_plugins","signup_another_blog_init","signup_blogform","signup_blog_init","signup_create_blog_meta","signup_extra_fields","signup_finished","signup_header","signup_hidden_fields","signup_user_init","single_template","site_option_{$option}","subdirectory_reserved_names","switch_blog","tables_to_repair","taxonomy_feed_link","template_include","theme_locale","the_feed_link","the_shortlink","the_widget","twentyten_attachment_size","twentyten_author_bio_avatar_size","twentyten_credits","twentyten_header_image_height","twentyten_header_image_width","unarchive_blog","unload_textdomain","unzip_file_use_ziparchive","update_blog_public","update_bulk_plugins_complete_actions","update_bulk_theme_complete_actions","update_option_{$option}","update_site_option","update_site_option_{$option}","update_welcome_email","update_welcome_subject","update_welcome_user_email","update_welcome_user_subject","update_wpmu_options","user_edit_form_tag","user_new_form_tag","walker_nav_menu_start_el","widgets_admin_page","wpmuadminedit","wpmuadminresult","wpmublogsaction","wpmueditblogaction","wpmu_activate_blog","wpmu_activate_user","wpmu_active_signup","wpmu_blogs_columns","wpmu_blog_updated","wpmu_delete_blog_upload_dir","wpmu_delete_user","wpmu_drop_tables","wpmu_new_blog","wpmu_new_user","wpmu_options","wpmu_signup_blog_notification","wpmu_signup_blog_notification_email","wpmu_signup_blog_notification_subject","wpmu_signup_user_notification","wpmu_signup_user_notification_email","wpmu_signup_user_notification_subject","wpmu_update_blog_options","wpmu_upgrade_page","wpmu_upgrade_site","wpmu_users_columns","wpmu_validate_blog_signup","wpmu_validate_user_signup","wpmu_welcome_notification","wpmu_welcome_user_notification","wp_check_filetype_and_ext","wp_create_nav_menu","wp_delete_nav_menu","wp_die_handler","wp_edit_nav_menu_walker","wp_feed_options","wp_get_nav_menus","wp_get_nav_menu_items","wp_link_pages_args","wp_loaded","wp_nav_menu","wp_nav_menu_args","wp_nav_menu_container_allowedtags","wp_nav_menu_items","wp_nav_menu_{$menu->slug}_items","wp_register_sidebar_widget","wp_setup_nav_menu_item","wp_signup_location","wp_unregister_sidebar_widget","wp_update_nav_menu","wp_update_nav_menu_item","wp_upload_bits","{$per_page}","{$taxonomy}_add_form","{$taxonomy}_add_form_fields","{$taxonomy}_edit_form","{$taxonomy}_edit_form_fields","{$taxonomy}_pre_add_form","{$taxonomy}_pre_edit_form","{$taxonomy}_row_actions","{$type}_upload_iframe_src","add_admin_bar_menus","add_{$meta_type}_meta","add_{$meta_type}_metadata","admin_bar_init","admin_bar_menu","admin_title","after_theme_row","after_theme_row_{$theme_key}","akismet_comment_nonce","akismet_optimize_table","akismet_show_user_comments_approved","akismet_submit_nonspam_comment","akismet_submit_spam_comment","all_admin_notices","all_themes","bulk_actions-{$screen->id}","can_edit_network","comments_clauses","custom_header_options","default_hidden_meta_boxes","delete_{$meta_type}_meta","delete_{$meta_type}_metadata","doing_it_wrong_run","doing_it_wrong_trigger_error","edit_profile_url","edit_term_link","enter_title_here","esc_textarea","force_filtered_html_on_import","get_ancestors","get_edit_term_link","get_media_item_args","get_meta_sql","get_terms_args","get_the_categories","get_the_terms","get_{$meta_type}_metadata","in_theme_update_message-{$theme_key}","list_pages","load-categories-php","load-edit-link-categories-php","load-page-new-php","load-page-php","load_image_to_edit_attachmenturl","load_image_to_edit_filesystempath","login_enqueue_scripts","login_footer","manage_plugins_custom_column","manage_sites_action_links","manage_sites_custom_column","manage_themes_custom_column","manage_{$post->post_type}_posts_custom_column","manage_{$screen->id}_sortable_columns","manage_{$screen->taxonomy}_custom_column","mature_blog","media_upload_mime_type_links","ms_user_list_site_actions","nav_menu_item_id","network_admin_edit_{$action}","network_admin_menu","network_admin_notices","network_sites_updated_message_{$action}","network_site_users_after_list_table","posts_clauses","posts_clauses_request","post_comment_status_meta_box-options","post_format_rewrite_base","post_type_archive_feed_link","post_type_archive_link","post_type_archive_title","pre_get_comments","pre_user_query","schedule_event","secure_auth_cookie","secure_auth_redirect","secure_logged_in_cookie","secure_signon_cookie","show_admin_bar","show_network_site_users_add_existing_form","show_network_site_users_add_new_form","show_recent_comments_widget_style","single_term_title","swfupload_post_params","swfupload_success_handler","terms_clauses","theme_action_links_{$theme_key}","theme_row_meta","the_comments","tiny_mce_preload_dialogs","twentyten_attachment_height","unmature_blog","update_{$meta_type}_metadata","user_admin_menu","user_admin_notices","user_admin_url","user_dashboard_url","use_default_gallery_style","views_{$screen->id}","wp_admin_bar_class","wp_after_admin_bar_render","wp_before_admin_bar_render","wp_get_current_commenter","wp_insert_post_parent","wp_nav_menu_objects","wp_network_dashboard_setup","wp_network_dashboard_widgets","wp_unique_post_slug_is_bad_attachment_slug","wp_unique_post_slug_is_bad_flat_slug","wp_unique_post_slug_is_bad_hierarchical_slug","wp_update_term_parent","wp_user_dashboard_setup","wp_user_dashboard_widgets","wp_xmlrpc_server_class","_network_admin_menu","_user_admin_menu","{$permastructname}_rewrite_rules","{$prefix}plugin_action_links","{$prefix}plugin_action_links_{$plugin_file}","after_delete_post","after_wp_tiny_mce","atom_author","before_delete_post","before_wp_tiny_mce","browse-happy-notice","category_archive_meta","close_comments_for_post_types","display_media_states","found_users_query","image_memory_limit","is_protected_meta","login_init","ms_user_row_actions","nav_menu_items_{$post_type_name}","option_page_capability_{$option_page}","postbox_classes_{$page}_{$id}","redirect_network_admin_request","redirect_user_admin_request","sanitize_meta","sanitize_mime_type","screen_options_show_screen","tag_archive_meta","twentyeleven_attachment_size","twentyeleven_author_bio_avatar_size","twentyeleven_color_schemes","twentyeleven_credits","twentyeleven_default_theme_options","twentyeleven_enqueue_color_scheme","twentyeleven_header_image_height","twentyeleven_header_image_width","twentyeleven_layouts","twentyeleven_layout_classes","twentyeleven_status_avatar","twentyeleven_theme_options_validate","update-core-custom_{$action}","use_google_chrome_frame","wp_fullscreen_buttons","after_switch_theme","auth_post_meta_{$meta_key}","dbdelta_create_queries","dbdelta_insert_queries","dbdelta_queries","hidden_meta_boxes","image_size_names_choose","is_multi_author","page_attributes_dropdown_pages_args","plupload_init","post-plupload-upload-ui","pre-plupload-upload-ui","pre_ent2ncr","print_late_styles","quicktags_settings","registered_post_type","registered_taxonomy","sanitize_{$meta_type}_meta_{$meta_key}","tiny_mce_plugins","type_url_form_media","upload_post_params","wp_insert_post_empty_content","wp_is_large_network","wp_trash_post","wp_trim_words","wp_unique_post_slug","wp_upload_resize","wxr_export_skip_postmeta","_core_updated_successfully","{$type}_send_to_editor_url","akismet_delete_commentmeta_interval","akismet_ua","allowed_http_origin","allowed_http_origins","autocomplete_users_for_site_admins","comment_add_author_url","comment_remove_author_url","current_theme_supports-{$feature}","customize_allowed_urls","customize_controls_enqueue_scripts","customize_controls_init","customize_controls_print_footer_scripts","customize_controls_print_scripts","customize_controls_print_styles","customize_preview_init","customize_preview_{$this->id}","customize_register","customize_render_control","customize_render_control_{$this->id}","customize_render_section","customize_render_section_{$this->id}","customize_sanitize_js_{$this->id}","customize_sanitize_{$this->id}","customize_save","customize_save_{$this->id_data[base]}","customize_update_{$this->type}","customize_value_{$this->id_data[base]}","default_option_{$option}","default_site_option_{$option}","deleted_{$meta_type}meta","delete_{$meta_type}meta","extra_theme_headers","http_origin","image_resize_dimensions","plupload_default_params","plupload_default_settings","posts_request_ids","post_types_to_delete_with_user","refresh_blog_details","sanitize_trackback_urls","set_comment_cookies","set_url_scheme","split_the_query","start_previewing_theme","stop_previewing_theme","theme_install_actions","widget_comments_args","widget_posts_args","wp_atom_server_class","wp_cache_themes_persistently","wp_die_ajax_handler","wp_die_app_handler","wp_die_xmlrpc_handler","wp_http_cookie_value","wp_terms_checklist_args","xmlrpc_call_success_blogger_deletePost","xmlrpc_call_success_blogger_editPost","xmlrpc_call_success_blogger_newPost","xmlrpc_call_success_mw_editPost","xmlrpc_call_success_mw_newMediaObject","xmlrpc_call_success_mw_newPost","xmlrpc_call_success_wp_deleteCategory","xmlrpc_call_success_wp_deleteComment","xmlrpc_call_success_wp_deletePage","xmlrpc_call_success_wp_editComment","xmlrpc_call_success_wp_newCategory","xmlrpc_call_success_wp_newComment","xmlrpc_default_posttype_fields","xmlrpc_default_post_fields","xmlrpc_default_taxonomy_fields","xmlrpc_prepare_comment","xmlrpc_prepare_media_item","xmlrpc_prepare_page","xmlrpc_prepare_post","xmlrpc_prepare_post_type","xmlrpc_prepare_taxonomy","xmlrpc_prepare_term","xmlrpc_wp_insert_post_data","after_theme_row_{$stylesheet}","attachment_submitbox_misc_actions","blog_option_{$option}","bulk_actions-{$this->screen->id}","cron_request","domain_exists","do_parse_request","edit_form_after_editor","edit_form_after_title","exit_on_http_head","export_args","export_filters","get_edit_user_link","image_editor_default_mime_type","image_editor_save_pre","is_email_address_unsafe","load-importer-{$importer}","login_body_class","make_delete_blog","make_undelete_blog","manage_taxonomies_for_attachment_columns","manage_taxonomies_for_{$post_type}_columns","manage_{$this->screen->id}_sortable_columns","manage_{$this->screen->taxonomy}_custom_column","media_view_settings","media_view_strings","mime_types","network_sites_updated_message_{$updated}","nonce_user_logged_out","oembed_fetch_url","option_enable_xmlrpc","post_link_category","post_type_labels_{$post_type}","pre_get_space_used","pre_http_send_through_proxy","pre_option_enable_xmlrpc","print_media_templates","restrict_manage_comments","restrict_manage_users","theme_action_links_{$stylesheet}","twentytwelve_attachment_size","twentytwelve_author_bio_avatar_size","twentytwelve_credits","twentytwelve_status_avatar","upload_ui_over_quota","validate_password_reset","views_{$this->screen->id}","welcome_panel","wp_checkdate","wp_editor_set_quality","wp_enqueue_media","wp_get_update_data","wp_image_editors","wp_image_editor_before_change","wp_kses_allowed_html","wp_prepare_attachment_for_js","wp_save_image_editor_file","xmlrpc_default_revision_fields","xmlrpc_default_user_fields","xmlrpc_enabled","xmlrpc_login_error","xmlrpc_prepare_user","xmlrpc_rsd_apis","{$adjacent}_image_link","activate_blog","activate_header","activate_wp_head","added_existing_user"]

subsite-theme-activator/subsite-theme-activator.php
23:add_filter('theme_action_links', 'sa_add_subsite_activate_action', 10, 2);

theme-downloader/readme.txt
42:* Added some code in r721178 to account for Network Admin Themes page passing different arguments to the theme_action_links filter.

theme-downloader/theme-downloader.php
19:		add_filter( 'theme_action_links', array( $this, 'theme_action_links' ), 10, 3 );
24:	function theme_action_links( $actions, $theme, $ms_theme = null ) {

theme-logic/init.php
31:			add_filter( 'theme_action_links', array( &$this, 'theme_action_links' ), 100, 2 );
90:	function theme_action_links( $actions, $theme ) {

theme-visibility-manager/themes-visibility-manager.php
127:add_filter( 'theme_action_links', 'add_themes_visibility_links', 10, 2 );

wp-getting-started/wp-getting-started.php
117:            add_filter ( 'theme_action_links', array ( &$this, 'modify_theme_action_links' ), 10, 2 );
144:        public function modify_theme_action_links( $actions ) {

wp-mobile-detector/admin/themes.php
196:	$actions = apply_filters('theme_action_links', $actions, $themes[$theme_name]);

wpmu-theme-usage-info/cets_theme_info.php
42:			add_filter( 'theme_action_links', array( &$this, 'action_links'), 9, 3);
138:		// $actions       = apply_filters( 'theme_action_links', $actions, $theme );

I'll run through them all shortly to see which if any this would break. I strongly suspect that this is more apt to fix breakage issues than break them, but we'll see.

#5 @georgestephanis
11 years ago

It would fix the following plugins that didn't seem to test with multisite:

theme-logic/init.php (114 downloads) http://wordpress.org/plugins/theme-logic/
theme-visibility-manager/themes-visibility-manager.php (1,640 downloads) http://wordpress.org/plugins/theme-visibility-manager/ -- seems to be useless now as functionality is available in core.

The following plugins would break:

subsite-theme-activator/subsite-theme-activator.php (747 downloads) http://wordpress.org/plugins/subsite-theme-activator/ (but it would break in non-network-admin already) (easy to fix)

#6 @ryan
11 years ago

Looks good.

#7 @ryan
11 years ago

  • Keywords has-patch commit added; needs-patch dev-feedback removed
  • Milestone changed from Awaiting Review to 3.7

#8 @ryan
11 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In 25032:

Be consistent with the arguments passed to the theme_action_links filter. Stop passing stylesheet from class-wp-ms-themes-list-table.php.

Props georgestephanis
fixes #24478

Note: See TracTickets for help on using tickets.