Skip to content

Remove private functions #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

IanDelMar
Copy link
Contributor

@IanDelMar IanDelMar commented Apr 28, 2023

Removes function that are marked private using @access private .

This removes 341 functions:
  • _wp_ajax_delete_comment_response()
  • _wp_ajax_add_hierarchical_term()
  • wp_link_manager_disabled_message()
  • _wp_credits_add_profile_link()
  • _wp_credits_build_object_link()
  • _wp_dashboard_control_callback()
  • _wp_dashboard_recent_comments_row()
  • _relocate_children()
  • _wp_privacy_requests_screen_options()
  • _wp_handle_upload()
  • _unzip_file_ziparchive()
  • _unzip_file_pclzip()
  • _wp_image_meta_replace_original()
  • _wp_make_subsizes()
  • _load_image_to_edit_path()
  • _copy_image_file()
  • _usort_by_first_member()
  • _cleanup_image_add_caption()
  • wp_make_theme_file_tree()
  • wp_print_theme_file_tree()
  • wp_make_plugin_file_tree()
  • wp_print_plugin_file_tree()
  • _wp_privacy_settings_filter_draft_page_titles()
  • _access_denied_splash()
  • _thickbox_path_admin_subfolder()
  • _wp_nav_menu_meta_box_object()
  • _wp_delete_orphaned_draft_menu_items()
  • _wp_expand_nav_menu_post_data()
  • _get_plugin_data_markup_translate()
  • _sort_uname_callback()
  • deactivated_plugins_notice()
  • _fix_attachment_links()
  • _disable_block_editor_for_navigation_post_type()
  • _disable_content_editor_for_navigation_post_type()
  • _enable_content_editor_for_navigation_post_type()
  • _wp_privacy_resend_request()
  • _wp_privacy_completed_request()
  • _wp_personal_data_handle_actions()
  • _wp_personal_data_cleanup_requests()
  • _get_plugin_from_callback()
  • _local_storage_notice()
  • _get_template_edit_filename()
  • _upgrade_core_deactivate_incompatible_plugins()
  • __get_option()
  • delete_users_add_js()
  • _sort_name_callback()
  • startElement()
  • endElement()
  • _wp_menu_output()
  • _add_themes_utility_last()
  • _add_plugin_file_editor_to_tools()
  • _wp_admin_bar_init()
  • _get_admin_bar_pref()
  • __clear_multi_author_cache()
  • _wp_get_iframed_editor_assets()
  • _register_core_block_patterns_and_categories()
  • wp_normalize_remote_block_pattern()
  • _register_remote_theme_patterns()
  • _register_theme_block_patterns()
  • wp_register_alignment_support()
  • wp_apply_alignment_support()
  • wp_register_border_support()
  • wp_apply_border_support()
  • wp_has_border_feature_support()
  • wp_register_colors_support()
  • wp_apply_colors_support()
  • wp_register_custom_classname_support()
  • wp_apply_custom_classname_support()
  • wp_register_dimensions_support()
  • wp_apply_dimensions_support()
  • wp_tinycolor_bound01()
  • _wp_tinycolor_bound_alpha()
  • wp_tinycolor_rgb_to_rgb()
  • wp_tinycolor_hue_to_rgb()
  • wp_tinycolor_hsl_to_rgb()
  • wp_tinycolor_string_to_rgb()
  • wp_get_duotone_filter_id()
  • wp_get_duotone_filter_property()
  • wp_get_duotone_filter_svg()
  • wp_register_duotone_support()
  • wp_render_duotone_support()
  • wp_get_elements_class_name()
  • wp_render_elements_support()
  • wp_render_elements_support_styles()
  • wp_get_block_default_classname()
  • wp_apply_generated_classname_support()
  • wp_register_layout_support()
  • wp_get_layout_style()
  • wp_render_layout_support_flag()
  • wp_restore_group_inner_container()
  • wp_restore_image_outer_container()
  • wp_register_position_support()
  • wp_render_position_support()
  • _wp_get_presets_class_name()
  • _wp_add_block_level_presets_class()
  • _wp_add_block_level_preset_styles()
  • wp_register_spacing_support()
  • wp_apply_spacing_support()
  • wp_register_typography_support()
  • wp_apply_typography_support()
  • wp_get_computed_fluid_typography_value()
  • wp_should_skip_block_supports_serialization()
  • _filter_block_template_part_area()
  • _get_block_templates_paths()
  • _get_block_template_file()
  • _get_block_templates_files()
  • _add_block_template_info()
  • _add_block_template_part_area_info()
  • _flatten_blocks()
  • _inject_theme_attribute_in_block_template_content()
  • _remove_theme_attribute_in_block_template_content()
  • _build_block_template_result_from_file()
  • _wp_build_title_and_description_for_single_post_type_block_template()
  • _wp_build_title_and_description_for_taxonomy_block_template()
  • _build_block_template_result_from_post()
  • _add_template_loader_filters()
  • resolve_block_template()
  • _block_template_render_title_tag()
  • get_the_block_template_html()
  • _block_template_viewport_meta_tag()
  • _strip_template_file_suffix()
  • _block_template_render_without_post_block_context()
  • _resolve_template_for_new_post()
  • _excerpt_render_inner_blocks()
  • _restore_wpautop_hook()
  • _walk_bookmarks()
  • _remove_qs_args_if_not_in_url()
  • _wp_object_name_sort_cb()
  • _wp_object_count_sort_cb()
  • _make_cat_compat()
  • _get_comment_reply_id()
  • _clear_modified_cache_on_transition_comment_status()
  • _close_comments_for_old_posts()
  • _close_comments_for_old_post()
  • _wp_cron()
  • _get_cron_array()
  • _set_cron_array()
  • _upgrade_cron_array()
  • funky_javascript_callback()
  • _search_terms_tidy()
  • default_topic_count_text()
  • _preview_theme_template_filter()
  • _preview_theme_stylesheet_filter()
  • preview_theme_ob_filter()
  • preview_theme_ob_filter_callback()
  • _usort_terms_by_ID()
  • _usort_terms_by_name()
  • _sort_nav_menu_items()
  • wp_unregister_GLOBALS()
  • _wp_register_meta_args_whitelist()
  • _excerpt_render_inner_columns_blocks()
  • wp_skip_border_serialization()
  • wp_skip_dimensions_serialization()
  • wp_skip_spacing_serialization()
  • _get_path_to_translation()
  • _get_path_to_translation_from_lang_dir()
  • wp_typography_get_css_variable_inline_style()
  • _filter_query_attachment_filenames()
  • _resolve_home_block_template()
  • _wp_oembed_get_object()
  • _oembed_rest_pre_serve_request()
  • _oembed_create_xml()
  • _oembed_filter_feed_content()
  • _wptexturize_pushpop_element()
  • _get_wptexturize_split_regex()
  • _get_wptexturize_shortcode_regex()
  • _autop_newline_preservation_helper()
  • _wp_specialchars()
  • _make_url_clickable_cb()
  • _make_web_ftp_clickable_cb()
  • _make_email_clickable_cb()
  • _split_str_by_whitespace()
  • _wp_iso_convert()
  • _deep_replace()
  • _links_add_base()
  • _links_add_target()
  • _sanitize_text_fields()
  • _print_emoji_detection_script()
  • _wp_emoji_list()
  • _http_build_query()
  • _wp_upload_dir()
  • _wp_check_alternate_file_names()
  • _wp_check_existing_file_names()
  • _default_wp_die_handler()
  • _ajax_wp_die_handler()
  • _json_wp_die_handler()
  • _jsonp_wp_die_handler()
  • _xmlrpc_wp_die_handler()
  • _xml_wp_die_handler()
  • _scalar_wp_die_handler()
  • _wp_die_process_input()
  • _wp_json_sanity_check()
  • _wp_json_convert_string()
  • _wp_json_prepare_data()
  • _config_wp_home()
  • _config_wp_siteurl()
  • _delete_option_fresh_site()
  • _mce_set_direction()
  • _wp_array_get()
  • _wp_array_set()
  • _deprecated_hook()
  • _wp_timezone_choice_usort_callback()
  • _cleanup_header_comment()
  • wp_find_hierarchy_loop()
  • wp_find_hierarchy_loop_tortoise_hare()
  • _device_can_upload()
  • _canonical_charset()
  • wp_get_default_update_php_url()
  • wp_get_default_update_https_url()
  • _wp_render_title_tag()
  • __checked_selected_helper()
  • _wp_http_get_object()
  • _get_component_from_parsed_url_array()
  • _wp_translate_php_url_constant_to_key()
  • wp_update_https_detection_errors()
  • wp_schedule_https_detection()
  • wp_cron_conditionally_prevent_sslverify()
  • wp_is_local_html_output()
  • wp_update_https_migration_required()
  • _wp_kses_split_callback()
  • wp_kses_split2()
  • wp_kses_bad_protocol_once2()
  • wp_kses_normalize_entities2()
  • wp_kses_normalize_entities3()
  • _wp_kses_decode_entities_chr()
  • _wp_kses_decode_entities_chr_hexdec()
  • _wp_add_global_attributes()
  • _wp_kses_allow_pdf_objects()
  • _load_textdomain_just_in_time()
  • translate_settings_using_i18n_schema()
  • _get_page_link()
  • _navigation_markup()
  • wp_fix_server_vars()
  • wp_check_php_mysql_versions()
  • wp_maintenance()
  • timer_start()
  • wp_debug_mode()
  • wp_set_lang_dir()
  • wp_set_wpdb_vars()
  • wp_start_object_cache()
  • wp_not_installed()
  • wp_get_mu_plugins()
  • wp_get_active_and_valid_plugins()
  • wp_get_active_and_valid_themes()
  • wp_set_internal_encoding()
  • wp_magic_quotes()
  • shutdown_action_hook()
  • wp_load_translations_early()
  • _wp_get_attachment_relative_path()
  • _wp_get_image_size_from_meta()
  • _wp_add_additional_image_sizes()
  • wp_increase_content_media_count()
  • _wp_register_meta_args_allowed_list()
  • wp_get_active_network_plugins()
  • ms_load_current_site_and_network()
  • ms_not_installed()
  • get_current_site_name()
  • wpmu_current_site()
  • _wp_menu_item_classes_by_context()
  • _nav_menu_item_id_use_once()
  • _is_valid_nav_menu_item()
  • _wp_delete_post_menu_item()
  • _wp_delete_tax_menu_item()
  • _wp_auto_add_pages_to_menu()
  • _wp_delete_customize_changeset_dependent_auto_drafts()
  • _wp_menus_changed()
  • _wp_reset_invalid_menu_item_parent()
  • wp_set_all_user_settings()
  • _wp_sanitize_utf8_in_redirect()
  • _wp_sanitize_utf8_in_redirect()
  • _wp_call_all_hook()
  • _wp_filter_build_unique_id()
  • _post_format_request()
  • _post_format_link()
  • _post_format_get_term()
  • _post_format_get_terms()
  • _post_format_wp_get_object_terms()
  • _wp_link_page()
  • _wp_relative_upload_path()
  • _wp_privacy_statuses()
  • _post_type_meta_capabilities()
  • get_post_type_labels()
  • _get_custom_object_labels()
  • _add_post_type_submenus()
  • _count_posts_cache_key()
  • _reset_front_page_settings_for_post()
  • _truncate_post_slug()
  • _page_traverse_name()
  • _get_last_post_time()
  • _transition_post_status()
  • _future_post_hook()
  • _publish_post_hook()
  • _update_term_count_on_transition_post_status()
  • wp_add_trashed_suffix_to_post_name_for_trashed_posts()
  • wp_add_trashed_suffix_to_post_name_for_post()
  • _find_post_by_old_slug()
  • _find_post_by_old_date()
  • _wp_post_revision_fields()
  • _wp_post_revision_data()
  • _wp_put_post_revision()
  • _set_preview()
  • _show_post_preview()
  • _wp_preview_terms_filter()
  • _wp_preview_post_thumbnail_filter()
  • _wp_get_post_revision_version()
  • _wp_upgrade_revisions_of_post()
  • _wp_filter_taxonomy_base()
  • _wp_normalize_relative_css_links()
  • _wp_theme_json_webfonts_handler()
  • do_shortcode_tag()
  • _get_term_hierarchy()
  • _get_term_children()
  • _pad_term_counts()
  • _update_post_term_count()
  • wp_filter_wp_template_unique_post_slug()
  • the_block_template_skip_link()
  • wp_enable_block_templates()
  • _get_random_header_data()
  • _custom_header_background_just_in_time()
  • _custom_logo_header_styles()
  • _remove_theme_support()
  • _delete_attachment_theme_mod()
  • _wp_customize_publish_changeset()
  • _wp_keep_alive_customize_changeset_dependent_auto_drafts()
  • _add_default_theme_supports()
  • _maybe_update_plugins()
  • _maybe_update_themes()
  • _get_additional_user_keys()
  • _wp_get_user_contactmethods()
  • _wp_get_current_user()
  • _wp_privacy_action_request_types()
  • _wp_privacy_account_request_confirmed()
  • _wp_privacy_account_request_confirmed_message()
  • wp_register_persisted_preferences_meta()
  • wp_get_sidebars_widgets()
  • wp_set_sidebars_widgets()
  • wp_get_widget_defaults()
  • _wp_sidebars_changed()
  • wp_setup_widgets_block_editor()
  • wp_check_widget_editor_deps()
  • _wp_block_theme_register_classic_sidebars()

@szepeviktor
Copy link
Member

I see you are planning to destroy others' static analysis 🙃

@IanDelMar
Copy link
Contributor Author

You mean static analysis of the core itself?

@szepeviktor
Copy link
Member

szepeviktor commented Apr 28, 2023

No, simply the usage of phpstan-wordpress

I'm not able to decide whether to merge it or close it.
I too have theories!! But no facts.

What to do now?

@szepeviktor
Copy link
Member

szepeviktor commented Apr 28, 2023

In other words: how many of the removed 341 functions are called in PHPStan users' code?? Mainly tools and frameworks - tools frequently fiddle with core constants etc.

WordPress ecosystem has only 1 consistent thing: very low code quality.

@szepeviktor
Copy link
Member

szepeviktor commented Apr 28, 2023

In what 10 "leading" projects should I try to run Psalm/PHPStan without these @access private tagged functions?
@johnbillion

@IanDelMar
Copy link
Contributor Author

Two scenarios:

  1. Those @access private were added incorrectly.
  2. Users do use functions that were not meant to be used by users.

In the first scenario someone will open an issue here about stubs being incorrect. Which then ideally will lead to the removal of the incorrect @access private from the core. In the second scenario it's risky to use that function as it is intended to be used by core functions and classes anyways, no?

The intention of doing this was not to destroy anything or make life difficult for anyone. If there is concern that this will happen it's better to not merge this PR.

@szepeviktor
Copy link
Member

Okay-okay. These are clear theories.
In real life WP "developers" are copy-pasting anything and everything.
They surely do not care whether it is a "private" function!

@szepeviktor
Copy link
Member

Does WPCS raise an error when "private" functions are called??

@IanDelMar
Copy link
Contributor Author

Good question.

@szepeviktor
Copy link
Member

@spacedmonkey You have the brains!
WordPress/WordPress-Coding-Standards#723
Could you help us (not)removing @access private tagged functions from core stubs?

@IanDelMar
Copy link
Contributor Author

I tested _get_block_templates_files(). No warning and no error by WPCS.

@szepeviktor
Copy link
Member

They have that open PR, linked above.

@herndlm
Copy link
Contributor

herndlm commented Apr 28, 2023

Interesting idea. This is the function counterpart of what php-stubs/generator#15 was for methods, right?

@szepeviktor
Copy link
Member

szepeviktor commented Apr 29, 2023

Yes.

I am thinking about the same solution as in WC and WP-CLI stubs: release two stubs files.
One with every function, one without "private" functions.

@szepeviktor
Copy link
Member

szepeviktor commented Apr 29, 2023

To proceed with this we need to look like an application: src/ + PSR-4

visitor.php

<?php

return new OurVisitor();

@IanDelMar
Copy link
Contributor Author

Do we really need one file with all functions and one without private functions? Can't we have the private functions as complement?

@szepeviktor
Copy link
Member

Can't we have the private functions as complement?

I'm very much into that.
How to do that?

@IanDelMar
Copy link
Contributor Author

I'm thinking of something, but I have to do something else now. Give me a few hours and I'll give you an example.

@johnbillion
Copy link
Contributor

I'd be tempted just to keep these in place. It's certain that these functions are being used outside of their intended "private" access (whatever that means in the context of a non-namespaced procedural function) so the stubs may as well be provided because they already exist.

In #62 the private methods were removed because they are actually inaccessible.

@szepeviktor
Copy link
Member

their intended "private" access (whatever that means in the context of a non-namespaced procedural function)

I guess "internal".

@szepeviktor
Copy link
Member

@IanDelMar It would be fun to emit a warning "Please avoid using internal functions" - something like https://github.com/phpstan/phpstan-deprecation-rules based on @access private tags.

@IanDelMar
Copy link
Contributor Author

I have been very busy the last few days and will continue to be so next week. But then I'll have a look at it.

@spacedmonkey
Copy link

I would generate a stub with and without private functions. Leave the current one as is, so not to break anything but have an option to include stubs without private functions. That is my two cents.

@swissspidy
Copy link
Contributor

swissspidy commented May 13, 2023

+1 to keeping the stubs as is but using custom rules to emit warnings for usage. I tried to whip something together at https://github.com/swissspidy/phpstan-no-private for that. Currently very broken, but it definitely seems possible to do this.

@swissspidy
Copy link
Contributor

Update: it now seems to work 🎉 So I'd recommend using https://github.com/swissspidy/phpstan-no-private for this scenario

@szepeviktor
Copy link
Member

Resolved in https://github.com/swissspidy/phpstan-no-private/releases/tag/v0.1.0 🎉

@IanDelMar IanDelMar deleted the private branch September 9, 2024 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants