���� JFIF �� �
"" $(4,$&1'-=-157:::#+?D?8C49:7
7%%77777777777777777777777777777777777777777777777777�� { �" �� �� 5 !1AQa"q�2��BR��#b������� �� �� ? ��D@DDD@DDD@DDkK��6 �UG�4V�1��
�����릟�@�#���RY�dqp�
����� �o�7�m�s�<��VPS�e~V�چ8���X�T��$��c�� 9��ᘆ�m6@ WU�f�Don��r��5}9��}��hc�fF��/r=hi�� �͇�*�� b�.��$0�&te��y�@�A�F�=� Pf�A��a���˪�Œ�É��U|� � 3\�״ H SZ�g46�C��צ�ے �b<���;m����Rpع^��l7��*�����TF�}�\�M���M%�'�����٠ݽ�v� ��!-�����?�N!La��A+[`#���M����'�~oR�?��v^)��=��h����A��X�.���˃����^Æ��ܯsO"B�c>;
�e�4��5�k��/CB��.
�J?��;�҈�������������������~�<�VZ�ê¼2/)Í”jC���ע�V�G�!���!�F������\�� Kj�R�oc�h���:Þ I��1"2�q×°8��Р@ז���_C0�ր��A��lQ��@纼�!7��F�� �]�sZ
B�62r�v�z~�K�7�c��5�.���ӄq&�Z�d�<�kk���T&8�|���I���� Ws}���ǽ�cqnΑ�_���3��|N�-y,��i���ȗ_�\60���@��6����D@DDD@DDD@DDD@DDD@DDc�KN66<�c��64=r�����
Ď0��h���t&(�hnb[� ?��^��\��â|�,�/h�\��R��5�?
�0�!צ܉-����G����٬��Q�zA���1�����V��� �:R���`�$��ik��H����D4�����#dk����� h�}����7���w%�������*o8wG�LycuT�.���ܯ7��I��u^���)��/c�,s�Nq�ۺ�;�ך�YH2���.5B���DDD@DDD@DDD@DDD@DDD@V|�a�j{7c��X�F\�3MuA׾hb� ��n��F������ ��8�(��e����Pp�\"G�`s��m��ާaW�K��O����|;ei����֋�[�q��";a��1����Y�G�W/�߇�&�<���Ќ�H'q�m���)�X+!���=�m�ۚ丷~6a^X�)���,�>#&6G���Y��{����"" """ """ """ """ ""��at\/�a�8 �yp%�lhl�n����)���i�t��B�������������?��
' . __( 'The Privacy screen lets you either build a new privacy-policy page or choose one you already have to show.' ) . '
' . '' . __( 'This screen includes suggestions to help you write your own privacy policy. However, it is your responsibility to use these resources correctly, to provide the information required by your privacy policy, and to keep this information current and accurate.' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Privacy Settings' ) . '
' ); if ( ! empty( $action ) ) { check_admin_referer( $action ); if ( 'set-privacy-page' === $action ) { $privacy_policy_page_id = isset( $_POST['page_for_privacy_policy'] ) ? (int) $_POST['page_for_privacy_policy'] : 0; update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); $privacy_page_updated_message = __( 'Privacy Policy page updated successfully.' ); if ( $privacy_policy_page_id ) { /* * Don't always link to the menu customizer: * * - Unpublished pages can't be selected by default. * - `WP_Customize_Nav_Menus::__construct()` checks the user's capabilities. * - Themes might not "officially" support menus. */ if ( 'publish' === get_post_status( $privacy_policy_page_id ) && current_user_can( 'edit_theme_options' ) && current_theme_supports( 'menus' ) ) { $privacy_page_updated_message = sprintf( /* translators: %s: URL to Customizer -> Menus. */ __( 'Privacy Policy page setting updated successfully. Remember to update your menus!' ), esc_url( add_query_arg( 'autofocus[panel]', 'nav_menus', admin_url( 'customize.php' ) ) ) ); } } add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', $privacy_page_updated_message, 'success' ); } elseif ( 'create-privacy-page' === $action ) { if ( ! class_exists( 'WP_Privacy_Policy_Content' ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-privacy-policy-content.php'; } $privacy_policy_page_content = WP_Privacy_Policy_Content::get_default_content(); $privacy_policy_page_id = wp_insert_post( array( 'post_title' => __( 'Privacy Policy' ), 'post_status' => 'draft', 'post_type' => 'page', 'post_content' => $privacy_policy_page_content, ), true ); if ( is_wp_error( $privacy_policy_page_id ) ) { add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', __( 'Unable to create a Privacy Policy page.' ), 'error' ); } else { update_option( 'wp_page_for_privacy_policy', $privacy_policy_page_id ); wp_redirect( admin_url( 'post.php?post=' . $privacy_policy_page_id . '&action=edit' ) ); exit; } } } // If a Privacy Policy page ID is available, make sure the page actually exists. If not, display an error. $privacy_policy_page_exists = false; $privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( ! empty( $privacy_policy_page_id ) ) { $privacy_policy_page = get_post( $privacy_policy_page_id ); if ( ! $privacy_policy_page instanceof WP_Post ) { add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', __( 'The currently selected Privacy Policy page does not exist. Please create or select a new page.' ), 'error' ); } else { if ( 'trash' === $privacy_policy_page->post_status ) { add_settings_error( 'page_for_privacy_policy', 'page_for_privacy_policy', sprintf( /* translators: %s: URL to Pages Trash. */ __( 'The currently selected Privacy Policy page is in the Trash. Please create or select a new Privacy Policy page or restore the current page.' ), 'edit.php?post_status=trash&post_type=page' ), 'error' ); } else { $privacy_policy_page_exists = true; } } } $parent_file = 'options-general.php'; wp_enqueue_script( 'privacy-tools' ); require_once ABSPATH . 'wp-admin/admin-header.php'; ?>' . __( 'Uploading Files allows you to choose the folder and path for storing your uploaded files.' ) . '
'; } $media_options_help .= '' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview' ), 'content' => $media_options_help, ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Media Settings' ) . '
' . '' . __( 'Support forums' ) . '
' ); require_once ABSPATH . 'wp-admin/admin-header.php'; ?>%s
', __( 'File does not exist! Please double check the name and try again.' ) ) ); } else { // Get the extension of the file. if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { $ext = strtolower( $matches[1] ); // If extension is not in the acceptable list, skip it. if ( ! in_array( $ext, $editable_extensions, true ) ) { wp_die( sprintf( '%s
', __( 'Files of this type are not editable.' ) ) ); } } } get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview' ), 'content' => '' . __( 'You can use the plugin file editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.' ) . '
' . '' . __( 'Choose a plugin to edit from the dropdown menu and click the Select button. Click once on any file name to load it in the editor, and make your changes. Do not forget to save your changes (Update File) when you are finished.' ) . '
' . '' . __( 'The documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Look Up takes you to a web page about that particular function.' ) . '
' . '' . __( 'When using a keyboard to navigate:' ) . '
' . '' . __( 'If you want to make changes but do not want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.' ) . '
' . ( is_network_admin() ? '' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '
' : '' ), ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Editing Plugins' ) . '
' . '' . __( 'Documentation on Writing Plugins' ) . '
' . '' . __( 'Support forums' ) . '
' ); $settings = array( 'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), ); wp_enqueue_script( 'wp-theme-plugin-editor' ); wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); require_once ABSPATH . 'wp-admin/admin-header.php'; update_recently_edited( WP_PLUGIN_DIR . '/' . $file ); if ( ! empty( $posted_content ) ) { $content = $posted_content; } else { $content = file_get_contents( $real_file ); } if ( str_ends_with( $real_file, '.php' ) ) { $functions = wp_doc_link_parse( $content ); if ( ! empty( $functions ) ) { $docs_select = ''; } } $content = esc_textarea( $content ); ?>' . __( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ) . '
' . $error . ''; wp_admin_notice( $message, array( 'type' => 'error', 'id' => 'message', 'paragraph_wrap' => false, ) ); endif; ?>
' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '
', 403 ); } $is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); $is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] ); $is_template_part_editor = $is_template_part || $is_template_part_path; $is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] ); $is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] ); $is_patterns_editor = $is_patterns || $is_patterns_path; if ( ! wp_is_block_theme() ) { if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) { wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); } elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) { wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); } } // Used in the HTML title tag. $title = _x( 'Editor', 'site editor title tag' ); $parent_file = 'themes.php'; // Flag that we're loading the block editor. $current_screen = get_current_screen(); $current_screen->is_block_editor( true ); // Default to is-fullscreen-mode to avoid jumps in the UI. add_filter( 'admin_body_class', static function ( $classes ) { return "$classes is-fullscreen-mode"; } ); $indexed_template_types = array(); foreach ( get_default_block_template_types() as $slug => $template_type ) { $template_type['slug'] = (string) $slug; $indexed_template_types[] = $template_type; } $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); $custom_settings = array( 'siteUrl' => site_url(), 'postsPerPage' => get_option( 'posts_per_page' ), 'styles' => get_block_editor_theme_styles(), 'defaultTemplateTypes' => $indexed_template_types, 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 'supportsLayout' => wp_theme_has_theme_json(), 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), ); // Add additional back-compat patterns registered by `current_screen` et al. $custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); $custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { $post_type = get_post_type_object( $_GET['postType'] ); if ( ! $post_type ) { wp_die( __( 'Invalid post type.' ) ); } } $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); $active_theme = get_stylesheet(); $navigation_rest_route = rest_get_route_for_post_type_items( 'wp_navigation' ); $preload_paths = array( array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ), array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ), '/wp/v2/types?context=view', '/wp/v2/types/wp_template?context=edit', '/wp/v2/types/wp_template_part?context=edit', '/wp/v2/templates?context=edit&per_page=-1', '/wp/v2/template-parts?context=edit&per_page=-1', '/wp/v2/themes?context=edit&status=active', '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', array( '/wp/v2/global-styles/' . $active_global_styles_id, 'OPTIONS' ), '/wp/v2/global-styles/themes/' . $active_theme . '?context=view', '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', array( $navigation_rest_route, 'OPTIONS' ), array( add_query_arg( array( 'context' => 'edit', 'per_page' => 100, 'order' => 'desc', 'orderby' => 'date', // array indices are required to avoid query being encoded and not matching in cache. 'status[0]' => 'publish', 'status[1]' => 'draft', ), $navigation_rest_route ), 'GET', ), ); block_editor_rest_api_preload( $preload_paths, $block_editor_context ); wp_add_inline_script( 'wp-edit-site', sprintf( 'wp.domReady( function() { wp.editSite.initializeEditor( "site-editor", %s ); } );', wp_json_encode( $editor_settings ) ) ); // Preload server-registered block schemas. wp_add_inline_script( 'wp-blocks', 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' ); // Preload server-registered block bindings sources. $registered_sources = get_all_registered_block_bindings_sources(); if ( ! empty( $registered_sources ) ) { $filtered_sources = array(); foreach ( $registered_sources as $source ) { $filtered_sources[] = array( 'name' => $source->name, 'label' => $source->label, 'usesContext' => $source->uses_context, ); } $script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) ); wp_add_inline_script( 'wp-blocks', $script ); } wp_add_inline_script( 'wp-blocks', sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ), 'after' ); wp_enqueue_script( 'wp-edit-site' ); wp_enqueue_script( 'wp-format-library' ); wp_enqueue_style( 'wp-edit-site' ); wp_enqueue_style( 'wp-format-library' ); wp_enqueue_media(); if ( current_theme_supports( 'wp-block-styles' ) && ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) ) { wp_enqueue_style( 'wp-block-library-theme' ); } /** This action is documented in wp-admin/edit-form-blocks.php */ do_action( 'enqueue_block_editor_assets' ); require_once ABSPATH . 'wp-admin/admin-header.php'; ?>' . __( 'This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.' ) . '
' . '' . __( 'In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Import' ) . '
' . '' . __( 'Support' ) . '
' ); if ( current_user_can( 'install_plugins' ) ) { // List of popular importer plugins from the WordPress.org API. $popular_importers = wp_get_popular_importers(); } else { $popular_importers = array(); } // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'. if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; if ( $importer_id !== $_GET['invalid'] ) { // Prevent redirect loops. wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) ); exit; } unset( $importer_id ); } add_thickbox(); wp_enqueue_script( 'plugin-install' ); wp_enqueue_script( 'updates' ); require_once ABSPATH . 'wp-admin/admin-header.php'; $parent_file = 'tools.php'; ?>' . __( 'No importers are available.' ) . '
'; // TODO: Make more helpful. } else { uasort( $importers, '_usort_by_first_member' ); ?>{$data[0]} {$action} | {$data[1]} |
' . __( 'Permalinks are the permanent URLs to your individual pages and blog posts, as well as your category and tag archives. A permalink is the web address used to link to your content. The URL to each post should be permanent, and never change — hence the name permalink.' ) . '
' . '' . __( 'This screen allows you to choose your permalink structure. You can choose from common settings or create custom URL structures.' ) . '
' . '' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '
', ) ); get_current_screen()->add_help_tab( array( 'id' => 'permalink-settings', 'title' => __( 'Permalink Settings' ), 'content' => '' . __( 'Permalinks can contain useful information, such as the post date, title, or other elements. You can choose from any of the suggested permalink formats, or you can craft your own if you select Custom Structure.' ) . '
' . '' . sprintf(
/* translators: %s: Percent sign (%). */
__( 'If you pick an option other than Plain, your general URL path with structure tags (terms surrounded by %s) will also appear in the custom structure field and your path can be further modified there.' ),
'%
'
) . '
' . sprintf(
/* translators: 1: %category%, 2: %tag% */
__( 'When you assign multiple categories or tags to a post, only one can show up in the permalink: the lowest numbered category. This applies if your custom structure includes %1$s or %2$s.' ),
'%category%
',
'%tag%
'
) . '
' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '
', ) ); get_current_screen()->add_help_tab( array( 'id' => 'custom-structures', 'title' => __( 'Custom Structures' ), 'content' => '' . __( 'The Optional fields let you customize the “category” and “tag” base names that will appear in archive URLs. For example, the page listing all posts in the “Uncategorized” category could be /topics/uncategorized
instead of /category/uncategorized
.' ) . '
' . __( 'You must click the Save Changes button at the bottom of the screen for new settings to take effect.' ) . '
', ) ); $help_sidebar_content = '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Permalinks Settings' ) . '
' . '' . __( 'Documentation on Using Permalinks' ) . '
'; if ( $is_nginx ) { $help_sidebar_content .= '' . __( 'Documentation on Nginx configuration.' ) . '
'; } $help_sidebar_content .= '' . __( 'Support forums' ) . '
'; get_current_screen()->set_help_sidebar( $help_sidebar_content ); unset( $help_sidebar_content ); $home_path = get_home_path(); $iis7_permalinks = iis7_supports_permalinks(); $permalink_structure = get_option( 'permalink_structure' ); $index_php_prefix = ''; $blog_prefix = ''; if ( ! got_url_rewrite() ) { $index_php_prefix = '/index.php'; } /* * In a subdirectory configuration of multisite, the `/blog` prefix is used by * default on the main site to avoid collisions with other sites created on that * network. If the `permalink_structure` option has been changed to remove this * base prefix, WordPress core can no longer account for the possible collision. */ if ( is_multisite() && ! is_subdomain_install() && is_main_site() && str_starts_with( $permalink_structure, '/blog/' ) ) { $blog_prefix = '/blog'; } $category_base = get_option( 'category_base' ); $tag_base = get_option( 'tag_base' ); $structure_updated = false; $htaccess_update_required = false; if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) ) { check_admin_referer( 'update-permalink' ); if ( isset( $_POST['permalink_structure'] ) ) { if ( isset( $_POST['selection'] ) && 'custom' !== $_POST['selection'] ) { $permalink_structure = $_POST['selection']; } else { $permalink_structure = $_POST['permalink_structure']; } if ( ! empty( $permalink_structure ) ) { $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) ); if ( $index_php_prefix && $blog_prefix ) { $permalink_structure = $index_php_prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure ); } else { $permalink_structure = $blog_prefix . $permalink_structure; } } $permalink_structure = sanitize_option( 'permalink_structure', $permalink_structure ); $wp_rewrite->set_permalink_structure( $permalink_structure ); $structure_updated = true; } if ( isset( $_POST['category_base'] ) ) { $category_base = $_POST['category_base']; if ( ! empty( $category_base ) ) { $category_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); } $wp_rewrite->set_category_base( $category_base ); } if ( isset( $_POST['tag_base'] ) ) { $tag_base = $_POST['tag_base']; if ( ! empty( $tag_base ) ) { $tag_base = $blog_prefix . preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); } $wp_rewrite->set_tag_base( $tag_base ); } } if ( $iis7_permalinks ) { if ( ( ! file_exists( $home_path . 'web.config' ) && win_is_writable( $home_path ) ) || win_is_writable( $home_path . 'web.config' ) ) { $writable = true; } else { $writable = false; } } elseif ( $is_nginx || $is_caddy ) { $writable = false; } else { if ( ( ! file_exists( $home_path . '.htaccess' ) && is_writable( $home_path ) ) || is_writable( $home_path . '.htaccess' ) ) { $writable = true; } else { $writable = false; $existing_rules = array_filter( extract_from_markers( $home_path . '.htaccess', 'WordPress' ) ); $new_rules = array_filter( explode( "\n", $wp_rewrite->mod_rewrite_rules() ) ); $htaccess_update_required = ( $new_rules !== $existing_rules ); } } $using_index_permalinks = $wp_rewrite->using_index_permalinks(); if ( $structure_updated ) { $message = __( 'Permalink structure updated.' ); if ( ! is_multisite() && $permalink_structure && ! $using_index_permalinks ) { if ( $iis7_permalinks ) { if ( ! $writable ) { $message = sprintf( /* translators: %s: web.config */ __( 'You should update your %s file now.' ), 'web.config
'
);
} else {
$message = sprintf(
/* translators: %s: web.config */
__( 'Permalink structure updated. Remove write access on %s file now!' ),
'web.config
'
);
}
} elseif ( ! $is_nginx && ! $is_caddy && $htaccess_update_required && ! $writable ) {
$message = sprintf(
/* translators: %s: .htaccess */
__( 'You should update your %s file now.' ),
'.htaccess
'
);
}
}
if ( ! get_settings_errors() ) {
add_settings_error( 'general', 'settings_updated', $message, 'success' );
}
set_transient( 'settings_errors', get_settings_errors(), 30 ); // 30 seconds.
wp_redirect( admin_url( 'options-permalink.php?settings-updated=true' ) );
exit;
}
flush_rewrite_rules();
require_once ABSPATH . 'wp-admin/admin-header.php';
?>
Error: Your %1$s file is not writable, so updating it automatically was not possible. This is the URL rewrite rule you should have in your %1$s file. Click in the field and press %3$s (or %4$s on Mac) to select all. Then insert this rule inside of the %5$s element in %1$s file.' ),
'web.config
',
__( 'https://developer.wordpress.org/advanced-administration/server/file-permissions/' ),
'Ctrl + A',
'⌘ + A',
'/<configuration>/<system.webServer>/<rewrite>/<rules>
'
);
?>
web.config' ); ?>
Error: The root directory of your site is not writable, so creating a file automatically was not possible. This is the URL rewrite rule you should have in your %2$s file. Create a new file called %2$s in the root directory of your site. Click in the field and press %3$s (or %4$s on Mac) to select all. Then insert this code into the %2$s file.' ),
__( 'https://developer.wordpress.org/advanced-administration/server/file-permissions/' ),
'web.config
',
'Ctrl + A',
'⌘ + A'
);
?>
web.config' ); ?>
Error: Your %1$s file is not writable, so updating it automatically was not possible. These are the mod_rewrite rules you should have in your %1$s file. Click in the field and press %3$s (or %4$s on Mac) to select all.' ),
'.htaccess
',
__( 'https://developer.wordpress.org/advanced-administration/server/file-permissions/' ),
'Ctrl + A',
'⌘ + A'
);
?>
' . __( 'The title field and the big Post Editing Area are fixed in place, but you can reposition all the other boxes using drag and drop. You can also minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'customize-display', 'title' => __( 'Customizing This Display' ), 'content' => $customize_display, ) ); $title_and_editor = '' . __( 'Title — Enter a title for your post. After you enter a title, you’ll see the permalink below, which you can edit.' ) . '
'; $title_and_editor .= '' . __( 'Post editor — Enter the text for your post. There are two modes of editing: Visual and Text. Choose the mode by clicking on the appropriate tab.' ) . '
'; $title_and_editor .= '' . __( 'Visual mode gives you an editor that is similar to a word processor. Click the Toolbar Toggle button to get a second row of controls.' ) . '
'; $title_and_editor .= '' . __( 'The Text mode allows you to enter HTML along with your post text. Note that <p> and <br> tags are converted to line breaks when switching to the Text editor to make it less cluttered. When you type, a single line break can be used instead of typing <br>, and two line breaks instead of paragraph tags. The line breaks are converted back to tags automatically.' ) . '
'; $title_and_editor .= '' . __( 'You can insert media files by clicking the button above the post editor and following the directions. You can align or edit images using the inline formatting toolbar available in Visual mode.' ) . '
'; $title_and_editor .= '' . __( 'You can enable distraction-free writing mode using the icon to the right. This feature is not available for old browsers or devices with small screens, and requires that the full-height editor be enabled in Screen Options.' ) . '
'; $title_and_editor .= '' . sprintf( /* translators: %s: Alt + F10 */ __( 'Keyboard users: When you are working in the visual editor, you can use %s to access the toolbar.' ), 'Alt + F10' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'title-post-editor', 'title' => __( 'Title and Post Editor' ), 'content' => $title_and_editor, ) ); get_current_screen()->set_help_sidebar( '' . sprintf( /* translators: %s: URL to Press This bookmarklet. */ __( 'You can also create posts with the Press This bookmarklet.' ), 'tools.php' ) . '
' . '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Writing and Editing Posts' ) . '
' . '' . __( 'Support forums' ) . '
' ); } elseif ( 'page' === $post_type ) { $about_pages = '' . __( 'Pages are similar to posts in that they have a title, body text, and associated metadata, but they are different in that they are not part of the chronological blog stream, kind of like permanent posts. Pages are not categorized or tagged, but can have a hierarchy. You can nest pages under other pages by making one the “Parent” of the other, creating a group of pages.' ) . '
' . '' . __( 'Creating a Page is very similar to creating a Post, and the screens can be customized in the same way using drag and drop, the Screen Options tab, and expanding/collapsing boxes as you choose. This screen also has the distraction-free writing space, available in both the Visual and Text modes via the Fullscreen buttons. The Page editor mostly works the same as the Post editor, but there are some Page-specific features in the Page Attributes box.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'about-pages', 'title' => __( 'About Pages' ), 'content' => $about_pages, ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Adding New Pages' ) . '
' . '' . __( 'Documentation on Editing Pages' ) . '
' . '' . __( 'Support forums' ) . '
' ); } elseif ( 'attachment' === $post_type ) { get_current_screen()->add_help_tab( array( 'id' => 'overview', 'title' => __( 'Overview' ), 'content' => '' . __( 'This screen allows you to edit fields for metadata in a file within the media library.' ) . '
' . '' . __( 'For images only, you can click on Edit Image under the thumbnail to expand out an inline image editor with icons for cropping, rotating, or flipping the image as well as for undoing and redoing. The boxes on the right give you more options for scaling the image, for cropping it, and for cropping the thumbnail in a different way than you crop the original image. You can click on Help in those boxes to get more information.' ) . '
' . '' . __( 'Note that you crop the image by clicking on it (the Crop icon is already selected) and dragging the cropping frame to select the desired part. Then click Save to retain the cropping.' ) . '
' . '' . __( 'Remember to click Update to save metadata entered or changed.' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Edit Media' ) . '
' . '' . __( 'Support forums' ) . '
' ); } if ( 'post' === $post_type || 'page' === $post_type ) { $inserting_media = '' . __( 'You can upload and insert media (images, audio, documents, etc.) by clicking the Add Media button. You can select from the images and files already uploaded to the Media Library, or upload new media to add to your page or post. To create an image gallery, select the images to add and click the “Create a new gallery” button.' ) . '
'; $inserting_media .= '' . __( 'You can also embed media from many popular websites including Twitter, YouTube, Flickr and others by pasting the media URL on its own line into the content of your post/page. Learn more about embeds.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'inserting-media', 'title' => __( 'Inserting Media' ), 'content' => $inserting_media, ) ); } if ( 'post' === $post_type ) { $publish_box = '' . __( 'Several boxes on this screen contain settings for how your content will be published, including:' ) . '
'; $publish_box .= '' . __( 'Send Trackbacks — Trackbacks are a way to notify legacy blog systems that you’ve linked to them. Enter the URL(s) you want to send trackbacks. If you link to other WordPress sites they’ll be notified automatically using pingbacks, and this field is unnecessary.' ) . '
'; $discussion_settings .= '' . __( 'Discussion — You can turn comments and pings on or off, and if there are comments on the post, you can see them here and moderate them.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'discussion-settings', 'title' => __( 'Discussion Settings' ), 'content' => $discussion_settings, ) ); } elseif ( 'page' === $post_type ) { $page_attributes = '' . __( 'Parent — You can arrange your pages in hierarchies. For example, you could have an “About” page that has “Life Story” and “My Dog” pages under it. There are no limits to how many levels you can nest pages.' ) . '
' . '' . __( 'Template — Some themes have custom templates you can use for certain pages that might have additional features or custom layouts. If so, you’ll see them in this dropdown menu.' ) . '
' . '' . __( 'Order — Pages are usually ordered alphabetically, but you can choose your own order by entering a number (1 for first, etc.) in this field.' ) . '
'; get_current_screen()->add_help_tab( array( 'id' => 'page-attributes', 'title' => __( 'Page Attributes' ), 'content' => $page_attributes, ) ); } require_once ABSPATH . 'wp-admin/admin-header.php'; ?>$message
\n"; wp_ob_end_flush_all(); flush(); } /** * @since 2.8.0 * * @param string $content * @return array */ function wp_doc_link_parse( $content ) { if ( ! is_string( $content ) || empty( $content ) ) { return array(); } if ( ! function_exists( 'token_get_all' ) ) { return array(); } $tokens = token_get_all( $content ); $count = count( $tokens ); $functions = array(); $ignore_functions = array(); for ( $t = 0; $t < $count - 2; $t++ ) { if ( ! is_array( $tokens[ $t ] ) ) { continue; } if ( T_STRING === $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) { // If it's a function or class defined locally, there's not going to be any docs available. if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) ) || ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR === $tokens[ $t - 1 ][0] ) ) { $ignore_functions[] = $tokens[ $t ][1]; } // Add this to our stack of unique references. $functions[] = $tokens[ $t ][1]; } } $functions = array_unique( $functions ); sort( $functions ); /** * Filters the list of functions and classes to be ignored from the documentation lookup. * * @since 2.8.0 * * @param string[] $ignore_functions Array of names of functions and classes to be ignored. */ $ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); $ignore_functions = array_unique( $ignore_functions ); $output = array(); foreach ( $functions as $function ) { if ( in_array( $function, $ignore_functions, true ) ) { continue; } $output[] = $function; } return $output; } /** * Saves option for number of rows when listing posts, pages, comments, etc. * * @since 2.8.0 */ function set_screen_options() { if ( ! isset( $_POST['wp_screen_options'] ) || ! is_array( $_POST['wp_screen_options'] ) ) { return; } check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' ); $user = wp_get_current_user(); if ( ! $user ) { return; } $option = $_POST['wp_screen_options']['option']; $value = $_POST['wp_screen_options']['value']; if ( sanitize_key( $option ) !== $option ) { return; } $map_option = $option; $type = str_replace( 'edit_', '', $map_option ); $type = str_replace( '_per_page', '', $type ); if ( in_array( $type, get_taxonomies(), true ) ) { $map_option = 'edit_tags_per_page'; } elseif ( in_array( $type, get_post_types(), true ) ) { $map_option = 'edit_per_page'; } else { $option = str_replace( '-', '_', $option ); } switch ( $map_option ) { case 'edit_per_page': case 'users_per_page': case 'edit_comments_per_page': case 'upload_per_page': case 'edit_tags_per_page': case 'plugins_per_page': case 'export_personal_data_requests_per_page': case 'remove_personal_data_requests_per_page': // Network admin. case 'sites_network_per_page': case 'users_network_per_page': case 'site_users_network_per_page': case 'plugins_network_per_page': case 'themes_network_per_page': case 'site_themes_network_per_page': $value = (int) $value; if ( $value < 1 || $value > 999 ) { return; } break; default: $screen_option = false; if ( str_ends_with( $option, '_page' ) || 'layout_columns' === $option ) { /** * Filters a screen option value before it is set. * * The filter can also be used to modify non-standard `[items]_per_page` * settings. See the parent function for a full list of standard options. * * Returning false from the filter will skip saving the current option. * * @since 2.8.0 * @since 5.4.2 Only applied to options ending with '_page', * or the 'layout_columns' option. * * @see set_screen_options() * * @param mixed $screen_option The value to save instead of the option value. * Default false (to skip saving the current option). * @param string $option The option name. * @param int $value The option value. */ $screen_option = apply_filters( 'set-screen-option', $screen_option, $option, $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } /** * Filters a screen option value before it is set. * * The dynamic portion of the hook name, `$option`, refers to the option name. * * Returning false from the filter will skip saving the current option. * * @since 5.4.2 * * @see set_screen_options() * * @param mixed $screen_option The value to save instead of the option value. * Default false (to skip saving the current option). * @param string $option The option name. * @param int $value The option value. */ $value = apply_filters( "set_screen_option_{$option}", $screen_option, $option, $value ); if ( false === $value ) { return; } break; } update_user_meta( $user->ID, $option, $value ); $url = remove_query_arg( array( 'pagenum', 'apage', 'paged' ), wp_get_referer() ); if ( isset( $_POST['mode'] ) ) { $url = add_query_arg( array( 'mode' => $_POST['mode'] ), $url ); } wp_safe_redirect( $url ); exit; } /** * Checks if rewrite rule for WordPress already exists in the IIS 7+ configuration file. * * @since 2.8.0 * * @param string $filename The file path to the configuration file. * @return bool */ function iis7_rewrite_rule_exists( $filename ) { if ( ! file_exists( $filename ) ) { return false; } if ( ! class_exists( 'DOMDocument', false ) ) { return false; } $doc = new DOMDocument(); if ( $doc->load( $filename ) === false ) { return false; } $xpath = new DOMXPath( $doc ); $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); if ( 0 === $rules->length ) { return false; } return true; } /** * Deletes WordPress rewrite rule from web.config file if it exists there. * * @since 2.8.0 * * @param string $filename Name of the configuration file. * @return bool */ function iis7_delete_rewrite_rule( $filename ) { // If configuration file does not exist then rules also do not exist, so there is nothing to delete. if ( ! file_exists( $filename ) ) { return true; } if ( ! class_exists( 'DOMDocument', false ) ) { return false; } $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; if ( $doc->load( $filename ) === false ) { return false; } $xpath = new DOMXPath( $doc ); $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' ); if ( $rules->length > 0 ) { $child = $rules->item( 0 ); $parent = $child->parentNode; $parent->removeChild( $child ); $doc->formatOutput = true; saveDomDocument( $doc, $filename ); } return true; } /** * Adds WordPress rewrite rule to the IIS 7+ configuration file. * * @since 2.8.0 * * @param string $filename The file path to the configuration file. * @param string $rewrite_rule The XML fragment with URL Rewrite rule. * @return bool */ function iis7_add_rewrite_rule( $filename, $rewrite_rule ) { if ( ! class_exists( 'DOMDocument', false ) ) { return false; } // If configuration file does not exist then we create one. if ( ! file_exists( $filename ) ) { $fp = fopen( $filename, 'w' ); fwrite( $fp, '' . __( 'There is a new version of %1$s available. View version %4$s details.' ) . '
', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'] ); } elseif ( empty( $update['package'] ) ) { $html = sprintf( /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number. */ '' . __( 'There is a new version of %1$s available. View version %4$s details. Automatic update is unavailable for this theme.' ) . '
', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'] ); } else { $html = sprintf( /* translators: 1: Theme name, 2: Theme details URL, 3: Additional link attributes, 4: Version number, 5: Update URL, 6: Additional link attributes. */ '' . __( 'There is a new version of %1$s available. View version %4$s details or update now.' ) . '
', $theme_name, esc_url( $details_url ), sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', /* translators: 1: Theme name, 2: Version number. */ esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $update['new_version'] ) ) ), $update['new_version'], $update_url, sprintf( 'aria-label="%s" id="update-theme" data-slug="%s"', /* translators: %s: Theme name. */ esc_attr( sprintf( _x( 'Update %s now', 'theme' ), $theme_name ) ), $stylesheet ) ); } } } return $html; } /** * Retrieves list of WordPress theme features (aka theme tags). * * @since 3.1.0 * @since 3.2.0 Added 'Gray' color and 'Featured Image Header', 'Featured Images', * 'Full Width Template', and 'Post Formats' features. * @since 3.5.0 Added 'Flexible Header' feature. * @since 3.8.0 Renamed 'Width' filter to 'Layout'. * @since 3.8.0 Renamed 'Fixed Width' and 'Flexible Width' options * to 'Fixed Layout' and 'Fluid Layout'. * @since 3.8.0 Added 'Accessibility Ready' feature and 'Responsive Layout' option. * @since 3.9.0 Combined 'Layout' and 'Columns' filters. * @since 4.6.0 Removed 'Colors' filter. * @since 4.6.0 Added 'Grid Layout' option. * Removed 'Fixed Layout', 'Fluid Layout', and 'Responsive Layout' options. * @since 4.6.0 Added 'Custom Logo' and 'Footer Widgets' features. * Removed 'Blavatar' feature. * @since 4.6.0 Added 'Blog', 'E-Commerce', 'Education', 'Entertainment', 'Food & Drink', * 'Holiday', 'News', 'Photography', and 'Portfolio' subjects. * Removed 'Photoblogging' and 'Seasonal' subjects. * @since 4.9.0 Reordered the filters from 'Layout', 'Features', 'Subject' * to 'Subject', 'Features', 'Layout'. * @since 4.9.0 Removed 'BuddyPress', 'Custom Menu', 'Flexible Header', * 'Front Page Posting', 'Microformats', 'RTL Language Support', * 'Threaded Comments', and 'Translation Ready' features. * @since 5.5.0 Added 'Block Editor Patterns', 'Block Editor Styles', * and 'Full Site Editing' features. * @since 5.5.0 Added 'Wide Blocks' layout option. * @since 5.8.1 Added 'Template Editing' feature. * @since 6.1.1 Replaced 'Full Site Editing' feature name with 'Site Editor'. * @since 6.2.0 Added 'Style Variations' feature. * * @param bool $api Optional. Whether try to fetch tags from the WordPress.org API. Defaults to true. * @return array Array of features keyed by category with translations keyed by slug. */ function get_theme_feature_list( $api = true ) { // Hard-coded list is used if API is not accessible. $features = array( __( 'Subject' ) => array( 'blog' => __( 'Blog' ), 'e-commerce' => __( 'E-Commerce' ), 'education' => __( 'Education' ), 'entertainment' => __( 'Entertainment' ), 'food-and-drink' => __( 'Food & Drink' ), 'holiday' => __( 'Holiday' ), 'news' => __( 'News' ), 'photography' => __( 'Photography' ), 'portfolio' => __( 'Portfolio' ), ), __( 'Features' ) => array( 'accessibility-ready' => __( 'Accessibility Ready' ), 'block-patterns' => __( 'Block Editor Patterns' ), 'block-styles' => __( 'Block Editor Styles' ), 'custom-background' => __( 'Custom Background' ), 'custom-colors' => __( 'Custom Colors' ), 'custom-header' => __( 'Custom Header' ), 'custom-logo' => __( 'Custom Logo' ), 'editor-style' => __( 'Editor Style' ), 'featured-image-header' => __( 'Featured Image Header' ), 'featured-images' => __( 'Featured Images' ), 'footer-widgets' => __( 'Footer Widgets' ), 'full-site-editing' => __( 'Site Editor' ), 'full-width-template' => __( 'Full Width Template' ), 'post-formats' => __( 'Post Formats' ), 'sticky-post' => __( 'Sticky Post' ), 'style-variations' => __( 'Style Variations' ), 'template-editing' => __( 'Template Editing' ), 'theme-options' => __( 'Theme Options' ), ), __( 'Layout' ) => array( 'grid-layout' => __( 'Grid Layout' ), 'one-column' => __( 'One Column' ), 'two-columns' => __( 'Two Columns' ), 'three-columns' => __( 'Three Columns' ), 'four-columns' => __( 'Four Columns' ), 'left-sidebar' => __( 'Left Sidebar' ), 'right-sidebar' => __( 'Right Sidebar' ), 'wide-blocks' => __( 'Wide Blocks' ), ), ); if ( ! $api || ! current_user_can( 'install_themes' ) ) { return $features; } $feature_list = get_site_transient( 'wporg_theme_feature_list' ); if ( ! $feature_list ) { set_site_transient( 'wporg_theme_feature_list', array(), 3 * HOUR_IN_SECONDS ); } if ( ! $feature_list ) { $feature_list = themes_api( 'feature_list', array() ); if ( is_wp_error( $feature_list ) ) { return $features; } } if ( ! $feature_list ) { return $features; } set_site_transient( 'wporg_theme_feature_list', $feature_list, 3 * HOUR_IN_SECONDS ); $category_translations = array( 'Layout' => __( 'Layout' ), 'Features' => __( 'Features' ), 'Subject' => __( 'Subject' ), ); $wporg_features = array(); // Loop over the wp.org canonical list and apply translations. foreach ( (array) $feature_list as $feature_category => $feature_items ) { if ( isset( $category_translations[ $feature_category ] ) ) { $feature_category = $category_translations[ $feature_category ]; } $wporg_features[ $feature_category ] = array(); foreach ( $feature_items as $feature ) { if ( isset( $features[ $feature_category ][ $feature ] ) ) { $wporg_features[ $feature_category ][ $feature ] = $features[ $feature_category ][ $feature ]; } else { $wporg_features[ $feature_category ][ $feature ] = $feature; } } } return $wporg_features; } /** * Retrieves theme installer pages from the WordPress.org Themes API. * * It is possible for a theme to override the Themes API result with three * filters. Assume this is for themes, which can extend on the Theme Info to * offer more choices. This is very powerful and must be used with care, when * overriding the filters. * * The first filter, {@see 'themes_api_args'}, is for the args and gives the action * as the second parameter. The hook for {@see 'themes_api_args'} must ensure that * an object is returned. * * The second filter, {@see 'themes_api'}, allows a plugin to override the WordPress.org * Theme API entirely. If `$action` is 'query_themes', 'theme_information', or 'feature_list', * an object MUST be passed. If `$action` is 'hot_tags', an array should be passed. * * Finally, the third filter, {@see 'themes_api_result'}, makes it possible to filter the * response object or array, depending on the `$action` type. * * Supported arguments per action: * * | Argument Name | 'query_themes' | 'theme_information' | 'hot_tags' | 'feature_list' | * | -------------------| :------------: | :-----------------: | :--------: | :--------------: | * | `$slug` | No | Yes | No | No | * | `$per_page` | Yes | No | No | No | * | `$page` | Yes | No | No | No | * | `$number` | No | No | Yes | No | * | `$search` | Yes | No | No | No | * | `$tag` | Yes | No | No | No | * | `$author` | Yes | No | No | No | * | `$user` | Yes | No | No | No | * | `$browse` | Yes | No | No | No | * | `$locale` | Yes | Yes | No | No | * | `$fields` | Yes | Yes | No | No | * * @since 2.8.0 * * @param string $action API action to perform: Accepts 'query_themes', 'theme_information', * 'hot_tags' or 'feature_list'. * @param array|object $args { * Optional. Array or object of arguments to serialize for the Themes API. Default empty array. * * @type string $slug The theme slug. Default empty. * @type int $per_page Number of themes per page. Default 24. * @type int $page Number of current page. Default 1. * @type int $number Number of tags to be queried. * @type string $search A search term. Default empty. * @type string $tag Tag to filter themes. Default empty. * @type string $author Username of an author to filter themes. Default empty. * @type string $user Username to query for their favorites. Default empty. * @type string $browse Browse view: 'featured', 'popular', 'updated', 'favorites'. * @type string $locale Locale to provide context-sensitive results. Default is the value of get_locale(). * @type array $fields { * Array of fields which should or should not be returned. * * @type bool $description Whether to return the theme full description. Default false. * @type bool $sections Whether to return the theme readme sections: description, installation, * FAQ, screenshots, other notes, and changelog. Default false. * @type bool $rating Whether to return the rating in percent and total number of ratings. * Default false. * @type bool $ratings Whether to return the number of rating for each star (1-5). Default false. * @type bool $downloaded Whether to return the download count. Default false. * @type bool $downloadlink Whether to return the download link for the package. Default false. * @type bool $last_updated Whether to return the date of the last update. Default false. * @type bool $tags Whether to return the assigned tags. Default false. * @type bool $homepage Whether to return the theme homepage link. Default false. * @type bool $screenshots Whether to return the screenshots. Default false. * @type int $screenshot_count Number of screenshots to return. Default 1. * @type bool $screenshot_url Whether to return the URL of the first screenshot. Default false. * @type bool $photon_screenshots Whether to return the screenshots via Photon. Default false. * @type bool $template Whether to return the slug of the parent theme. Default false. * @type bool $parent Whether to return the slug, name and homepage of the parent theme. Default false. * @type bool $versions Whether to return the list of all available versions. Default false. * @type bool $theme_url Whether to return theme's URL. Default false. * @type bool $extended_author Whether to return nicename or nicename and display name. Default false. * } * } * @return object|array|WP_Error Response object or array on success, WP_Error on failure. See the * {@link https://developer.wordpress.org/reference/functions/themes_api/ function reference article} * for more information on the make-up of possible return objects depending on the value of `$action`. */ function themes_api( $action, $args = array() ) { if ( is_array( $args ) ) { $args = (object) $args; } if ( 'query_themes' === $action ) { if ( ! isset( $args->per_page ) ) { $args->per_page = 24; } } if ( ! isset( $args->locale ) ) { $args->locale = get_user_locale(); } if ( ! isset( $args->wp_version ) ) { $args->wp_version = substr( wp_get_wp_version(), 0, 3 ); // x.y } /** * Filters arguments used to query for installer pages from the WordPress.org Themes API. * * Important: An object MUST be returned to this filter. * * @since 2.8.0 * * @param object $args Arguments used to query for installer pages from the WordPress.org Themes API. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. */ $args = apply_filters( 'themes_api_args', $args, $action ); /** * Filters whether to override the WordPress.org Themes API. * * Returning a non-false value will effectively short-circuit the WordPress.org API request. * * If `$action` is 'query_themes', 'theme_information', or 'feature_list', an object MUST * be passed. If `$action` is 'hot_tags', an array should be passed. * * @since 2.8.0 * * @param false|object|array $override Whether to override the WordPress.org Themes API. Default false. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param object $args Arguments used to query for installer pages from the Themes API. */ $res = apply_filters( 'themes_api', false, $action, $args ); if ( ! $res ) { $url = 'http://api.wordpress.org/themes/info/1.2/'; $url = add_query_arg( array( 'action' => $action, 'request' => $args, ), $url ); $http_url = $url; $ssl = wp_http_supports( array( 'ssl' ) ); if ( $ssl ) { $url = set_url_scheme( $url, 'https' ); } $http_args = array( 'timeout' => 15, 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), ); $request = wp_remote_get( $url, $http_args ); if ( $ssl && is_wp_error( $request ) ) { if ( ! wp_doing_ajax() ) { wp_trigger_error( __FUNCTION__, sprintf( /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), __( 'https://wordpress.org/support/forums/' ) ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); } $request = wp_remote_get( $http_url, $http_args ); } if ( is_wp_error( $request ) ) { $res = new WP_Error( 'themes_api_failed', sprintf( /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), __( 'https://wordpress.org/support/forums/' ) ), $request->get_error_message() ); } else { $res = json_decode( wp_remote_retrieve_body( $request ), true ); if ( is_array( $res ) ) { // Object casting is required in order to match the info/1.0 format. $res = (object) $res; } elseif ( null === $res ) { $res = new WP_Error( 'themes_api_failed', sprintf( /* translators: %s: Support forums URL. */ __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ), __( 'https://wordpress.org/support/forums/' ) ), wp_remote_retrieve_body( $request ) ); } if ( isset( $res->error ) ) { $res = new WP_Error( 'themes_api_failed', $res->error ); } } if ( ! is_wp_error( $res ) ) { // Back-compat for info/1.2 API, upgrade the theme objects in query_themes to objects. if ( 'query_themes' === $action ) { foreach ( $res->themes as $i => $theme ) { $res->themes[ $i ] = (object) $theme; } } // Back-compat for info/1.2 API, downgrade the feature_list result back to an array. if ( 'feature_list' === $action ) { $res = (array) $res; } } } /** * Filters the returned WordPress.org Themes API response. * * @since 2.8.0 * * @param array|stdClass|WP_Error $res WordPress.org Themes API response. * @param string $action Requested action. Likely values are 'theme_information', * 'feature_list', or 'query_themes'. * @param stdClass $args Arguments used to query for installer pages from the WordPress.org Themes API. */ return apply_filters( 'themes_api_result', $res, $action, $args ); } /** * Prepares themes for JavaScript. * * @since 3.8.0 * * @param WP_Theme[] $themes Optional. Array of theme objects to prepare. * Defaults to all allowed themes. * * @return array An associative array of theme data, sorted by name. */ function wp_prepare_themes_for_js( $themes = null ) { $current_theme = get_stylesheet(); /** * Filters theme data before it is prepared for JavaScript. * * Passing a non-empty array will result in wp_prepare_themes_for_js() returning * early with that value instead. * * @since 4.2.0 * * @param array $prepared_themes An associative array of theme data. Default empty array. * @param WP_Theme[]|null $themes An array of theme objects to prepare, if any. * @param string $current_theme The active theme slug. */ $prepared_themes = (array) apply_filters( 'pre_prepare_themes_for_js', array(), $themes, $current_theme ); if ( ! empty( $prepared_themes ) ) { return $prepared_themes; } // Make sure the active theme is listed first. $prepared_themes[ $current_theme ] = array(); if ( null === $themes ) { $themes = wp_get_themes( array( 'allowed' => true ) ); if ( ! isset( $themes[ $current_theme ] ) ) { $themes[ $current_theme ] = wp_get_theme(); } } $updates = array(); $no_updates = array(); if ( ! is_multisite() && current_user_can( 'update_themes' ) ) { $updates_transient = get_site_transient( 'update_themes' ); if ( isset( $updates_transient->response ) ) { $updates = $updates_transient->response; } if ( isset( $updates_transient->no_update ) ) { $no_updates = $updates_transient->no_update; } } WP_Theme::sort_by_name( $themes ); $parents = array(); $auto_updates = (array) get_site_option( 'auto_update_themes', array() ); foreach ( $themes as $theme ) { $slug = $theme->get_stylesheet(); $encoded_slug = urlencode( $slug ); $parent = false; if ( $theme->parent() ) { $parent = $theme->parent(); $parents[ $slug ] = $parent->get_stylesheet(); $parent = $parent->display( 'Name' ); } $customize_action = null; $can_edit_theme_options = current_user_can( 'edit_theme_options' ); $can_customize = current_user_can( 'customize' ); $is_block_theme = $theme->is_block_theme(); if ( $is_block_theme && $can_edit_theme_options ) { $customize_action = admin_url( 'site-editor.php' ); if ( $current_theme !== $slug ) { $customize_action = add_query_arg( 'wp_theme_preview', $slug, $customize_action ); } } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) { $customize_action = wp_customize_url( $slug ); } if ( null !== $customize_action ) { $customize_action = add_query_arg( array( 'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ), ), $customize_action ); $customize_action = esc_url( $customize_action ); } $update_requires_wp = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null; $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null; $auto_update = in_array( $slug, $auto_updates, true ); $auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update'; if ( isset( $updates[ $slug ] ) ) { $auto_update_supported = true; $auto_update_filter_payload = (object) $updates[ $slug ]; } elseif ( isset( $no_updates[ $slug ] ) ) { $auto_update_supported = true; $auto_update_filter_payload = (object) $no_updates[ $slug ]; } else { $auto_update_supported = false; /* * Create the expected payload for the auto_update_theme filter, this is the same data * as contained within $updates or $no_updates but used when the Theme is not known. */ $auto_update_filter_payload = (object) array( 'theme' => $slug, 'new_version' => $theme->get( 'Version' ), 'url' => '', 'package' => '', 'requires' => $theme->get( 'RequiresWP' ), 'requires_php' => $theme->get( 'RequiresPHP' ), ); } $auto_update_forced = wp_is_auto_update_forced_for_item( 'theme', null, $auto_update_filter_payload ); $prepared_themes[ $slug ] = array( 'id' => $slug, 'name' => $theme->display( 'Name' ), 'screenshot' => array( $theme->get_screenshot() ), // @todo Multiple screenshots. 'description' => $theme->display( 'Description' ), 'author' => $theme->display( 'Author', false, true ), 'authorAndUri' => $theme->display( 'Author' ), 'tags' => $theme->display( 'Tags' ), 'version' => $theme->get( 'Version' ), 'compatibleWP' => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ), 'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ), 'updateResponse' => array( 'compatibleWP' => is_wp_version_compatible( $update_requires_wp ), 'compatiblePHP' => is_php_version_compatible( $update_requires_php ), ), 'parent' => $parent, 'active' => $slug === $current_theme, 'hasUpdate' => isset( $updates[ $slug ] ), 'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ), 'update' => get_theme_update_available( $theme ), 'autoupdate' => array( 'enabled' => $auto_update || $auto_update_forced, 'supported' => $auto_update_supported, 'forced' => $auto_update_forced, ), 'actions' => array( 'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null, 'customize' => $customize_action, 'delete' => ( ! is_multisite() && current_user_can( 'delete_themes' ) ) ? wp_nonce_url( admin_url( 'themes.php?action=delete&stylesheet=' . $encoded_slug ), 'delete-theme_' . $slug ) : null, 'autoupdate' => wp_is_auto_update_enabled_for_type( 'theme' ) && ! is_multisite() && current_user_can( 'update_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&stylesheet=' . $encoded_slug ), 'updates' ) : null, ), 'blockTheme' => $theme->is_block_theme(), ); } // Remove 'delete' action if theme has an active child. if ( ! empty( $parents ) && array_key_exists( $current_theme, $parents ) ) { unset( $prepared_themes[ $parents[ $current_theme ] ]['actions']['delete'] ); } /** * Filters the themes prepared for JavaScript, for themes.php. * * Could be useful for changing the order, which is by name by default. * * @since 3.8.0 * * @param array $prepared_themes Array of theme data. */ $prepared_themes = apply_filters( 'wp_prepare_themes_for_js', $prepared_themes ); $prepared_themes = array_values( $prepared_themes ); return array_filter( $prepared_themes ); } /** * Prints JS templates for the theme-browsing UI in the Customizer. * * @since 4.2.0 */ function customize_themes_print_templates() { ?> delete( $extension ); if ( ! $result ) { return new WP_Error( 'could_not_resume_theme', __( 'Could not resume the theme.' ) ); } return true; } /** * Renders an admin notice in case some themes have been paused due to errors. * * @since 5.2.0 * * @global string $pagenow The filename of the current screen. * @global WP_Paused_Extensions_Storage $_paused_themes */ function paused_themes_notice() { if ( 'themes.php' === $GLOBALS['pagenow'] ) { return; } if ( ! current_user_can( 'resume_themes' ) ) { return; } if ( ! isset( $GLOBALS['_paused_themes'] ) || empty( $GLOBALS['_paused_themes'] ) ) { return; } $message = sprintf( '%s
%s
' . __( 'Warning! Wildcard DNS may not be configured correctly!' ) . '
'; $msg .= '' . sprintf(
/* translators: %s: Host name. */
__( 'The installer attempted to contact a random hostname (%s) on your domain.' ),
'' . $hostname . '
'
);
if ( ! empty( $errstr ) ) {
/* translators: %s: Error message. */
$msg .= ' ' . sprintf( __( 'This resulted in an error message: %s' ), '' . $errstr . '
' );
}
$msg .= '
' . sprintf(
/* translators: %s: Asterisk symbol (*). */
__( 'To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a %s hostname record pointing at your web server in your DNS configuration tool.' ),
'*
'
) . '
' . __( 'You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.' ) . '
'; return new WP_Error( 'no_wildcard_dns', $msg ); } } return true; } /** * Creates WordPress network meta and sets the default values. * * @since 5.1.0 * * @global wpdb $wpdb WordPress database abstraction object. * @global int $wp_db_version WordPress database version. * * @param int $network_id Network ID to populate meta for. * @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array. */ function populate_network_meta( $network_id, array $meta = array() ) { global $wpdb, $wp_db_version; $network_id = (int) $network_id; $email = ! empty( $meta['admin_email'] ) ? $meta['admin_email'] : ''; $subdomain_install = isset( $meta['subdomain_install'] ) ? (int) $meta['subdomain_install'] : 0; // If a user with the provided email does not exist, default to the current user as the new network admin. $site_user = ! empty( $email ) ? get_user_by( 'email', $email ) : false; if ( false === $site_user ) { $site_user = wp_get_current_user(); } if ( empty( $email ) ) { $email = $site_user->user_email; } $template = get_option( 'template' ); $stylesheet = get_option( 'stylesheet' ); $allowed_themes = array( $stylesheet => true ); if ( $template !== $stylesheet ) { $allowed_themes[ $template ] = true; } if ( WP_DEFAULT_THEME !== $stylesheet && WP_DEFAULT_THEME !== $template ) { $allowed_themes[ WP_DEFAULT_THEME ] = true; } // If WP_DEFAULT_THEME doesn't exist, also include the latest core default theme. if ( ! wp_get_theme( WP_DEFAULT_THEME )->exists() ) { $core_default = WP_Theme::get_core_default_theme(); if ( $core_default ) { $allowed_themes[ $core_default->get_stylesheet() ] = true; } } if ( function_exists( 'clean_network_cache' ) ) { clean_network_cache( $network_id ); } else { wp_cache_delete( $network_id, 'networks' ); } if ( ! is_multisite() ) { $site_admins = array( $site_user->user_login ); $users = get_users( array( 'fields' => array( 'user_login' ), 'role' => 'administrator', ) ); if ( $users ) { foreach ( $users as $user ) { $site_admins[] = $user->user_login; } $site_admins = array_unique( $site_admins ); } } else { $site_admins = get_site_option( 'site_admins' ); } /* translators: Do not translate USERNAME, SITE_NAME, BLOG_URL, PASSWORD: those are placeholders. */ $welcome_email = __( 'Howdy USERNAME, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with the following information: Username: USERNAME Password: PASSWORD Log in here: BLOG_URLwp-login.php We hope you enjoy your new site. Thanks! --The Team @ SITE_NAME' ); $allowed_file_types = array(); $all_mime_types = get_allowed_mime_types(); foreach ( $all_mime_types as $ext => $mime ) { array_push( $allowed_file_types, ...explode( '|', $ext ) ); } $upload_filetypes = array_unique( $allowed_file_types ); $sitemeta = array( 'site_name' => __( 'My Network' ), 'admin_email' => $email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => implode( ' ', $upload_filetypes ), 'blog_upload_space' => 100, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array( 'www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files' ), 'wpmu_upgrade_site' => $wp_db_version, 'welcome_email' => $welcome_email, /* translators: %s: Site link. */ 'first_post' => __( 'Welcome to %s. This is your first post. Edit or delete it, then start writing!' ), // @todo - Network admins should have a method of editing the network siteurl (used for cookie hash). 'siteurl' => get_option( 'siteurl' ) . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => is_multisite() ? get_site_option( 'upload_space_check_disabled' ) : '1', 'subdomain_install' => $subdomain_install, 'ms_files_rewriting' => is_multisite() ? get_site_option( 'ms_files_rewriting' ) : '0', 'user_count' => get_site_option( 'user_count' ), 'initial_db_version' => get_option( 'initial_db_version' ), 'active_sitewide_plugins' => array(), 'WPLANG' => get_locale(), ); if ( ! $subdomain_install ) { $sitemeta['illegal_names'][] = 'blog'; } $sitemeta = wp_parse_args( $meta, $sitemeta ); /** * Filters meta for a network on creation. * * @since 3.7.0 * * @param array $sitemeta Associative array of network meta keys and values to be inserted. * @param int $network_id ID of network to populate. */ $sitemeta = apply_filters( 'populate_network_meta', $sitemeta, $network_id ); $insert = ''; foreach ( $sitemeta as $meta_key => $meta_value ) { if ( is_array( $meta_value ) ) { $meta_value = serialize( $meta_value ); } if ( ! empty( $insert ) ) { $insert .= ', '; } $insert .= $wpdb->prepare( '( %d, %s, %s)', $network_id, $meta_key, $meta_value ); } $wpdb->query( "INSERT INTO $wpdb->sitemeta ( site_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared } /** * Creates WordPress site meta and sets the default values. * * @since 5.1.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $site_id Site ID to populate meta for. * @param array $meta Optional. Custom meta $key => $value pairs to use. Default empty array. */ function populate_site_meta( $site_id, array $meta = array() ) { global $wpdb; $site_id = (int) $site_id; if ( ! is_site_meta_supported() ) { return; } if ( empty( $meta ) ) { return; } /** * Filters meta for a site on creation. * * @since 5.2.0 * * @param array $meta Associative array of site meta keys and values to be inserted. * @param int $site_id ID of site to populate. */ $site_meta = apply_filters( 'populate_site_meta', $meta, $site_id ); $insert = ''; foreach ( $site_meta as $meta_key => $meta_value ) { if ( is_array( $meta_value ) ) { $meta_value = serialize( $meta_value ); } if ( ! empty( $insert ) ) { $insert .= ', '; } $insert .= $wpdb->prepare( '( %d, %s, %s)', $site_id, $meta_key, $meta_value ); } $wpdb->query( "INSERT INTO $wpdb->blogmeta ( blog_id, meta_key, meta_value ) VALUES " . $insert ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared wp_cache_delete( $site_id, 'blog_meta' ); wp_cache_set_sites_last_changed(); } includes/post.php 0000644 00000237423 14717704420 0010071 0 ustar 00 cap->create_posts ) ) { if ( 'page' === $post_data['post_type'] ) { return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) ); } else { return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) ); } } if ( isset( $post_data['content'] ) ) { $post_data['post_content'] = $post_data['content']; } if ( isset( $post_data['excerpt'] ) ) { $post_data['post_excerpt'] = $post_data['excerpt']; } if ( isset( $post_data['parent_id'] ) ) { $post_data['post_parent'] = (int) $post_data['parent_id']; } if ( isset( $post_data['trackback_url'] ) ) { $post_data['to_ping'] = $post_data['trackback_url']; } $post_data['user_ID'] = get_current_user_id(); if ( ! empty( $post_data['post_author_override'] ) ) { $post_data['post_author'] = (int) $post_data['post_author_override']; } else { if ( ! empty( $post_data['post_author'] ) ) { $post_data['post_author'] = (int) $post_data['post_author']; } else { $post_data['post_author'] = (int) $post_data['user_ID']; } } if ( isset( $post_data['user_ID'] ) && ( $post_data['post_author'] !== $post_data['user_ID'] ) && ! current_user_can( $ptype->cap->edit_others_posts ) ) { if ( $update ) { if ( 'page' === $post_data['post_type'] ) { return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) ); } else { return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to edit posts as this user.' ) ); } } else { if ( 'page' === $post_data['post_type'] ) { return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) ); } else { return new WP_Error( 'edit_others_posts', __( 'Sorry, you are not allowed to create posts as this user.' ) ); } } } if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); // No longer an auto-draft. if ( 'auto-draft' === $post_data['post_status'] ) { $post_data['post_status'] = 'draft'; } if ( ! get_post_status_object( $post_data['post_status'] ) ) { unset( $post_data['post_status'] ); } } // What to do based on which button they pressed. if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) { $post_data['post_status'] = 'draft'; } if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) { $post_data['post_status'] = 'private'; } if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] ) && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] ) ) { $post_data['post_status'] = 'publish'; } if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) { $post_data['post_status'] = 'draft'; } if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) { $post_data['post_status'] = 'pending'; } if ( isset( $post_data['ID'] ) ) { $post_id = $post_data['ID']; } else { $post_id = false; } $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false; if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) { $post_data['post_status'] = $previous_status ? $previous_status : 'pending'; } $published_statuses = array( 'publish', 'future' ); /* * Posts 'submitted for approval' are submitted to $_POST the same as if they were being published. * Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts. */ if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses, true ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) { if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) { $post_data['post_status'] = 'pending'; } } if ( ! isset( $post_data['post_status'] ) ) { $post_data['post_status'] = 'auto-draft' === $previous_status ? 'draft' : $previous_status; } if ( isset( $post_data['post_password'] ) && ! current_user_can( $ptype->cap->publish_posts ) ) { unset( $post_data['post_password'] ); } if ( ! isset( $post_data['comment_status'] ) ) { $post_data['comment_status'] = 'closed'; } if ( ! isset( $post_data['ping_status'] ) ) { $post_data['ping_status'] = 'closed'; } foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) { if ( ! empty( $post_data[ 'hidden_' . $timeunit ] ) && $post_data[ 'hidden_' . $timeunit ] !== $post_data[ $timeunit ] ) { $post_data['edit_date'] = '1'; break; } } if ( ! empty( $post_data['edit_date'] ) ) { $aa = $post_data['aa']; $mm = $post_data['mm']; $jj = $post_data['jj']; $hh = $post_data['hh']; $mn = $post_data['mn']; $ss = $post_data['ss']; $aa = ( $aa <= 0 ) ? gmdate( 'Y' ) : $aa; $mm = ( $mm <= 0 ) ? gmdate( 'n' ) : $mm; $jj = ( $jj > 31 ) ? 31 : $jj; $jj = ( $jj <= 0 ) ? gmdate( 'j' ) : $jj; $hh = ( $hh > 23 ) ? $hh - 24 : $hh; $mn = ( $mn > 59 ) ? $mn - 60 : $mn; $ss = ( $ss > 59 ) ? $ss - 60 : $ss; $post_data['post_date'] = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa, $mm, $jj, $hh, $mn, $ss ); $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] ); if ( ! $valid_date ) { return new WP_Error( 'invalid_date', __( 'Invalid date.' ) ); } /* * Only assign a post date if the user has explicitly set a new value. * See #59125 and #19907. */ $previous_date = $post_id ? get_post_field( 'post_date', $post_id ) : false; if ( $previous_date && $previous_date !== $post_data['post_date'] ) { $post_data['edit_date'] = true; $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] ); } else { $post_data['edit_date'] = false; unset( $post_data['post_date'] ); unset( $post_data['post_date_gmt'] ); } } if ( isset( $post_data['post_category'] ) ) { $category_object = get_taxonomy( 'category' ); if ( ! current_user_can( $category_object->cap->assign_terms ) ) { unset( $post_data['post_category'] ); } } return $post_data; } /** * Returns only allowed post data fields. * * @since 5.0.1 * * @param array|WP_Error|null $post_data The array of post data to process, or an error object. * Defaults to the `$_POST` superglobal. * @return array|WP_Error Array of post data on success, WP_Error on failure. */ function _wp_get_allowed_postdata( $post_data = null ) { if ( empty( $post_data ) ) { $post_data = $_POST; } // Pass through errors. if ( is_wp_error( $post_data ) ) { return $post_data; } return array_diff_key( $post_data, array_flip( array( 'meta_input', 'file', 'guid' ) ) ); } /** * Updates an existing post with values provided in `$_POST`. * * If post data is passed as an argument, it is treated as an array of data * keyed appropriately for turning into a post object. * * If post data is not passed, the `$_POST` global variable is used instead. * * @since 1.5.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param array|null $post_data Optional. The array of post data to process. * Defaults to the `$_POST` superglobal. * @return int Post ID. */ function edit_post( $post_data = null ) { global $wpdb; if ( empty( $post_data ) ) { $post_data = &$_POST; } // Clear out any data in internal vars. unset( $post_data['filter'] ); $post_id = (int) $post_data['post_ID']; $post = get_post( $post_id ); $post_data['post_type'] = $post->post_type; $post_data['post_mime_type'] = $post->post_mime_type; if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); if ( 'inherit' === $post_data['post_status'] ) { unset( $post_data['post_status'] ); } } $ptype = get_post_type_object( $post_data['post_type'] ); if ( ! current_user_can( 'edit_post', $post_id ) ) { if ( 'page' === $post_data['post_type'] ) { wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); } else { wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); } } if ( post_type_supports( $ptype->name, 'revisions' ) ) { $revisions = wp_get_post_revisions( $post_id, array( 'order' => 'ASC', 'posts_per_page' => 1, ) ); $revision = current( $revisions ); // Check if the revisions have been upgraded. if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 ) { _wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_id ) ); } } if ( isset( $post_data['visibility'] ) ) { switch ( $post_data['visibility'] ) { case 'public': $post_data['post_password'] = ''; break; case 'password': unset( $post_data['sticky'] ); break; case 'private': $post_data['post_status'] = 'private'; $post_data['post_password'] = ''; unset( $post_data['sticky'] ); break; } } $post_data = _wp_translate_postdata( true, $post_data ); if ( is_wp_error( $post_data ) ) { wp_die( $post_data->get_error_message() ); } $translated = _wp_get_allowed_postdata( $post_data ); // Post formats. if ( isset( $post_data['post_format'] ) ) { set_post_format( $post_id, $post_data['post_format'] ); } $format_meta_urls = array( 'url', 'link_url', 'quote_source_url' ); foreach ( $format_meta_urls as $format_meta_url ) { $keyed = '_format_' . $format_meta_url; if ( isset( $post_data[ $keyed ] ) ) { update_post_meta( $post_id, $keyed, wp_slash( sanitize_url( wp_unslash( $post_data[ $keyed ] ) ) ) ); } } $format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' ); foreach ( $format_keys as $key ) { $keyed = '_format_' . $key; if ( isset( $post_data[ $keyed ] ) ) { if ( current_user_can( 'unfiltered_html' ) ) { update_post_meta( $post_id, $keyed, $post_data[ $keyed ] ); } else { update_post_meta( $post_id, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) ); } } } if ( 'attachment' === $post_data['post_type'] && preg_match( '#^(audio|video)/#', $post_data['post_mime_type'] ) ) { $id3data = wp_get_attachment_metadata( $post_id ); if ( ! is_array( $id3data ) ) { $id3data = array(); } foreach ( wp_get_attachment_id3_keys( $post, 'edit' ) as $key => $label ) { if ( isset( $post_data[ 'id3_' . $key ] ) ) { $id3data[ $key ] = sanitize_text_field( wp_unslash( $post_data[ 'id3_' . $key ] ) ); } } wp_update_attachment_metadata( $post_id, $id3data ); } // Meta stuff. if ( isset( $post_data['meta'] ) && $post_data['meta'] ) { foreach ( $post_data['meta'] as $key => $value ) { $meta = get_post_meta_by_id( $key ); if ( ! $meta ) { continue; } if ( (int) $meta->post_id !== $post_id ) { continue; } if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'edit_post_meta', $post_id, $meta->meta_key ) ) { continue; } if ( is_protected_meta( $value['key'], 'post' ) || ! current_user_can( 'edit_post_meta', $post_id, $value['key'] ) ) { continue; } update_meta( $key, $value['key'], $value['value'] ); } } if ( isset( $post_data['deletemeta'] ) && $post_data['deletemeta'] ) { foreach ( $post_data['deletemeta'] as $key => $value ) { $meta = get_post_meta_by_id( $key ); if ( ! $meta ) { continue; } if ( (int) $meta->post_id !== $post_id ) { continue; } if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $post_id, $meta->meta_key ) ) { continue; } delete_meta( $key ); } } // Attachment stuff. if ( 'attachment' === $post_data['post_type'] ) { if ( isset( $post_data['_wp_attachment_image_alt'] ) ) { $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] ); if ( get_post_meta( $post_id, '_wp_attachment_image_alt', true ) !== $image_alt ) { $image_alt = wp_strip_all_tags( $image_alt, true ); // update_post_meta() expects slashed. update_post_meta( $post_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) ); } } $attachment_data = isset( $post_data['attachments'][ $post_id ] ) ? $post_data['attachments'][ $post_id ] : array(); /** This filter is documented in wp-admin/includes/media.php */ $translated = apply_filters( 'attachment_fields_to_save', $translated, $attachment_data ); } // Convert taxonomy input to term IDs, to avoid ambiguity. if ( isset( $post_data['tax_input'] ) ) { foreach ( (array) $post_data['tax_input'] as $taxonomy => $terms ) { $tax_object = get_taxonomy( $taxonomy ); if ( $tax_object && isset( $tax_object->meta_box_sanitize_cb ) ) { $translated['tax_input'][ $taxonomy ] = call_user_func_array( $tax_object->meta_box_sanitize_cb, array( $taxonomy, $terms ) ); } } } add_meta( $post_id ); update_post_meta( $post_id, '_edit_last', get_current_user_id() ); $success = wp_update_post( $translated ); // If the save failed, see if we can confidence check the main fields and try again. if ( ! $success && is_callable( array( $wpdb, 'strip_invalid_text_for_column' ) ) ) { $fields = array( 'post_title', 'post_content', 'post_excerpt' ); foreach ( $fields as $field ) { if ( isset( $translated[ $field ] ) ) { $translated[ $field ] = $wpdb->strip_invalid_text_for_column( $wpdb->posts, $field, $translated[ $field ] ); } } wp_update_post( $translated ); } // Now that we have an ID we can fix any attachment anchor hrefs. _fix_attachment_links( $post_id ); wp_set_post_lock( $post_id ); if ( current_user_can( $ptype->cap->edit_others_posts ) && current_user_can( $ptype->cap->publish_posts ) ) { if ( ! empty( $post_data['sticky'] ) ) { stick_post( $post_id ); } else { unstick_post( $post_id ); } } return $post_id; } /** * Processes the post data for the bulk editing of posts. * * Updates all bulk edited posts/pages, adding (but not removing) tags and * categories. Skips pages when they would be their own parent or child. * * @since 2.7.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param array|null $post_data Optional. The array of post data to process. * Defaults to the `$_POST` superglobal. * @return array */ function bulk_edit_posts( $post_data = null ) { global $wpdb; if ( empty( $post_data ) ) { $post_data = &$_POST; } if ( isset( $post_data['post_type'] ) ) { $ptype = get_post_type_object( $post_data['post_type'] ); } else { $ptype = get_post_type_object( 'post' ); } if ( ! current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' === $ptype->name ) { wp_die( __( 'Sorry, you are not allowed to edit pages.' ) ); } else { wp_die( __( 'Sorry, you are not allowed to edit posts.' ) ); } } if ( '-1' === $post_data['_status'] ) { $post_data['post_status'] = null; unset( $post_data['post_status'] ); } else { $post_data['post_status'] = $post_data['_status']; } unset( $post_data['_status'] ); if ( ! empty( $post_data['post_status'] ) ) { $post_data['post_status'] = sanitize_key( $post_data['post_status'] ); if ( 'inherit' === $post_data['post_status'] ) { unset( $post_data['post_status'] ); } } $post_ids = array_map( 'intval', (array) $post_data['post'] ); $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky', 'post_format', ); foreach ( $reset as $field ) { if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || '-1' === $post_data[ $field ] ) ) { unset( $post_data[ $field ] ); } } if ( isset( $post_data['post_category'] ) ) { if ( is_array( $post_data['post_category'] ) && ! empty( $post_data['post_category'] ) ) { $new_cats = array_map( 'absint', $post_data['post_category'] ); } else { unset( $post_data['post_category'] ); } } $tax_input = array(); if ( isset( $post_data['tax_input'] ) ) { foreach ( $post_data['tax_input'] as $tax_name => $terms ) { if ( empty( $terms ) ) { continue; } if ( is_taxonomy_hierarchical( $tax_name ) ) { $tax_input[ $tax_name ] = array_map( 'absint', $terms ); } else { $comma = _x( ',', 'tag delimiter' ); if ( ',' !== $comma ) { $terms = str_replace( $comma, ',', $terms ); } $tax_input[ $tax_name ] = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) ); } } } if ( isset( $post_data['post_parent'] ) && (int) $post_data['post_parent'] ) { $parent = (int) $post_data['post_parent']; $pages = $wpdb->get_results( "SELECT ID, post_parent FROM $wpdb->posts WHERE post_type = 'page'" ); $children = array(); for ( $i = 0; $i < 50 && $parent > 0; $i++ ) { $children[] = $parent; foreach ( $pages as $page ) { if ( (int) $page->ID === $parent ) { $parent = (int) $page->post_parent; break; } } } } $updated = array(); $skipped = array(); $locked = array(); $shared_post_data = $post_data; foreach ( $post_ids as $post_id ) { // Start with fresh post data with each iteration. $post_data = $shared_post_data; $post_type_object = get_post_type_object( get_post_type( $post_id ) ); if ( ! isset( $post_type_object ) || ( isset( $children ) && in_array( $post_id, $children, true ) ) || ! current_user_can( 'edit_post', $post_id ) ) { $skipped[] = $post_id; continue; } if ( wp_check_post_lock( $post_id ) ) { $locked[] = $post_id; continue; } $post = get_post( $post_id ); $tax_names = get_object_taxonomies( $post ); foreach ( $tax_names as $tax_name ) { $taxonomy_obj = get_taxonomy( $tax_name ); if ( ! $taxonomy_obj->show_in_quick_edit ) { continue; } if ( isset( $tax_input[ $tax_name ] ) && current_user_can( $taxonomy_obj->cap->assign_terms ) ) { $new_terms = $tax_input[ $tax_name ]; } else { $new_terms = array(); } if ( $taxonomy_obj->hierarchical ) { $current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'ids' ) ); } else { $current_terms = (array) wp_get_object_terms( $post_id, $tax_name, array( 'fields' => 'names' ) ); } $post_data['tax_input'][ $tax_name ] = array_merge( $current_terms, $new_terms ); } if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) { $cats = (array) wp_get_post_categories( $post_id ); if ( isset( $post_data['indeterminate_post_category'] ) && is_array( $post_data['indeterminate_post_category'] ) ) { $indeterminate_post_category = $post_data['indeterminate_post_category']; } else { $indeterminate_post_category = array(); } $indeterminate_cats = array_intersect( $cats, $indeterminate_post_category ); $determinate_cats = array_diff( $new_cats, $indeterminate_post_category ); $post_data['post_category'] = array_unique( array_merge( $indeterminate_cats, $determinate_cats ) ); unset( $post_data['tax_input']['category'] ); } $post_data['post_ID'] = $post_id; $post_data['post_type'] = $post->post_type; $post_data['post_mime_type'] = $post->post_mime_type; foreach ( array( 'comment_status', 'ping_status', 'post_author' ) as $field ) { if ( ! isset( $post_data[ $field ] ) ) { $post_data[ $field ] = $post->$field; } } $post_data = _wp_translate_postdata( true, $post_data ); if ( is_wp_error( $post_data ) ) { $skipped[] = $post_id; continue; } $post_data = _wp_get_allowed_postdata( $post_data ); if ( isset( $shared_post_data['post_format'] ) ) { set_post_format( $post_id, $shared_post_data['post_format'] ); } // Prevent wp_insert_post() from overwriting post format with the old data. unset( $post_data['tax_input']['post_format'] ); // Reset post date of scheduled post to be published. if ( in_array( $post->post_status, array( 'future', 'draft' ), true ) && 'publish' === $post_data['post_status'] ) { $post_data['post_date'] = current_time( 'mysql' ); $post_data['post_date_gmt'] = ''; } $post_id = wp_update_post( $post_data ); update_post_meta( $post_id, '_edit_last', get_current_user_id() ); $updated[] = $post_id; if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) { if ( 'sticky' === $post_data['sticky'] ) { stick_post( $post_id ); } else { unstick_post( $post_id ); } } } /** * Fires after processing the post data for bulk edit. * * @since 6.3.0 * * @param int[] $updated An array of updated post IDs. * @param array $shared_post_data Associative array containing the post data. */ do_action( 'bulk_edit_posts', $updated, $shared_post_data ); return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked, ); } /** * Returns default post information to use when populating the "Write Post" form. * * @since 2.0.0 * * @param string $post_type Optional. A post type string. Default 'post'. * @param bool $create_in_db Optional. Whether to insert the post into database. Default false. * @return WP_Post Post object containing all the default post data as attributes */ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) { $post_title = ''; if ( ! empty( $_REQUEST['post_title'] ) ) { $post_title = esc_html( wp_unslash( $_REQUEST['post_title'] ) ); } $post_content = ''; if ( ! empty( $_REQUEST['content'] ) ) { $post_content = esc_html( wp_unslash( $_REQUEST['content'] ) ); } $post_excerpt = ''; if ( ! empty( $_REQUEST['excerpt'] ) ) { $post_excerpt = esc_html( wp_unslash( $_REQUEST['excerpt'] ) ); } if ( $create_in_db ) { $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft', ), false, false ); $post = get_post( $post_id ); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) { set_post_format( $post, get_option( 'default_post_format' ) ); } wp_after_insert_post( $post, false, null ); // Schedule auto-draft cleanup. if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) { wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' ); } } else { $post = new stdClass(); $post->ID = 0; $post->post_author = ''; $post->post_date = ''; $post->post_date_gmt = ''; $post->post_password = ''; $post->post_name = ''; $post->post_type = $post_type; $post->post_status = 'draft'; $post->to_ping = ''; $post->pinged = ''; $post->comment_status = get_default_comment_status( $post_type ); $post->ping_status = get_default_comment_status( $post_type, 'pingback' ); $post->post_pingback = get_option( 'default_pingback_flag' ); $post->post_category = get_option( 'default_category' ); $post->page_template = 'default'; $post->post_parent = 0; $post->menu_order = 0; $post = new WP_Post( $post ); } /** * Filters the default post content initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_content Default post content. * @param WP_Post $post Post object. */ $post->post_content = (string) apply_filters( 'default_content', $post_content, $post ); /** * Filters the default post title initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_title Default post title. * @param WP_Post $post Post object. */ $post->post_title = (string) apply_filters( 'default_title', $post_title, $post ); /** * Filters the default post excerpt initially used in the "Write Post" form. * * @since 1.5.0 * * @param string $post_excerpt Default post excerpt. * @param WP_Post $post Post object. */ $post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post ); return $post; } /** * Determines if a post exists based on title, content, date and type. * * @since 2.0.0 * @since 5.2.0 Added the `$type` parameter. * @since 5.8.0 Added the `$status` parameter. * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $title Post title. * @param string $content Optional. Post content. * @param string $date Optional. Post date. * @param string $type Optional. Post type. * @param string $status Optional. Post status. * @return int Post ID if post exists, 0 otherwise. */ function post_exists( $title, $content = '', $date = '', $type = '', $status = '' ) { global $wpdb; $post_title = wp_unslash( sanitize_post_field( 'post_title', $title, 0, 'db' ) ); $post_content = wp_unslash( sanitize_post_field( 'post_content', $content, 0, 'db' ) ); $post_date = wp_unslash( sanitize_post_field( 'post_date', $date, 0, 'db' ) ); $post_type = wp_unslash( sanitize_post_field( 'post_type', $type, 0, 'db' ) ); $post_status = wp_unslash( sanitize_post_field( 'post_status', $status, 0, 'db' ) ); $query = "SELECT ID FROM $wpdb->posts WHERE 1=1"; $args = array(); if ( ! empty( $date ) ) { $query .= ' AND post_date = %s'; $args[] = $post_date; } if ( ! empty( $title ) ) { $query .= ' AND post_title = %s'; $args[] = $post_title; } if ( ! empty( $content ) ) { $query .= ' AND post_content = %s'; $args[] = $post_content; } if ( ! empty( $type ) ) { $query .= ' AND post_type = %s'; $args[] = $post_type; } if ( ! empty( $status ) ) { $query .= ' AND post_status = %s'; $args[] = $post_status; } if ( ! empty( $args ) ) { return (int) $wpdb->get_var( $wpdb->prepare( $query, $args ) ); } return 0; } /** * Creates a new post from the "Write Post" form using `$_POST` information. * * @since 2.1.0 * * @global WP_User $current_user * * @return int|WP_Error Post ID on success, WP_Error on failure. */ function wp_write_post() { if ( isset( $_POST['post_type'] ) ) { $ptype = get_post_type_object( $_POST['post_type'] ); } else { $ptype = get_post_type_object( 'post' ); } if ( ! current_user_can( $ptype->cap->edit_posts ) ) { if ( 'page' === $ptype->name ) { return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) ); } else { return new WP_Error( 'edit_posts', __( 'Sorry, you are not allowed to create posts or drafts on this site.' ) ); } } $_POST['post_mime_type'] = ''; // Clear out any data in internal vars. unset( $_POST['filter'] ); // Edit, don't write, if we have a post ID. if ( isset( $_POST['post_ID'] ) ) { return edit_post(); } if ( isset( $_POST['visibility'] ) ) { switch ( $_POST['visibility'] ) { case 'public': $_POST['post_password'] = ''; break; case 'password': unset( $_POST['sticky'] ); break; case 'private': $_POST['post_status'] = 'private'; $_POST['post_password'] = ''; unset( $_POST['sticky'] ); break; } } $translated = _wp_translate_postdata( false ); if ( is_wp_error( $translated ) ) { return $translated; } $translated = _wp_get_allowed_postdata( $translated ); // Create the post. $post_id = wp_insert_post( $translated ); if ( is_wp_error( $post_id ) ) { return $post_id; } if ( empty( $post_id ) ) { return 0; } add_meta( $post_id ); add_post_meta( $post_id, '_edit_last', $GLOBALS['current_user']->ID ); // Now that we have an ID we can fix any attachment anchor hrefs. _fix_attachment_links( $post_id ); wp_set_post_lock( $post_id ); return $post_id; } /** * Calls wp_write_post() and handles the errors. * * @since 2.0.0 * * @return int|void Post ID on success, void on failure. */ function write_post() { $result = wp_write_post(); if ( is_wp_error( $result ) ) { wp_die( $result->get_error_message() ); } else { return $result; } } // // Post Meta. // /** * Adds post meta data defined in the `$_POST` superglobal for a post with given ID. * * @since 1.2.0 * * @param int $post_id * @return int|bool */ function add_meta( $post_id ) { $post_id = (int) $post_id; $metakeyselect = isset( $_POST['metakeyselect'] ) ? wp_unslash( trim( $_POST['metakeyselect'] ) ) : ''; $metakeyinput = isset( $_POST['metakeyinput'] ) ? wp_unslash( trim( $_POST['metakeyinput'] ) ) : ''; $metavalue = isset( $_POST['metavalue'] ) ? $_POST['metavalue'] : ''; if ( is_string( $metavalue ) ) { $metavalue = trim( $metavalue ); } if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) { /* * We have a key/value pair. If both the select and the input * for the key have data, the input takes precedence. */ if ( '#NONE#' !== $metakeyselect ) { $metakey = $metakeyselect; } if ( $metakeyinput ) { $metakey = $metakeyinput; // Default. } if ( is_protected_meta( $metakey, 'post' ) || ! current_user_can( 'add_post_meta', $post_id, $metakey ) ) { return false; } $metakey = wp_slash( $metakey ); return add_post_meta( $post_id, $metakey, $metavalue ); } return false; } /** * Deletes post meta data by meta ID. * * @since 1.2.0 * * @param int $mid * @return bool */ function delete_meta( $mid ) { return delete_metadata_by_mid( 'post', $mid ); } /** * Returns a list of previously defined keys. * * @since 1.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return string[] Array of meta key names. */ function get_meta_keys() { global $wpdb; $keys = $wpdb->get_col( "SELECT meta_key FROM $wpdb->postmeta GROUP BY meta_key ORDER BY meta_key" ); return $keys; } /** * Returns post meta data by meta ID. * * @since 2.1.0 * * @param int $mid * @return object|bool */ function get_post_meta_by_id( $mid ) { return get_metadata_by_mid( 'post', $mid ); } /** * Returns meta data for the given post ID. * * @since 1.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $post_id A post ID. * @return array[] { * Array of meta data arrays for the given post ID. * * @type array ...$0 { * Associative array of meta data. * * @type string $meta_key Meta key. * @type mixed $meta_value Meta value. * @type string $meta_id Meta ID as a numeric string. * @type string $post_id Post ID as a numeric string. * } * } */ function has_meta( $post_id ) { global $wpdb; return $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value, meta_id, post_id FROM $wpdb->postmeta WHERE post_id = %d ORDER BY meta_key,meta_id", $post_id ), ARRAY_A ); } /** * Updates post meta data by meta ID. * * @since 1.2.0 * * @param int $meta_id Meta ID. * @param string $meta_key Meta key. Expect slashed. * @param string $meta_value Meta value. Expect slashed. * @return bool */ function update_meta( $meta_id, $meta_key, $meta_value ) { $meta_key = wp_unslash( $meta_key ); $meta_value = wp_unslash( $meta_value ); return update_metadata_by_mid( 'post', $meta_id, $meta_value, $meta_key ); } // // Private. // /** * Replaces hrefs of attachment anchors with up-to-date permalinks. * * @since 2.3.0 * @access private * * @param int|WP_Post $post Post ID or post object. * @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success. */ function _fix_attachment_links( $post ) { $post = get_post( $post, ARRAY_A ); $content = $post['post_content']; // Don't run if no pretty permalinks or post is not published, scheduled, or privately published. if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) { return; } // Short if there aren't any links or no '?attachment_id=' strings (strpos cannot be zero). if ( ! strpos( $content, '?attachment_id=' ) || ! preg_match_all( '/]+)>[\s\S]+?<\/a>/', $content, $link_matches ) ) { return; } $site_url = get_bloginfo( 'url' ); $site_url = substr( $site_url, (int) strpos( $site_url, '://' ) ); // Remove the http(s). $replace = ''; foreach ( $link_matches[1] as $key => $value ) { if ( ! strpos( $value, '?attachment_id=' ) || ! strpos( $value, 'wp-att-' ) || ! preg_match( '/href=(["\'])[^"\']*\?attachment_id=(\d+)[^"\']*\\1/', $value, $url_match ) || ! preg_match( '/rel=["\'][^"\']*wp-att-(\d+)/', $value, $rel_match ) ) { continue; } $quote = $url_match[1]; // The quote (single or double). $url_id = (int) $url_match[2]; $rel_id = (int) $rel_match[1]; if ( ! $url_id || ! $rel_id || $url_id != $rel_id || ! str_contains( $url_match[0], $site_url ) ) { continue; } $link = $link_matches[0][ $key ]; $replace = str_replace( $url_match[0], 'href=' . $quote . get_attachment_link( $url_id ) . $quote, $link ); $content = str_replace( $link, $replace, $content ); } if ( $replace ) { $post['post_content'] = $content; // Escape data pulled from DB. $post = add_magic_quotes( $post ); return wp_update_post( $post ); } } /** * Returns all the possible statuses for a post type. * * @since 2.5.0 * * @param string $type The post_type you want the statuses for. Default 'post'. * @return string[] An array of all the statuses for the supplied post type. */ function get_available_post_statuses( $type = 'post' ) { $statuses = wp_count_posts( $type ); return array_keys( get_object_vars( $statuses ) ); } /** * Runs the query to fetch the posts for listing on the edit posts page. * * @since 2.5.0 * * @param array|false $q Optional. Array of query variables to use to build the query. * Defaults to the `$_GET` superglobal. * @return array */ function wp_edit_posts_query( $q = false ) { if ( false === $q ) { $q = $_GET; } $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $post_statuses = get_post_stati(); if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) { $post_type = $q['post_type']; } else { $post_type = 'post'; } $avail_post_stati = get_available_post_statuses( $post_type ); $post_status = ''; $perm = ''; if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_statuses, true ) ) { $post_status = $q['post_status']; $perm = 'readable'; } $orderby = ''; if ( isset( $q['orderby'] ) ) { $orderby = $q['orderby']; } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) { $orderby = 'modified'; } $order = ''; if ( isset( $q['order'] ) ) { $order = $q['order']; } elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) { $order = 'ASC'; } $per_page = "edit_{$post_type}_per_page"; $posts_per_page = (int) get_user_option( $per_page ); if ( empty( $posts_per_page ) || $posts_per_page < 1 ) { $posts_per_page = 20; } /** * Filters the number of items per page to show for a specific 'per_page' type. * * The dynamic portion of the hook name, `$post_type`, refers to the post type. * * Possible hook names include: * * - `edit_post_per_page` * - `edit_page_per_page` * - `edit_attachment_per_page` * * @since 3.0.0 * * @param int $posts_per_page Number of posts to display per page for the given post * type. Default 20. */ $posts_per_page = apply_filters( "edit_{$post_type}_per_page", $posts_per_page ); /** * Filters the number of posts displayed per page when specifically listing "posts". * * @since 2.8.0 * * @param int $posts_per_page Number of posts to be displayed. Default 20. * @param string $post_type The post type. */ $posts_per_page = apply_filters( 'edit_posts_per_page', $posts_per_page, $post_type ); $query = compact( 'post_type', 'post_status', 'perm', 'order', 'orderby', 'posts_per_page' ); // Hierarchical types require special args. if ( is_post_type_hierarchical( $post_type ) && empty( $orderby ) ) { $query['orderby'] = 'menu_order title'; $query['order'] = 'asc'; $query['posts_per_page'] = -1; $query['posts_per_archive_page'] = -1; $query['fields'] = 'id=>parent'; } if ( ! empty( $q['show_sticky'] ) ) { $query['post__in'] = (array) get_option( 'sticky_posts' ); } wp( $query ); return $avail_post_stati; } /** * Returns the query variables for the current attachments request. * * @since 4.2.0 * * @param array|false $q Optional. Array of query variables to use to build the query. * Defaults to the `$_GET` superglobal. * @return array The parsed query vars. */ function wp_edit_attachments_query_vars( $q = false ) { if ( false === $q ) { $q = $_GET; } $q['m'] = isset( $q['m'] ) ? (int) $q['m'] : 0; $q['cat'] = isset( $q['cat'] ) ? (int) $q['cat'] : 0; $q['post_type'] = 'attachment'; $post_type = get_post_type_object( 'attachment' ); $states = 'inherit'; if ( current_user_can( $post_type->cap->read_private_posts ) ) { $states .= ',private'; } $q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states; $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states; $media_per_page = (int) get_user_option( 'upload_per_page' ); if ( empty( $media_per_page ) || $media_per_page < 1 ) { $media_per_page = 20; } /** * Filters the number of items to list per page when listing media items. * * @since 2.9.0 * * @param int $media_per_page Number of media to list. Default 20. */ $q['posts_per_page'] = apply_filters( 'upload_per_page', $media_per_page ); $post_mime_types = get_post_mime_types(); if ( isset( $q['post_mime_type'] ) && ! array_intersect( (array) $q['post_mime_type'], array_keys( $post_mime_types ) ) ) { unset( $q['post_mime_type'] ); } foreach ( array_keys( $post_mime_types ) as $type ) { if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) { $q['post_mime_type'] = $type; break; } } if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) { $q['post_parent'] = 0; } if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) { $q['author'] = get_current_user_id(); } // Filter query clauses to include filenames. if ( isset( $q['s'] ) ) { add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' ); } return $q; } /** * Executes a query for attachments. An array of WP_Query arguments * can be passed in, which will override the arguments set by this function. * * @since 2.5.0 * * @param array|false $q Optional. Array of query variables to use to build the query. * Defaults to the `$_GET` superglobal. * @return array */ function wp_edit_attachments_query( $q = false ) { wp( wp_edit_attachments_query_vars( $q ) ); $post_mime_types = get_post_mime_types(); $avail_post_mime_types = get_available_post_mime_types( 'attachment' ); return array( $post_mime_types, $avail_post_mime_types ); } /** * Returns the list of classes to be used by a meta box. * * @since 2.5.0 * * @param string $box_id Meta box ID (used in the 'id' attribute for the meta box). * @param string $screen_id The screen on which the meta box is shown. * @return string Space-separated string of class names. */ function postbox_classes( $box_id, $screen_id ) { if ( isset( $_GET['edit'] ) && $_GET['edit'] === $box_id ) { $classes = array( '' ); } elseif ( get_user_option( 'closedpostboxes_' . $screen_id ) ) { $closed = get_user_option( 'closedpostboxes_' . $screen_id ); if ( ! is_array( $closed ) ) { $classes = array( '' ); } else { $classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' ); } } else { $classes = array( '' ); } /** * Filters the postbox classes for a specific screen and box ID combo. * * The dynamic portions of the hook name, `$screen_id` and `$box_id`, refer to * the screen ID and meta box ID, respectively. * * @since 3.2.0 * * @param string[] $classes An array of postbox classes. */ $classes = apply_filters( "postbox_classes_{$screen_id}_{$box_id}", $classes ); return implode( ' ', $classes ); } /** * Returns a sample permalink based on the post name. * * @since 2.5.0 * * @param int|WP_Post $post Post ID or post object. * @param string|null $title Optional. Title to override the post's current title * when generating the post name. Default null. * @param string|null $name Optional. Name to override the post name. Default null. * @return array { * Array containing the sample permalink with placeholder for the post name, and the post name. * * @type string $0 The permalink with placeholder for the post name. * @type string $1 The post name. * } */ function get_sample_permalink( $post, $title = null, $name = null ) { $post = get_post( $post ); if ( ! $post ) { return array( '', '' ); } $ptype = get_post_type_object( $post->post_type ); $original_status = $post->post_status; $original_date = $post->post_date; $original_name = $post->post_name; $original_filter = $post->filter; // Hack: get_permalink() would return plain permalink for drafts, so we will fake that our post is published. if ( in_array( $post->post_status, array( 'auto-draft', 'draft', 'pending', 'future' ), true ) ) { $post->post_status = 'publish'; $post->post_name = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID ); } /* * If the user wants to set a new name -- override the current one. * Note: if empty name is supplied -- use the title instead, see #6072. */ if ( ! is_null( $name ) ) { $post->post_name = sanitize_title( $name ? $name : $title, $post->ID ); } $post->post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent ); $post->filter = 'sample'; $permalink = get_permalink( $post, true ); // Replace custom post_type token with generic pagename token for ease of use. $permalink = str_replace( "%$post->post_type%", '%pagename%', $permalink ); // Handle page hierarchy. if ( $ptype->hierarchical ) { $uri = get_page_uri( $post ); if ( $uri ) { $uri = untrailingslashit( $uri ); $uri = strrev( stristr( strrev( $uri ), '/' ) ); $uri = untrailingslashit( $uri ); } /** This filter is documented in wp-admin/edit-tag-form.php */ $uri = apply_filters( 'editable_slug', $uri, $post ); if ( ! empty( $uri ) ) { $uri .= '/'; } $permalink = str_replace( '%pagename%', "{$uri}%pagename%", $permalink ); } /** This filter is documented in wp-admin/edit-tag-form.php */ $permalink = array( $permalink, apply_filters( 'editable_slug', $post->post_name, $post ) ); $post->post_status = $original_status; $post->post_date = $original_date; $post->post_name = $original_name; $post->filter = $original_filter; /** * Filters the sample permalink. * * @since 4.4.0 * * @param array $permalink { * Array containing the sample permalink with placeholder for the post name, and the post name. * * @type string $0 The permalink with placeholder for the post name. * @type string $1 The post name. * } * @param int $post_id Post ID. * @param string $title Post title. * @param string $name Post name (slug). * @param WP_Post $post Post object. */ return apply_filters( 'get_sample_permalink', $permalink, $post->ID, $title, $name, $post ); } /** * Returns the HTML of the sample permalink slug editor. * * @since 2.5.0 * * @param int|WP_Post $post Post ID or post object. * @param string|null $new_title Optional. New title. Default null. * @param string|null $new_slug Optional. New slug. Default null. * @return string The HTML of the sample permalink slug editor. */ function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) { $post = get_post( $post ); if ( ! $post ) { return ''; } list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug ); $view_link = false; $preview_target = ''; if ( current_user_can( 'read_post', $post->ID ) ) { if ( 'draft' === $post->post_status || empty( $post->post_name ) ) { $view_link = get_preview_post_link( $post ); $preview_target = " target='wp-preview-{$post->ID}'"; } else { if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) { $view_link = get_permalink( $post ); } else { // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set. $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); } } } // Permalinks without a post/page name placeholder don't have anything to edit. if ( ! str_contains( $permalink, '%postname%' ) && ! str_contains( $permalink, '%pagename%' ) ) { $return = '' . __( 'Permalink:' ) . "\n"; if ( false !== $view_link ) { $display_link = urldecode( $view_link ); $return .= '' . esc_html( $display_link ) . "\n"; } else { $return .= '' . $permalink . "\n"; } // Encourage a pretty permalink setting. if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) ) { $return .= '' . __( 'Change Permalink Structure' ) . "\n"; } } else { if ( mb_strlen( $post_name ) > 34 ) { $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '…' . mb_substr( $post_name, -16 ); } else { $post_name_abridged = $post_name; } $post_name_html = '' . esc_html( $post_name_abridged ) . ''; $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) ); $return = '' . __( 'Permalink:' ) . "\n"; $return .= '' . $display_link . "\n"; $return .= ''; // Fix bi-directional text display defect in RTL languages. $return .= '\n"; $return .= '' . esc_html( $post_name ) . "\n"; } /** * Filters the sample permalink HTML markup. * * @since 2.9.0 * @since 4.4.0 Added `$post` parameter. * * @param string $return Sample permalink HTML markup. * @param int $post_id Post ID. * @param string|null $new_title New sample permalink title. * @param string|null $new_slug New sample permalink slug. * @param WP_Post $post Post object. */ $return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post ); return $return; } /** * Returns HTML for the post thumbnail meta box. * * @since 2.9.0 * * @param int|null $thumbnail_id Optional. Thumbnail attachment ID. Default null. * @param int|WP_Post|null $post Optional. The post ID or object associated * with the thumbnail. Defaults to global $post. * @return string The post thumbnail HTML. */ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { $_wp_additional_image_sizes = wp_get_additional_image_sizes(); $post = get_post( $post ); $post_type_object = get_post_type_object( $post->post_type ); $set_thumbnail_link = ' '; $upload_iframe_src = get_upload_iframe_src( 'image', $post->ID ); $content = sprintf( $set_thumbnail_link, esc_url( $upload_iframe_src ), '', // Empty when there's no featured image set, `aria-describedby` attribute otherwise. esc_html( $post_type_object->labels->set_featured_image ) ); if ( $thumbnail_id && get_post( $thumbnail_id ) ) { $size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : array( 266, 266 ); /** * Filters the size used to display the post thumbnail image in the 'Featured image' meta box. * * Note: When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' * image size is registered, which differs from the 'thumbnail' image size * managed via the Settings > Media screen. * * @since 4.4.0 * * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param int $thumbnail_id Post thumbnail attachment ID. * @param WP_Post $post The post object associated with the thumbnail. */ $size = apply_filters( 'admin_post_thumbnail_size', $size, $thumbnail_id, $post ); $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $size ); if ( ! empty( $thumbnail_html ) ) { $content = sprintf( $set_thumbnail_link, esc_url( $upload_iframe_src ), ' aria-describedby="set-post-thumbnail-desc"', $thumbnail_html ); $content .= ' '; $content .= ' '; } } $content .= ''; /** * Filters the admin post thumbnail HTML markup to return. * * @since 2.9.0 * @since 3.5.0 Added the `$post_id` parameter. * @since 4.6.0 Added the `$thumbnail_id` parameter. * * @param string $content Admin post thumbnail HTML markup. * @param int $post_id Post ID. * @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one. */ return apply_filters( 'admin_post_thumbnail_html', $content, $post->ID, $thumbnail_id ); } /** * Determines whether the post is currently being edited by another user. * * @since 2.5.0 * * @param int|WP_Post $post ID or object of the post to check for editing. * @return int|false ID of the user with lock. False if the post does not exist, post is not locked, * the user with lock does not exist, or the post is locked by current user. */ function wp_check_post_lock( $post ) { $post = get_post( $post ); if ( ! $post ) { return false; } $lock = get_post_meta( $post->ID, '_edit_lock', true ); if ( ! $lock ) { return false; } $lock = explode( ':', $lock ); $time = $lock[0]; $user = isset( $lock[1] ) ? (int) $lock[1] : (int) get_post_meta( $post->ID, '_edit_last', true ); if ( ! get_userdata( $user ) ) { return false; } /** This filter is documented in wp-admin/includes/ajax-actions.php */ $time_window = apply_filters( 'wp_check_post_lock_window', 150 ); if ( $time && $time > time() - $time_window && get_current_user_id() !== $user ) { return $user; } return false; } /** * Marks the post as currently being edited by the current user. * * @since 2.5.0 * * @param int|WP_Post $post ID or object of the post being edited. * @return array|false { * Array of the lock time and user ID. False if the post does not exist, or there * is no current user. * * @type int $0 The current time as a Unix timestamp. * @type int $1 The ID of the current user. * } */ function wp_set_post_lock( $post ) { $post = get_post( $post ); if ( ! $post ) { return false; } $user_id = get_current_user_id(); if ( 0 === $user_id ) { return false; } $now = time(); $lock = "$now:$user_id"; update_post_meta( $post->ID, '_edit_lock', $lock ); return array( $now, $user_id ); } /** * Outputs the HTML for the notice to say that someone else is editing or has taken over editing of this post. * * @since 2.8.5 */ function _admin_notice_post_locked() { $post = get_post(); if ( ! $post ) { return; } $user = null; $user_id = wp_check_post_lock( $post->ID ); if ( $user_id ) { $user = get_userdata( $user_id ); } if ( $user ) { /** * Filters whether to show the post locked dialog. * * Returning false from the filter will prevent the dialog from being displayed. * * @since 3.6.0 * * @param bool $display Whether to display the dialog. Default true. * @param WP_Post $post Post object. * @param WP_User $user The user with the lock for the post. */ if ( ! apply_filters( 'show_post_locked_dialog', true, $post, $user ) ) { return; } $locked = true; } else { $locked = false; } $sendback = wp_get_referer(); $sendback_text = __( 'Go back' ); if ( ! $locked || ! $sendback || str_contains( $sendback, 'post.php' ) || str_contains( $sendback, 'post-new.php' ) ) { $sendback = admin_url( 'edit.php' ); if ( 'post' !== $post->post_type ) { $sendback = add_query_arg( 'post_type', $post->post_type, $sendback ); } $post_type_object = get_post_type_object( $post->post_type ); if ( $post_type_object ) { $sendback_text = $post_type_object->labels->all_items; } } $hidden = $locked ? '' : ' hidden'; ?>' . __( 'Sorry, you are not allowed to edit the links for this site.' ) . '
', 403 ); } $_POST['link_url'] = esc_url( $_POST['link_url'] ); $_POST['link_name'] = esc_html( $_POST['link_name'] ); $_POST['link_image'] = esc_html( $_POST['link_image'] ); $_POST['link_rss'] = esc_url( $_POST['link_rss'] ); if ( ! isset( $_POST['link_visible'] ) || 'N' !== $_POST['link_visible'] ) { $_POST['link_visible'] = 'Y'; } if ( ! empty( $link_id ) ) { $_POST['link_id'] = $link_id; return wp_update_link( $_POST ); } else { return wp_insert_link( $_POST ); } } /** * Retrieves the default link for editing. * * @since 2.0.0 * * @return stdClass Default link object. */ function get_default_link_to_edit() { $link = new stdClass(); if ( isset( $_GET['linkurl'] ) ) { $link->link_url = esc_url( wp_unslash( $_GET['linkurl'] ) ); } else { $link->link_url = ''; } if ( isset( $_GET['name'] ) ) { $link->link_name = esc_attr( wp_unslash( $_GET['name'] ) ); } else { $link->link_name = ''; } $link->link_visible = 'Y'; return $link; } /** * Deletes a specified link from the database. * * @since 2.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $link_id ID of the link to delete. * @return true Always true. */ function wp_delete_link( $link_id ) { global $wpdb; /** * Fires before a link is deleted. * * @since 2.0.0 * * @param int $link_id ID of the link to delete. */ do_action( 'delete_link', $link_id ); wp_delete_object_term_relationships( $link_id, 'link_category' ); $wpdb->delete( $wpdb->links, array( 'link_id' => $link_id ) ); /** * Fires after a link has been deleted. * * @since 2.2.0 * * @param int $link_id ID of the deleted link. */ do_action( 'deleted_link', $link_id ); clean_bookmark_cache( $link_id ); return true; } /** * Retrieves the link category IDs associated with the link specified. * * @since 2.1.0 * * @param int $link_id Link ID to look up. * @return int[] The IDs of the requested link's categories. */ function wp_get_link_cats( $link_id = 0 ) { $cats = wp_get_object_terms( $link_id, 'link_category', array( 'fields' => 'ids' ) ); return array_unique( $cats ); } /** * Retrieves link data based on its ID. * * @since 2.0.0 * * @param int|stdClass $link Link ID or object to retrieve. * @return object Link object for editing. */ function get_link_to_edit( $link ) { return get_bookmark( $link, OBJECT, 'edit' ); } /** * Inserts a link into the database, or updates an existing link. * * Runs all the necessary sanitizing, provides default values if arguments are missing, * and finally saves the link. * * @since 2.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param array $linkdata { * Elements that make up the link to insert. * * @type int $link_id Optional. The ID of the existing link if updating. * @type string $link_url The URL the link points to. * @type string $link_name The title of the link. * @type string $link_image Optional. A URL of an image. * @type string $link_target Optional. The target element for the anchor tag. * @type string $link_description Optional. A short description of the link. * @type string $link_visible Optional. 'Y' means visible, anything else means not. * @type int $link_owner Optional. A user ID. * @type int $link_rating Optional. A rating for the link. * @type string $link_rel Optional. A relationship of the link to you. * @type string $link_notes Optional. An extended description of or notes on the link. * @type string $link_rss Optional. A URL of an associated RSS feed. * @type int $link_category Optional. The term ID of the link category. * If empty, uses default link category. * } * @param bool $wp_error Optional. Whether to return a WP_Error object on failure. Default false. * @return int|WP_Error Value 0 or WP_Error on failure. The link ID on success. */ function wp_insert_link( $linkdata, $wp_error = false ) { global $wpdb; $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0, ); $parsed_args = wp_parse_args( $linkdata, $defaults ); $parsed_args = wp_unslash( sanitize_bookmark( $parsed_args, 'db' ) ); $link_id = $parsed_args['link_id']; $link_name = $parsed_args['link_name']; $link_url = $parsed_args['link_url']; $update = false; if ( ! empty( $link_id ) ) { $update = true; } if ( '' === trim( $link_name ) ) { if ( '' !== trim( $link_url ) ) { $link_name = $link_url; } else { return 0; } } if ( '' === trim( $link_url ) ) { return 0; } $link_rating = ( ! empty( $parsed_args['link_rating'] ) ) ? $parsed_args['link_rating'] : 0; $link_image = ( ! empty( $parsed_args['link_image'] ) ) ? $parsed_args['link_image'] : ''; $link_target = ( ! empty( $parsed_args['link_target'] ) ) ? $parsed_args['link_target'] : ''; $link_visible = ( ! empty( $parsed_args['link_visible'] ) ) ? $parsed_args['link_visible'] : 'Y'; $link_owner = ( ! empty( $parsed_args['link_owner'] ) ) ? $parsed_args['link_owner'] : get_current_user_id(); $link_notes = ( ! empty( $parsed_args['link_notes'] ) ) ? $parsed_args['link_notes'] : ''; $link_description = ( ! empty( $parsed_args['link_description'] ) ) ? $parsed_args['link_description'] : ''; $link_rss = ( ! empty( $parsed_args['link_rss'] ) ) ? $parsed_args['link_rss'] : ''; $link_rel = ( ! empty( $parsed_args['link_rel'] ) ) ? $parsed_args['link_rel'] : ''; $link_category = ( ! empty( $parsed_args['link_category'] ) ) ? $parsed_args['link_category'] : array(); // Make sure we set a valid category. if ( ! is_array( $link_category ) || 0 === count( $link_category ) ) { $link_category = array( get_option( 'default_link_category' ) ); } if ( $update ) { if ( false === $wpdb->update( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ), compact( 'link_id' ) ) ) { if ( $wp_error ) { return new WP_Error( 'db_update_error', __( 'Could not update link in the database.' ), $wpdb->last_error ); } else { return 0; } } } else { if ( false === $wpdb->insert( $wpdb->links, compact( 'link_url', 'link_name', 'link_image', 'link_target', 'link_description', 'link_visible', 'link_owner', 'link_rating', 'link_rel', 'link_notes', 'link_rss' ) ) ) { if ( $wp_error ) { return new WP_Error( 'db_insert_error', __( 'Could not insert link into the database.' ), $wpdb->last_error ); } else { return 0; } } $link_id = (int) $wpdb->insert_id; } wp_set_link_cats( $link_id, $link_category ); if ( $update ) { /** * Fires after a link was updated in the database. * * @since 2.0.0 * * @param int $link_id ID of the link that was updated. */ do_action( 'edit_link', $link_id ); } else { /** * Fires after a link was added to the database. * * @since 2.0.0 * * @param int $link_id ID of the link that was added. */ do_action( 'add_link', $link_id ); } clean_bookmark_cache( $link_id ); return $link_id; } /** * Updates link with the specified link categories. * * @since 2.1.0 * * @param int $link_id ID of the link to update. * @param int[] $link_categories Array of link category IDs to add the link to. */ function wp_set_link_cats( $link_id = 0, $link_categories = array() ) { // If $link_categories isn't already an array, make it one: if ( ! is_array( $link_categories ) || 0 === count( $link_categories ) ) { $link_categories = array( get_option( 'default_link_category' ) ); } $link_categories = array_map( 'intval', $link_categories ); $link_categories = array_unique( $link_categories ); wp_set_object_terms( $link_id, $link_categories, 'link_category' ); clean_bookmark_cache( $link_id ); } /** * Updates a link in the database. * * @since 2.0.0 * * @param array $linkdata Link data to update. See wp_insert_link() for accepted arguments. * @return int|WP_Error Value 0 or WP_Error on failure. The updated link ID on success. */ function wp_update_link( $linkdata ) { $link_id = (int) $linkdata['link_id']; $link = get_bookmark( $link_id, ARRAY_A ); // Escape data pulled from DB. $link = wp_slash( $link ); // Passed link category list overwrites existing category list if not empty. if ( isset( $linkdata['link_category'] ) && is_array( $linkdata['link_category'] ) && count( $linkdata['link_category'] ) > 0 ) { $link_cats = $linkdata['link_category']; } else { $link_cats = $link['link_category']; } // Merge old and new fields with new fields overwriting old ones. $linkdata = array_merge( $link, $linkdata ); $linkdata['link_category'] = $link_cats; return wp_insert_link( $linkdata ); } /** * Outputs the 'disabled' message for the WordPress Link Manager. * * @since 3.5.0 * @access private * * @global string $pagenow The filename of the current screen. */ function wp_link_manager_disabled_message() { global $pagenow; if ( ! in_array( $pagenow, array( 'link-manager.php', 'link-add.php', 'link.php' ), true ) ) { return; } add_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); $really_can_manage_links = current_user_can( 'manage_links' ); remove_filter( 'pre_option_link_manager_enabled', '__return_true', 100 ); if ( $really_can_manage_links ) { $plugins = get_plugins(); if ( empty( $plugins['link-manager/link-manager.php'] ) ) { if ( current_user_can( 'install_plugins' ) ) { $install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=link-manager' ), 'install-plugin_link-manager' ); wp_die( sprintf( /* translators: %s: A link to install the Link Manager plugin. */ __( 'If you are looking to use the link manager, please install the Link Manager plugin.' ), esc_url( $install_url ) ) ); } } elseif ( is_plugin_inactive( 'link-manager/link-manager.php' ) ) { if ( current_user_can( 'activate_plugins' ) ) { $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=link-manager/link-manager.php' ), 'activate-plugin_link-manager/link-manager.php' ); wp_die( sprintf( /* translators: %s: A link to activate the Link Manager plugin. */ __( 'Please activate the Link Manager plugin to use the link manager.' ), esc_url( $activate_url ) ) ); } } } wp_die( __( 'Sorry, you are not allowed to edit the links for this site.' ) ); } includes/privacy-tools.php 0000644 00000101266 14717704420 0011712 0 ustar 00 post_type ) { return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) ); } $result = wp_send_user_request( $request_id ); if ( is_wp_error( $result ) ) { return $result; } elseif ( ! $result ) { return new WP_Error( 'privacy_request_error', __( 'Unable to initiate confirmation for personal data request.' ) ); } return true; } /** * Marks a request as completed by the admin and logs the current timestamp. * * @since 4.9.6 * @access private * * @param int $request_id Request ID. * @return int|WP_Error Request ID on success, or a WP_Error on failure. */ function _wp_privacy_completed_request( $request_id ) { // Get the request. $request_id = absint( $request_id ); $request = wp_get_user_request( $request_id ); if ( ! $request ) { return new WP_Error( 'privacy_request_error', __( 'Invalid personal data request.' ) ); } update_post_meta( $request_id, '_wp_user_request_completed_timestamp', time() ); $result = wp_update_post( array( 'ID' => $request_id, 'post_status' => 'request-completed', ) ); return $result; } /** * Handle list table actions. * * @since 4.9.6 * @access private */ function _wp_personal_data_handle_actions() { if ( isset( $_POST['privacy_action_email_retry'] ) ) { check_admin_referer( 'bulk-privacy_requests' ); $request_id = absint( current( array_keys( (array) wp_unslash( $_POST['privacy_action_email_retry'] ) ) ) ); $result = _wp_privacy_resend_request( $request_id ); if ( is_wp_error( $result ) ) { add_settings_error( 'privacy_action_email_retry', 'privacy_action_email_retry', $result->get_error_message(), 'error' ); } else { add_settings_error( 'privacy_action_email_retry', 'privacy_action_email_retry', __( 'Confirmation request sent again successfully.' ), 'success' ); } } elseif ( isset( $_POST['action'] ) ) { $action = ! empty( $_POST['action'] ) ? sanitize_key( wp_unslash( $_POST['action'] ) ) : ''; switch ( $action ) { case 'add_export_personal_data_request': case 'add_remove_personal_data_request': check_admin_referer( 'personal-data-request' ); if ( ! isset( $_POST['type_of_action'], $_POST['username_or_email_for_privacy_request'] ) ) { add_settings_error( 'action_type', 'action_type', __( 'Invalid personal data action.' ), 'error' ); } $action_type = sanitize_text_field( wp_unslash( $_POST['type_of_action'] ) ); $username_or_email_address = sanitize_text_field( wp_unslash( $_POST['username_or_email_for_privacy_request'] ) ); $email_address = ''; $status = 'pending'; if ( ! isset( $_POST['send_confirmation_email'] ) ) { $status = 'confirmed'; } if ( ! in_array( $action_type, _wp_privacy_action_request_types(), true ) ) { add_settings_error( 'action_type', 'action_type', __( 'Invalid personal data action.' ), 'error' ); } if ( ! is_email( $username_or_email_address ) ) { $user = get_user_by( 'login', $username_or_email_address ); if ( ! $user instanceof WP_User ) { add_settings_error( 'username_or_email_for_privacy_request', 'username_or_email_for_privacy_request', __( 'Unable to add this request. A valid email address or username must be supplied.' ), 'error' ); } else { $email_address = $user->user_email; } } else { $email_address = $username_or_email_address; } if ( empty( $email_address ) ) { break; } $request_id = wp_create_user_request( $email_address, $action_type, array(), $status ); $message = ''; if ( is_wp_error( $request_id ) ) { $message = $request_id->get_error_message(); } elseif ( ! $request_id ) { $message = __( 'Unable to initiate confirmation request.' ); } if ( $message ) { add_settings_error( 'username_or_email_for_privacy_request', 'username_or_email_for_privacy_request', $message, 'error' ); break; } if ( 'pending' === $status ) { wp_send_user_request( $request_id ); $message = __( 'Confirmation request initiated successfully.' ); } elseif ( 'confirmed' === $status ) { $message = __( 'Request added successfully.' ); } if ( $message ) { add_settings_error( 'username_or_email_for_privacy_request', 'username_or_email_for_privacy_request', $message, 'success' ); break; } } } } /** * Cleans up failed and expired requests before displaying the list table. * * @since 4.9.6 * @access private */ function _wp_personal_data_cleanup_requests() { /** This filter is documented in wp-includes/user.php */ $expires = (int) apply_filters( 'user_request_key_expiration', DAY_IN_SECONDS ); $requests_query = new WP_Query( array( 'post_type' => 'user_request', 'posts_per_page' => -1, 'post_status' => 'request-pending', 'fields' => 'ids', 'date_query' => array( array( 'column' => 'post_modified_gmt', 'before' => $expires . ' seconds ago', ), ), ) ); $request_ids = $requests_query->posts; foreach ( $request_ids as $request_id ) { wp_update_post( array( 'ID' => $request_id, 'post_status' => 'request-failed', 'post_password' => '', ) ); } } /** * Generate a single group for the personal data export report. * * @since 4.9.6 * @since 5.4.0 Added the `$group_id` and `$groups_count` parameters. * * @param array $group_data { * The group data to render. * * @type string $group_label The user-facing heading for the group, e.g. 'Comments'. * @type array $items { * An array of group items. * * @type array $group_item_data { * An array of name-value pairs for the item. * * @type string $name The user-facing name of an item name-value pair, e.g. 'IP Address'. * @type string $value The user-facing value of an item data pair, e.g. '50.60.70.0'. * } * } * } * @param string $group_id The group identifier. * @param int $groups_count The number of all groups * @return string The HTML for this group and its items. */ function wp_privacy_generate_personal_data_export_group_html( $group_data, $group_id = '', $groups_count = 1 ) { $group_id_attr = sanitize_title_with_dashes( $group_data['group_label'] . '-' . $group_id ); $group_html = '' . esc_html( $group_data['group_description'] ) . '
'; } $group_html .= '' . esc_html( $group_item_datum['name'] ) . ' | '; $group_html .= '' . wp_kses( $value, 'personal_data_export' ) . ' | '; $group_html .= '
---|
_export_data_grouped
' ),
'5.8.0'
);
}
$groups = null;
$groups_count = 0;
}
// Convert the groups to JSON format.
$groups_json = wp_json_encode( $groups );
if ( false === $groups_json ) {
$error_message = sprintf(
/* translators: %s: Error message. */
__( 'Unable to encode the personal data for export. Error: %s' ),
json_last_error_msg()
);
wp_send_json_error( $error_message );
}
/*
* Handle the JSON export.
*/
$file = fopen( $json_report_pathname, 'w' );
if ( false === $file ) {
wp_send_json_error( __( 'Unable to open personal data export file (JSON report) for writing.' ) );
}
fwrite( $file, '{' );
fwrite( $file, '"' . $title . '":' );
fwrite( $file, $groups_json );
fwrite( $file, '}' );
fclose( $file );
/*
* Handle the HTML export.
*/
$file = fopen( $html_report_pathname, 'w' );
if ( false === $file ) {
wp_send_json_error( __( 'Unable to open personal data export (HTML report) for writing.' ) );
}
fwrite( $file, "\n" );
fwrite( $file, "\n" );
fwrite( $file, "\n" );
fwrite( $file, "\n" );
fwrite( $file, "' );
fwrite( $file, ''search-submit' ) ); ?>
! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '' : '', 'name' => __( 'Plugin' ), 'description' => __( 'Description' ), ); if ( $this->show_autoupdates && ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { $columns['auto-updates'] = __( 'Automatic Updates' ); } return $columns; } /** * @return array */ protected function get_sortable_columns() { return array(); } /** * @global array $totals * @global string $status * @return array */ protected function get_views() { global $totals, $status; $status_links = array(); foreach ( $totals as $type => $count ) { if ( ! $count ) { continue; } switch ( $type ) { case 'all': /* translators: %s: Number of plugins. */ $text = _nx( 'All (%s)', 'All (%s)', $count, 'plugins' ); break; case 'active': /* translators: %s: Number of plugins. */ $text = _n( 'Active (%s)', 'Active (%s)', $count ); break; case 'recently_activated': /* translators: %s: Number of plugins. */ $text = _n( 'Recently Active (%s)', 'Recently Active (%s)', $count ); break; case 'inactive': /* translators: %s: Number of plugins. */ $text = _n( 'Inactive (%s)', 'Inactive (%s)', $count ); break; case 'mustuse': /* translators: %s: Number of plugins. */ $text = _n( 'Must-Use (%s)', 'Must-Use (%s)', $count ); break; case 'dropins': /* translators: %s: Number of plugins. */ $text = _n( 'Drop-in (%s)', 'Drop-ins (%s)', $count ); break; case 'paused': /* translators: %s: Number of plugins. */ $text = _n( 'Paused (%s)', 'Paused (%s)', $count ); break; case 'upgrade': /* translators: %s: Number of plugins. */ $text = _n( 'Update Available (%s)', 'Update Available (%s)', $count ); break; case 'auto-update-enabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Enabled (%s)', 'Auto-updates Enabled (%s)', $count ); break; case 'auto-update-disabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Disabled (%s)', 'Auto-updates Disabled (%s)', $count ); break; } if ( 'search' !== $type ) { $status_links[ $type ] = array( 'url' => add_query_arg( 'plugin_status', $type, 'plugins.php' ), 'label' => sprintf( $text, number_format_i18n( $count ) ), 'current' => $type === $status, ); } } return $this->get_views_links( $status_links ); } /** * @global string $status * @return array */ protected function get_bulk_actions() { global $status; $actions = array(); if ( 'active' !== $status ) { $actions['activate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Activate', 'plugin' ) : _x( 'Activate', 'plugin' ); } if ( 'inactive' !== $status && 'recent' !== $status ) { $actions['deactivate-selected'] = $this->screen->in_admin( 'network' ) ? _x( 'Network Deactivate', 'plugin' ) : _x( 'Deactivate', 'plugin' ); } if ( ! is_multisite() || $this->screen->in_admin( 'network' ) ) { if ( current_user_can( 'update_plugins' ) ) { $actions['update-selected'] = __( 'Update' ); } if ( current_user_can( 'delete_plugins' ) && ( 'active' !== $status ) ) { $actions['delete-selected'] = __( 'Delete' ); } if ( $this->show_autoupdates ) { if ( 'auto-update-enabled' !== $status ) { $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); } if ( 'auto-update-disabled' !== $status ) { $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); } } } return $actions; } /** * @global string $status * @param string $which */ public function bulk_actions( $which = '' ) { global $status; if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) { return; } parent::bulk_actions( $which ); } /** * @global string $status * @param string $which */ protected function extra_tablenav( $which ) { global $status; if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) { return; } echo '' . sprintf(
/* translators: %s: mu-plugins directory name. */
__( 'Files in the %s directory are executed automatically.' ),
'' . str_replace( ABSPATH, '/', WPMU_PLUGIN_DIR ) . '
'
) . '
' . sprintf(
/* translators: %s: wp-content directory name. */
__( 'Drop-ins are single files, found in the %s directory, that replace or enhance WordPress features in ways that are not possible for traditional plugins.' ),
'' . str_replace( ABSPATH, '', WP_CONTENT_DIR ) . '
'
) . '
' . $dropins[ $plugin_file ][0] . '
'; } elseif ( defined( $dropins[ $plugin_file ][1] ) && constant( $dropins[ $plugin_file ][1] ) ) { // Constant is true. $is_active = true; $description = '' . $dropins[ $plugin_file ][0] . '
'; } else { $is_active = false; $description = '' . $dropins[ $plugin_file ][0] . ' define('" . $dropins[ $plugin_file ][1] . "', true);
",
'wp-config.php
'
) . '
' . $plugin_data['Description'] . '
'; } } else { if ( $screen->in_admin( 'network' ) ) { $is_active = is_plugin_active_for_network( $plugin_file ); } else { $is_active = is_plugin_active( $plugin_file ); $restrict_network_active = ( is_multisite() && is_plugin_active_for_network( $plugin_file ) ); $restrict_network_only = ( is_multisite() && is_network_only_plugin( $plugin_file ) && ! $is_active ); } if ( $screen->in_admin( 'network' ) ) { if ( $is_active ) { if ( current_user_can( 'manage_network_plugins' ) ) { if ( $has_active_dependents ) { $actions['deactivate'] = __( 'Deactivate' ) . '' . __( 'You cannot deactivate this plugin as other plugins require it.' ) . ''; } else { $deactivate_url = 'plugins.php?action=deactivate' . '&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['deactivate'] = sprintf( '%s', wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), _x( 'Network Deactivate', 'plugin' ) ); } } } else { if ( current_user_can( 'manage_network_plugins' ) ) { if ( $compatible_php && $compatible_wp ) { if ( $has_unmet_dependencies ) { $actions['activate'] = _x( 'Network Activate', 'plugin' ) . '' . __( 'You cannot activate this plugin as it has unmet requirements.' ) . ''; } else { $activate_url = 'plugins.php?action=activate' . '&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['activate'] = sprintf( '%s', wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ), _x( 'Network Activate', 'plugin' ) ); } } else { $actions['activate'] = sprintf( '%s', _x( 'Cannot Activate', 'plugin' ) ); } } if ( current_user_can( 'delete_plugins' ) && ! is_plugin_active( $plugin_file ) ) { if ( $has_dependents && ! $has_circular_dependency ) { $actions['delete'] = __( 'Delete' ) . '' . __( 'You cannot delete this plugin as other plugins require it.' ) . ''; } else { $delete_url = 'plugins.php?action=delete-selected' . '&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['delete'] = sprintf( '%s', wp_nonce_url( $delete_url, 'bulk-plugins' ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' ) ); } } } } else { if ( $restrict_network_active ) { $actions = array( 'network_active' => __( 'Network Active' ), ); } elseif ( $restrict_network_only ) { $actions = array( 'network_only' => __( 'Network Only' ), ); } elseif ( $is_active ) { if ( current_user_can( 'deactivate_plugin', $plugin_file ) ) { if ( $has_active_dependents ) { $actions['deactivate'] = __( 'Deactivate' ) . '' . __( 'You cannot deactivate this plugin as other plugins depend on it.' ) . ''; } else { $deactivate_url = 'plugins.php?action=deactivate' . '&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['deactivate'] = sprintf( '%s', wp_nonce_url( $deactivate_url, 'deactivate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Deactivate' ) ); } } if ( current_user_can( 'resume_plugin', $plugin_file ) && is_plugin_paused( $plugin_file ) ) { $resume_url = 'plugins.php?action=resume' . '&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['resume'] = sprintf( '%s', wp_nonce_url( $resume_url, 'resume-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Resume' ) ); } } else { if ( current_user_can( 'activate_plugin', $plugin_file ) ) { if ( $compatible_php && $compatible_wp ) { if ( $has_unmet_dependencies ) { $actions['activate'] = _x( 'Activate', 'plugin' ) . '' . __( 'You cannot activate this plugin as it has unmet requirements.' ) . ''; } else { $activate_url = 'plugins.php?action=activate' . '&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['activate'] = sprintf( '%s', wp_nonce_url( $activate_url, 'activate-plugin_' . $plugin_file ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ), _x( 'Activate', 'plugin' ) ); } } else { $actions['activate'] = sprintf( '%s', _x( 'Cannot Activate', 'plugin' ) ); } } if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) { if ( $has_dependents && ! $has_circular_dependency ) { $actions['delete'] = __( 'Delete' ) . '' . __( 'You cannot delete this plugin as other plugins require it.' ) . ''; } else { $delete_url = 'plugins.php?action=delete-selected' . '&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s; $actions['delete'] = sprintf( '%s', wp_nonce_url( $delete_url, 'bulk-plugins' ), esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' ) ); } } } // End if $is_active. } // End if $screen->in_admin( 'network' ). } // End if $context. $actions = array_filter( $actions ); if ( $screen->in_admin( 'network' ) ) { /** * Filters the action links displayed for each plugin in the Network Admin Plugins list table. * * @since 3.1.0 * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( 'network_admin_plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); /** * Filters the list of action links displayed for a specific plugin in the Network Admin Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 3.1.0 * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( "network_admin_plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); } else { /** * Filters the action links displayed for each plugin in the Plugins list table. * * @since 2.5.0 * @since 2.6.0 The `$context` parameter was added. * @since 4.9.0 The 'Edit' link was removed from the list of action links. * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. With Multisite active * this can also include 'network_active' and 'network_only' items. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( 'plugin_action_links', $actions, $plugin_file, $plugin_data, $context ); /** * Filters the list of action links displayed for a specific plugin in the Plugins list table. * * The dynamic portion of the hook name, `$plugin_file`, refers to the path * to the plugin file, relative to the plugins directory. * * @since 2.7.0 * @since 4.9.0 The 'Edit' link was removed from the list of action links. * * @param string[] $actions An array of plugin action links. By default this can include * 'activate', 'deactivate', and 'delete'. With Multisite active * this can also include 'network_active' and 'network_only' items. * @param string $plugin_file Path to the plugin file relative to the plugins directory. * @param array $plugin_data An array of plugin data. See get_plugin_data() * and the {@see 'plugin_row_meta'} filter for the list * of possible values. * @param string $context The plugin context. By default this can include 'all', * 'active', 'inactive', 'recently_activated', 'upgrade', * 'mustuse', 'dropins', and 'search'. */ $actions = apply_filters( "plugin_action_links_{$plugin_file}", $actions, $plugin_file, $plugin_data, $context ); } $class = $is_active ? 'active' : 'inactive'; $checkbox_id = 'checkbox_' . md5( $plugin_file ); $disabled = ''; if ( $has_dependents || $has_unmet_dependencies ) { $disabled = 'disabled'; } if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) { $checkbox = ''; } else { $checkbox = sprintf( '' . '', $checkbox_id, /* translators: Hidden accessibility text. %s: Plugin name. */ sprintf( __( 'Select %s' ), $plugin_data['Name'] ), esc_attr( $plugin_file ) ); } if ( 'dropins' !== $context ) { $description = '' . ( $plugin_data['Description'] ? $plugin_data['Description'] : ' ' ) . '
'; $plugin_name = $plugin_data['Name']; } if ( ! empty( $totals['upgrade'] ) && ! empty( $plugin_data['update'] ) || ! $compatible_php || ! $compatible_wp ) { $class .= ' update'; } $paused = ! $screen->in_admin( 'network' ) && is_plugin_paused( $plugin_file ); if ( $paused ) { $class .= ' paused'; } if ( is_uninstallable_plugin( $plugin_file ) ) { $class .= ' is-uninstallable'; } printf( '%s
', $notice_text ); $error = wp_get_plugin_error( $plugin_file ); if ( false !== $error ) { printf( '%s
', '', false ); } elseif ( current_user_can( 'update_core' ) ) { $incompatible_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Please update WordPress.' ), self_admin_url( 'update-core.php' ) ); } elseif ( current_user_can( 'update_php' ) ) { $incompatible_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); $incompatible_message .= wp_update_php_annotation( '
', '', false ); } } elseif ( ! $compatible_wp ) { $incompatible_message .= __( 'This plugin does not work with your version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { $incompatible_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Please update WordPress.' ), self_admin_url( 'update-core.php' ) ); } } elseif ( ! $compatible_php ) { $incompatible_message .= __( 'This plugin does not work with your version of PHP.' ); if ( current_user_can( 'update_php' ) ) { $incompatible_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ); $incompatible_message .= wp_update_php_annotation( '
', '', false ); } } wp_admin_notice( $incompatible_message, array( 'type' => 'error', 'additional_classes' => array( 'notice-alt', 'inline', 'update-message' ), ) ); echo '
%1$s
%2$s
%1$s
%2$s' . __( 'Search for themes by keyword.' ) . '
'; } ?> prepare_items(); $wp_list_table->single_row( $theme ); } /** * Displays theme content based on theme list. * * @since 2.8.0 * * @global WP_Theme_Install_List_Table $wp_list_table */ function display_themes() { global $wp_list_table; if ( ! isset( $wp_list_table ) ) { $wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' ); } $wp_list_table->prepare_items(); $wp_list_table->display(); } /** * Displays theme information in dialog box form. * * @since 2.8.0 * * @global WP_Theme_Install_List_Table $wp_list_table */ function install_theme_information() { global $wp_list_table; $theme = themes_api( 'theme_information', array( 'slug' => wp_unslash( $_REQUEST['theme'] ) ) ); if ( is_wp_error( $theme ) ) { wp_die( $theme ); } iframe_header( __( 'Theme Installation' ) ); if ( ! isset( $wp_list_table ) ) { $wp_list_table = _get_list_table( 'WP_Theme_Install_List_Table' ); } $wp_list_table->theme_installer_single( $theme ); iframe_footer(); exit; } includes/class-core-upgrader.php 0000644 00000035527 14717704420 0012747 0 ustar 00 strings['up_to_date'] = __( 'WordPress is at the latest version.' ); $this->strings['locked'] = __( 'Another update is currently in progress.' ); $this->strings['no_package'] = __( 'Update package not available.' ); /* translators: %s: Package URL. */ $this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' ); $this->strings['unpack_package'] = __( 'Unpacking the update…' ); $this->strings['copy_failed'] = __( 'Could not copy files.' ); $this->strings['copy_failed_space'] = __( 'Could not copy files. You may have run out of disk space.' ); $this->strings['start_rollback'] = __( 'Attempting to restore the previous version.' ); $this->strings['rollback_was_required'] = __( 'Due to an error during updating, WordPress has been restored to your previous version.' ); } /** * Upgrades WordPress core. * * @since 2.8.0 * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * @global callable $_wp_filesystem_direct_method * * @param object $current Response object for whether WordPress is current. * @param array $args { * Optional. Arguments for upgrading WordPress core. Default empty array. * * @type bool $pre_check_md5 Whether to check the file checksums before * attempting the upgrade. Default true. * @type bool $attempt_rollback Whether to attempt to rollback the chances if * there is a problem. Default false. * @type bool $do_rollback Whether to perform this "upgrade" as a rollback. * Default false. * } * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure. */ public function upgrade( $current, $args = array() ) { global $wp_filesystem; require ABSPATH . WPINC . '/version.php'; // $wp_version; $start_time = time(); $defaults = array( 'pre_check_md5' => true, 'attempt_rollback' => false, 'do_rollback' => false, 'allow_relaxed_file_ownership' => false, ); $parsed_args = wp_parse_args( $args, $defaults ); $this->init(); $this->upgrade_strings(); // Is an update available? if ( ! isset( $current->response ) || 'latest' === $current->response ) { return new WP_Error( 'up_to_date', $this->strings['up_to_date'] ); } $res = $this->fs_connect( array( ABSPATH, WP_CONTENT_DIR ), $parsed_args['allow_relaxed_file_ownership'] ); if ( ! $res || is_wp_error( $res ) ) { return $res; } $wp_dir = trailingslashit( $wp_filesystem->abspath() ); $partial = true; if ( $parsed_args['do_rollback'] ) { $partial = false; } elseif ( $parsed_args['pre_check_md5'] && ! $this->check_files() ) { $partial = false; } /* * If partial update is returned from the API, use that, unless we're doing * a reinstallation. If we cross the new_bundled version number, then use * the new_bundled zip. Don't though if the constant is set to skip bundled items. * If the API returns a no_content zip, go with it. Finally, default to the full zip. */ if ( $parsed_args['do_rollback'] && $current->packages->rollback ) { $to_download = 'rollback'; } elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version === $current->partial_version && $partial ) { $to_download = 'partial'; } elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) && ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) { $to_download = 'new_bundled'; } elseif ( $current->packages->no_content ) { $to_download = 'no_content'; } else { $to_download = 'full'; } // Lock to prevent multiple Core Updates occurring. $lock = WP_Upgrader::create_lock( 'core_updater', 15 * MINUTE_IN_SECONDS ); if ( ! $lock ) { return new WP_Error( 'locked', $this->strings['locked'] ); } $download = $this->download_package( $current->packages->$to_download, false ); /* * Allow for signature soft-fail. * WARNING: This may be removed in the future. */ if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) { // Output the failure error as a normal feedback, and not as an error: /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $download->get_error_message() ); // Report this failure back to WordPress.org for debugging purposes. wp_version_check( array( 'signature_failure_code' => $download->get_error_code(), 'signature_failure_data' => $download->get_error_data(), ) ); // Pretend this error didn't happen. $download = $download->get_error_data( 'softfail-filename' ); } if ( is_wp_error( $download ) ) { WP_Upgrader::release_lock( 'core_updater' ); return $download; } $working_dir = $this->unpack_package( $download ); if ( is_wp_error( $working_dir ) ) { WP_Upgrader::release_lock( 'core_updater' ); return $working_dir; } // Copy update-core.php from the new version into place. if ( ! $wp_filesystem->copy( $working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true ) ) { $wp_filesystem->delete( $working_dir, true ); WP_Upgrader::release_lock( 'core_updater' ); return new WP_Error( 'copy_failed_for_update_core_file', __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ), 'wp-admin/includes/update-core.php' ); } $wp_filesystem->chmod( $wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE ); wp_opcache_invalidate( ABSPATH . 'wp-admin/includes/update-core.php' ); require_once ABSPATH . 'wp-admin/includes/update-core.php'; if ( ! function_exists( 'update_core' ) ) { WP_Upgrader::release_lock( 'core_updater' ); return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); } $result = update_core( $working_dir, $wp_dir ); // In the event of an issue, we may be able to roll back. if ( $parsed_args['attempt_rollback'] && $current->packages->rollback && ! $parsed_args['do_rollback'] ) { $try_rollback = false; if ( is_wp_error( $result ) ) { $error_code = $result->get_error_code(); /* * Not all errors are equal. These codes are critical: copy_failed__copy_dir, * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full. * do_rollback allows for update_core() to trigger a rollback if needed. */ if ( str_contains( $error_code, 'do_rollback' ) ) { $try_rollback = true; } elseif ( str_contains( $error_code, '__copy_dir' ) ) { $try_rollback = true; } elseif ( 'disk_full' === $error_code ) { $try_rollback = true; } } if ( $try_rollback ) { /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $result ); /** This filter is documented in wp-admin/includes/update-core.php */ apply_filters( 'update_feedback', $this->strings['start_rollback'] ); $rollback_result = $this->upgrade( $current, array_merge( $parsed_args, array( 'do_rollback' => true ) ) ); $original_result = $result; $result = new WP_Error( 'rollback_was_required', $this->strings['rollback_was_required'], (object) array( 'update' => $original_result, 'rollback' => $rollback_result, ) ); } } /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ do_action( 'upgrader_process_complete', $this, array( 'action' => 'update', 'type' => 'core', ) ); // Clear the current updates. delete_site_transient( 'update_core' ); if ( ! $parsed_args['do_rollback'] ) { $stats = array( 'update_type' => $current->response, 'success' => true, 'fs_method' => $wp_filesystem->method, 'fs_method_forced' => defined( 'FS_METHOD' ) || has_filter( 'filesystem_method' ), 'fs_method_direct' => ! empty( $GLOBALS['_wp_filesystem_direct_method'] ) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 'time_taken' => time() - $start_time, 'reported' => $wp_version, 'attempted' => $current->version, ); if ( is_wp_error( $result ) ) { $stats['success'] = false; // Did a rollback occur? if ( ! empty( $try_rollback ) ) { $stats['error_code'] = $original_result->get_error_code(); $stats['error_data'] = $original_result->get_error_data(); // Was the rollback successful? If not, collect its error too. $stats['rollback'] = ! is_wp_error( $rollback_result ); if ( is_wp_error( $rollback_result ) ) { $stats['rollback_code'] = $rollback_result->get_error_code(); $stats['rollback_data'] = $rollback_result->get_error_data(); } } else { $stats['error_code'] = $result->get_error_code(); $stats['error_data'] = $result->get_error_data(); } } wp_version_check( $stats ); } WP_Upgrader::release_lock( 'core_updater' ); return $result; } /** * Determines if this WordPress Core version should update to an offered version or not. * * @since 3.7.0 * * @param string $offered_ver The offered version, of the format x.y.z. * @return bool True if we should update to the offered version, otherwise false. */ public static function should_update_to_version( $offered_ver ) { require ABSPATH . WPINC . '/version.php'; // $wp_version; // x.y.z $current_branch = implode( '.', array_slice( preg_split( '/[.-]/', $wp_version ), 0, 2 ) ); // x.y $new_branch = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y $current_is_development_version = (bool) strpos( $wp_version, '-' ); // Defaults: $upgrade_dev = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled'; $upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled'; $upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled'; // WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false. if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) { if ( false === WP_AUTO_UPDATE_CORE ) { // Defaults to turned off, unless a filter allows it. $upgrade_dev = false; $upgrade_minor = false; $upgrade_major = false; } elseif ( true === WP_AUTO_UPDATE_CORE || in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true ) ) { // ALL updates for core. $upgrade_dev = true; $upgrade_minor = true; $upgrade_major = true; } elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) { // Only minor updates for core. $upgrade_dev = false; $upgrade_minor = true; $upgrade_major = false; } } // 1: If we're already on that version, not much point in updating? if ( $offered_ver === $wp_version ) { return false; } // 2: If we're running a newer version, that's a nope. if ( version_compare( $wp_version, $offered_ver, '>' ) ) { return false; } $failure_data = get_site_option( 'auto_core_update_failed' ); if ( $failure_data ) { // If this was a critical update failure, cannot update. if ( ! empty( $failure_data['critical'] ) ) { return false; } // Don't claim we can update on update-core.php if we have a non-critical failure logged. if ( $wp_version === $failure_data['current'] && str_contains( $offered_ver, '.1.next.minor' ) ) { return false; } /* * Cannot update if we're retrying the same A to B update that caused a non-critical failure. * Some non-critical failures do allow retries, like download_failed. * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2. */ if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) { return false; } } // 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2. if ( $current_is_development_version ) { /** * Filters whether to enable automatic core updates for development versions. * * @since 3.7.0 * * @param bool $upgrade_dev Whether to enable automatic updates for * development versions. */ if ( ! apply_filters( 'allow_dev_auto_core_updates', $upgrade_dev ) ) { return false; } // Else fall through to minor + major branches below. } // 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4). if ( $current_branch === $new_branch ) { /** * Filters whether to enable minor automatic core updates. * * @since 3.7.0 * * @param bool $upgrade_minor Whether to enable minor automatic core updates. */ return apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor ); } // 5: Major version updates (3.7.0 -> 3.8.0 -> 3.9.1). if ( version_compare( $new_branch, $current_branch, '>' ) ) { /** * Filters whether to enable major automatic core updates. * * @since 3.7.0 * * @param bool $upgrade_major Whether to enable major automatic core updates. */ return apply_filters( 'allow_major_auto_core_updates', $upgrade_major ); } // If we're not sure, we don't want it. return false; } /** * Compares the disk file checksums against the expected checksums. * * @since 3.7.0 * * @global string $wp_version The WordPress version string. * @global string $wp_local_package Locale code of the package. * * @return bool True if the checksums match, otherwise false. */ public function check_files() { global $wp_version, $wp_local_package; $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' ); if ( ! is_array( $checksums ) ) { return false; } foreach ( $checksums as $file => $checksum ) { // Skip files which get updated. if ( str_starts_with( $file, 'wp-content' ) ) { continue; } if ( ! file_exists( ABSPATH . $file ) || md5_file( ABSPATH . $file ) !== $checksum ) { return false; } } return true; } } includes/network.php 0000644 00000064544 14717704420 0010577 0 ustar 00 prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $wpdb->site ) ); if ( $wpdb->get_var( $sql ) ) { return $wpdb->get_var( "SELECT domain FROM $wpdb->site ORDER BY id ASC LIMIT 1" ); } return false; } /** * Allow subdomain installation * * @since 3.0.0 * @return bool Whether subdomain installation is allowed */ function allow_subdomain_install() { $home = get_option( 'home' ); $domain = parse_url( $home, PHP_URL_HOST ); if ( parse_url( $home, PHP_URL_PATH ) || 'localhost' === $domain || preg_match( '|^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|', $domain ) ) { return false; } return true; } /** * Allow subdirectory installation. * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @return bool Whether subdirectory installation is allowed */ function allow_subdirectory_install() { global $wpdb; /** * Filters whether to enable the subdirectory installation feature in Multisite. * * @since 3.0.0 * * @param bool $allow Whether to enable the subdirectory installation feature in Multisite. * Default false. */ if ( apply_filters( 'allow_subdirectory_install', false ) ) { return true; } if ( defined( 'ALLOW_SUBDIRECTORY_INSTALL' ) && ALLOW_SUBDIRECTORY_INSTALL ) { return true; } $post = $wpdb->get_row( "SELECT ID FROM $wpdb->posts WHERE post_date < DATE_SUB(NOW(), INTERVAL 1 MONTH) AND post_status = 'publish'" ); if ( empty( $post ) ) { return true; } return false; } /** * Get base domain of network. * * @since 3.0.0 * @return string Base domain. */ function get_clean_basedomain() { $existing_domain = network_domain_check(); if ( $existing_domain ) { return $existing_domain; } $domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) ); $slash = strpos( $domain, '/' ); if ( $slash ) { $domain = substr( $domain, 0, $slash ); } return $domain; } /** * Prints step 1 for Network installation process. * * @todo Realistically, step 1 should be a welcome screen explaining what a Network is and such. * Navigating to Tools > Network should not be a sudden "Welcome to a new install process! * Fill this out and click here." See also contextual help todo. * * @since 3.0.0 * * @global bool $is_apache * * @param false|WP_Error $errors Optional. Error object. Default false. */ function network_step1( $errors = false ) { global $is_apache; if ( defined( 'DO_NOT_UPGRADE_GLOBAL_TABLES' ) ) { $cannot_define_constant_message = '' . __( 'Error:' ) . ' '; $cannot_define_constant_message .= sprintf( /* translators: %s: DO_NOT_UPGRADE_GLOBAL_TABLES */ __( 'The constant %s cannot be defined when creating a network.' ), 'DO_NOT_UPGRADE_GLOBAL_TABLES
'
);
wp_admin_notice(
$cannot_define_constant_message,
array(
'additional_classes' => array( 'error' ),
)
);
echo '';
require_once ABSPATH . 'wp-admin/admin-footer.php';
die();
}
$active_plugins = get_option( 'active_plugins' );
if ( ! empty( $active_plugins ) ) {
wp_admin_notice(
'' . __( 'Warning:' ) . ' ' . sprintf(
/* translators: %s: URL to Plugins screen. */
__( 'Please deactivate your plugins before enabling the Network feature.' ),
admin_url( 'plugins.php?plugin_status=active' )
),
array( 'type' => 'warning' )
);
echo '' . __( 'Once the network is created, you may reactivate your plugins.' ) . '
'; echo ''; require_once ABSPATH . 'wp-admin/admin-footer.php'; die(); } // Strip standard port from hostname. $hostname = preg_replace( '/(?::80|:443)$/', '', get_clean_basedomain() ); echo ' get_error_message(), array( 'additional_classes' => array( 'error' ), ) ); } if ( $_POST ) { if ( allow_subdomain_install() ) { $subdomain_install = allow_subdirectory_install() ? ! empty( $_POST['subdomain_install'] ) : true; } else { $subdomain_install = false; } } else { if ( is_multisite() ) { $subdomain_install = is_subdomain_install(); ?> get_var( "SELECT meta_value FROM $wpdb->sitemeta WHERE site_id = 1 AND meta_key = 'subdomain_install'" ); wp_admin_notice( '' . __( 'Warning:' ) . ' ' . __( 'An existing WordPress network was detected.' ), array( 'additional_classes' => array( 'error' ), ) ); ?> ' . __( 'Caution:' ) . ' '; $notice_args = array( 'type' => 'warning', 'additional_classes' => array( 'inline' ), ); if ( file_exists( $home_path . '.htaccess' ) ) { $notice_message .= sprintf( /* translators: 1: wp-config.php, 2: .htaccess */ __( 'You should back up your existing %1$s and %2$s files.' ), 'wp-config.php
',
'.htaccess
'
);
} elseif ( file_exists( $home_path . 'web.config' ) ) {
$notice_message .= sprintf(
/* translators: 1: wp-config.php, 2: web.config */
__( 'You should back up your existing %1$s and %2$s files.' ),
'wp-config.php
',
'web.config
'
);
} else {
$notice_message .= sprintf(
/* translators: %s: wp-config.php */
__( 'You should back up your existing %s file.' ),
'wp-config.php
'
);
}
wp_admin_notice( $notice_message, $notice_args );
}
?>
above the line reading %3$s:' ),
'wp-config.php
',
'' . $location_of_wp_config . '
',
/*
* translators: This string should only be translated if wp-config-sample.php is localized.
* You can check the localized release package or
* https://i18n.svn.wordpress.org//* ' . __( 'That’s all, stop editing! Happy publishing.' ) . ' */
'
);
?>
wp-config.php'
);
} else {
printf(
/* translators: %s: wp-config.php */
__( 'These unique authentication keys are also missing from your %s file.' ),
'wp-config.php
'
);
}
?>
';
printf(
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
__( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ),
'web.config
',
'' . $home_path . '
'
);
echo '
' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
'; } ?>'; printf( /* translators: %s: Documentation URL. */ __( 'It seems your network is running with Nginx web server. Learn more about further configuration.' ), __( 'https://developer.wordpress.org/advanced-administration/server/web-server/nginx/' ) ); echo '
'; else : // End $is_nginx. Construct an .htaccess file instead: $ms_files_rewriting = ''; if ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) { $ms_files_rewriting = "\n# uploaded files\nRewriteRule ^"; $ms_files_rewriting .= $subdir_match . "files/(.+) {$rewrite_base}" . WPINC . "/ms-files.php?file={$subdir_replacement_12} [L]" . "\n"; } $htaccess_file = <<';
printf(
/* translators: 1: File name (.htaccess or web.config), 2: File path. */
__( 'Add the following to your %1$s file in %2$s, replacing other WordPress rules:' ),
'.htaccess
',
'' . $home_path . '
'
);
echo '
' . __( 'Warning:' ) . ' ' . __( 'Subdirectory networks may not be fully compatible with custom wp-content directories.' ) . '
'; } ?> status; $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); $download_data_markup = ''; $download_data_markup .= '' . ''; $row_actions['download-data'] = $download_data_markup; if ( 'request-completed' !== $status ) { $complete_request_markup = ' ' . '' . ' '; $download_data_markup .= ''; $complete_request_markup .= sprintf( '%s', esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'complete', 'request_id' => array( $request_id ), ), admin_url( 'export-personal-data.php' ) ), 'bulk-privacy_requests' ) ), esc_attr( sprintf( /* translators: %s: Request email. */ __( 'Mark export request for “%s” as completed.' ), $item->email ) ), __( 'Complete request' ) ); $complete_request_markup .= ''; } if ( ! empty( $complete_request_markup ) ) { $row_actions['complete-request'] = $complete_request_markup; } return sprintf( '%2$s %3$s', esc_url( 'mailto:' . $item->email ), $item->email, $this->row_actions( $row_actions ) ); } /** * Displays the next steps column. * * @since 4.9.6 * * @param WP_User_Request $item Item being shown. */ public function column_next_steps( $item ) { $status = $item->status; switch ( $status ) { case 'request-pending': esc_html_e( 'Waiting for confirmation' ); break; case 'request-confirmed': /** This filter is documented in wp-admin/includes/ajax-actions.php */ $exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() ); $exporters_count = count( $exporters ); $request_id = $item->ID; $nonce = wp_create_nonce( 'wp-privacy-export-personal-data-' . $request_id ); echo '' . $api->get_error_message() . '
' ); } $this->items = $api->themes; $this->set_pagination_args( array( 'total_items' => $api->info['results'], 'per_page' => $args['per_page'], 'infinite_scroll' => true, ) ); } /** */ public function no_items() { _e( 'No themes match your request.' ); } /** * @global array $tabs * @global string $tab * @return array */ protected function get_views() { global $tabs, $tab; $display_tabs = array(); foreach ( (array) $tabs as $action => $text ) { $display_tabs[ 'theme-install-' . $action ] = array( 'url' => self_admin_url( 'theme-install.php?tab=' . $action ), 'label' => $text, 'current' => $action === $tab, ); } return $this->get_views_links( $display_tabs ); } /** * Displays the theme install table. * * Overrides the parent display() method to provide a different container. * * @since 3.1.0 */ public function display() { wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' ); ?>$tax_name, 'hide_empty' => 0, 'name' => 'new' . $tax_name . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', ); /** * Filters the arguments for the taxonomy parent dropdown on the Post Edit page. * * @since 4.4.0 * * @param array $parent_dropdown_args { * Optional. Array of arguments to generate parent dropdown. * * @type string $taxonomy Name of the taxonomy to retrieve. * @type bool $hide_if_empty True to skip generating markup if no * categories are found. Default 0. * @type string $name Value for the 'name' attribute * of the select element. * Default "new{$tax_name}_parent". * @type string $orderby Which column to use for ordering * terms. Default 'name'. * @type bool|int $hierarchical Whether to traverse the taxonomy * hierarchy. Default 1. * @type string $show_option_none Text to display for the "none" option. * Default "— {$parent} —", * where `$parent` is 'parent_item' * taxonomy label. * } */ $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); wp_dropdown_categories( $parent_dropdown_args ); ?>
Learn more about manual excerpts.' ), __( 'https://wordpress.org/documentation/article/what-is-an-excerpt-classic-editor/' ) ); ?>
to_ping ) ) . '" aria-describedby="trackback-url-desc" />'; if ( '' !== $post->pinged ) { $pings = '' . __( 'Already pinged:' ) . '
pingbacks, no other action necessary.' ), __( 'https://wordpress.org/documentation/article/introduction-to-blogging/#comments' ) ); ?>
use in your theme.' ), __( 'https://wordpress.org/documentation/article/assign-custom-fields/' ) ); ?>
$post->ID, 'count' => true, 'orderby' => 'none', ) ); $wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table' ); $wp_list_table->display( true ); if ( 1 > $total ) { echo '' . __( 'No comments yet.' ) . '
'; } else { $hidden = get_hidden_meta_boxes( get_current_screen() ); if ( ! in_array( 'commentsdiv', $hidden, true ) ) { ?> post_name, $post ); ?> post_type ); ?> array( $post_type_object->cap->edit_posts ), 'name' => 'post_author_override', 'selected' => empty( $post->ID ) ? $user_ID : $post->post_author, 'include_selected' => true, 'show' => 'display_name_with_login', ) ); } /** * Displays list of revisions. * * @since 2.6.0 * * @param WP_Post $post Current post object. */ function post_revisions_meta_box( $post ) { wp_list_post_revisions( $post ); } // // Page-related Meta Boxes. // /** * Displays page attributes form fields. * * @since 2.7.0 * * @param WP_Post $post Current post object. */ function page_attributes_meta_box( $post ) { if ( is_post_type_hierarchical( $post->post_type ) ) : $dropdown_args = array( 'post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __( '(no parent)' ), 'sort_column' => 'menu_order, post_title', 'echo' => 0, ); /** * Filters the arguments used to generate a Pages drop-down element. * * @since 3.3.0 * * @see wp_dropdown_pages() * * @param array $dropdown_args Array of arguments used to generate the pages drop-down. * @param WP_Post $post The current post. */ $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); $pages = wp_dropdown_pages( $dropdown_args ); if ( ! empty( $pages ) ) : ?> 0 && (int) get_option( 'page_for_posts' ) !== $post->ID ) : $template = ! empty( $post->page_template ) ? $post->page_template : false; ?>post_type, 'page-attributes' ) ) : ?> post_type && get_current_screen()->get_help_tabs() ) : ?>
XFN.' ); ?>
' . __( 'You can customize the look of your site without touching any of your theme’s code by using a custom background. Your background can be an image or a color.' ) . '
' . '' . __( 'To use a background image, simply upload it or choose an image that has already been uploaded to your Media Library by clicking the “Choose Image” button. You can display a single instance of your image, or tile it to fill the screen. You can have your background fixed in place, so your site content moves on top of it, or you can have it scroll with your site.' ) . '
' . '' . __( 'You can also choose a background color by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '
' . '' . __( 'Do not forget to click on the Save Changes button when you are finished.' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Custom Background' ) . '
' . '' . __( 'Support forums' ) . '
' ); wp_enqueue_media(); wp_enqueue_script( 'custom-background' ); wp_enqueue_style( 'wp-color-picker' ); } /** * Executes custom background modification. * * @since 3.0.0 */ public function take_action() { if ( empty( $_POST ) ) { return; } if ( isset( $_POST['reset-background'] ) ) { check_admin_referer( 'custom-background-reset', '_wpnonce-custom-background-reset' ); remove_theme_mod( 'background_image' ); remove_theme_mod( 'background_image_thumb' ); $this->updated = true; return; } if ( isset( $_POST['remove-background'] ) ) { // @todo Uploaded files are not removed here. check_admin_referer( 'custom-background-remove', '_wpnonce-custom-background-remove' ); set_theme_mod( 'background_image', '' ); set_theme_mod( 'background_image_thumb', '' ); $this->updated = true; wp_safe_redirect( $_POST['_wp_http_referer'] ); return; } if ( isset( $_POST['background-preset'] ) ) { check_admin_referer( 'custom-background' ); if ( in_array( $_POST['background-preset'], array( 'default', 'fill', 'fit', 'repeat', 'custom' ), true ) ) { $preset = $_POST['background-preset']; } else { $preset = 'default'; } set_theme_mod( 'background_preset', $preset ); } if ( isset( $_POST['background-position'] ) ) { check_admin_referer( 'custom-background' ); $position = explode( ' ', $_POST['background-position'] ); if ( in_array( $position[0], array( 'left', 'center', 'right' ), true ) ) { $position_x = $position[0]; } else { $position_x = 'left'; } if ( in_array( $position[1], array( 'top', 'center', 'bottom' ), true ) ) { $position_y = $position[1]; } else { $position_y = 'top'; } set_theme_mod( 'background_position_x', $position_x ); set_theme_mod( 'background_position_y', $position_y ); } if ( isset( $_POST['background-size'] ) ) { check_admin_referer( 'custom-background' ); if ( in_array( $_POST['background-size'], array( 'auto', 'contain', 'cover' ), true ) ) { $size = $_POST['background-size']; } else { $size = 'auto'; } set_theme_mod( 'background_size', $size ); } if ( isset( $_POST['background-repeat'] ) ) { check_admin_referer( 'custom-background' ); $repeat = $_POST['background-repeat']; if ( 'no-repeat' !== $repeat ) { $repeat = 'repeat'; } set_theme_mod( 'background_repeat', $repeat ); } if ( isset( $_POST['background-attachment'] ) ) { check_admin_referer( 'custom-background' ); $attachment = $_POST['background-attachment']; if ( 'fixed' !== $attachment ) { $attachment = 'scroll'; } set_theme_mod( 'background_attachment', $attachment ); } if ( isset( $_POST['background-color'] ) ) { check_admin_referer( 'custom-background' ); $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['background-color'] ); if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { set_theme_mod( 'background_color', $color ); } else { set_theme_mod( 'background_color', '' ); } } $this->updated = true; } /** * Displays the custom background page. * * @since 3.0.0 */ public function admin_page() { ?>
admin_image_div_callback ) {
call_user_func( $this->admin_image_div_callback );
} else {
$background_styles = '';
$bgcolor = get_background_color();
if ( $bgcolor ) {
$background_styles .= 'background-color: #' . $bgcolor . ';';
}
$background_image_thumb = get_background_image();
if ( $background_image_thumb ) {
$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( 'background_image_thumb', str_replace( '%', '%%', $background_image_thumb ) ) ) );
$background_position_x = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
$background_position_y = get_theme_mod( 'background_position_y', get_theme_support( 'custom-background', 'default-position-y' ) );
$background_size = get_theme_mod( 'background_size', get_theme_support( 'custom-background', 'default-size' ) );
$background_repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
$background_attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
// Background-image URL must be single quote, see below.
$background_styles .= " background-image: url('$background_image_thumb');"
. " background-size: $background_size;"
. " background-position: $background_position_x $background_position_y;"
. " background-repeat: $background_repeat;"
. " background-attachment: $background_attachment;";
}
?>
|
|
' . esc_html( $compare_from->post_title ) . ' | ' . esc_html( $compare_to->post_title ) . ' | '; } else { $diff .= '' . esc_html( $compare_from->post_title ) . ' | '; // In single column mode, only show the title once if unchanged. if ( $compare_from->post_title !== $compare_to->post_title ) { $diff .= '|
' . esc_html( $compare_to->post_title ) . ' | '; } } $diff .= '
style.css
'
)
);
}
// All these headers are needed on Theme_Installer_Skin::do_overwrite().
$info = get_file_data(
$working_directory . 'style.css',
array(
'Name' => 'Theme Name',
'Version' => 'Version',
'Author' => 'Author',
'Template' => 'Template',
'RequiresWP' => 'Requires at least',
'RequiresPHP' => 'Requires PHP',
)
);
if ( empty( $info['Name'] ) ) {
return new WP_Error(
'incompatible_archive_theme_no_name',
$this->strings['incompatible_archive'],
sprintf(
/* translators: %s: style.css */
__( 'The %s stylesheet does not contain a valid theme header.' ),
'style.css
'
)
);
}
/*
* Parent themes must contain an index file:
* - classic themes require /index.php
* - block themes require /templates/index.html or block-templates/index.html (deprecated 5.9.0).
*/
if (
empty( $info['Template'] ) &&
! file_exists( $working_directory . 'index.php' ) &&
! file_exists( $working_directory . 'templates/index.html' ) &&
! file_exists( $working_directory . 'block-templates/index.html' )
) {
return new WP_Error(
'incompatible_archive_theme_no_index',
$this->strings['incompatible_archive'],
sprintf(
/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
__( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. Child themes need to have a %4$s header in the %5$s stylesheet.' ),
'templates/index.html
',
'index.php
',
__( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
'Template
',
'style.css
'
)
);
}
$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
$requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
if ( ! is_php_version_compatible( $requires_php ) ) {
$error = sprintf(
/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
__( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
PHP_VERSION,
$requires_php
);
return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
}
if ( ! is_wp_version_compatible( $requires_wp ) ) {
$error = sprintf(
/* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
__( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
$wp_version,
$requires_wp
);
return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
}
$this->new_theme_data = $info;
return $source;
}
/**
* Turns on maintenance mode before attempting to upgrade the active theme.
*
* Hooked to the {@see 'upgrader_pre_install'} filter by Theme_Upgrader::upgrade() and
* Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @param bool|WP_Error $response The installation response before the installation has started.
* @param array $theme Theme arguments.
* @return bool|WP_Error The original `$response` parameter or WP_Error.
*/
public function current_before( $response, $theme ) {
if ( is_wp_error( $response ) ) {
return $response;
}
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
// Only run if active theme.
if ( get_stylesheet() !== $theme ) {
return $response;
}
// Change to maintenance mode. Bulk edit handles this separately.
if ( ! $this->bulk ) {
$this->maintenance_mode( true );
}
return $response;
}
/**
* Turns off maintenance mode after upgrading the active theme.
*
* Hooked to the {@see 'upgrader_post_install'} filter by Theme_Upgrader::upgrade()
* and Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @param bool|WP_Error $response The installation response after the installation has finished.
* @param array $theme Theme arguments.
* @return bool|WP_Error The original `$response` parameter or WP_Error.
*/
public function current_after( $response, $theme ) {
if ( is_wp_error( $response ) ) {
return $response;
}
$theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
// Only run if active theme.
if ( get_stylesheet() !== $theme ) {
return $response;
}
// Ensure stylesheet name hasn't changed after the upgrade:
if ( get_stylesheet() === $theme && $theme !== $this->result['destination_name'] ) {
wp_clean_themes_cache();
$stylesheet = $this->result['destination_name'];
switch_theme( $stylesheet );
}
// Time to remove maintenance mode. Bulk edit handles this separately.
if ( ! $this->bulk ) {
$this->maintenance_mode( false );
}
return $response;
}
/**
* Deletes the old theme during an upgrade.
*
* Hooked to the {@see 'upgrader_clear_destination'} filter by Theme_Upgrader::upgrade()
* and Theme_Upgrader::bulk_upgrade().
*
* @since 2.8.0
*
* @global WP_Filesystem_Base $wp_filesystem Subclass
*
* @param bool $removed
* @param string $local_destination
* @param string $remote_destination
* @param array $theme
* @return bool
*/
public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
global $wp_filesystem;
if ( is_wp_error( $removed ) ) {
return $removed; // Pass errors through.
}
if ( ! isset( $theme['theme'] ) ) {
return $removed;
}
$theme = $theme['theme'];
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) {
return false;
}
}
return true;
}
/**
* Gets the WP_Theme object for a theme.
*
* @since 2.8.0
* @since 3.0.0 The `$theme` argument was added.
*
* @param string $theme The directory name of the theme. This is optional, and if not supplied,
* the directory name from the last result will be used.
* @return WP_Theme|false The theme's info object, or false `$theme` is not supplied
* and the last result isn't set.
*/
public function theme_info( $theme = null ) {
if ( empty( $theme ) ) {
if ( ! empty( $this->result['destination_name'] ) ) {
$theme = $this->result['destination_name'];
} else {
return false;
}
}
$theme = wp_get_theme( $theme );
$theme->cache_delete();
return $theme;
}
}
includes/ajax-actions.php 0000644 00000450113 14717704420 0011456 0 ustar 00 id and the JS global 'pagenow'.
if ( ! empty( $_POST['screen_id'] ) ) {
$screen_id = sanitize_key( $_POST['screen_id'] );
} else {
$screen_id = 'front';
}
if ( ! empty( $_POST['data'] ) ) {
$data = wp_unslash( (array) $_POST['data'] );
/**
* Filters Heartbeat Ajax response in no-privilege environments.
*
* @since 3.6.0
*
* @param array $response The no-priv Heartbeat response.
* @param array $data The $_POST data sent.
* @param string $screen_id The screen ID.
*/
$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
}
/**
* Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
*
* @since 3.6.0
*
* @param array $response The no-priv Heartbeat response.
* @param string $screen_id The screen ID.
*/
$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
/**
* Fires when Heartbeat ticks in no-privilege environments.
*
* Allows the transport to be easily replaced with long-polling.
*
* @since 3.6.0
*
* @param array $response The no-priv Heartbeat response.
* @param string $screen_id The screen ID.
*/
do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
// Send the current time according to the server.
$response['server_time'] = time();
wp_send_json( $response );
}
//
// GET-based Ajax handlers.
//
/**
* Handles fetching a list table via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_fetch_list() {
$list_class = $_GET['list_args']['class'];
check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
$wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
if ( ! $wp_list_table ) {
wp_die( 0 );
}
if ( ! $wp_list_table->ajax_user_can() ) {
wp_die( -1 );
}
$wp_list_table->ajax_response();
wp_die( 0 );
}
/**
* Handles tag search via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_ajax_tag_search() {
if ( ! isset( $_GET['tax'] ) ) {
wp_die( 0 );
}
$taxonomy = sanitize_key( $_GET['tax'] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
wp_die( 0 );
}
if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
wp_die( -1 );
}
$search = wp_unslash( $_GET['q'] );
$comma = _x( ',', 'tag delimiter' );
if ( ',' !== $comma ) {
$search = str_replace( $comma, ',', $search );
}
if ( str_contains( $search, ',' ) ) {
$search = explode( ',', $search );
$search = $search[ count( $search ) - 1 ];
}
$search = trim( $search );
/**
* Filters the minimum number of characters required to fire a tag search via Ajax.
*
* @since 4.0.0
*
* @param int $characters The minimum number of characters required. Default 2.
* @param WP_Taxonomy $taxonomy_object The taxonomy object.
* @param string $search The search term.
*/
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $taxonomy_object, $search );
/*
* Require $term_search_min_chars chars for matching (default: 2)
* ensure it's a non-negative, non-zero integer.
*/
if ( ( 0 === $term_search_min_chars ) || ( strlen( $search ) < $term_search_min_chars ) ) {
wp_die();
}
$results = get_terms(
array(
'taxonomy' => $taxonomy,
'name__like' => $search,
'fields' => 'names',
'hide_empty' => false,
'number' => isset( $_GET['number'] ) ? (int) $_GET['number'] : 0,
)
);
/**
* Filters the Ajax term search results.
*
* @since 6.1.0
*
* @param string[] $results Array of term names.
* @param WP_Taxonomy $taxonomy_object The taxonomy object.
* @param string $search The search term.
*/
$results = apply_filters( 'ajax_term_search_results', $results, $taxonomy_object, $search );
echo implode( "\n", $results );
wp_die();
}
/**
* Handles compression testing via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_wp_compression_test() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( -1 );
}
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
// Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 0 );
} else {
update_option( 'can_compress_scripts', 0, true );
}
wp_die( 0 );
}
if ( isset( $_GET['test'] ) ) {
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
header( 'Content-Type: application/javascript; charset=UTF-8' );
$force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
if ( '1' === $_GET['test'] ) {
echo $test_str;
wp_die();
} elseif ( '2' === $_GET['test'] ) {
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
wp_die( -1 );
}
if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
header( 'Content-Encoding: deflate' );
$out = gzdeflate( $test_str, 1 );
} elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
header( 'Content-Encoding: gzip' );
$out = gzencode( $test_str, 1 );
} else {
wp_die( -1 );
}
echo $out;
wp_die();
} elseif ( 'no' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' );
// Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 0 );
} else {
update_option( 'can_compress_scripts', 0, true );
}
} elseif ( 'yes' === $_GET['test'] ) {
check_ajax_referer( 'update_can_compress_scripts' );
// Use `update_option()` on single site to mark the option for autoloading.
if ( is_multisite() ) {
update_site_option( 'can_compress_scripts', 1 );
} else {
update_option( 'can_compress_scripts', 1, true );
}
}
}
wp_die( 0 );
}
/**
* Handles image editor previews via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_imgedit_preview() {
$post_id = (int) $_GET['postid'];
if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( -1 );
}
check_ajax_referer( "image_editor-$post_id" );
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
if ( ! stream_preview_image( $post_id ) ) {
wp_die( -1 );
}
wp_die();
}
/**
* Handles oEmbed caching via AJAX.
*
* @since 3.1.0
*
* @global WP_Embed $wp_embed WordPress Embed object.
*/
function wp_ajax_oembed_cache() {
$GLOBALS['wp_embed']->cache_oembed( $_GET['post'] );
wp_die( 0 );
}
/**
* Handles user autocomplete via AJAX.
*
* @since 3.4.0
*/
function wp_ajax_autocomplete_user() {
if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) {
wp_die( -1 );
}
/** This filter is documented in wp-admin/user-new.php */
if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) {
wp_die( -1 );
}
$return = array();
/*
* Check the type of request.
* Current allowed values are `add` and `search`.
*/
if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) {
$type = $_REQUEST['autocomplete_type'];
} else {
$type = 'add';
}
/*
* Check the desired field for value.
* Current allowed values are `user_email` and `user_login`.
*/
if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) {
$field = $_REQUEST['autocomplete_field'];
} else {
$field = 'user_login';
}
// Exclude current users of this blog.
if ( isset( $_REQUEST['site_id'] ) ) {
$id = absint( $_REQUEST['site_id'] );
} else {
$id = get_current_blog_id();
}
$include_blog_users = ( 'search' === $type ? get_users(
array(
'blog_id' => $id,
'fields' => 'ID',
)
) : array() );
$exclude_blog_users = ( 'add' === $type ? get_users(
array(
'blog_id' => $id,
'fields' => 'ID',
)
) : array() );
$users = get_users(
array(
'blog_id' => false,
'search' => '*' . $_REQUEST['term'] . '*',
'include' => $include_blog_users,
'exclude' => $exclude_blog_users,
'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
)
);
foreach ( $users as $user ) {
$return[] = array(
/* translators: 1: User login, 2: User email address. */
'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ),
'value' => $user->$field,
);
}
wp_die( wp_json_encode( $return ) );
}
/**
* Handles Ajax requests for community events
*
* @since 4.8.0
*/
function wp_ajax_get_community_events() {
require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
check_ajax_referer( 'community_events' );
$search = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
$timezone = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
$user_id = get_current_user_id();
$saved_location = get_user_option( 'community-events-location', $user_id );
$events_client = new WP_Community_Events( $user_id, $saved_location );
$events = $events_client->get_events( $search, $timezone );
$ip_changed = false;
if ( is_wp_error( $events ) ) {
wp_send_json_error(
array(
'error' => $events->get_error_message(),
)
);
} else {
if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
$ip_changed = true;
} elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) {
$ip_changed = true;
}
/*
* The location should only be updated when it changes. The API doesn't always return
* a full location; sometimes it's missing the description or country. The location
* that was saved during the initial request is known to be good and complete, though.
* It should be left intact until the user explicitly changes it (either by manually
* searching for a new location, or by changing their IP address).
*
* If the location was updated with an incomplete response from the API, then it could
* break assumptions that the UI makes (e.g., that there will always be a description
* that corresponds to a latitude/longitude location).
*
* The location is stored network-wide, so that the user doesn't have to set it on each site.
*/
if ( $ip_changed || $search ) {
update_user_meta( $user_id, 'community-events-location', $events['location'] );
}
wp_send_json_success( $events );
}
}
/**
* Handles dashboard widgets via AJAX.
*
* @since 3.4.0
*/
function wp_ajax_dashboard_widgets() {
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
$pagenow = $_GET['pagenow'];
if ( 'dashboard-user' === $pagenow || 'dashboard-network' === $pagenow || 'dashboard' === $pagenow ) {
set_current_screen( $pagenow );
}
switch ( $_GET['widget'] ) {
case 'dashboard_primary':
wp_dashboard_primary();
break;
}
wp_die();
}
/**
* Handles Customizer preview logged-in status via AJAX.
*
* @since 3.4.0
*/
function wp_ajax_logged_in() {
wp_die( 1 );
}
//
// Ajax helpers.
//
/**
* Sends back current comment total and new page links if they need to be updated.
*
* Contrary to normal success Ajax response ("1"), die with time() on success.
*
* @since 2.7.0
* @access private
*
* @param int $comment_id
* @param int $delta
*/
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
$total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0;
$per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0;
$page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0;
$url = isset( $_POST['_url'] ) ? sanitize_url( $_POST['_url'] ) : '';
// JS didn't send us everything we need to know. Just die with success message.
if ( ! $total || ! $per_page || ! $page || ! $url ) {
$time = time();
$comment = get_comment( $comment_id );
$comment_status = '';
$comment_link = '';
if ( $comment ) {
$comment_status = $comment->comment_approved;
}
if ( 1 === (int) $comment_status ) {
$comment_link = get_comment_link( $comment );
}
$counts = wp_count_comments();
$x = new WP_Ajax_Response(
array(
'what' => 'comment',
// Here for completeness - not used.
'id' => $comment_id,
'supplemental' => array(
'status' => $comment_status,
'postId' => $comment ? $comment->comment_post_ID : '',
'time' => $time,
'in_moderation' => $counts->moderated,
'i18n_comments_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment', '%s Comments', $counts->approved ),
number_format_i18n( $counts->approved )
),
'i18n_moderation_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
number_format_i18n( $counts->moderated )
),
'comment_link' => $comment_link,
),
)
);
$x->send();
}
$total += $delta;
if ( $total < 0 ) {
$total = 0;
}
// Only do the expensive stuff on a page-break, and about 1 other time per page.
if ( 0 === $total % $per_page || 1 === mt_rand( 1, $per_page ) ) {
$post_id = 0;
// What type of comment count are we looking for?
$status = 'all';
$parsed = parse_url( $url );
if ( isset( $parsed['query'] ) ) {
parse_str( $parsed['query'], $query_vars );
if ( ! empty( $query_vars['comment_status'] ) ) {
$status = $query_vars['comment_status'];
}
if ( ! empty( $query_vars['p'] ) ) {
$post_id = (int) $query_vars['p'];
}
if ( ! empty( $query_vars['comment_type'] ) ) {
$type = $query_vars['comment_type'];
}
}
if ( empty( $type ) ) {
// Only use the comment count if not filtering by a comment_type.
$comment_count = wp_count_comments( $post_id );
// We're looking for a known type of comment count.
if ( isset( $comment_count->$status ) ) {
$total = $comment_count->$status;
}
}
// Else use the decremented value from above.
}
// The time since the last comment count.
$time = time();
$comment = get_comment( $comment_id );
$counts = wp_count_comments();
$x = new WP_Ajax_Response(
array(
'what' => 'comment',
'id' => $comment_id,
'supplemental' => array(
'status' => $comment ? $comment->comment_approved : '',
'postId' => $comment ? $comment->comment_post_ID : '',
/* translators: %s: Number of comments. */
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
'total_pages' => (int) ceil( $total / $per_page ),
'total_pages_i18n' => number_format_i18n( (int) ceil( $total / $per_page ) ),
'total' => $total,
'time' => $time,
'in_moderation' => $counts->moderated,
'i18n_moderation_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
number_format_i18n( $counts->moderated )
),
),
)
);
$x->send();
}
//
// POST-based Ajax handlers.
//
/**
* Handles adding a hierarchical term via AJAX.
*
* @since 3.1.0
* @access private
*/
function _wp_ajax_add_hierarchical_term() {
$action = $_POST['action'];
$taxonomy = get_taxonomy( substr( $action, 4 ) );
check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
wp_die( -1 );
}
$names = explode( ',', $_POST[ 'new' . $taxonomy->name ] );
$parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0;
if ( 0 > $parent ) {
$parent = 0;
}
if ( 'category' === $taxonomy->name ) {
$post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array();
} else {
$post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array();
}
$checked_categories = array_map( 'absint', (array) $post_category );
$popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
foreach ( $names as $cat_name ) {
$cat_name = trim( $cat_name );
$category_nicename = sanitize_title( $cat_name );
if ( '' === $category_nicename ) {
continue;
}
$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
if ( ! $cat_id || is_wp_error( $cat_id ) ) {
continue;
} else {
$cat_id = $cat_id['term_id'];
}
$checked_categories[] = $cat_id;
if ( $parent ) { // Do these all at once in a second.
continue;
}
ob_start();
wp_terms_checklist(
0,
array(
'taxonomy' => $taxonomy->name,
'descendants_and_self' => $cat_id,
'selected_cats' => $checked_categories,
'popular_cats' => $popular_ids,
)
);
$data = ob_get_clean();
$add = array(
'what' => $taxonomy->name,
'id' => $cat_id,
'data' => str_replace( array( "\n", "\t" ), '', $data ),
'position' => -1,
);
}
if ( $parent ) { // Foncy - replace the parent and all its children.
$parent = get_term( $parent, $taxonomy->name );
$term_id = $parent->term_id;
while ( $parent->parent ) { // Get the top parent.
$parent = get_term( $parent->parent, $taxonomy->name );
if ( is_wp_error( $parent ) ) {
break;
}
$term_id = $parent->term_id;
}
ob_start();
wp_terms_checklist(
0,
array(
'taxonomy' => $taxonomy->name,
'descendants_and_self' => $term_id,
'selected_cats' => $checked_categories,
'popular_cats' => $popular_ids,
)
);
$data = ob_get_clean();
$add = array(
'what' => $taxonomy->name,
'id' => $term_id,
'data' => str_replace( array( "\n", "\t" ), '', $data ),
'position' => -1,
);
}
ob_start();
wp_dropdown_categories(
array(
'taxonomy' => $taxonomy->name,
'hide_empty' => 0,
'name' => 'new' . $taxonomy->name . '_parent',
'orderby' => 'name',
'hierarchical' => 1,
'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
)
);
$sup = ob_get_clean();
$add['supplemental'] = array( 'newcat_parent' => $sup );
$x = new WP_Ajax_Response( $add );
$x->send();
}
/**
* Handles deleting a comment via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_delete_comment() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$comment = get_comment( $id );
if ( ! $comment ) {
wp_die( time() );
}
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
wp_die( -1 );
}
check_ajax_referer( "delete-comment_$id" );
$status = wp_get_comment_status( $comment );
$delta = -1;
if ( isset( $_POST['trash'] ) && '1' === $_POST['trash'] ) {
if ( 'trash' === $status ) {
wp_die( time() );
}
$r = wp_trash_comment( $comment );
} elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {
if ( 'trash' !== $status ) {
wp_die( time() );
}
$r = wp_untrash_comment( $comment );
// Undo trash, not in Trash.
if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) {
$delta = 1;
}
} elseif ( isset( $_POST['spam'] ) && '1' === $_POST['spam'] ) {
if ( 'spam' === $status ) {
wp_die( time() );
}
$r = wp_spam_comment( $comment );
} elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {
if ( 'spam' !== $status ) {
wp_die( time() );
}
$r = wp_unspam_comment( $comment );
// Undo spam, not in spam.
if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) {
$delta = 1;
}
} elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {
$r = wp_delete_comment( $comment );
} else {
wp_die( -1 );
}
if ( $r ) {
// Decide if we need to send back '1' or a more complicated response including page links and comment counts.
_wp_ajax_delete_comment_response( $comment->comment_ID, $delta );
}
wp_die( 0 );
}
/**
* Handles deleting a tag via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_delete_tag() {
$tag_id = (int) $_POST['tag_ID'];
check_ajax_referer( "delete-tag_$tag_id" );
if ( ! current_user_can( 'delete_term', $tag_id ) ) {
wp_die( -1 );
}
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
$tag = get_term( $tag_id, $taxonomy );
if ( ! $tag || is_wp_error( $tag ) ) {
wp_die( 1 );
}
if ( wp_delete_term( $tag_id, $taxonomy ) ) {
wp_die( 1 );
} else {
wp_die( 0 );
}
}
/**
* Handles deleting a link via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_delete_link() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "delete-bookmark_$id" );
if ( ! current_user_can( 'manage_links' ) ) {
wp_die( -1 );
}
$link = get_bookmark( $id );
if ( ! $link || is_wp_error( $link ) ) {
wp_die( 1 );
}
if ( wp_delete_link( $id ) ) {
wp_die( 1 );
} else {
wp_die( 0 );
}
}
/**
* Handles deleting meta via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_delete_meta() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "delete-meta_$id" );
$meta = get_metadata_by_mid( 'post', $id );
if ( ! $meta ) {
wp_die( 1 );
}
if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) {
wp_die( -1 );
}
if ( delete_meta( $meta->meta_id ) ) {
wp_die( 1 );
}
wp_die( 0 );
}
/**
* Handles deleting a post via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_delete_post( $action ) {
if ( empty( $action ) ) {
$action = 'delete-post';
}
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_post', $id ) ) {
wp_die( -1 );
}
if ( ! get_post( $id ) ) {
wp_die( 1 );
}
if ( wp_delete_post( $id ) ) {
wp_die( 1 );
} else {
wp_die( 0 );
}
}
/**
* Handles sending a post to the Trash via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_trash_post( $action ) {
if ( empty( $action ) ) {
$action = 'trash-post';
}
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_post', $id ) ) {
wp_die( -1 );
}
if ( ! get_post( $id ) ) {
wp_die( 1 );
}
if ( 'trash-post' === $action ) {
$done = wp_trash_post( $id );
} else {
$done = wp_untrash_post( $id );
}
if ( $done ) {
wp_die( 1 );
}
wp_die( 0 );
}
/**
* Handles restoring a post from the Trash via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_untrash_post( $action ) {
if ( empty( $action ) ) {
$action = 'untrash-post';
}
wp_ajax_trash_post( $action );
}
/**
* Handles deleting a page via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_delete_page( $action ) {
if ( empty( $action ) ) {
$action = 'delete-page';
}
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_page', $id ) ) {
wp_die( -1 );
}
if ( ! get_post( $id ) ) {
wp_die( 1 );
}
if ( wp_delete_post( $id ) ) {
wp_die( 1 );
} else {
wp_die( 0 );
}
}
/**
* Handles dimming a comment via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_dim_comment() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$comment = get_comment( $id );
if ( ! $comment ) {
$x = new WP_Ajax_Response(
array(
'what' => 'comment',
'id' => new WP_Error(
'invalid_comment',
/* translators: %d: Comment ID. */
sprintf( __( 'Comment %d does not exist' ), $id )
),
)
);
$x->send();
}
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) {
wp_die( -1 );
}
$current = wp_get_comment_status( $comment );
if ( isset( $_POST['new'] ) && $_POST['new'] === $current ) {
wp_die( time() );
}
check_ajax_referer( "approve-comment_$id" );
if ( in_array( $current, array( 'unapproved', 'spam' ), true ) ) {
$result = wp_set_comment_status( $comment, 'approve', true );
} else {
$result = wp_set_comment_status( $comment, 'hold', true );
}
if ( is_wp_error( $result ) ) {
$x = new WP_Ajax_Response(
array(
'what' => 'comment',
'id' => $result,
)
);
$x->send();
}
// Decide if we need to send back '1' or a more complicated response including page links and comment counts.
_wp_ajax_delete_comment_response( $comment->comment_ID );
wp_die( 0 );
}
/**
* Handles adding a link category via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_add_link_category( $action ) {
if ( empty( $action ) ) {
$action = 'add-link-category';
}
check_ajax_referer( $action );
$taxonomy_object = get_taxonomy( 'link_category' );
if ( ! current_user_can( $taxonomy_object->cap->manage_terms ) ) {
wp_die( -1 );
}
$names = explode( ',', wp_unslash( $_POST['newcat'] ) );
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
$cat_name = trim( $cat_name );
$slug = sanitize_title( $cat_name );
if ( '' === $slug ) {
continue;
}
$cat_id = wp_insert_term( $cat_name, 'link_category' );
if ( ! $cat_id || is_wp_error( $cat_id ) ) {
continue;
} else {
$cat_id = $cat_id['term_id'];
}
$cat_name = esc_html( $cat_name );
$x->add(
array(
'what' => 'link-category',
'id' => $cat_id,
'data' => "",
'position' => -1,
)
);
}
$x->send();
}
/**
* Handles adding a tag via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_add_tag() {
check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! current_user_can( $taxonomy_object->cap->edit_terms ) ) {
wp_die( -1 );
}
$x = new WP_Ajax_Response();
$tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
if ( $tag && ! is_wp_error( $tag ) ) {
$tag = get_term( $tag['term_id'], $taxonomy );
}
if ( ! $tag || is_wp_error( $tag ) ) {
$message = __( 'An error has occurred. Please reload the page and try again.' );
$error_code = 'error';
if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
$message = $tag->get_error_message();
}
if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
$error_code = $tag->get_error_code();
}
$x->add(
array(
'what' => 'taxonomy',
'data' => new WP_Error( $error_code, $message ),
)
);
$x->send();
}
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
$level = 0;
$noparents = '';
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
ob_start();
$wp_list_table->single_row( $tag, $level );
$noparents = ob_get_clean();
}
ob_start();
$wp_list_table->single_row( $tag );
$parents = ob_get_clean();
require ABSPATH . 'wp-admin/includes/edit-tag-messages.php';
$message = '';
if ( isset( $messages[ $taxonomy_object->name ][1] ) ) {
$message = $messages[ $taxonomy_object->name ][1];
} elseif ( isset( $messages['_item'][1] ) ) {
$message = $messages['_item'][1];
}
$x->add(
array(
'what' => 'taxonomy',
'data' => $message,
'supplemental' => array(
'parents' => $parents,
'noparents' => $noparents,
'notice' => $message,
),
)
);
$x->add(
array(
'what' => 'term',
'position' => $level,
'supplemental' => (array) $tag,
)
);
$x->send();
}
/**
* Handles getting a tagcloud via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_get_tagcloud() {
if ( ! isset( $_POST['tax'] ) ) {
wp_die( 0 );
}
$taxonomy = sanitize_key( $_POST['tax'] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
wp_die( 0 );
}
if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
wp_die( -1 );
}
$tags = get_terms(
array(
'taxonomy' => $taxonomy,
'number' => 45,
'orderby' => 'count',
'order' => 'DESC',
)
);
if ( empty( $tags ) ) {
wp_die( $taxonomy_object->labels->not_found );
}
if ( is_wp_error( $tags ) ) {
wp_die( $tags->get_error_message() );
}
foreach ( $tags as $key => $tag ) {
$tags[ $key ]->link = '#';
$tags[ $key ]->id = $tag->term_id;
}
// We need raw tag names here, so don't filter the output.
$return = wp_generate_tag_cloud(
$tags,
array(
'filter' => 0,
'format' => 'list',
)
);
if ( empty( $return ) ) {
wp_die( 0 );
}
echo $return;
wp_die();
}
/**
* Handles getting comments via AJAX.
*
* @since 3.1.0
*
* @global int $post_id
*
* @param string $action Action to perform.
*/
function wp_ajax_get_comments( $action ) {
global $post_id;
if ( empty( $action ) ) {
$action = 'get-comments';
}
check_ajax_referer( $action );
if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
$id = absint( $_REQUEST['p'] );
if ( ! empty( $id ) ) {
$post_id = $id;
}
}
if ( empty( $post_id ) ) {
wp_die( -1 );
}
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
if ( ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( -1 );
}
$wp_list_table->prepare_items();
if ( ! $wp_list_table->has_items() ) {
wp_die( 1 );
}
$x = new WP_Ajax_Response();
ob_start();
foreach ( $wp_list_table->items as $comment ) {
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) {
continue;
}
get_comment( $comment );
$wp_list_table->single_row( $comment );
}
$comment_list_item = ob_get_clean();
$x->add(
array(
'what' => 'comments',
'data' => $comment_list_item,
)
);
$x->send();
}
/**
* Handles replying to a comment via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_replyto_comment( $action ) {
if ( empty( $action ) ) {
$action = 'replyto-comment';
}
check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
$comment_post_id = (int) $_POST['comment_post_ID'];
$post = get_post( $comment_post_id );
if ( ! $post ) {
wp_die( -1 );
}
if ( ! current_user_can( 'edit_post', $comment_post_id ) ) {
wp_die( -1 );
}
if ( empty( $post->post_status ) ) {
wp_die( 1 );
} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
wp_die( __( 'You cannot reply to a comment on a draft post.' ) );
}
$user = wp_get_current_user();
if ( $user->exists() ) {
$comment_author = wp_slash( $user->display_name );
$comment_author_email = wp_slash( $user->user_email );
$comment_author_url = wp_slash( $user->user_url );
$user_id = $user->ID;
if ( current_user_can( 'unfiltered_html' ) ) {
if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) ) {
$_POST['_wp_unfiltered_html_comment'] = '';
}
if ( wp_create_nonce( 'unfiltered-html-comment' ) !== $_POST['_wp_unfiltered_html_comment'] ) {
kses_remove_filters(); // Start with a clean slate.
kses_init_filters(); // Set up the filters.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
add_filter( 'pre_comment_content', 'wp_filter_kses' );
}
}
} else {
wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
}
$comment_content = trim( $_POST['content'] );
if ( '' === $comment_content ) {
wp_die( __( 'Please type your comment text.' ) );
}
$comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : 'comment';
$comment_parent = 0;
if ( isset( $_POST['comment_ID'] ) ) {
$comment_parent = absint( $_POST['comment_ID'] );
}
$comment_auto_approved = false;
$commentdata = array(
'comment_post_ID' => $comment_post_id,
);
$commentdata += compact(
'comment_author',
'comment_author_email',
'comment_author_url',
'comment_content',
'comment_type',
'comment_parent',
'user_id'
);
// Automatically approve parent comment.
if ( ! empty( $_POST['approve_parent'] ) ) {
$parent = get_comment( $comment_parent );
if ( $parent && '0' === $parent->comment_approved && (int) $parent->comment_post_ID === $comment_post_id ) {
if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
wp_die( -1 );
}
if ( wp_set_comment_status( $parent, 'approve' ) ) {
$comment_auto_approved = true;
}
}
}
$comment_id = wp_new_comment( $commentdata );
if ( is_wp_error( $comment_id ) ) {
wp_die( $comment_id->get_error_message() );
}
$comment = get_comment( $comment_id );
if ( ! $comment ) {
wp_die( 1 );
}
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
ob_start();
if ( isset( $_REQUEST['mode'] ) && 'dashboard' === $_REQUEST['mode'] ) {
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
_wp_dashboard_recent_comments_row( $comment );
} else {
if ( isset( $_REQUEST['mode'] ) && 'single' === $_REQUEST['mode'] ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
} else {
$wp_list_table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
}
$wp_list_table->single_row( $comment );
}
$comment_list_item = ob_get_clean();
$response = array(
'what' => 'comment',
'id' => $comment->comment_ID,
'data' => $comment_list_item,
'position' => $position,
);
$counts = wp_count_comments();
$response['supplemental'] = array(
'in_moderation' => $counts->moderated,
'i18n_comments_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment', '%s Comments', $counts->approved ),
number_format_i18n( $counts->approved )
),
'i18n_moderation_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
number_format_i18n( $counts->moderated )
),
);
if ( $comment_auto_approved ) {
$response['supplemental']['parent_approved'] = $parent->comment_ID;
$response['supplemental']['parent_post_id'] = $parent->comment_post_ID;
}
$x = new WP_Ajax_Response();
$x->add( $response );
$x->send();
}
/**
* Handles editing a comment via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_edit_comment() {
check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );
$comment_id = (int) $_POST['comment_ID'];
if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
wp_die( -1 );
}
if ( '' === $_POST['content'] ) {
wp_die( __( 'Please type your comment text.' ) );
}
if ( isset( $_POST['status'] ) ) {
$_POST['comment_status'] = $_POST['status'];
}
$updated = edit_comment();
if ( is_wp_error( $updated ) ) {
wp_die( $updated->get_error_message() );
}
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
/*
* Checkbox is used to differentiate between the Edit Comments screen (1)
* and the Comments section on the Edit Post screen (0).
*/
$checkbox = ( isset( $_POST['checkbox'] ) && '1' === $_POST['checkbox'] ) ? 1 : 0;
$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
$comment = get_comment( $comment_id );
if ( empty( $comment->comment_ID ) ) {
wp_die( -1 );
}
ob_start();
$wp_list_table->single_row( $comment );
$comment_list_item = ob_get_clean();
$x = new WP_Ajax_Response();
$x->add(
array(
'what' => 'edit_comment',
'id' => $comment->comment_ID,
'data' => $comment_list_item,
'position' => $position,
)
);
$x->send();
}
/**
* Handles adding a menu item via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_add_menu_item() {
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
/*
* For performance reasons, we omit some object properties from the checklist.
* The following is a hacky way to restore them when adding non-custom items.
*/
$menu_items_data = array();
foreach ( (array) $_POST['menu-item'] as $menu_item_data ) {
if (
! empty( $menu_item_data['menu-item-type'] ) &&
'custom' !== $menu_item_data['menu-item-type'] &&
! empty( $menu_item_data['menu-item-object-id'] )
) {
switch ( $menu_item_data['menu-item-type'] ) {
case 'post_type':
$_object = get_post( $menu_item_data['menu-item-object-id'] );
break;
case 'post_type_archive':
$_object = get_post_type_object( $menu_item_data['menu-item-object'] );
break;
case 'taxonomy':
$_object = get_term( $menu_item_data['menu-item-object-id'], $menu_item_data['menu-item-object'] );
break;
}
$_menu_items = array_map( 'wp_setup_nav_menu_item', array( $_object ) );
$_menu_item = reset( $_menu_items );
// Restore the missing menu item properties.
$menu_item_data['menu-item-description'] = $_menu_item->description;
}
$menu_items_data[] = $menu_item_data;
}
$item_ids = wp_save_nav_menu_items( 0, $menu_items_data );
if ( is_wp_error( $item_ids ) ) {
wp_die( 0 );
}
$menu_items = array();
foreach ( (array) $item_ids as $menu_item_id ) {
$menu_obj = get_post( $menu_item_id );
if ( ! empty( $menu_obj->ID ) ) {
$menu_obj = wp_setup_nav_menu_item( $menu_obj );
$menu_obj->title = empty( $menu_obj->title ) ? __( 'Menu Item' ) : $menu_obj->title;
$menu_obj->label = $menu_obj->title; // Don't show "(pending)" in ajax-added items.
$menu_items[] = $menu_obj;
}
}
/** This filter is documented in wp-admin/includes/nav-menu.php */
$walker_class_name = apply_filters( 'wp_edit_nav_menu_walker', 'Walker_Nav_Menu_Edit', $_POST['menu'] );
if ( ! class_exists( $walker_class_name ) ) {
wp_die( 0 );
}
if ( ! empty( $menu_items ) ) {
$args = array(
'after' => '',
'before' => '',
'link_after' => '',
'link_before' => '',
'walker' => new $walker_class_name(),
);
echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
}
wp_die();
}
/**
* Handles adding meta via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_add_meta() {
check_ajax_referer( 'add-meta', '_ajax_nonce-add-meta' );
$c = 0;
$pid = (int) $_POST['post_id'];
$post = get_post( $pid );
if ( isset( $_POST['metakeyselect'] ) || isset( $_POST['metakeyinput'] ) ) {
if ( ! current_user_can( 'edit_post', $pid ) ) {
wp_die( -1 );
}
if ( isset( $_POST['metakeyselect'] ) && '#NONE#' === $_POST['metakeyselect'] && empty( $_POST['metakeyinput'] ) ) {
wp_die( 1 );
}
// If the post is an autodraft, save the post as a draft and then attempt to save the meta.
if ( 'auto-draft' === $post->post_status ) {
$post_data = array();
$post_data['action'] = 'draft'; // Warning fix.
$post_data['post_ID'] = $pid;
$post_data['post_type'] = $post->post_type;
$post_data['post_status'] = 'draft';
$now = time();
$post_data['post_title'] = sprintf(
/* translators: 1: Post creation date, 2: Post creation time. */
__( 'Draft created on %1$s at %2$s' ),
gmdate( __( 'F j, Y' ), $now ),
gmdate( __( 'g:i a' ), $now )
);
$pid = edit_post( $post_data );
if ( $pid ) {
if ( is_wp_error( $pid ) ) {
$x = new WP_Ajax_Response(
array(
'what' => 'meta',
'data' => $pid,
)
);
$x->send();
}
$mid = add_meta( $pid );
if ( ! $mid ) {
wp_die( __( 'Please provide a custom field value.' ) );
}
} else {
wp_die( 0 );
}
} else {
$mid = add_meta( $pid );
if ( ! $mid ) {
wp_die( __( 'Please provide a custom field value.' ) );
}
}
$meta = get_metadata_by_mid( 'post', $mid );
$pid = (int) $meta->post_id;
$meta = get_object_vars( $meta );
$x = new WP_Ajax_Response(
array(
'what' => 'meta',
'id' => $mid,
'data' => _list_meta_row( $meta, $c ),
'position' => 1,
'supplemental' => array( 'postid' => $pid ),
)
);
} else { // Update?
$mid = (int) key( $_POST['meta'] );
$key = wp_unslash( $_POST['meta'][ $mid ]['key'] );
$value = wp_unslash( $_POST['meta'][ $mid ]['value'] );
if ( '' === trim( $key ) ) {
wp_die( __( 'Please provide a custom field name.' ) );
}
$meta = get_metadata_by_mid( 'post', $mid );
if ( ! $meta ) {
wp_die( 0 ); // If meta doesn't exist.
}
if (
is_protected_meta( $meta->meta_key, 'post' ) || is_protected_meta( $key, 'post' ) ||
! current_user_can( 'edit_post_meta', $meta->post_id, $meta->meta_key ) ||
! current_user_can( 'edit_post_meta', $meta->post_id, $key )
) {
wp_die( -1 );
}
if ( $meta->meta_value !== $value || $meta->meta_key !== $key ) {
$u = update_metadata_by_mid( 'post', $mid, $value, $key );
if ( ! $u ) {
wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
}
}
$x = new WP_Ajax_Response(
array(
'what' => 'meta',
'id' => $mid,
'old_id' => $mid,
'data' => _list_meta_row(
array(
'meta_key' => $key,
'meta_value' => $value,
'meta_id' => $mid,
),
$c
),
'position' => 0,
'supplemental' => array( 'postid' => $meta->post_id ),
)
);
}
$x->send();
}
/**
* Handles adding a user via AJAX.
*
* @since 3.1.0
*
* @param string $action Action to perform.
*/
function wp_ajax_add_user( $action ) {
if ( empty( $action ) ) {
$action = 'add-user';
}
check_ajax_referer( $action );
if ( ! current_user_can( 'create_users' ) ) {
wp_die( -1 );
}
$user_id = edit_user();
if ( ! $user_id ) {
wp_die( 0 );
} elseif ( is_wp_error( $user_id ) ) {
$x = new WP_Ajax_Response(
array(
'what' => 'user',
'id' => $user_id,
)
);
$x->send();
}
$user_object = get_userdata( $user_id );
$wp_list_table = _get_list_table( 'WP_Users_List_Table' );
$role = current( $user_object->roles );
$x = new WP_Ajax_Response(
array(
'what' => 'user',
'id' => $user_id,
'data' => $wp_list_table->single_row( $user_object, '', $role ),
'supplemental' => array(
'show-link' => sprintf(
/* translators: %s: The new user. */
__( 'User %s added' ),
'' . $user_object->user_login . ''
),
'role' => $role,
),
)
);
$x->send();
}
/**
* Handles closed post boxes via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_closed_postboxes() {
check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
$closed = isset( $_POST['closed'] ) ? explode( ',', $_POST['closed'] ) : array();
$closed = array_filter( $closed );
$hidden = isset( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
$hidden = array_filter( $hidden );
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
}
$user = wp_get_current_user();
if ( ! $user ) {
wp_die( -1 );
}
if ( is_array( $closed ) ) {
update_user_meta( $user->ID, "closedpostboxes_$page", $closed );
}
if ( is_array( $hidden ) ) {
// Postboxes that are always shown.
$hidden = array_diff( $hidden, array( 'submitdiv', 'linksubmitdiv', 'manage-menu', 'create-menu' ) );
update_user_meta( $user->ID, "metaboxhidden_$page", $hidden );
}
wp_die( 1 );
}
/**
* Handles hidden columns via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_hidden_columns() {
check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
}
$user = wp_get_current_user();
if ( ! $user ) {
wp_die( -1 );
}
$hidden = ! empty( $_POST['hidden'] ) ? explode( ',', $_POST['hidden'] ) : array();
update_user_meta( $user->ID, "manage{$page}columnshidden", $hidden );
wp_die( 1 );
}
/**
* Handles updating whether to display the welcome panel via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_update_welcome_panel() {
check_ajax_referer( 'welcome-panel-nonce', 'welcomepanelnonce' );
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
update_user_meta( get_current_user_id(), 'show_welcome_panel', empty( $_POST['visible'] ) ? 0 : 1 );
wp_die( 1 );
}
/**
* Handles for retrieving menu meta boxes via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_menu_get_metabox() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
if ( isset( $_POST['item-type'] ) && 'post_type' === $_POST['item-type'] ) {
$type = 'posttype';
$callback = 'wp_nav_menu_item_post_type_meta_box';
$items = (array) get_post_types( array( 'show_in_nav_menus' => true ), 'object' );
} elseif ( isset( $_POST['item-type'] ) && 'taxonomy' === $_POST['item-type'] ) {
$type = 'taxonomy';
$callback = 'wp_nav_menu_item_taxonomy_meta_box';
$items = (array) get_taxonomies( array( 'show_ui' => true ), 'object' );
}
if ( ! empty( $_POST['item-object'] ) && isset( $items[ $_POST['item-object'] ] ) ) {
$menus_meta_box_object = $items[ $_POST['item-object'] ];
/** This filter is documented in wp-admin/includes/nav-menu.php */
$item = apply_filters( 'nav_menu_meta_box_object', $menus_meta_box_object );
$box_args = array(
'id' => 'add-' . $item->name,
'title' => $item->labels->name,
'callback' => $callback,
'args' => $item,
);
ob_start();
$callback( null, $box_args );
$markup = ob_get_clean();
echo wp_json_encode(
array(
'replace-id' => $type . '-' . $item->name,
'markup' => $markup,
)
);
}
wp_die();
}
/**
* Handles internal linking via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_wp_link_ajax() {
check_ajax_referer( 'internal-linking', '_ajax_linking_nonce' );
$args = array();
if ( isset( $_POST['search'] ) ) {
$args['s'] = wp_unslash( $_POST['search'] );
}
if ( isset( $_POST['term'] ) ) {
$args['s'] = wp_unslash( $_POST['term'] );
}
$args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
if ( ! class_exists( '_WP_Editors', false ) ) {
require ABSPATH . WPINC . '/class-wp-editor.php';
}
$results = _WP_Editors::wp_link_query( $args );
if ( ! isset( $results ) ) {
wp_die( 0 );
}
echo wp_json_encode( $results );
echo "\n";
wp_die();
}
/**
* Handles saving menu locations via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_menu_locations_save() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
check_ajax_referer( 'add-menu_item', 'menu-settings-column-nonce' );
if ( ! isset( $_POST['menu-locations'] ) ) {
wp_die( 0 );
}
set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_POST['menu-locations'] ) );
wp_die( 1 );
}
/**
* Handles saving the meta box order via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_meta_box_order() {
check_ajax_referer( 'meta-box-order' );
$order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;
$page_columns = isset( $_POST['page_columns'] ) ? $_POST['page_columns'] : 'auto';
if ( 'auto' !== $page_columns ) {
$page_columns = (int) $page_columns;
}
$page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 );
}
$user = wp_get_current_user();
if ( ! $user ) {
wp_die( -1 );
}
if ( $order ) {
update_user_meta( $user->ID, "meta-box-order_$page", $order );
}
if ( $page_columns ) {
update_user_meta( $user->ID, "screen_layout_$page", $page_columns );
}
wp_send_json_success();
}
/**
* Handles menu quick searching via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_menu_quick_search() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( -1 );
}
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
_wp_ajax_menu_quick_search( $_POST );
wp_die();
}
/**
* Handles retrieving a permalink via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_get_permalink() {
check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
wp_die( get_preview_post_link( $post_id ) );
}
/**
* Handles retrieving a sample permalink via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_sample_permalink() {
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
$post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
$title = isset( $_POST['new_title'] ) ? $_POST['new_title'] : '';
$slug = isset( $_POST['new_slug'] ) ? $_POST['new_slug'] : null;
wp_die( get_sample_permalink_html( $post_id, $title, $slug ) );
}
/**
* Handles Quick Edit saving a post from a list table via AJAX.
*
* @since 3.1.0
*
* @global string $mode List table view mode.
*/
function wp_ajax_inline_save() {
global $mode;
check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
if ( ! isset( $_POST['post_ID'] ) || ! (int) $_POST['post_ID'] ) {
wp_die();
}
$post_id = (int) $_POST['post_ID'];
if ( 'page' === $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( __( 'Sorry, you are not allowed to edit this post.' ) );
}
}
$last = wp_check_post_lock( $post_id );
if ( $last ) {
$last_user = get_userdata( $last );
$last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
/* translators: %s: User's display name. */
$msg_template = __( 'Saving is disabled: %s is currently editing this post.' );
if ( 'page' === $_POST['post_type'] ) {
/* translators: %s: User's display name. */
$msg_template = __( 'Saving is disabled: %s is currently editing this page.' );
}
printf( $msg_template, esc_html( $last_user_name ) );
wp_die();
}
$data = &$_POST;
$post = get_post( $post_id, ARRAY_A );
// Since it's coming from the database.
$post = wp_slash( $post );
$data['content'] = $post['post_content'];
$data['excerpt'] = $post['post_excerpt'];
// Rename.
$data['user_ID'] = get_current_user_id();
if ( isset( $data['post_parent'] ) ) {
$data['parent_id'] = $data['post_parent'];
}
// Status.
if ( isset( $data['keep_private'] ) && 'private' === $data['keep_private'] ) {
$data['visibility'] = 'private';
$data['post_status'] = 'private';
} else {
$data['post_status'] = $data['_status'];
}
if ( empty( $data['comment_status'] ) ) {
$data['comment_status'] = 'closed';
}
if ( empty( $data['ping_status'] ) ) {
$data['ping_status'] = 'closed';
}
// Exclude terms from taxonomies that are not supposed to appear in Quick Edit.
if ( ! empty( $data['tax_input'] ) ) {
foreach ( $data['tax_input'] as $taxonomy => $terms ) {
$tax_object = get_taxonomy( $taxonomy );
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'] ) ) {
unset( $data['tax_input'][ $taxonomy ] );
}
}
}
// Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published.
if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ), true ) ) {
$post['post_status'] = 'publish';
$data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] );
}
// Update the post.
edit_post();
$wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) );
$mode = 'excerpt' === $_POST['post_view'] ? 'excerpt' : 'list';
$level = 0;
if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) {
$request_post = array( get_post( $_POST['post_ID'] ) );
$parent = $request_post[0]->post_parent;
while ( $parent > 0 ) {
$parent_post = get_post( $parent );
$parent = $parent_post->post_parent;
++$level;
}
}
$wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level );
wp_die();
}
/**
* Handles Quick Edit saving for a term via AJAX.
*
* @since 3.1.0
*/
function wp_ajax_inline_save_tax() {
check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
$taxonomy = sanitize_key( $_POST['taxonomy'] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
wp_die( 0 );
}
if ( ! isset( $_POST['tax_ID'] ) || ! (int) $_POST['tax_ID'] ) {
wp_die( -1 );
}
$id = (int) $_POST['tax_ID'];
if ( ! current_user_can( 'edit_term', $id ) ) {
wp_die( -1 );
}
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => 'edit-' . $taxonomy ) );
$tag = get_term( $id, $taxonomy );
$_POST['description'] = $tag->description;
$updated = wp_update_term( $id, $taxonomy, $_POST );
if ( $updated && ! is_wp_error( $updated ) ) {
$tag = get_term( $updated['term_id'], $taxonomy );
if ( ! $tag || is_wp_error( $tag ) ) {
if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
wp_die( $tag->get_error_message() );
}
wp_die( __( 'Item not updated.' ) );
}
} else {
if ( is_wp_error( $updated ) && $updated->get_error_message() ) {
wp_die( $updated->get_error_message() );
}
wp_die( __( 'Item not updated.' ) );
}
$level = 0;
$parent = $tag->parent;
while ( $parent > 0 ) {
$parent_tag = get_term( $parent, $taxonomy );
$parent = $parent_tag->parent;
++$level;
}
$wp_list_table->single_row( $tag, $level );
wp_die();
}
/**
* Handles querying posts for the Find Posts modal via AJAX.
*
* @see window.findPosts
*
* @since 3.1.0
*/
function wp_ajax_find_posts() {
check_ajax_referer( 'find-posts' );
$post_types = get_post_types( array( 'public' => true ), 'objects' );
unset( $post_types['attachment'] );
$args = array(
'post_type' => array_keys( $post_types ),
'post_status' => 'any',
'posts_per_page' => 50,
);
$search = wp_unslash( $_POST['ps'] );
if ( '' !== $search ) {
$args['s'] = $search;
}
$posts = get_posts( $args );
if ( ! $posts ) {
wp_send_json_error( __( 'No items found.' ) );
}
$html = '' . __( 'Title' ) . ' | ' . __( 'Type' ) . ' | ' . __( 'Date' ) . ' | ' . __( 'Status' ) . ' | |
---|---|---|---|---|
'; $html .= ' | ' . esc_html( $post_types[ $post->post_type ]->labels->singular_name ) . ' | ' . esc_html( $time ) . ' | ' . esc_html( $stat ) . ' |
' . __( 'An error has occurred. Please reload the page and try again.' ) . '
'; $sidebars = wp_get_sidebars_widgets(); $sidebar = isset( $sidebars[ $sidebar_id ] ) ? $sidebars[ $sidebar_id ] : array(); // Delete. if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { if ( ! isset( $wp_registered_widgets[ $widget_id ] ) ) { wp_die( $error ); } $sidebar = array_diff( $sidebar, array( $widget_id ) ); $_POST = array( 'sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1', ); /** This action is documented in wp-admin/widgets.php */ do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base ); } elseif ( $settings && preg_match( '/__i__|%i%/', key( $settings ) ) ) { if ( ! $multi_number ) { wp_die( $error ); } $_POST[ 'widget-' . $id_base ] = array( $multi_number => reset( $settings ) ); $widget_id = $id_base . '-' . $multi_number; $sidebar[] = $widget_id; } $_POST['widget-id'] = $sidebar; foreach ( (array) $wp_registered_widget_updates as $name => $control ) { if ( $name === $id_base ) { if ( ! is_callable( $control['callback'] ) ) { continue; } ob_start(); call_user_func_array( $control['callback'], $control['params'] ); ob_end_clean(); break; } } if ( isset( $_POST['delete_widget'] ) && $_POST['delete_widget'] ) { $sidebars[ $sidebar_id ] = $sidebar; wp_set_sidebars_widgets( $sidebars ); echo "deleted:$widget_id"; wp_die(); } if ( ! empty( $_POST['add_new'] ) ) { wp_die(); } $form = $wp_registered_widget_controls[ $widget_id ]; if ( $form ) { call_user_func_array( $form['callback'], $form['params'] ); } wp_die(); } /** * Handles updating a widget via AJAX. * * @since 3.9.0 * * @global WP_Customize_Manager $wp_customize */ function wp_ajax_update_widget() { global $wp_customize; $wp_customize->widgets->wp_ajax_update_widget(); } /** * Handles removing inactive widgets via AJAX. * * @since 4.4.0 */ function wp_ajax_delete_inactive_widgets() { check_ajax_referer( 'remove-inactive-widgets', 'removeinactivewidgets' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( -1 ); } unset( $_POST['removeinactivewidgets'], $_POST['action'] ); /** This action is documented in wp-admin/includes/ajax-actions.php */ do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/includes/ajax-actions.php */ do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/widgets.php */ do_action( 'sidebar_admin_setup' ); $sidebars_widgets = wp_get_sidebars_widgets(); foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) { $pieces = explode( '-', $widget_id ); $multi_number = array_pop( $pieces ); $id_base = implode( '-', $pieces ); $widget = get_option( 'widget_' . $id_base ); unset( $widget[ $multi_number ] ); update_option( 'widget_' . $id_base, $widget ); unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] ); } wp_set_sidebars_widgets( $sidebars_widgets ); wp_die(); } /** * Handles creating missing image sub-sizes for just uploaded images via AJAX. * * @since 5.3.0 */ function wp_ajax_media_create_image_subsizes() { check_ajax_referer( 'media-form' ); if ( ! current_user_can( 'upload_files' ) ) { wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to upload files.' ) ) ); } if ( empty( $_POST['attachment_id'] ) ) { wp_send_json_error( array( 'message' => __( 'Upload failed. Please reload and try again.' ) ) ); } $attachment_id = (int) $_POST['attachment_id']; if ( ! empty( $_POST['_wp_upload_failed_cleanup'] ) ) { // Upload failed. Cleanup. if ( wp_attachment_is_image( $attachment_id ) && current_user_can( 'delete_post', $attachment_id ) ) { $attachment = get_post( $attachment_id ); // Created at most 10 min ago. if ( $attachment && ( time() - strtotime( $attachment->post_date_gmt ) < 600 ) ) { wp_delete_attachment( $attachment_id, true ); wp_send_json_success(); } } } /* * Set a custom header with the attachment_id. * Used by the browser/client to resume creating image sub-sizes after a PHP fatal error. */ if ( ! headers_sent() ) { header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id ); } /* * This can still be pretty slow and cause timeout or out of memory errors. * The js that handles the response would need to also handle HTTP 500 errors. */ wp_update_image_subsizes( $attachment_id ); if ( ! empty( $_POST['_legacy_support'] ) ) { // The old (inline) uploader. Only needs the attachment_id. $response = array( 'id' => $attachment_id ); } else { // Media modal and Media Library grid view. $response = wp_prepare_attachment_for_js( $attachment_id ); if ( ! $response ) { wp_send_json_error( array( 'message' => __( 'Upload failed.' ) ) ); } } // At this point the image has been uploaded successfully. wp_send_json_success( $response ); } /** * Handles uploading attachments via AJAX. * * @since 3.3.0 */ function wp_ajax_upload_attachment() { check_ajax_referer( 'media-form' ); /* * This function does not use wp_send_json_success() / wp_send_json_error() * as the html4 Plupload handler requires a text/html Content-Type for older IE. * See https://core.trac.wordpress.org/ticket/31037 */ if ( ! current_user_can( 'upload_files' ) ) { echo wp_json_encode( array( 'success' => false, 'data' => array( 'message' => __( 'Sorry, you are not allowed to upload files.' ), 'filename' => esc_html( $_FILES['async-upload']['name'] ), ), ) ); wp_die(); } if ( isset( $_REQUEST['post_id'] ) ) { $post_id = $_REQUEST['post_id']; if ( ! current_user_can( 'edit_post', $post_id ) ) { echo wp_json_encode( array( 'success' => false, 'data' => array( 'message' => __( 'Sorry, you are not allowed to attach files to this post.' ), 'filename' => esc_html( $_FILES['async-upload']['name'] ), ), ) ); wp_die(); } } else { $post_id = null; } $post_data = ! empty( $_REQUEST['post_data'] ) ? _wp_get_allowed_postdata( _wp_translate_postdata( false, (array) $_REQUEST['post_data'] ) ) : array(); if ( is_wp_error( $post_data ) ) { wp_die( $post_data->get_error_message() ); } // If the context is custom header or background, make sure the uploaded file is an image. if ( isset( $post_data['context'] ) && in_array( $post_data['context'], array( 'custom-header', 'custom-background' ), true ) ) { $wp_filetype = wp_check_filetype_and_ext( $_FILES['async-upload']['tmp_name'], $_FILES['async-upload']['name'] ); if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) ) { echo wp_json_encode( array( 'success' => false, 'data' => array( 'message' => __( 'The uploaded file is not a valid image. Please try again.' ), 'filename' => esc_html( $_FILES['async-upload']['name'] ), ), ) ); wp_die(); } } $attachment_id = media_handle_upload( 'async-upload', $post_id, $post_data ); if ( is_wp_error( $attachment_id ) ) { echo wp_json_encode( array( 'success' => false, 'data' => array( 'message' => $attachment_id->get_error_message(), 'filename' => esc_html( $_FILES['async-upload']['name'] ), ), ) ); wp_die(); } if ( isset( $post_data['context'] ) && isset( $post_data['theme'] ) ) { if ( 'custom-background' === $post_data['context'] ) { update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', $post_data['theme'] ); } if ( 'custom-header' === $post_data['context'] ) { update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', $post_data['theme'] ); } } $attachment = wp_prepare_attachment_for_js( $attachment_id ); if ( ! $attachment ) { wp_die(); } echo wp_json_encode( array( 'success' => true, 'data' => $attachment, ) ); wp_die(); } /** * Handles image editing via AJAX. * * @since 3.1.0 */ function wp_ajax_image_editor() { $attachment_id = (int) $_POST['postid']; if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) { wp_die( -1 ); } check_ajax_referer( "image_editor-$attachment_id" ); require_once ABSPATH . 'wp-admin/includes/image-edit.php'; $msg = false; switch ( $_POST['do'] ) { case 'save': $msg = wp_save_image( $attachment_id ); if ( ! empty( $msg->error ) ) { wp_send_json_error( $msg ); } wp_send_json_success( $msg ); break; case 'scale': $msg = wp_save_image( $attachment_id ); break; case 'restore': $msg = wp_restore_image( $attachment_id ); break; } ob_start(); wp_image_editor( $attachment_id, $msg ); $html = ob_get_clean(); if ( ! empty( $msg->error ) ) { wp_send_json_error( array( 'message' => $msg, 'html' => $html, ) ); } wp_send_json_success( array( 'message' => $msg, 'html' => $html, ) ); } /** * Handles setting the featured image via AJAX. * * @since 3.1.0 */ function wp_ajax_set_post_thumbnail() { $json = ! empty( $_REQUEST['json'] ); // New-style request. $post_id = (int) $_POST['post_id']; if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); } $thumbnail_id = (int) $_POST['thumbnail_id']; if ( $json ) { check_ajax_referer( "update-post_$post_id" ); } else { check_ajax_referer( "set_post_thumbnail-$post_id" ); } if ( -1 === $thumbnail_id ) { if ( delete_post_thumbnail( $post_id ) ) { $return = _wp_post_thumbnail_html( null, $post_id ); $json ? wp_send_json_success( $return ) : wp_die( $return ); } else { wp_die( 0 ); } } if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) { $return = _wp_post_thumbnail_html( $thumbnail_id, $post_id ); $json ? wp_send_json_success( $return ) : wp_die( $return ); } wp_die( 0 ); } /** * Handles retrieving HTML for the featured image via AJAX. * * @since 4.6.0 */ function wp_ajax_get_post_thumbnail_html() { $post_id = (int) $_POST['post_id']; check_ajax_referer( "update-post_$post_id" ); if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); } $thumbnail_id = (int) $_POST['thumbnail_id']; // For backward compatibility, -1 refers to no featured image. if ( -1 === $thumbnail_id ) { $thumbnail_id = null; } $return = _wp_post_thumbnail_html( $thumbnail_id, $post_id ); wp_send_json_success( $return ); } /** * Handles setting the featured image for an attachment via AJAX. * * @since 4.0.0 * * @see set_post_thumbnail() */ function wp_ajax_set_attachment_thumbnail() { if ( empty( $_POST['urls'] ) || ! is_array( $_POST['urls'] ) ) { wp_send_json_error(); } $thumbnail_id = (int) $_POST['thumbnail_id']; if ( empty( $thumbnail_id ) ) { wp_send_json_error(); } if ( false === check_ajax_referer( 'set-attachment-thumbnail', '_ajax_nonce', false ) ) { wp_send_json_error(); } $post_ids = array(); // For each URL, try to find its corresponding post ID. foreach ( $_POST['urls'] as $url ) { $post_id = attachment_url_to_postid( $url ); if ( ! empty( $post_id ) ) { $post_ids[] = $post_id; } } if ( empty( $post_ids ) ) { wp_send_json_error(); } $success = 0; // For each found attachment, set its thumbnail. foreach ( $post_ids as $post_id ) { if ( ! current_user_can( 'edit_post', $post_id ) ) { continue; } if ( set_post_thumbnail( $post_id, $thumbnail_id ) ) { ++$success; } } if ( 0 === $success ) { wp_send_json_error(); } else { wp_send_json_success(); } wp_send_json_error(); } /** * Handles formatting a date via AJAX. * * @since 3.1.0 */ function wp_ajax_date_format() { wp_die( date_i18n( sanitize_option( 'date_format', wp_unslash( $_POST['date'] ) ) ) ); } /** * Handles formatting a time via AJAX. * * @since 3.1.0 */ function wp_ajax_time_format() { wp_die( date_i18n( sanitize_option( 'time_format', wp_unslash( $_POST['date'] ) ) ) ); } /** * Handles saving posts from the fullscreen editor via AJAX. * * @since 3.1.0 * @deprecated 4.3.0 */ function wp_ajax_wp_fullscreen_save_post() { $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; $post = null; if ( $post_id ) { $post = get_post( $post_id ); } check_ajax_referer( 'update-post_' . $post_id, '_wpnonce' ); $post_id = edit_post(); if ( is_wp_error( $post_id ) ) { wp_send_json_error(); } if ( $post ) { $last_date = mysql2date( __( 'F j, Y' ), $post->post_modified ); $last_time = mysql2date( __( 'g:i a' ), $post->post_modified ); } else { $last_date = date_i18n( __( 'F j, Y' ) ); $last_time = date_i18n( __( 'g:i a' ) ); } $last_id = get_post_meta( $post_id, '_edit_last', true ); if ( $last_id ) { $last_user = get_userdata( $last_id ); /* translators: 1: User's display name, 2: Date of last edit, 3: Time of last edit. */ $last_edited = sprintf( __( 'Last edited by %1$s on %2$s at %3$s' ), esc_html( $last_user->display_name ), $last_date, $last_time ); } else { /* translators: 1: Date of last edit, 2: Time of last edit. */ $last_edited = sprintf( __( 'Last edited on %1$s at %2$s' ), $last_date, $last_time ); } wp_send_json_success( array( 'last_edited' => $last_edited ) ); } /** * Handles removing a post lock via AJAX. * * @since 3.1.0 */ function wp_ajax_wp_remove_post_lock() { if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) ) { wp_die( 0 ); } $post_id = (int) $_POST['post_ID']; $post = get_post( $post_id ); if ( ! $post ) { wp_die( 0 ); } check_ajax_referer( 'update-post_' . $post_id ); if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( -1 ); } $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); if ( get_current_user_id() !== $active_lock[1] ) { wp_die( 0 ); } /** * Filters the post lock window duration. * * @since 3.3.0 * * @param int $interval The interval in seconds the post lock duration * should last, plus 5 seconds. Default 150. */ $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', 150 ) + 5 ) . ':' . $active_lock[1]; update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) ); wp_die( 1 ); } /** * Handles dismissing a WordPress pointer via AJAX. * * @since 3.1.0 */ function wp_ajax_dismiss_wp_pointer() { $pointer = $_POST['pointer']; if ( sanitize_key( $pointer ) !== $pointer ) { wp_die( 0 ); } // check_ajax_referer( 'dismiss-pointer_' . $pointer ); $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ); if ( in_array( $pointer, $dismissed, true ) ) { wp_die( 0 ); } $dismissed[] = $pointer; $dismissed = implode( ',', $dismissed ); update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed ); wp_die( 1 ); } /** * Handles getting an attachment via AJAX. * * @since 3.5.0 */ function wp_ajax_get_attachment() { if ( ! isset( $_REQUEST['id'] ) ) { wp_send_json_error(); } $id = absint( $_REQUEST['id'] ); if ( ! $id ) { wp_send_json_error(); } $post = get_post( $id ); if ( ! $post ) { wp_send_json_error(); } if ( 'attachment' !== $post->post_type ) { wp_send_json_error(); } if ( ! current_user_can( 'upload_files' ) ) { wp_send_json_error(); } $attachment = wp_prepare_attachment_for_js( $id ); if ( ! $attachment ) { wp_send_json_error(); } wp_send_json_success( $attachment ); } /** * Handles querying attachments via AJAX. * * @since 3.5.0 */ function wp_ajax_query_attachments() { if ( ! current_user_can( 'upload_files' ) ) { wp_send_json_error(); } $query = isset( $_REQUEST['query'] ) ? (array) $_REQUEST['query'] : array(); $keys = array( 's', 'order', 'orderby', 'posts_per_page', 'paged', 'post_mime_type', 'post_parent', 'author', 'post__in', 'post__not_in', 'year', 'monthnum', ); foreach ( get_taxonomies_for_attachments( 'objects' ) as $t ) { if ( $t->query_var && isset( $query[ $t->query_var ] ) ) { $keys[] = $t->query_var; } } $query = array_intersect_key( $query, array_flip( $keys ) ); $query['post_type'] = 'attachment'; if ( MEDIA_TRASH && ! empty( $_REQUEST['query']['post_status'] ) && 'trash' === $_REQUEST['query']['post_status'] ) { $query['post_status'] = 'trash'; } else { $query['post_status'] = 'inherit'; } if ( current_user_can( get_post_type_object( 'attachment' )->cap->read_private_posts ) ) { $query['post_status'] .= ',private'; } // Filter query clauses to include filenames. if ( isset( $query['s'] ) ) { add_filter( 'wp_allow_query_attachment_by_filename', '__return_true' ); } /** * Filters the arguments passed to WP_Query during an Ajax * call for querying attachments. * * @since 3.7.0 * * @see WP_Query::parse_query() * * @param array $query An array of query variables. */ $query = apply_filters( 'ajax_query_attachments_args', $query ); $attachments_query = new WP_Query( $query ); update_post_parent_caches( $attachments_query->posts ); $posts = array_map( 'wp_prepare_attachment_for_js', $attachments_query->posts ); $posts = array_filter( $posts ); $total_posts = $attachments_query->found_posts; if ( $total_posts < 1 ) { // Out-of-bounds, run the query again without LIMIT for total count. unset( $query['paged'] ); $count_query = new WP_Query(); $count_query->query( $query ); $total_posts = $count_query->found_posts; } $posts_per_page = (int) $attachments_query->get( 'posts_per_page' ); $max_pages = $posts_per_page ? (int) ceil( $total_posts / $posts_per_page ) : 0; header( 'X-WP-Total: ' . (int) $total_posts ); header( 'X-WP-TotalPages: ' . $max_pages ); wp_send_json_success( $posts ); } /** * Handles updating attachment attributes via AJAX. * * @since 3.5.0 */ function wp_ajax_save_attachment() { if ( ! isset( $_REQUEST['id'] ) || ! isset( $_REQUEST['changes'] ) ) { wp_send_json_error(); } $id = absint( $_REQUEST['id'] ); if ( ! $id ) { wp_send_json_error(); } check_ajax_referer( 'update-post_' . $id, 'nonce' ); if ( ! current_user_can( 'edit_post', $id ) ) { wp_send_json_error(); } $changes = $_REQUEST['changes']; $post = get_post( $id, ARRAY_A ); if ( 'attachment' !== $post['post_type'] ) { wp_send_json_error(); } if ( isset( $changes['parent'] ) ) { $post['post_parent'] = $changes['parent']; } if ( isset( $changes['title'] ) ) { $post['post_title'] = $changes['title']; } if ( isset( $changes['caption'] ) ) { $post['post_excerpt'] = $changes['caption']; } if ( isset( $changes['description'] ) ) { $post['post_content'] = $changes['description']; } if ( MEDIA_TRASH && isset( $changes['status'] ) ) { $post['post_status'] = $changes['status']; } if ( isset( $changes['alt'] ) ) { $alt = wp_unslash( $changes['alt'] ); if ( get_post_meta( $id, '_wp_attachment_image_alt', true ) !== $alt ) { $alt = wp_strip_all_tags( $alt, true ); update_post_meta( $id, '_wp_attachment_image_alt', wp_slash( $alt ) ); } } if ( wp_attachment_is( 'audio', $post['ID'] ) ) { $changed = false; $id3data = wp_get_attachment_metadata( $post['ID'] ); if ( ! is_array( $id3data ) ) { $changed = true; $id3data = array(); } foreach ( wp_get_attachment_id3_keys( (object) $post, 'edit' ) as $key => $label ) { if ( isset( $changes[ $key ] ) ) { $changed = true; $id3data[ $key ] = sanitize_text_field( wp_unslash( $changes[ $key ] ) ); } } if ( $changed ) { wp_update_attachment_metadata( $id, $id3data ); } } if ( MEDIA_TRASH && isset( $changes['status'] ) && 'trash' === $changes['status'] ) { wp_delete_post( $id ); } else { wp_update_post( $post ); } wp_send_json_success(); } /** * Handles saving backward compatible attachment attributes via AJAX. * * @since 3.5.0 */ function wp_ajax_save_attachment_compat() { if ( ! isset( $_REQUEST['id'] ) ) { wp_send_json_error(); } $id = absint( $_REQUEST['id'] ); if ( ! $id ) { wp_send_json_error(); } if ( empty( $_REQUEST['attachments'] ) || empty( $_REQUEST['attachments'][ $id ] ) ) { wp_send_json_error(); } $attachment_data = $_REQUEST['attachments'][ $id ]; check_ajax_referer( 'update-post_' . $id, 'nonce' ); if ( ! current_user_can( 'edit_post', $id ) ) { wp_send_json_error(); } $post = get_post( $id, ARRAY_A ); if ( 'attachment' !== $post['post_type'] ) { wp_send_json_error(); } /** This filter is documented in wp-admin/includes/media.php */ $post = apply_filters( 'attachment_fields_to_save', $post, $attachment_data ); if ( isset( $post['errors'] ) ) { $errors = $post['errors']; // @todo return me and display me! unset( $post['errors'] ); } wp_update_post( $post ); foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) { if ( isset( $attachment_data[ $taxonomy ] ) ) { wp_set_object_terms( $id, array_map( 'trim', preg_split( '/,+/', $attachment_data[ $taxonomy ] ) ), $taxonomy, false ); } } $attachment = wp_prepare_attachment_for_js( $id ); if ( ! $attachment ) { wp_send_json_error(); } wp_send_json_success( $attachment ); } /** * Handles saving the attachment order via AJAX. * * @since 3.5.0 */ function wp_ajax_save_attachment_order() { if ( ! isset( $_REQUEST['post_id'] ) ) { wp_send_json_error(); } $post_id = absint( $_REQUEST['post_id'] ); if ( ! $post_id ) { wp_send_json_error(); } if ( empty( $_REQUEST['attachments'] ) ) { wp_send_json_error(); } check_ajax_referer( 'update-post_' . $post_id, 'nonce' ); $attachments = $_REQUEST['attachments']; if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_send_json_error(); } foreach ( $attachments as $attachment_id => $menu_order ) { if ( ! current_user_can( 'edit_post', $attachment_id ) ) { continue; } $attachment = get_post( $attachment_id ); if ( ! $attachment ) { continue; } if ( 'attachment' !== $attachment->post_type ) { continue; } wp_update_post( array( 'ID' => $attachment_id, 'menu_order' => $menu_order, ) ); } wp_send_json_success(); } /** * Handles sending an attachment to the editor via AJAX. * * Generates the HTML to send an attachment to the editor. * Backward compatible with the {@see 'media_send_to_editor'} filter * and the chain of filters that follow. * * @since 3.5.0 */ function wp_ajax_send_attachment_to_editor() { check_ajax_referer( 'media-send-to-editor', 'nonce' ); $attachment = wp_unslash( $_POST['attachment'] ); $id = (int) $attachment['id']; $post = get_post( $id ); if ( ! $post ) { wp_send_json_error(); } if ( 'attachment' !== $post->post_type ) { wp_send_json_error(); } if ( current_user_can( 'edit_post', $id ) ) { // If this attachment is unattached, attach it. Primarily a back compat thing. $insert_into_post_id = (int) $_POST['post_id']; if ( 0 === $post->post_parent && $insert_into_post_id ) { wp_update_post( array( 'ID' => $id, 'post_parent' => $insert_into_post_id, ) ); } } $url = empty( $attachment['url'] ) ? '' : $attachment['url']; $rel = ( str_contains( $url, 'attachment_id' ) || get_attachment_link( $id ) === $url ); remove_filter( 'media_send_to_editor', 'image_media_send_to_editor' ); if ( str_starts_with( $post->post_mime_type, 'image' ) ) { $align = isset( $attachment['align'] ) ? $attachment['align'] : 'none'; $size = isset( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium'; $alt = isset( $attachment['image_alt'] ) ? $attachment['image_alt'] : ''; // No whitespace-only captions. $caption = isset( $attachment['post_excerpt'] ) ? $attachment['post_excerpt'] : ''; if ( '' === trim( $caption ) ) { $caption = ''; } $title = ''; // We no longer insert title tags into tags, as they are redundant. $html = get_image_send_to_editor( $id, $caption, $title, $align, $url, $rel, $size, $alt ); } elseif ( wp_attachment_is( 'video', $post ) || wp_attachment_is( 'audio', $post ) ) { $html = stripslashes_deep( $_POST['html'] ); } else { $html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : ''; $rel = $rel ? ' rel="attachment wp-att-' . $id . '"' : ''; // Hard-coded string, $id is already sanitized. if ( ! empty( $url ) ) { $html = '' . $html . ''; } } /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( 'media_send_to_editor', $html, $id, $attachment ); wp_send_json_success( $html ); } /** * Handles sending a link to the editor via AJAX. * * Generates the HTML to send a non-image embed link to the editor. * * Backward compatible with the following filters: * - file_send_to_editor_url * - audio_send_to_editor_url * - video_send_to_editor_url * * @since 3.5.0 * * @global WP_Post $post Global post object. * @global WP_Embed $wp_embed WordPress Embed object. */ function wp_ajax_send_link_to_editor() { global $post, $wp_embed; check_ajax_referer( 'media-send-to-editor', 'nonce' ); $src = wp_unslash( $_POST['src'] ); if ( ! $src ) { wp_send_json_error(); } if ( ! strpos( $src, '://' ) ) { $src = 'http://' . $src; } $src = sanitize_url( $src ); if ( ! $src ) { wp_send_json_error(); } $link_text = trim( wp_unslash( $_POST['link_text'] ) ); if ( ! $link_text ) { $link_text = wp_basename( $src ); } $post = get_post( isset( $_POST['post_id'] ) ? $_POST['post_id'] : 0 ); // Ping WordPress for an embed. $check_embed = $wp_embed->run_shortcode( '[embed]' . $src . '[/embed]' ); // Fallback that WordPress creates when no oEmbed was found. $fallback = $wp_embed->maybe_make_link( $src ); if ( $check_embed !== $fallback ) { // TinyMCE view for [embed] will parse this. $html = '[embed]' . $src . '[/embed]'; } elseif ( $link_text ) { $html = '' . $link_text . ''; } else { $html = ''; } // Figure out what filter to run: $type = 'file'; $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ); if ( $ext ) { $ext_type = wp_ext2type( $ext ); if ( 'audio' === $ext_type || 'video' === $ext_type ) { $type = $ext_type; } } /** This filter is documented in wp-admin/includes/media.php */ $html = apply_filters( "{$type}_send_to_editor_url", $html, $src, $link_text ); wp_send_json_success( $html ); } /** * Handles the Heartbeat API via AJAX. * * Runs when the user is logged in. * * @since 3.6.0 */ function wp_ajax_heartbeat() { if ( empty( $_POST['_nonce'] ) ) { wp_send_json_error(); } $response = array(); $data = array(); $nonce_state = wp_verify_nonce( $_POST['_nonce'], 'heartbeat-nonce' ); // 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'. if ( ! empty( $_POST['screen_id'] ) ) { $screen_id = sanitize_key( $_POST['screen_id'] ); } else { $screen_id = 'front'; } if ( ! empty( $_POST['data'] ) ) { $data = wp_unslash( (array) $_POST['data'] ); } if ( 1 !== $nonce_state ) { /** * Filters the nonces to send to the New/Edit Post screen. * * @since 4.3.0 * * @param array $response The Heartbeat response. * @param array $data The $_POST data sent. * @param string $screen_id The screen ID. */ $response = apply_filters( 'wp_refresh_nonces', $response, $data, $screen_id ); if ( false === $nonce_state ) { // User is logged in but nonces have expired. $response['nonces_expired'] = true; wp_send_json( $response ); } } if ( ! empty( $data ) ) { /** * Filters the Heartbeat response received. * * @since 3.6.0 * * @param array $response The Heartbeat response. * @param array $data The $_POST data sent. * @param string $screen_id The screen ID. */ $response = apply_filters( 'heartbeat_received', $response, $data, $screen_id ); } /** * Filters the Heartbeat response sent. * * @since 3.6.0 * * @param array $response The Heartbeat response. * @param string $screen_id The screen ID. */ $response = apply_filters( 'heartbeat_send', $response, $screen_id ); /** * Fires when Heartbeat ticks in logged-in environments. * * Allows the transport to be easily replaced with long-polling. * * @since 3.6.0 * * @param array $response The Heartbeat response. * @param string $screen_id The screen ID. */ do_action( 'heartbeat_tick', $response, $screen_id ); // Send the current time according to the server. $response['server_time'] = time(); wp_send_json( $response ); } /** * Handles getting revision diffs via AJAX. * * @since 3.6.0 */ function wp_ajax_get_revision_diffs() { require ABSPATH . 'wp-admin/includes/revision.php'; $post = get_post( (int) $_REQUEST['post_id'] ); if ( ! $post ) { wp_send_json_error(); } if ( ! current_user_can( 'edit_post', $post->ID ) ) { wp_send_json_error(); } // Really just pre-loading the cache here. $revisions = wp_get_post_revisions( $post->ID, array( 'check_enabled' => false ) ); if ( ! $revisions ) { wp_send_json_error(); } $return = array(); // Removes the script timeout limit by setting it to 0 allowing ample time for diff UI setup. if ( function_exists( 'set_time_limit' ) ) { set_time_limit( 0 ); } foreach ( $_REQUEST['compare'] as $compare_key ) { list( $compare_from, $compare_to ) = explode( ':', $compare_key ); // from:to $return[] = array( 'id' => $compare_key, 'fields' => wp_get_revision_ui_diff( $post, $compare_from, $compare_to ), ); } wp_send_json_success( $return ); } /** * Handles auto-saving the selected color scheme for * a user's own profile via AJAX. * * @since 3.8.0 * * @global array $_wp_admin_css_colors */ function wp_ajax_save_user_color_scheme() { global $_wp_admin_css_colors; check_ajax_referer( 'save-color-scheme', 'nonce' ); $color_scheme = sanitize_key( $_POST['color_scheme'] ); if ( ! isset( $_wp_admin_css_colors[ $color_scheme ] ) ) { wp_send_json_error(); } $previous_color_scheme = get_user_meta( get_current_user_id(), 'admin_color', true ); update_user_meta( get_current_user_id(), 'admin_color', $color_scheme ); wp_send_json_success( array( 'previousScheme' => 'admin-color-' . $previous_color_scheme, 'currentScheme' => 'admin-color-' . $color_scheme, ) ); } /** * Handles getting themes from themes_api() via AJAX. * * @since 3.9.0 * * @global array $themes_allowedtags * @global array $theme_field_defaults */ function wp_ajax_query_themes() { global $themes_allowedtags, $theme_field_defaults; if ( ! current_user_can( 'install_themes' ) ) { wp_send_json_error(); } $args = wp_parse_args( wp_unslash( $_REQUEST['request'] ), array( 'per_page' => 20, 'fields' => array_merge( (array) $theme_field_defaults, array( 'reviews_url' => true, // Explicitly request the reviews URL to be linked from the Add Themes screen. ) ), ) ); if ( isset( $args['browse'] ) && 'favorites' === $args['browse'] && ! isset( $args['user'] ) ) { $user = get_user_option( 'wporg_favorites' ); if ( $user ) { $args['user'] = $user; } } $old_filter = isset( $args['browse'] ) ? $args['browse'] : 'search'; /** This filter is documented in wp-admin/includes/class-wp-theme-install-list-table.php */ $args = apply_filters( 'install_themes_table_api_args_' . $old_filter, $args ); $api = themes_api( 'query_themes', $args ); if ( is_wp_error( $api ) ) { wp_send_json_error(); } $update_php = network_admin_url( 'update.php?action=install-theme' ); $installed_themes = search_theme_directories(); if ( false === $installed_themes ) { $installed_themes = array(); } foreach ( $installed_themes as $theme_slug => $theme_data ) { // Ignore child themes. if ( str_contains( $theme_slug, '/' ) ) { unset( $installed_themes[ $theme_slug ] ); } } foreach ( $api->themes as &$theme ) { $theme->install_url = add_query_arg( array( 'theme' => $theme->slug, '_wpnonce' => wp_create_nonce( 'install-theme_' . $theme->slug ), ), $update_php ); if ( current_user_can( 'switch_themes' ) ) { if ( is_multisite() ) { $theme->activate_url = add_query_arg( array( 'action' => 'enable', '_wpnonce' => wp_create_nonce( 'enable-theme_' . $theme->slug ), 'theme' => $theme->slug, ), network_admin_url( 'themes.php' ) ); } else { $theme->activate_url = add_query_arg( array( 'action' => 'activate', '_wpnonce' => wp_create_nonce( 'switch-theme_' . $theme->slug ), 'stylesheet' => $theme->slug, ), admin_url( 'themes.php' ) ); } } $is_theme_installed = array_key_exists( $theme->slug, $installed_themes ); // We only care about installed themes. $theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme(); if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { $customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug ); $theme->customize_url = add_query_arg( array( 'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ), ), $customize_url ); } $theme->name = wp_kses( $theme->name, $themes_allowedtags ); $theme->author = wp_kses( $theme->author['display_name'], $themes_allowedtags ); $theme->version = wp_kses( $theme->version, $themes_allowedtags ); $theme->description = wp_kses( $theme->description, $themes_allowedtags ); $theme->stars = wp_star_rating( array( 'rating' => $theme->rating, 'type' => 'percent', 'number' => $theme->num_ratings, 'echo' => false, ) ); $theme->num_ratings = number_format_i18n( $theme->num_ratings ); $theme->preview_url = set_url_scheme( $theme->preview_url ); $theme->compatible_wp = is_wp_version_compatible( $theme->requires ); $theme->compatible_php = is_php_version_compatible( $theme->requires_php ); } wp_send_json_success( $api ); } /** * Applies [embed] Ajax handlers to a string. * * @since 4.0.0 * * @global WP_Post $post Global post object. * @global WP_Embed $wp_embed WordPress Embed object. * @global WP_Scripts $wp_scripts * @global int $content_width */ function wp_ajax_parse_embed() { global $post, $wp_embed, $content_width; if ( empty( $_POST['shortcode'] ) ) { wp_send_json_error(); } $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0; if ( $post_id > 0 ) { $post = get_post( $post_id ); if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) { wp_send_json_error(); } setup_postdata( $post ); } elseif ( ! current_user_can( 'edit_posts' ) ) { // See WP_oEmbed_Controller::get_proxy_item_permissions_check(). wp_send_json_error(); } $shortcode = wp_unslash( $_POST['shortcode'] ); preg_match( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); $atts = shortcode_parse_atts( $matches[3] ); if ( ! empty( $matches[5] ) ) { $url = $matches[5]; } elseif ( ! empty( $atts['src'] ) ) { $url = $atts['src']; } else { $url = ''; } $parsed = false; $wp_embed->return_false_on_fail = true; if ( 0 === $post_id ) { /* * Refresh oEmbeds cached outside of posts that are past their TTL. * Posts are excluded because they have separate logic for refreshing * their post meta caches. See WP_Embed::cache_oembed(). */ $wp_embed->usecache = false; } if ( is_ssl() && str_starts_with( $url, 'http://' ) ) { /* * Admin is ssl and the user pasted non-ssl URL. * Check if the provider supports ssl embeds and use that for the preview. */ $ssl_shortcode = preg_replace( '%^(\\[embed[^\\]]*\\])http://%i', '$1https://', $shortcode ); $parsed = $wp_embed->run_shortcode( $ssl_shortcode ); if ( ! $parsed ) { $no_ssl_support = true; } } // Set $content_width so any embeds fit in the destination iframe. if ( isset( $_POST['maxwidth'] ) && is_numeric( $_POST['maxwidth'] ) && $_POST['maxwidth'] > 0 ) { if ( ! isset( $content_width ) ) { $content_width = (int) $_POST['maxwidth']; } else { $content_width = min( $content_width, (int) $_POST['maxwidth'] ); } } if ( $url && ! $parsed ) { $parsed = $wp_embed->run_shortcode( $shortcode ); } if ( ! $parsed ) { wp_send_json_error( array( 'type' => 'not-embeddable', /* translators: %s: URL that could not be embedded. */ 'message' => sprintf( __( '%s failed to embed.' ), '' . esc_html( $url ) . '
' ),
)
);
}
if ( has_shortcode( $parsed, 'audio' ) || has_shortcode( $parsed, 'video' ) ) {
$styles = '';
$mce_styles = wpview_media_sandbox_styles();
foreach ( $mce_styles as $style ) {
$styles .= sprintf( '', $style );
}
$html = do_shortcode( $parsed );
global $wp_scripts;
if ( ! empty( $wp_scripts ) ) {
$wp_scripts->done = array();
}
ob_start();
wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) );
$scripts = ob_get_clean();
$parsed = $styles . $html . $scripts;
}
if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) ||
preg_match( '%]*href="http://%', $parsed ) ) ) ) {
// Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked.
wp_send_json_error(
array(
'type' => 'not-ssl',
'message' => __( 'This preview is unavailable in the editor.' ),
)
);
}
$return = array(
'body' => $parsed,
'attr' => $wp_embed->last_attr,
);
if ( str_contains( $parsed, 'class="wp-embedded-content' ) ) {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
$script_src = includes_url( 'js/wp-embed.js' );
} else {
$script_src = includes_url( 'js/wp-embed.min.js' );
}
$return['head'] = '';
$return['sandbox'] = true;
}
wp_send_json_success( $return );
}
/**
* @since 4.0.0
*
* @global WP_Post $post Global post object.
* @global WP_Scripts $wp_scripts
*/
function wp_ajax_parse_media_shortcode() {
global $post, $wp_scripts;
if ( empty( $_POST['shortcode'] ) ) {
wp_send_json_error();
}
$shortcode = wp_unslash( $_POST['shortcode'] );
// Only process previews for media related shortcodes:
$found_shortcodes = get_shortcode_tags_in_content( $shortcode );
$media_shortcodes = array(
'audio',
'embed',
'playlist',
'video',
'gallery',
);
$other_shortcodes = array_diff( $found_shortcodes, $media_shortcodes );
if ( ! empty( $other_shortcodes ) ) {
wp_send_json_error();
}
if ( ! empty( $_POST['post_ID'] ) ) {
$post = get_post( (int) $_POST['post_ID'] );
}
// The embed shortcode requires a post.
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
if ( in_array( 'embed', $found_shortcodes, true ) ) {
wp_send_json_error();
}
} else {
setup_postdata( $post );
}
$parsed = do_shortcode( $shortcode );
if ( empty( $parsed ) ) {
wp_send_json_error(
array(
'type' => 'no-items',
'message' => __( 'No items found.' ),
)
);
}
$head = '';
$styles = wpview_media_sandbox_styles();
foreach ( $styles as $style ) {
$head .= '';
}
if ( ! empty( $wp_scripts ) ) {
$wp_scripts->done = array();
}
ob_start();
echo $parsed;
if ( 'playlist' === $_REQUEST['type'] ) {
wp_underscore_playlist_templates();
wp_print_scripts( 'wp-playlist' );
} else {
wp_print_scripts( array( 'mediaelement-vimeo', 'wp-mediaelement' ) );
}
wp_send_json_success(
array(
'head' => $head,
'body' => ob_get_clean(),
)
);
}
/**
* Handles destroying multiple open sessions for a user via AJAX.
*
* @since 4.1.0
*/
function wp_ajax_destroy_sessions() {
$user = get_userdata( (int) $_POST['user_id'] );
if ( $user ) {
if ( ! current_user_can( 'edit_user', $user->ID ) ) {
$user = false;
} elseif ( ! wp_verify_nonce( $_POST['nonce'], 'update-user_' . $user->ID ) ) {
$user = false;
}
}
if ( ! $user ) {
wp_send_json_error(
array(
'message' => __( 'Could not log out user sessions. Please try again.' ),
)
);
}
$sessions = WP_Session_Tokens::get_instance( $user->ID );
if ( get_current_user_id() === $user->ID ) {
$sessions->destroy_others( wp_get_session_token() );
$message = __( 'You are now logged out everywhere else.' );
} else {
$sessions->destroy_all();
/* translators: %s: User's display name. */
$message = sprintf( __( '%s has been logged out.' ), $user->display_name );
}
wp_send_json_success( array( 'message' => $message ) );
}
/**
* Handles cropping an image via AJAX.
*
* @since 4.3.0
*/
function wp_ajax_crop_image() {
$attachment_id = absint( $_POST['id'] );
check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' );
if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
wp_send_json_error();
}
$context = str_replace( '_', '-', $_POST['context'] );
$data = array_map( 'absint', $_POST['cropDetails'] );
$cropped = wp_crop_image( $attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height'] );
if ( ! $cropped || is_wp_error( $cropped ) ) {
wp_send_json_error( array( 'message' => __( 'Image could not be processed.' ) ) );
}
switch ( $context ) {
case 'site-icon':
require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
$wp_site_icon = new WP_Site_Icon();
// Skip creating a new attachment if the attachment is a Site Icon.
if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) === $context ) {
// Delete the temporary cropped file, we don't need it.
wp_delete_file( $cropped );
// Additional sizes in wp_prepare_attachment_for_js().
add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
break;
}
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
// Copy attachment properties.
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context );
// Update the attachment.
add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
$attachment_id = $wp_site_icon->insert_attachment( $attachment, $cropped );
remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
// Additional sizes in wp_prepare_attachment_for_js().
add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
break;
default:
/**
* Fires before a cropped image is saved.
*
* Allows to add filters to modify the way a cropped image is saved.
*
* @since 4.3.0
*
* @param string $context The Customizer control requesting the cropped image.
* @param int $attachment_id The attachment ID of the original image.
* @param string $cropped Path to the cropped image file.
*/
do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped );
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
// Copy attachment properties.
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context );
$attachment_id = wp_insert_attachment( $attachment, $cropped );
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
/**
* Filters the cropped image attachment metadata.
*
* @since 4.3.0
*
* @see wp_generate_attachment_metadata()
*
* @param array $metadata Attachment metadata.
*/
$metadata = apply_filters( 'wp_ajax_cropped_attachment_metadata', $metadata );
wp_update_attachment_metadata( $attachment_id, $metadata );
/**
* Filters the attachment ID for a cropped image.
*
* @since 4.3.0
*
* @param int $attachment_id The attachment ID of the cropped image.
* @param string $context The Customizer control requesting the cropped image.
*/
$attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', $attachment_id, $context );
}
wp_send_json_success( wp_prepare_attachment_for_js( $attachment_id ) );
}
/**
* Handles generating a password via AJAX.
*
* @since 4.4.0
*/
function wp_ajax_generate_password() {
wp_send_json_success( wp_generate_password( 24 ) );
}
/**
* Handles generating a password in the no-privilege context via AJAX.
*
* @since 5.7.0
*/
function wp_ajax_nopriv_generate_password() {
wp_send_json_success( wp_generate_password( 24 ) );
}
/**
* Handles saving the user's WordPress.org username via AJAX.
*
* @since 4.4.0
*/
function wp_ajax_save_wporg_username() {
if ( ! current_user_can( 'install_themes' ) && ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error();
}
check_ajax_referer( 'save_wporg_username_' . get_current_user_id() );
$username = isset( $_REQUEST['username'] ) ? wp_unslash( $_REQUEST['username'] ) : false;
if ( ! $username ) {
wp_send_json_error();
}
wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) );
}
/**
* Handles installing a theme via AJAX.
*
* @since 4.6.0
*
* @see Theme_Upgrader
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_install_theme() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_theme_specified',
'errorMessage' => __( 'No theme specified.' ),
)
);
}
$slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
$status = array(
'install' => 'theme',
'slug' => $slug,
);
if ( ! current_user_can( 'install_themes' ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to install themes on this site.' );
wp_send_json_error( $status );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/theme.php';
$api = themes_api(
'theme_information',
array(
'slug' => $slug,
'fields' => array( 'sections' => false ),
)
);
if ( is_wp_error( $api ) ) {
$status['errorMessage'] = $api->get_error_message();
wp_send_json_error( $status );
}
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Theme_Upgrader( $skin );
$result = $upgrader->install( $api->download_link );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $skin->get_upgrade_messages();
}
if ( is_wp_error( $result ) ) {
$status['errorCode'] = $result->get_error_code();
$status['errorMessage'] = $result->get_error_message();
wp_send_json_error( $status );
} elseif ( is_wp_error( $skin->result ) ) {
$status['errorCode'] = $skin->result->get_error_code();
$status['errorMessage'] = $skin->result->get_error_message();
wp_send_json_error( $status );
} elseif ( $skin->get_errors()->has_errors() ) {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status );
} elseif ( is_null( $result ) ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
$status['themeName'] = wp_get_theme( $slug )->get( 'Name' );
if ( current_user_can( 'switch_themes' ) ) {
if ( is_multisite() ) {
$status['activateUrl'] = add_query_arg(
array(
'action' => 'enable',
'_wpnonce' => wp_create_nonce( 'enable-theme_' . $slug ),
'theme' => $slug,
),
network_admin_url( 'themes.php' )
);
} else {
$status['activateUrl'] = add_query_arg(
array(
'action' => 'activate',
'_wpnonce' => wp_create_nonce( 'switch-theme_' . $slug ),
'stylesheet' => $slug,
),
admin_url( 'themes.php' )
);
}
}
$theme = wp_get_theme( $slug );
$status['blockTheme'] = $theme->is_block_theme();
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$status['customizeUrl'] = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
wp_customize_url( $slug )
);
}
/*
* See WP_Theme_Install_List_Table::_get_theme_status() if we wanted to check
* on post-installation status.
*/
wp_send_json_success( $status );
}
/**
* Handles updating a theme via AJAX.
*
* @since 4.6.0
*
* @see Theme_Upgrader
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_update_theme() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_theme_specified',
'errorMessage' => __( 'No theme specified.' ),
)
);
}
$stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) );
$status = array(
'update' => 'theme',
'slug' => $stylesheet,
'oldVersion' => '',
'newVersion' => '',
);
if ( ! current_user_can( 'update_themes' ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to update themes for this site.' );
wp_send_json_error( $status );
}
$theme = wp_get_theme( $stylesheet );
if ( $theme->exists() ) {
$status['oldVersion'] = $theme->get( 'Version' );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$current = get_site_transient( 'update_themes' );
if ( empty( $current ) ) {
wp_update_themes();
}
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Theme_Upgrader( $skin );
$result = $upgrader->bulk_upgrade( array( $stylesheet ) );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $skin->get_upgrade_messages();
}
if ( is_wp_error( $skin->result ) ) {
$status['errorCode'] = $skin->result->get_error_code();
$status['errorMessage'] = $skin->result->get_error_message();
wp_send_json_error( $status );
} elseif ( $skin->get_errors()->has_errors() ) {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status );
} elseif ( is_array( $result ) && ! empty( $result[ $stylesheet ] ) ) {
// Theme is already at the latest version.
if ( true === $result[ $stylesheet ] ) {
$status['errorMessage'] = $upgrader->strings['up_to_date'];
wp_send_json_error( $status );
}
$theme = wp_get_theme( $stylesheet );
if ( $theme->exists() ) {
$status['newVersion'] = $theme->get( 'Version' );
}
wp_send_json_success( $status );
} elseif ( false === $result ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
// An unhandled error occurred.
$status['errorMessage'] = __( 'Theme update failed.' );
wp_send_json_error( $status );
}
/**
* Handles deleting a theme via AJAX.
*
* @since 4.6.0
*
* @see delete_theme()
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_delete_theme() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_theme_specified',
'errorMessage' => __( 'No theme specified.' ),
)
);
}
$stylesheet = preg_replace( '/[^A-z0-9_\-]/', '', wp_unslash( $_POST['slug'] ) );
$status = array(
'delete' => 'theme',
'slug' => $stylesheet,
);
if ( ! current_user_can( 'delete_themes' ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to delete themes on this site.' );
wp_send_json_error( $status );
}
if ( ! wp_get_theme( $stylesheet )->exists() ) {
$status['errorMessage'] = __( 'The requested theme does not exist.' );
wp_send_json_error( $status );
}
// Check filesystem credentials. `delete_theme()` will bail otherwise.
$url = wp_nonce_url( 'themes.php?action=delete&stylesheet=' . urlencode( $stylesheet ), 'delete-theme_' . $stylesheet );
ob_start();
$credentials = request_filesystem_credentials( $url );
ob_end_clean();
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
require_once ABSPATH . 'wp-admin/includes/theme.php';
$result = delete_theme( $stylesheet );
if ( is_wp_error( $result ) ) {
$status['errorMessage'] = $result->get_error_message();
wp_send_json_error( $status );
} elseif ( false === $result ) {
$status['errorMessage'] = __( 'Theme could not be deleted.' );
wp_send_json_error( $status );
}
wp_send_json_success( $status );
}
/**
* Handles installing a plugin via AJAX.
*
* @since 4.6.0
*
* @see Plugin_Upgrader
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_install_plugin() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_plugin_specified',
'errorMessage' => __( 'No plugin specified.' ),
)
);
}
$status = array(
'install' => 'plugin',
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
);
if ( ! current_user_can( 'install_plugins' ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.' );
wp_send_json_error( $status );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api(
'plugin_information',
array(
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
'fields' => array(
'sections' => false,
),
)
);
if ( is_wp_error( $api ) ) {
$status['errorMessage'] = $api->get_error_message();
wp_send_json_error( $status );
}
$status['pluginName'] = $api->name;
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$result = $upgrader->install( $api->download_link );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $skin->get_upgrade_messages();
}
if ( is_wp_error( $result ) ) {
$status['errorCode'] = $result->get_error_code();
$status['errorMessage'] = $result->get_error_message();
wp_send_json_error( $status );
} elseif ( is_wp_error( $skin->result ) ) {
$status['errorCode'] = $skin->result->get_error_code();
$status['errorMessage'] = $skin->result->get_error_message();
wp_send_json_error( $status );
} elseif ( $skin->get_errors()->has_errors() ) {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status );
} elseif ( is_null( $result ) ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
$install_status = install_plugin_install_status( $api );
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
// If installation request is coming from import page, do not return network activation link.
$plugins_url = ( 'import' === $pagenow ) ? admin_url( 'plugins.php' ) : network_admin_url( 'plugins.php' );
if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
$status['activateUrl'] = add_query_arg(
array(
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
'action' => 'activate',
'plugin' => $install_status['file'],
),
$plugins_url
);
}
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) && 'import' !== $pagenow ) {
$status['activateUrl'] = add_query_arg( array( 'networkwide' => 1 ), $status['activateUrl'] );
}
wp_send_json_success( $status );
}
/**
* Handles activating a plugin via AJAX.
*
* @since 6.5.0
*/
function wp_ajax_activate_plugin() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['name'] ) || empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'pluginName' => '',
'plugin' => '',
'errorCode' => 'no_plugin_specified',
'errorMessage' => __( 'No plugin specified.' ),
)
);
}
$status = array(
'activate' => 'plugin',
'slug' => wp_unslash( $_POST['slug'] ),
'pluginName' => wp_unslash( $_POST['name'] ),
'plugin' => wp_unslash( $_POST['plugin'] ),
);
if ( ! current_user_can( 'activate_plugin', $status['plugin'] ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to activate plugins on this site.' );
wp_send_json_error( $status );
}
if ( is_plugin_active( $status['plugin'] ) ) {
$status['errorMessage'] = sprintf(
/* translators: %s: Plugin name. */
__( '%s is already active.' ),
$status['pluginName']
);
}
$activated = activate_plugin( $status['plugin'] );
if ( is_wp_error( $activated ) ) {
$status['errorMessage'] = $activated->get_error_message();
wp_send_json_error( $status );
}
wp_send_json_success( $status );
}
/**
* Handles updating a plugin via AJAX.
*
* @since 4.2.0
*
* @see Plugin_Upgrader
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_update_plugin() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['plugin'] ) || empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_plugin_specified',
'errorMessage' => __( 'No plugin specified.' ),
)
);
}
$plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
$status = array(
'update' => 'plugin',
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
'oldVersion' => '',
'newVersion' => '',
);
if ( ! current_user_can( 'update_plugins' ) || 0 !== validate_file( $plugin ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to update plugins for this site.' );
wp_send_json_error( $status );
}
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
$status['plugin'] = $plugin;
$status['pluginName'] = $plugin_data['Name'];
if ( $plugin_data['Version'] ) {
/* translators: %s: Plugin version. */
$status['oldVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
wp_update_plugins();
$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$result = $upgrader->bulk_upgrade( array( $plugin ) );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $skin->get_upgrade_messages();
}
if ( is_wp_error( $skin->result ) ) {
$status['errorCode'] = $skin->result->get_error_code();
$status['errorMessage'] = $skin->result->get_error_message();
wp_send_json_error( $status );
} elseif ( $skin->get_errors()->has_errors() ) {
$status['errorMessage'] = $skin->get_error_messages();
wp_send_json_error( $status );
} elseif ( is_array( $result ) && ! empty( $result[ $plugin ] ) ) {
/*
* Plugin is already at the latest version.
*
* This may also be the return value if the `update_plugins` site transient is empty,
* e.g. when you update two plugins in quick succession before the transient repopulates.
*
* Preferably something can be done to ensure `update_plugins` isn't empty.
* For now, surface some sort of error here.
*/
if ( true === $result[ $plugin ] ) {
$status['errorMessage'] = $upgrader->strings['up_to_date'];
wp_send_json_error( $status );
}
$plugin_data = get_plugins( '/' . $result[ $plugin ]['destination_name'] );
$plugin_data = reset( $plugin_data );
if ( $plugin_data['Version'] ) {
/* translators: %s: Plugin version. */
$status['newVersion'] = sprintf( __( 'Version %s' ), $plugin_data['Version'] );
}
wp_send_json_success( $status );
} elseif ( false === $result ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
// An unhandled error occurred.
$status['errorMessage'] = __( 'Plugin update failed.' );
wp_send_json_error( $status );
}
/**
* Handles deleting a plugin via AJAX.
*
* @since 4.6.0
*
* @see delete_plugins()
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*/
function wp_ajax_delete_plugin() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_plugin_specified',
'errorMessage' => __( 'No plugin specified.' ),
)
);
}
$plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['plugin'] ) ) );
$status = array(
'delete' => 'plugin',
'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
);
if ( ! current_user_can( 'delete_plugins' ) || 0 !== validate_file( $plugin ) ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to delete plugins for this site.' );
wp_send_json_error( $status );
}
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
$status['plugin'] = $plugin;
$status['pluginName'] = $plugin_data['Name'];
if ( is_plugin_active( $plugin ) ) {
$status['errorMessage'] = __( 'You cannot delete a plugin while it is active on the main site.' );
wp_send_json_error( $status );
}
// Check filesystem credentials. `delete_plugins()` will bail otherwise.
$url = wp_nonce_url( 'plugins.php?action=delete-selected&verify-delete=1&checked[]=' . $plugin, 'bulk-plugins' );
ob_start();
$credentials = request_filesystem_credentials( $url );
ob_end_clean();
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
$result = delete_plugins( array( $plugin ) );
if ( is_wp_error( $result ) ) {
$status['errorMessage'] = $result->get_error_message();
wp_send_json_error( $status );
} elseif ( false === $result ) {
$status['errorMessage'] = __( 'Plugin could not be deleted.' );
wp_send_json_error( $status );
}
wp_send_json_success( $status );
}
/**
* Handles searching plugins via AJAX.
*
* @since 4.6.0
*
* @global string $s Search term.
*/
function wp_ajax_search_plugins() {
check_ajax_referer( 'updates' );
// Ensure after_plugin_row_{$plugin_file} gets hooked.
wp_plugin_update_rows();
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
if ( 'plugins-network' === $pagenow || 'plugins' === $pagenow ) {
set_current_screen( $pagenow );
}
/** @var WP_Plugins_List_Table $wp_list_table */
$wp_list_table = _get_list_table(
'WP_Plugins_List_Table',
array(
'screen' => get_current_screen(),
)
);
$status = array();
if ( ! $wp_list_table->ajax_user_can() ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' );
wp_send_json_error( $status );
}
// Set the correct requester, so pagination works.
$_SERVER['REQUEST_URI'] = add_query_arg(
array_diff_key(
$_POST,
array(
'_ajax_nonce' => null,
'action' => null,
)
),
network_admin_url( 'plugins.php', 'relative' )
);
$GLOBALS['s'] = wp_unslash( $_POST['s'] );
$wp_list_table->prepare_items();
ob_start();
$wp_list_table->display();
$status['count'] = count( $wp_list_table->items );
$status['items'] = ob_get_clean();
wp_send_json_success( $status );
}
/**
* Handles searching plugins to install via AJAX.
*
* @since 4.6.0
*/
function wp_ajax_search_install_plugins() {
check_ajax_referer( 'updates' );
$pagenow = isset( $_POST['pagenow'] ) ? sanitize_key( $_POST['pagenow'] ) : '';
if ( 'plugin-install-network' === $pagenow || 'plugin-install' === $pagenow ) {
set_current_screen( $pagenow );
}
/** @var WP_Plugin_Install_List_Table $wp_list_table */
$wp_list_table = _get_list_table(
'WP_Plugin_Install_List_Table',
array(
'screen' => get_current_screen(),
)
);
$status = array();
if ( ! $wp_list_table->ajax_user_can() ) {
$status['errorMessage'] = __( 'Sorry, you are not allowed to manage plugins for this site.' );
wp_send_json_error( $status );
}
// Set the correct requester, so pagination works.
$_SERVER['REQUEST_URI'] = add_query_arg(
array_diff_key(
$_POST,
array(
'_ajax_nonce' => null,
'action' => null,
)
),
network_admin_url( 'plugin-install.php', 'relative' )
);
$wp_list_table->prepare_items();
ob_start();
$wp_list_table->display();
$status['count'] = (int) $wp_list_table->get_pagination_arg( 'total_items' );
$status['items'] = ob_get_clean();
wp_send_json_success( $status );
}
/**
* Handles editing a theme or plugin file via AJAX.
*
* @since 4.9.0
*
* @see wp_edit_theme_plugin_file()
*/
function wp_ajax_edit_theme_plugin_file() {
$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); // Validation of args is done in wp_edit_theme_plugin_file().
if ( is_wp_error( $r ) ) {
wp_send_json_error(
array_merge(
array(
'code' => $r->get_error_code(),
'message' => $r->get_error_message(),
),
(array) $r->get_error_data()
)
);
} else {
wp_send_json_success(
array(
'message' => __( 'File edited successfully.' ),
)
);
}
}
/**
* Handles exporting a user's personal data via AJAX.
*
* @since 4.9.6
*/
function wp_ajax_wp_privacy_export_personal_data() {
if ( empty( $_POST['id'] ) ) {
wp_send_json_error( __( 'Missing request ID.' ) );
}
$request_id = (int) $_POST['id'];
if ( $request_id < 1 ) {
wp_send_json_error( __( 'Invalid request ID.' ) );
}
if ( ! current_user_can( 'export_others_personal_data' ) ) {
wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) );
}
check_ajax_referer( 'wp-privacy-export-personal-data-' . $request_id, 'security' );
// Get the request.
$request = wp_get_user_request( $request_id );
if ( ! $request || 'export_personal_data' !== $request->action_name ) {
wp_send_json_error( __( 'Invalid request type.' ) );
}
$email_address = $request->email;
if ( ! is_email( $email_address ) ) {
wp_send_json_error( __( 'A valid email address must be given.' ) );
}
if ( ! isset( $_POST['exporter'] ) ) {
wp_send_json_error( __( 'Missing exporter index.' ) );
}
$exporter_index = (int) $_POST['exporter'];
if ( ! isset( $_POST['page'] ) ) {
wp_send_json_error( __( 'Missing page index.' ) );
}
$page = (int) $_POST['page'];
$send_as_email = isset( $_POST['sendAsEmail'] ) ? ( 'true' === $_POST['sendAsEmail'] ) : false;
/**
* Filters the array of exporter callbacks.
*
* @since 4.9.6
*
* @param array $args {
* An array of callable exporters of personal data. Default empty array.
*
* @type array ...$0 {
* Array of personal data exporters.
*
* @type callable $callback Callable exporter function that accepts an
* email address and a page number and returns an
* array of name => value pairs of personal data.
* @type string $exporter_friendly_name Translated user facing friendly name for the
* exporter.
* }
* }
*/
$exporters = apply_filters( 'wp_privacy_personal_data_exporters', array() );
if ( ! is_array( $exporters ) ) {
wp_send_json_error( __( 'An exporter has improperly used the registration filter.' ) );
}
// Do we have any registered exporters?
if ( 0 < count( $exporters ) ) {
if ( $exporter_index < 1 ) {
wp_send_json_error( __( 'Exporter index cannot be negative.' ) );
}
if ( $exporter_index > count( $exporters ) ) {
wp_send_json_error( __( 'Exporter index is out of range.' ) );
}
if ( $page < 1 ) {
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
}
$exporter_keys = array_keys( $exporters );
$exporter_key = $exporter_keys[ $exporter_index - 1 ];
$exporter = $exporters[ $exporter_key ];
if ( ! is_array( $exporter ) ) {
wp_send_json_error(
/* translators: %s: Exporter array index. */
sprintf( __( 'Expected an array describing the exporter at index %s.' ), $exporter_key )
);
}
if ( ! array_key_exists( 'exporter_friendly_name', $exporter ) ) {
wp_send_json_error(
/* translators: %s: Exporter array index. */
sprintf( __( 'Exporter array at index %s does not include a friendly name.' ), $exporter_key )
);
}
$exporter_friendly_name = $exporter['exporter_friendly_name'];
if ( ! array_key_exists( 'callback', $exporter ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Exporter does not include a callback: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
if ( ! is_callable( $exporter['callback'] ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Exporter callback is not a valid callback: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
$callback = $exporter['callback'];
$response = call_user_func( $callback, $email_address, $page );
if ( is_wp_error( $response ) ) {
wp_send_json_error( $response );
}
if ( ! is_array( $response ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Expected response as an array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
if ( ! array_key_exists( 'data', $response ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Expected data in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
if ( ! is_array( $response['data'] ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Expected data array in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
if ( ! array_key_exists( 'done', $response ) ) {
wp_send_json_error(
/* translators: %s: Exporter friendly name. */
sprintf( __( 'Expected done (boolean) in response array from exporter: %s.' ), esc_html( $exporter_friendly_name ) )
);
}
} else {
// No exporters, so we're done.
$exporter_key = '';
$response = array(
'data' => array(),
'done' => true,
);
}
/**
* Filters a page of personal data exporter data. Used to build the export report.
*
* Allows the export response to be consumed by destinations in addition to Ajax.
*
* @since 4.9.6
*
* @param array $response The personal data for the given exporter and page number.
* @param int $exporter_index The index of the exporter that provided this data.
* @param string $email_address The email address associated with this personal data.
* @param int $page The page number for this response.
* @param int $request_id The privacy request post ID associated with this request.
* @param bool $send_as_email Whether the final results of the export should be emailed to the user.
* @param string $exporter_key The key (slug) of the exporter that provided this data.
*/
$response = apply_filters( 'wp_privacy_personal_data_export_page', $response, $exporter_index, $email_address, $page, $request_id, $send_as_email, $exporter_key );
if ( is_wp_error( $response ) ) {
wp_send_json_error( $response );
}
wp_send_json_success( $response );
}
/**
* Handles erasing personal data via AJAX.
*
* @since 4.9.6
*/
function wp_ajax_wp_privacy_erase_personal_data() {
if ( empty( $_POST['id'] ) ) {
wp_send_json_error( __( 'Missing request ID.' ) );
}
$request_id = (int) $_POST['id'];
if ( $request_id < 1 ) {
wp_send_json_error( __( 'Invalid request ID.' ) );
}
// Both capabilities are required to avoid confusion, see `_wp_personal_data_removal_page()`.
if ( ! current_user_can( 'erase_others_personal_data' ) || ! current_user_can( 'delete_users' ) ) {
wp_send_json_error( __( 'Sorry, you are not allowed to perform this action.' ) );
}
check_ajax_referer( 'wp-privacy-erase-personal-data-' . $request_id, 'security' );
// Get the request.
$request = wp_get_user_request( $request_id );
if ( ! $request || 'remove_personal_data' !== $request->action_name ) {
wp_send_json_error( __( 'Invalid request type.' ) );
}
$email_address = $request->email;
if ( ! is_email( $email_address ) ) {
wp_send_json_error( __( 'Invalid email address in request.' ) );
}
if ( ! isset( $_POST['eraser'] ) ) {
wp_send_json_error( __( 'Missing eraser index.' ) );
}
$eraser_index = (int) $_POST['eraser'];
if ( ! isset( $_POST['page'] ) ) {
wp_send_json_error( __( 'Missing page index.' ) );
}
$page = (int) $_POST['page'];
/**
* Filters the array of personal data eraser callbacks.
*
* @since 4.9.6
*
* @param array $args {
* An array of callable erasers of personal data. Default empty array.
*
* @type array ...$0 {
* Array of personal data exporters.
*
* @type callable $callback Callable eraser that accepts an email address and a page
* number, and returns an array with boolean values for
* whether items were removed or retained and any messages
* from the eraser, as well as if additional pages are
* available.
* @type string $exporter_friendly_name Translated user facing friendly name for the eraser.
* }
* }
*/
$erasers = apply_filters( 'wp_privacy_personal_data_erasers', array() );
// Do we have any registered erasers?
if ( 0 < count( $erasers ) ) {
if ( $eraser_index < 1 ) {
wp_send_json_error( __( 'Eraser index cannot be less than one.' ) );
}
if ( $eraser_index > count( $erasers ) ) {
wp_send_json_error( __( 'Eraser index is out of range.' ) );
}
if ( $page < 1 ) {
wp_send_json_error( __( 'Page index cannot be less than one.' ) );
}
$eraser_keys = array_keys( $erasers );
$eraser_key = $eraser_keys[ $eraser_index - 1 ];
$eraser = $erasers[ $eraser_key ];
if ( ! is_array( $eraser ) ) {
/* translators: %d: Eraser array index. */
wp_send_json_error( sprintf( __( 'Expected an array describing the eraser at index %d.' ), $eraser_index ) );
}
if ( ! array_key_exists( 'eraser_friendly_name', $eraser ) ) {
/* translators: %d: Eraser array index. */
wp_send_json_error( sprintf( __( 'Eraser array at index %d does not include a friendly name.' ), $eraser_index ) );
}
$eraser_friendly_name = $eraser['eraser_friendly_name'];
if ( ! array_key_exists( 'callback', $eraser ) ) {
wp_send_json_error(
sprintf(
/* translators: %s: Eraser friendly name. */
__( 'Eraser does not include a callback: %s.' ),
esc_html( $eraser_friendly_name )
)
);
}
if ( ! is_callable( $eraser['callback'] ) ) {
wp_send_json_error(
sprintf(
/* translators: %s: Eraser friendly name. */
__( 'Eraser callback is not valid: %s.' ),
esc_html( $eraser_friendly_name )
)
);
}
$callback = $eraser['callback'];
$response = call_user_func( $callback, $email_address, $page );
if ( is_wp_error( $response ) ) {
wp_send_json_error( $response );
}
if ( ! is_array( $response ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Did not receive array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! array_key_exists( 'items_removed', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Expected items_removed key in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! array_key_exists( 'items_retained', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Expected items_retained key in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! array_key_exists( 'messages', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Expected messages key in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! is_array( $response['messages'] ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Expected messages key to reference an array in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
if ( ! array_key_exists( 'done', $response ) ) {
wp_send_json_error(
sprintf(
/* translators: 1: Eraser friendly name, 2: Eraser array index. */
__( 'Expected done flag in response array from %1$s eraser (index %2$d).' ),
esc_html( $eraser_friendly_name ),
$eraser_index
)
);
}
} else {
// No erasers, so we're done.
$eraser_key = '';
$response = array(
'items_removed' => false,
'items_retained' => false,
'messages' => array(),
'done' => true,
);
}
/**
* Filters a page of personal data eraser data.
*
* Allows the erasure response to be consumed by destinations in addition to Ajax.
*
* @since 4.9.6
*
* @param array $response {
* The personal data for the given exporter and page number.
*
* @type bool $items_removed Whether items were actually removed or not.
* @type bool $items_retained Whether items were retained or not.
* @type string[] $messages An array of messages to add to the personal data export file.
* @type bool $done Whether the eraser is finished or not.
* }
* @param int $eraser_index The index of the eraser that provided this data.
* @param string $email_address The email address associated with this personal data.
* @param int $page The page number for this response.
* @param int $request_id The privacy request post ID associated with this request.
* @param string $eraser_key The key (slug) of the eraser that provided this data.
*/
$response = apply_filters( 'wp_privacy_personal_data_erasure_page', $response, $eraser_index, $email_address, $page, $request_id, $eraser_key );
if ( is_wp_error( $response ) ) {
wp_send_json_error( $response );
}
wp_send_json_success( $response );
}
/**
* Handles site health checks on server communication via AJAX.
*
* @since 5.2.0
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_dotorg_communication()
* @see WP_REST_Site_Health_Controller::test_dotorg_communication()
*/
function wp_ajax_health_check_dotorg_communication() {
_doing_it_wrong(
'wp_ajax_health_check_dotorg_communication',
sprintf(
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
__( 'The Site Health check for %1$s has been replaced with %2$s.' ),
'wp_ajax_health_check_dotorg_communication',
'WP_REST_Site_Health_Controller::test_dotorg_communication'
),
'5.6.0'
);
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}
$site_health = WP_Site_Health::get_instance();
wp_send_json_success( $site_health->get_test_dotorg_communication() );
}
/**
* Handles site health checks on background updates via AJAX.
*
* @since 5.2.0
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_background_updates()
* @see WP_REST_Site_Health_Controller::test_background_updates()
*/
function wp_ajax_health_check_background_updates() {
_doing_it_wrong(
'wp_ajax_health_check_background_updates',
sprintf(
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
__( 'The Site Health check for %1$s has been replaced with %2$s.' ),
'wp_ajax_health_check_background_updates',
'WP_REST_Site_Health_Controller::test_background_updates'
),
'5.6.0'
);
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}
$site_health = WP_Site_Health::get_instance();
wp_send_json_success( $site_health->get_test_background_updates() );
}
/**
* Handles site health checks on loopback requests via AJAX.
*
* @since 5.2.0
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::test_loopback_requests()
* @see WP_REST_Site_Health_Controller::test_loopback_requests()
*/
function wp_ajax_health_check_loopback_requests() {
_doing_it_wrong(
'wp_ajax_health_check_loopback_requests',
sprintf(
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
__( 'The Site Health check for %1$s has been replaced with %2$s.' ),
'wp_ajax_health_check_loopback_requests',
'WP_REST_Site_Health_Controller::test_loopback_requests'
),
'5.6.0'
);
check_ajax_referer( 'health-check-site-status' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Site_Health' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
}
$site_health = WP_Site_Health::get_instance();
wp_send_json_success( $site_health->get_test_loopback_requests() );
}
/**
* Handles site health check to update the result status via AJAX.
*
* @since 5.2.0
*/
function wp_ajax_health_check_site_status_result() {
check_ajax_referer( 'health-check-site-status-result' );
if ( ! current_user_can( 'view_site_health_checks' ) ) {
wp_send_json_error();
}
set_transient( 'health-check-site-status-result', wp_json_encode( $_POST['counts'] ) );
wp_send_json_success();
}
/**
* Handles site health check to get directories and database sizes via AJAX.
*
* @since 5.2.0
* @deprecated 5.6.0 Use WP_REST_Site_Health_Controller::get_directory_sizes()
* @see WP_REST_Site_Health_Controller::get_directory_sizes()
*/
function wp_ajax_health_check_get_sizes() {
_doing_it_wrong(
'wp_ajax_health_check_get_sizes',
sprintf(
// translators: 1: The Site Health action that is no longer used by core. 2: The new function that replaces it.
__( 'The Site Health check for %1$s has been replaced with %2$s.' ),
'wp_ajax_health_check_get_sizes',
'WP_REST_Site_Health_Controller::get_directory_sizes'
),
'5.6.0'
);
check_ajax_referer( 'health-check-site-status-result' );
if ( ! current_user_can( 'view_site_health_checks' ) || is_multisite() ) {
wp_send_json_error();
}
if ( ! class_exists( 'WP_Debug_Data' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
}
$sizes_data = WP_Debug_Data::get_sizes();
$all_sizes = array( 'raw' => 0 );
foreach ( $sizes_data as $name => $value ) {
$name = sanitize_text_field( $name );
$data = array();
if ( isset( $value['size'] ) ) {
if ( is_string( $value['size'] ) ) {
$data['size'] = sanitize_text_field( $value['size'] );
} else {
$data['size'] = (int) $value['size'];
}
}
if ( isset( $value['debug'] ) ) {
if ( is_string( $value['debug'] ) ) {
$data['debug'] = sanitize_text_field( $value['debug'] );
} else {
$data['debug'] = (int) $value['debug'];
}
}
if ( ! empty( $value['raw'] ) ) {
$data['raw'] = (int) $value['raw'];
}
$all_sizes[ $name ] = $data;
}
if ( isset( $all_sizes['total_size']['debug'] ) && 'not available' === $all_sizes['total_size']['debug'] ) {
wp_send_json_error( $all_sizes );
}
wp_send_json_success( $all_sizes );
}
/**
* Handles renewing the REST API nonce via AJAX.
*
* @since 5.3.0
*/
function wp_ajax_rest_nonce() {
exit( wp_create_nonce( 'wp_rest' ) );
}
/**
* Handles enabling or disable plugin and theme auto-updates via AJAX.
*
* @since 5.5.0
*/
function wp_ajax_toggle_auto_updates() {
check_ajax_referer( 'updates' );
if ( empty( $_POST['type'] ) || empty( $_POST['asset'] ) || empty( $_POST['state'] ) ) {
wp_send_json_error( array( 'error' => __( 'Invalid data. No selected item.' ) ) );
}
$asset = sanitize_text_field( urldecode( $_POST['asset'] ) );
if ( 'enable' !== $_POST['state'] && 'disable' !== $_POST['state'] ) {
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown state.' ) ) );
}
$state = $_POST['state'];
if ( 'plugin' !== $_POST['type'] && 'theme' !== $_POST['type'] ) {
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown type.' ) ) );
}
$type = $_POST['type'];
switch ( $type ) {
case 'plugin':
if ( ! current_user_can( 'update_plugins' ) ) {
$error_message = __( 'Sorry, you are not allowed to modify plugins.' );
wp_send_json_error( array( 'error' => $error_message ) );
}
$option = 'auto_update_plugins';
/** This filter is documented in wp-admin/includes/class-wp-plugins-list-table.php */
$all_items = apply_filters( 'all_plugins', get_plugins() );
break;
case 'theme':
if ( ! current_user_can( 'update_themes' ) ) {
$error_message = __( 'Sorry, you are not allowed to modify themes.' );
wp_send_json_error( array( 'error' => $error_message ) );
}
$option = 'auto_update_themes';
$all_items = wp_get_themes();
break;
default:
wp_send_json_error( array( 'error' => __( 'Invalid data. Unknown type.' ) ) );
}
if ( ! array_key_exists( $asset, $all_items ) ) {
$error_message = __( 'Invalid data. The item does not exist.' );
wp_send_json_error( array( 'error' => $error_message ) );
}
$auto_updates = (array) get_site_option( $option, array() );
if ( 'disable' === $state ) {
$auto_updates = array_diff( $auto_updates, array( $asset ) );
} else {
$auto_updates[] = $asset;
$auto_updates = array_unique( $auto_updates );
}
// Remove items that have been deleted since the site option was last updated.
$auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
update_site_option( $option, $auto_updates );
wp_send_json_success();
}
/**
* Handles sending a password reset link via AJAX.
*
* @since 5.7.0
*/
function wp_ajax_send_password_reset() {
// Validate the nonce for this action.
$user_id = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0;
check_ajax_referer( 'reset-password-for-' . $user_id, 'nonce' );
// Verify user capabilities.
if ( ! current_user_can( 'edit_user', $user_id ) ) {
wp_send_json_error( __( 'Cannot send password reset, permission denied.' ) );
}
// Send the password reset link.
$user = get_userdata( $user_id );
$results = retrieve_password( $user->user_login );
if ( true === $results ) {
wp_send_json_success(
/* translators: %s: User's display name. */
sprintf( __( 'A password reset link was emailed to %s.' ), $user->display_name )
);
} else {
wp_send_json_error( $results->get_error_message() );
}
}
includes/class-wp-links-list-table.php 0000644 00000022031 14717704420 0013774 0 ustar 00 'bookmarks',
'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
)
);
}
/**
* @return bool
*/
public function ajax_user_can() {
return current_user_can( 'manage_links' );
}
/**
* @global int $cat_id
* @global string $s
* @global string $orderby
* @global string $order
*/
public function prepare_items() {
global $cat_id, $s, $orderby, $order;
$cat_id = ! empty( $_REQUEST['cat_id'] ) ? absint( $_REQUEST['cat_id'] ) : 0;
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
$order = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
$s = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
$args = array(
'hide_invisible' => 0,
'hide_empty' => 0,
);
if ( 'all' !== $cat_id ) {
$args['category'] = $cat_id;
}
if ( ! empty( $s ) ) {
$args['search'] = $s;
}
if ( ! empty( $orderby ) ) {
$args['orderby'] = $orderby;
}
if ( ! empty( $order ) ) {
$args['order'] = $order;
}
$this->items = get_bookmarks( $args );
}
/**
*/
public function no_items() {
_e( 'No links found.' );
}
/**
* @return array
*/
protected function get_bulk_actions() {
$actions = array();
$actions['delete'] = __( 'Delete' );
return $actions;
}
/**
* @global int $cat_id
* @param string $which
*/
protected function extra_tablenav( $which ) {
global $cat_id;
if ( 'top' !== $which ) {
return;
}
?>
'; } /** * Download a language pack. * * @since 4.0.0 * * @see wp_get_available_translations() * * @param string $download Language code to download. * @return string|false Returns the language code if successfully downloaded * (or already installed), or false on failure. */ function wp_download_language_pack( $download ) { // Check if the translation is already installed. if ( in_array( $download, get_available_languages(), true ) ) { return $download; } if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) { return false; } // Confirm the translation is one we can download. $translations = wp_get_available_translations(); if ( ! $translations ) { return false; } foreach ( $translations as $translation ) { if ( $translation['language'] === $download ) { $translation_to_load = true; break; } } if ( empty( $translation_to_load ) ) { return false; } $translation = (object) $translation; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $skin = new Automatic_Upgrader_Skin(); $upgrader = new Language_Pack_Upgrader( $skin ); $translation->type = 'core'; $result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) ); if ( ! $result || is_wp_error( $result ) ) { return false; } return $translation->language; } /** * Check if WordPress has access to the filesystem without asking for * credentials. * * @since 4.0.0 * * @return bool Returns true on success, false on failure. */ function wp_can_install_language_pack() { if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) { return false; } require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $skin = new Automatic_Upgrader_Skin(); $upgrader = new Language_Pack_Upgrader( $skin ); $upgrader->init(); $check = $upgrader->fs_connect( array( WP_CONTENT_DIR, WP_LANG_DIR ) ); if ( ! $check || is_wp_error( $check ) ) { return false; } return true; } includes/class-wp-privacy-policy-content.php 0000644 00000100011 14717704420 0015233 0 ustar 00 $plugin_name, 'policy_text' => $policy_text, ); if ( ! in_array( $data, self::$policy_content, true ) ) { self::$policy_content[] = $data; } } /** * Performs a quick check to determine whether any privacy info has changed. * * @since 4.9.6 */ public static function text_change_check() { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); // The site doesn't have a privacy policy. if ( empty( $policy_page_id ) ) { return false; } if ( ! current_user_can( 'edit_post', $policy_page_id ) ) { return false; } $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Updates are not relevant if the user has not reviewed any suggestions yet. if ( empty( $old ) ) { return false; } $cached = get_option( '_wp_suggested_policy_text_has_changed' ); /* * When this function is called before `admin_init`, `self::$policy_content` * has not been populated yet, so use the cached result from the last * execution instead. */ if ( ! did_action( 'admin_init' ) ) { return 'changed' === $cached; } $new = self::$policy_content; // Remove the extra values added to the meta. foreach ( $old as $key => $data ) { if ( ! is_array( $data ) || ! empty( $data['removed'] ) ) { unset( $old[ $key ] ); continue; } $old[ $key ] = array( 'plugin_name' => $data['plugin_name'], 'policy_text' => $data['policy_text'], ); } // Normalize the order of texts, to facilitate comparison. sort( $old ); sort( $new ); /* * The == operator (equal, not identical) was used intentionally. * See https://www.php.net/manual/en/language.operators.array.php */ if ( $new != $old ) { /* * A plugin was activated or deactivated, or some policy text has changed. * Show a notice on the relevant screens to inform the admin. */ add_action( 'admin_notices', array( 'WP_Privacy_Policy_Content', 'policy_text_changed_notice' ) ); $state = 'changed'; } else { $state = 'not-changed'; } // Cache the result for use before `admin_init` (see above). if ( $cached !== $state ) { update_option( '_wp_suggested_policy_text_has_changed', $state, false ); } return 'changed' === $state; } /** * Outputs a warning when some privacy info has changed. * * @since 4.9.6 */ public static function policy_text_changed_notice() { $screen = get_current_screen()->id; if ( 'privacy' !== $screen ) { return; } $privacy_message = sprintf( /* translators: %s: Privacy Policy Guide URL. */ __( 'The suggested privacy policy text has changed. Please review the guide and update your privacy policy.' ), esc_url( admin_url( 'privacy-policy-guide.php?tab=policyguide' ) ) ); wp_admin_notice( $privacy_message, array( 'type' => 'warning', 'additional_classes' => array( 'policy-text-updated' ), 'dismissible' => true, ) ); } /** * Updates the cached policy info when the policy page is updated. * * @since 4.9.6 * @access private * * @param int $post_id The ID of the updated post. */ public static function _policy_page_updated( $post_id ) { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( ! $policy_page_id || $policy_page_id !== (int) $post_id ) { return; } // Remove updated|removed status. $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); $done = array(); $update_cache = false; foreach ( $old as $old_key => $old_data ) { if ( ! empty( $old_data['removed'] ) ) { // Remove the old policy text. $update_cache = true; continue; } if ( ! empty( $old_data['updated'] ) ) { // 'updated' is now 'added'. $done[] = array( 'plugin_name' => $old_data['plugin_name'], 'policy_text' => $old_data['policy_text'], 'added' => $old_data['updated'], ); $update_cache = true; } else { $done[] = $old_data; } } if ( $update_cache ) { delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Update the cache. foreach ( $done as $data ) { add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); } } } /** * Checks for updated, added or removed privacy policy information from plugins. * * Caches the current info in post_meta of the policy page. * * @since 4.9.6 * * @return array The privacy policy text/information added by core and plugins. */ public static function get_suggested_policy_text() { $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); $checked = array(); $time = time(); $update_cache = false; $new = self::$policy_content; $old = array(); if ( $policy_page_id ) { $old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); } // Check for no-changes and updates. foreach ( $new as $new_key => $new_data ) { foreach ( $old as $old_key => $old_data ) { $found = false; if ( $new_data['policy_text'] === $old_data['policy_text'] ) { // Use the new plugin name in case it was changed, translated, etc. if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) { $old_data['plugin_name'] = $new_data['plugin_name']; $update_cache = true; } // A plugin was re-activated. if ( ! empty( $old_data['removed'] ) ) { unset( $old_data['removed'] ); $old_data['added'] = $time; $update_cache = true; } $checked[] = $old_data; $found = true; } elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) { // The info for the policy was updated. $checked[] = array( 'plugin_name' => $new_data['plugin_name'], 'policy_text' => $new_data['policy_text'], 'updated' => $time, ); $found = true; $update_cache = true; } if ( $found ) { unset( $new[ $new_key ], $old[ $old_key ] ); continue 2; } } } if ( ! empty( $new ) ) { // A plugin was activated. foreach ( $new as $new_data ) { if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) { $new_data['added'] = $time; $checked[] = $new_data; } } $update_cache = true; } if ( ! empty( $old ) ) { // A plugin was deactivated. foreach ( $old as $old_data ) { if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) { $data = array( 'plugin_name' => $old_data['plugin_name'], 'policy_text' => $old_data['policy_text'], 'removed' => $time, ); $checked[] = $data; } } $update_cache = true; } if ( $update_cache && $policy_page_id ) { delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' ); // Update the cache. foreach ( $checked as $data ) { add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data ); } } return $checked; } /** * Adds a notice with a link to the guide when editing the privacy policy page. * * @since 4.9.6 * @since 5.0.0 The `$post` parameter was made optional. * * @global WP_Post $post Global post object. * * @param WP_Post|null $post The currently edited post. Default null. */ public static function notice( $post = null ) { if ( is_null( $post ) ) { global $post; } else { $post = get_post( $post ); } if ( ! ( $post instanceof WP_Post ) ) { return; } if ( ! current_user_can( 'manage_privacy_options' ) ) { return; } $current_screen = get_current_screen(); $policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' ); if ( 'post' !== $current_screen->base || $policy_page_id !== $post->ID ) { return; } $message = __( 'Need help putting together your new Privacy Policy page? Check out our guide for recommendations on what content to include, along with policies suggested by your plugins and theme.' ); $url = esc_url( admin_url( 'options-privacy.php?tab=policyguide' ) ); $label = __( 'View Privacy Policy Guide.' ); if ( get_current_screen()->is_block_editor() ) { wp_enqueue_script( 'wp-notices' ); $action = array( 'url' => $url, 'label' => $label, ); wp_add_inline_script( 'wp-notices', sprintf( 'wp.data.dispatch( "core/notices" ).createWarningNotice( "%s", { actions: [ %s ], isDismissible: false } )', $message, wp_json_encode( $action ) ), 'after' ); } else { $message .= sprintf( ' %s %s', $url, $label, /* translators: Hidden accessibility text. */ __( '(opens in a new tab)' ) ); wp_admin_notice( $message, array( 'type' => 'warning', 'additional_classes' => array( 'inline', 'wp-pp-notice' ), ) ); } } /** * Outputs the privacy policy guide together with content from the theme and plugins. * * @since 4.9.6 */ public static function privacy_policy_guide() { $content_array = self::get_suggested_policy_text(); $content = ''; $date_format = __( 'F j, Y' ); foreach ( $content_array as $section ) { $class = ''; $meta = ''; $removed = ''; if ( ! empty( $section['removed'] ) ) { $badge_class = ' red'; $date = date_i18n( $date_format, $section['removed'] ); /* translators: %s: Date of plugin deactivation. */ $badge_title = sprintf( __( 'Removed %s.' ), $date ); /* translators: %s: Date of plugin deactivation. */ $removed = sprintf( __( 'You deactivated this plugin on %s and may no longer need this policy.' ), $date ); $removed = wp_get_admin_notice( $removed, array( 'type' => 'info', 'additional_classes' => array( 'inline' ), ) ); } elseif ( ! empty( $section['updated'] ) ) { $badge_class = ' blue'; $date = date_i18n( $date_format, $section['updated'] ); /* translators: %s: Date of privacy policy text update. */ $badge_title = sprintf( __( 'Updated %s.' ), $date ); } $plugin_name = esc_html( $section['plugin_name'] ); $sanitized_policy_name = sanitize_title_with_dashes( $plugin_name ); ?>
' . __( 'In this section you should note your site URL, as well as the name of the company, organization, or individual behind it, and some accurate contact information.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'The amount of information you may be required to show will vary depending on your local or national business regulations. You may, for example, be required to display a physical address, a registered address, or your company registration number.' ) . '
'; } else { /* translators: Default privacy policy text. %s: Site URL. */ $strings[] = '' . $suggested_text . sprintf( __( 'Our website address is: %s.' ), get_bloginfo( 'url', 'display' ) ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should note what personal data you collect from users and site visitors. This may include personal data, such as name, email address, personal account preferences; transactional data, such as purchase information; and technical data, such as information about cookies.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'You should also note any collection and retention of sensitive personal data, such as data concerning health.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'In addition to listing what personal data you collect, you need to note why you collect it. These explanations must note either the legal basis for your data collection and retention or the active consent the user has given.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'Personal data is not just created by a user’s interactions with your site. Personal data is also generated from technical processes such as contact forms, comments, cookies, analytics, and third party embeds.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'By default WordPress does not collect any personal data about visitors, and only collects the data shown on the User Profile screen from registered users. However some of your plugins may collect personal data. You should add the relevant information below.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this subsection you should note what information is captured through comments. We have noted the data which WordPress collects by default.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this subsection you should note what information may be disclosed by users who can upload media files. All uploaded files are usually publicly accessible.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'By default, WordPress does not include a contact form. If you use a contact form plugin, use this subsection to note what personal data is captured when someone submits a contact form, and how long you keep it. For example, you may note that you keep contact form submissions for a certain period for customer service purposes, but you do not use the information submitted through them for marketing purposes.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this subsection you should list the cookies your website uses, including those set by your plugins, social media, and analytics. We have provided the cookies which WordPress installs by default.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.' ) . '
'; } if ( ! $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . $suggested_text . __( 'Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this subsection you should note what analytics package you use, how users can opt out of analytics tracking, and a link to your analytics provider’s privacy policy, if any.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'By default WordPress does not collect any analytics data. However, many web hosting accounts collect some anonymous analytics data. You may also have installed a WordPress plugin that provides analytics services. In that case, add information from that plugin here.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should name and list all third party providers with whom you share site data, including partners, cloud-based services, payment processors, and third party service providers, and note what data you share with them and why. Link to their own privacy policies if possible.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'By default WordPress does not share any personal data with anyone.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'If you request a password reset, your IP address will be included in the reset email.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should explain how long you retain personal data collected or processed by the website. While it is your responsibility to come up with the schedule of how long you keep each dataset for and why you keep it, that information does need to be listed here. For example, you may want to say that you keep contact form entries for six months, analytics records for a year, and customer purchase records for ten years.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue.' ) . '
'; /* translators: Default privacy policy text. */ $strings[] = '' . __( 'For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should explain what rights your users have over their data and how they can invoke those rights.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.' ) . '
'; } /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should list all transfers of your site data outside the European Union and describe the means by which that data is safeguarded to European data protection standards. This could include your web hosting, cloud storage, or other third party services.' ) . '
'; /* translators: Privacy policy tutorial. */ $strings[] = '' . __( 'European data protection law requires data about European residents which is transferred outside the European Union to be safeguarded to the same standards as if the data was in Europe. So in addition to listing where data goes, you should describe how you ensure that these standards are met either by yourself or by your third party providers, whether that is through an agreement such as Privacy Shield, model clauses in your contracts, or binding corporate rules.' ) . '
'; } else { /* translators: Default privacy policy text. */ $strings[] = '' . $suggested_text . __( 'Visitor comments may be checked through an automated spam detection service.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should provide a contact method for privacy-specific concerns. If you are required to have a Data Protection Officer, list their name and full contact details here as well.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'If you use your site for commercial purposes and you engage in more complex collection or processing of personal data, you should note the following information in your privacy policy in addition to the information we have already discussed.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should explain what measures you have taken to protect your users’ data. This could include technical measures such as encryption; security measures such as two factor authentication; and measures such as staff training in data protection. If you have carried out a Privacy Impact Assessment, you can mention it here too.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'In this section you should explain what procedures you have in place to deal with data breaches, either potential or real, such as internal reporting systems, contact mechanisms, or bug bounties.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'If your website receives data about users from third parties, including advertisers, this information must be included within the section of your privacy policy dealing with third party data.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'If your website provides a service which includes automated decision making - for example, allowing customers to apply for credit, or aggregating their data into an advertising profile - you must note that this is taking place, and include information about how that information is used, what decisions are made with that aggregated data, and what rights users have over decisions made without human intervention.' ) . '
'; } if ( $description ) { /* translators: Default privacy policy heading. */ $strings[] = '' . __( 'If you are a member of a regulated industry, or if you are subject to additional privacy laws, you may be required to disclose that information here.' ) . '
'; $strings[] = '' ) ) { $strings[ $key ] = "\n" . $string . "\n\n"; } if ( str_starts_with( $string, '
' . esc_html_x( 'Active', 'theme' ) . ' | ' . esc_html_x( 'Uploaded', 'theme' ) . ' | ||
---|---|---|---|
' . $label . ' | ' . wp_strip_all_tags( $old_value ) . ' | '; $table .= ( $diff_field || $diff_version || $invalid_parent ) ? '' : ' | '; $table .= wp_strip_all_tags( $new_value ) . ' |
' . esc_html__( 'The theme cannot be updated due to the following:' ) . '
'; $blocked_message .= '' . $warning . '
'; $overwrite = $this->is_downgrading ? 'downgrade-theme' : 'update-theme'; $install_actions['overwrite_theme'] = sprintf( '%s', wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'theme-upload' ), _x( 'Replace active with uploaded', 'theme' ) ); } else { echo $blocked_message; } $cancel_url = add_query_arg( 'action', 'upload-theme-cancel-overwrite', $this->url ); $install_actions['themes_page'] = sprintf( '%s', wp_nonce_url( $cancel_url, 'theme-upload-cancel-overwrite' ), __( 'Cancel and go back' ) ); /** * Filters the list of action links available following a single theme installation failure * when overwriting is allowed. * * @since 5.5.0 * * @param string[] $install_actions Array of theme action links. * @param object $api Object containing WordPress.org API theme data. * @param array $new_theme_data Array with uploaded theme data. */ $install_actions = apply_filters( 'install_theme_overwrite_actions', $install_actions, $this->api, $new_theme_data ); if ( ! empty( $install_actions ) ) { printf( ' ', __( 'The uploaded file has expired. Please go back and upload it again.' ) ); echo '' . implode( ' ', (array) $install_actions ) . '
'; } return true; } } includes/class-wp-media-list-table.php 0000644 00000062035 14717704420 0013743 0 ustar 00 detached = ( isset( $_REQUEST['attachment-filter'] ) && 'detached' === $_REQUEST['attachment-filter'] ); $this->modes = array( 'list' => __( 'List view' ), 'grid' => __( 'Grid view' ), ); parent::__construct( array( 'plural' => 'media', 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, ) ); } /** * @return bool */ public function ajax_user_can() { return current_user_can( 'upload_files' ); } /** * @global string $mode List table view mode. * @global WP_Query $wp_query WordPress Query object. * @global array $post_mime_types * @global array $avail_post_mime_types */ public function prepare_items() { global $mode, $wp_query, $post_mime_types, $avail_post_mime_types; $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; /* * Exclude attachments scheduled for deletion in the next two hours * if they are for zip packages for interrupted or failed updates. * See File_Upload_Upgrader class. */ $not_in = array(); $crons = _get_cron_array(); if ( is_array( $crons ) ) { foreach ( $crons as $cron ) { if ( isset( $cron['upgrader_scheduled_cleanup'] ) ) { $details = reset( $cron['upgrader_scheduled_cleanup'] ); if ( ! empty( $details['args'][0] ) ) { $not_in[] = (int) $details['args'][0]; } } } } if ( ! empty( $_REQUEST['post__not_in'] ) && is_array( $_REQUEST['post__not_in'] ) ) { $not_in = array_merge( array_values( $_REQUEST['post__not_in'] ), $not_in ); } if ( ! empty( $not_in ) ) { $_REQUEST['post__not_in'] = $not_in; } list( $post_mime_types, $avail_post_mime_types ) = wp_edit_attachments_query( $_REQUEST ); $this->is_trash = isset( $_REQUEST['attachment-filter'] ) && 'trash' === $_REQUEST['attachment-filter']; $this->set_pagination_args( array( 'total_items' => $wp_query->found_posts, 'total_pages' => $wp_query->max_num_pages, 'per_page' => $wp_query->query_vars['posts_per_page'], ) ); if ( $wp_query->posts ) { update_post_thumbnail_cache( $wp_query ); update_post_parent_caches( $wp_query->posts ); } } /** * @global array $post_mime_types * @global array $avail_post_mime_types * @return array */ protected function get_views() { global $post_mime_types, $avail_post_mime_types; $type_links = array(); $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter']; $type_links['all'] = sprintf( '', selected( $filter, true, false ), __( 'All media items' ) ); foreach ( $post_mime_types as $mime_type => $label ) { if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) { continue; } $selected = selected( $filter && str_starts_with( $filter, 'post_mime_type:' ) && wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ), true, false ); $type_links[ $mime_type ] = sprintf( '', esc_attr( $mime_type ), $selected, $label[0] ); } $type_links['detached'] = ''; $type_links['mine'] = sprintf( '', selected( 'mine' === $filter, true, false ), _x( 'Mine', 'media items' ) ); if ( $this->is_trash || ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) ) { $type_links['trash'] = sprintf( '', selected( 'trash' === $filter, true, false ), _x( 'Trash', 'attachment filter' ) ); } return $type_links; } /** * @return array */ protected function get_bulk_actions() { $actions = array(); if ( MEDIA_TRASH ) { if ( $this->is_trash ) { $actions['untrash'] = __( 'Restore' ); $actions['delete'] = __( 'Delete permanently' ); } else { $actions['trash'] = __( 'Move to Trash' ); } } else { $actions['delete'] = __( 'Delete permanently' ); } if ( $this->detached ) { $actions['attach'] = __( 'Attach' ); } return $actions; } /** * @param string $which */ protected function extra_tablenav( $which ) { if ( 'bar' !== $which ) { return; } ?>
ID ); echo esc_html( wp_basename( $file ) ); ?>
%s', esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ), get_the_author() ); } /** * Handles the description column output. * * @since 4.3.0 * @deprecated 6.2.0 * * @param WP_Post $post The current WP_Post object. */ public function column_desc( $post ) { _deprecated_function( __METHOD__, '6.2.0' ); echo has_excerpt() ? $post->post_excerpt : ''; } /** * Handles the date column output. * * @since 4.3.0 * * @param WP_Post $post The current WP_Post object. */ public function column_date( $post ) { if ( '0000-00-00 00:00:00' === $post->post_date ) { $h_time = __( 'Unpublished' ); } else { $time = get_post_timestamp( $post ); $time_diff = time() - $time; if ( $time && $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) { /* translators: %s: Human-readable time difference. */ $h_time = sprintf( __( '%s ago' ), human_time_diff( $time ) ); } else { $h_time = get_the_time( __( 'Y/m/d' ), $post ); } } /** * Filters the published time of an attachment displayed in the Media list table. * * @since 6.0.0 * * @param string $h_time The published time. * @param WP_Post $post Attachment object. * @param string $column_name The column name. */ echo apply_filters( 'media_date_column_time', $h_time, $post, 'date' ); } /** * Handles the parent column output. * * @since 4.3.0 * * @param WP_Post $post The current WP_Post object. */ public function column_parent( $post ) { $user_can_edit = current_user_can( 'edit_post', $post->ID ); if ( $post->post_parent > 0 ) { $parent = get_post( $post->post_parent ); } else { $parent = false; } if ( $parent ) { $title = _draft_or_post_title( $post->post_parent ); $parent_type = get_post_type_object( $parent->post_type ); if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $post->post_parent ) ) { printf( '%s', get_edit_post_link( $post->post_parent ), $title ); } elseif ( $parent_type && current_user_can( 'read_post', $post->post_parent ) ) { printf( '%s', $title ); } else { _e( '(Private post)' ); } if ( $user_can_edit ) : $detach_url = add_query_arg( array( 'parent_post_id' => $post->post_parent, 'media[]' => $post->ID, '_wpnonce' => wp_create_nonce( 'bulk-' . $this->_args['plural'] ), ), 'upload.php' ); printf( '.po
',
'.mo
',
'.l10n.php
'
)
);
}
return $source;
}
/**
* Gets the name of an item being updated.
*
* @since 3.7.0
*
* @param object $update The data for an update.
* @return string The name of the item being updated.
*/
public function get_name_for_update( $update ) {
switch ( $update->type ) {
case 'core':
return 'WordPress'; // Not translated.
case 'theme':
$theme = wp_get_theme( $update->slug );
if ( $theme->exists() ) {
return $theme->Get( 'Name' );
}
break;
case 'plugin':
$plugin_data = get_plugins( '/' . $update->slug );
$plugin_data = reset( $plugin_data );
if ( $plugin_data ) {
return $plugin_data['Name'];
}
break;
}
return '';
}
/**
* Clears existing translations where this item is going to be installed into.
*
* @since 5.1.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $remote_destination The location on the remote filesystem to be cleared.
* @return bool|WP_Error True upon success, WP_Error on failure.
*/
public function clear_destination( $remote_destination ) {
global $wp_filesystem;
$language_update = $this->skin->language_update;
$language_directory = WP_LANG_DIR . '/'; // Local path for use with glob().
if ( 'core' === $language_update->type ) {
$files = array(
$remote_destination . $language_update->language . '.po',
$remote_destination . $language_update->language . '.mo',
$remote_destination . $language_update->language . '.l10n.php',
$remote_destination . 'admin-' . $language_update->language . '.po',
$remote_destination . 'admin-' . $language_update->language . '.mo',
$remote_destination . 'admin-' . $language_update->language . '.l10n.php',
$remote_destination . 'admin-network-' . $language_update->language . '.po',
$remote_destination . 'admin-network-' . $language_update->language . '.mo',
$remote_destination . 'admin-network-' . $language_update->language . '.l10n.php',
$remote_destination . 'continents-cities-' . $language_update->language . '.po',
$remote_destination . 'continents-cities-' . $language_update->language . '.mo',
$remote_destination . 'continents-cities-' . $language_update->language . '.l10n.php',
);
$json_translation_files = glob( $language_directory . $language_update->language . '-*.json' );
if ( $json_translation_files ) {
foreach ( $json_translation_files as $json_translation_file ) {
$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
}
}
} else {
$files = array(
$remote_destination . $language_update->slug . '-' . $language_update->language . '.po',
$remote_destination . $language_update->slug . '-' . $language_update->language . '.mo',
$remote_destination . $language_update->slug . '-' . $language_update->language . '.l10n.php',
);
$language_directory = $language_directory . $language_update->type . 's/';
$json_translation_files = glob( $language_directory . $language_update->slug . '-' . $language_update->language . '-*.json' );
if ( $json_translation_files ) {
foreach ( $json_translation_files as $json_translation_file ) {
$files[] = str_replace( $language_directory, $remote_destination, $json_translation_file );
}
}
}
$files = array_filter( $files, array( $wp_filesystem, 'exists' ) );
// No files to delete.
if ( ! $files ) {
return true;
}
// Check all files are writable before attempting to clear the destination.
$unwritable_files = array();
// Check writability.
foreach ( $files as $file ) {
if ( ! $wp_filesystem->is_writable( $file ) ) {
// Attempt to alter permissions to allow writes and try again.
$wp_filesystem->chmod( $file, FS_CHMOD_FILE );
if ( ! $wp_filesystem->is_writable( $file ) ) {
$unwritable_files[] = $file;
}
}
}
if ( ! empty( $unwritable_files ) ) {
return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
}
foreach ( $files as $file ) {
if ( ! $wp_filesystem->delete( $file ) ) {
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
}
}
return true;
}
}
includes/plugin-install.php 0000644 00000115062 14717704420 0012040 0 ustar 00 per_page ) ) {
$args->per_page = 24;
}
}
if ( ! isset( $args->locale ) ) {
$args->locale = get_user_locale();
}
if ( ! isset( $args->wp_version ) ) {
$args->wp_version = substr( wp_get_wp_version(), 0, 3 ); // x.y
}
/**
* Filters the WordPress.org Plugin Installation API arguments.
*
* Important: An object MUST be returned to this filter.
*
* @since 2.7.0
*
* @param object $args Plugin API arguments.
* @param string $action The type of information being requested from the Plugin Installation API.
*/
$args = apply_filters( 'plugins_api_args', $args, $action );
/**
* Filters the response for the current WordPress.org Plugin Installation API request.
*
* Returning a non-false value will effectively short-circuit the WordPress.org API request.
*
* If `$action` is 'query_plugins' or 'plugin_information', an object MUST be passed.
* If `$action` is 'hot_tags', an array should be passed.
*
* @since 2.7.0
*
* @param false|object|array $result The result object or array. Default false.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
$res = apply_filters( 'plugins_api', false, $action, $args );
if ( false === $res ) {
$url = 'http://api.wordpress.org/plugins/info/1.2/';
$url = add_query_arg(
array(
'action' => $action,
'request' => $args,
),
$url
);
$http_url = $url;
$ssl = wp_http_supports( array( 'ssl' ) );
if ( $ssl ) {
$url = set_url_scheme( $url, 'https' );
}
$http_args = array(
'timeout' => 15,
'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
);
$request = wp_remote_get( $url, $http_args );
if ( $ssl && is_wp_error( $request ) ) {
if ( ! wp_is_json_request() ) {
wp_trigger_error(
__FUNCTION__,
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ),
__( 'https://wordpress.org/support/forums/' )
) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),
headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
);
}
$request = wp_remote_get( $http_url, $http_args );
}
if ( is_wp_error( $request ) ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ),
__( 'https://wordpress.org/support/forums/' )
),
$request->get_error_message()
);
} else {
$res = json_decode( wp_remote_retrieve_body( $request ), true );
if ( is_array( $res ) ) {
// Object casting is required in order to match the info/1.0 format.
$res = (object) $res;
} elseif ( null === $res ) {
$res = new WP_Error(
'plugins_api_failed',
sprintf(
/* translators: %s: Support forums URL. */
__( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the support forums.' ),
__( 'https://wordpress.org/support/forums/' )
),
wp_remote_retrieve_body( $request )
);
}
if ( isset( $res->error ) ) {
$res = new WP_Error( 'plugins_api_failed', $res->error );
}
}
} elseif ( ! is_wp_error( $res ) ) {
$res->external = true;
}
/**
* Filters the Plugin Installation API response results.
*
* @since 2.7.0
*
* @param object|WP_Error $res Response object or WP_Error.
* @param string $action The type of information being requested from the Plugin Installation API.
* @param object $args Plugin API arguments.
*/
return apply_filters( 'plugins_api_result', $res, $action, $args );
}
/**
* Retrieves popular WordPress plugin tags.
*
* @since 2.7.0
*
* @param array $args
* @return array|WP_Error
*/
function install_popular_tags( $args = array() ) {
$key = md5( serialize( $args ) );
$tags = get_site_transient( 'poptags_' . $key );
if ( false !== $tags ) {
return $tags;
}
$tags = plugins_api( 'hot_tags', $args );
if ( is_wp_error( $tags ) ) {
return $tags;
}
set_site_transient( 'poptags_' . $key, $tags, 3 * HOUR_IN_SECONDS );
return $tags;
}
/**
* Displays the Featured tab of Add Plugins screen.
*
* @since 2.7.0
*/
function install_dashboard() {
display_plugins_table();
?>
';
}
/**
* Displays a search form for searching plugins.
*
* @since 2.7.0
* @since 4.6.0 The `$type_selector` parameter was deprecated.
*
* @param bool $deprecated Not used.
*/
function install_search_form( $deprecated = true ) {
$type = isset( $_REQUEST['type'] ) ? wp_unslash( $_REQUEST['type'] ) : 'term';
$term = isset( $_REQUEST['s'] ) ? urldecode( wp_unslash( $_REQUEST['s'] ) ) : '';
?>
' . __( 'Plugins extend and expand the functionality of WordPress. You may install plugins in the WordPress Plugin Directory right from here, or upload a plugin in .zip format by clicking the button at the top of this page.' ) . '
', __( 'https://wordpress.org/plugins/' ) ); break; case 'install_plugins_recommended': echo '' . __( 'These suggestions are based on the plugins you and other users have installed.' ) . '
'; break; case 'install_plugins_favorites': if ( empty( $_GET['user'] ) && ! get_user_option( 'wporg_favorites' ) ) { return; } break; } ?> response ) ) { foreach ( (array) $update_plugins->response as $file => $plugin ) { if ( $plugin->slug === $api->slug ) { $status = 'update_available'; $update_file = $file; $version = $plugin->new_version; if ( current_user_can( 'update_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . $update_file ), 'upgrade-plugin_' . $update_file ); } break; } } } if ( 'install' === $status ) { if ( is_dir( WP_PLUGIN_DIR . '/' . $api->slug ) ) { $installed_plugin = get_plugins( '/' . $api->slug ); if ( empty( $installed_plugin ) ) { if ( current_user_can( 'install_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } } else { $key = array_keys( $installed_plugin ); /* * Use the first plugin regardless of the name. * Could have issues for multiple plugins in one directory if they share different version numbers. */ $key = reset( $key ); $update_file = $api->slug . '/' . $key; if ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '=' ) ) { $status = 'latest_installed'; } elseif ( version_compare( $api->version, $installed_plugin[ $key ]['Version'], '<' ) ) { $status = 'newer_installed'; $version = $installed_plugin[ $key ]['Version']; } else { // If the above update check failed, then that probably means that the update checker has out-of-date information, force a refresh. if ( ! $loop ) { delete_site_transient( 'update_plugins' ); wp_update_plugins(); return install_plugin_install_status( $api, true ); } } } } else { // "install" & no directory with that slug. if ( current_user_can( 'install_plugins' ) ) { $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $api->slug ), 'install-plugin_' . $api->slug ); } } } if ( isset( $_GET['from'] ) ) { $url .= '&from=' . urlencode( wp_unslash( $_GET['from'] ) ); } $file = $update_file; return compact( 'status', 'url', 'version', 'file' ); } /** * Displays plugin information in dialog box form. * * @since 2.7.0 * * @global string $tab */ function install_plugin_information() { global $tab; if ( empty( $_REQUEST['plugin'] ) ) { return; } $api = plugins_api( 'plugin_information', array( 'slug' => wp_unslash( $_REQUEST['plugin'] ), ) ); if ( is_wp_error( $api ) ) { wp_die( $api ); } $plugins_allowedtags = array( 'a' => array( 'href' => array(), 'title' => array(), 'target' => array(), ), 'abbr' => array( 'title' => array() ), 'acronym' => array( 'title' => array() ), 'code' => array(), 'pre' => array(), 'em' => array(), 'strong' => array(), 'div' => array( 'class' => array() ), 'span' => array( 'class' => array() ), 'p' => array(), 'br' => array(), 'ul' => array(), 'ol' => array(), 'li' => array(), 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(), 'img' => array( 'src' => array(), 'class' => array(), 'alt' => array(), ), 'blockquote' => array( 'cite' => true ), ); $plugins_section_titles = array( 'description' => _x( 'Description', 'Plugin installer section title' ), 'installation' => _x( 'Installation', 'Plugin installer section title' ), 'faq' => _x( 'FAQ', 'Plugin installer section title' ), 'screenshots' => _x( 'Screenshots', 'Plugin installer section title' ), 'changelog' => _x( 'Changelog', 'Plugin installer section title' ), 'reviews' => _x( 'Reviews', 'Plugin installer section title' ), 'other_notes' => _x( 'Other Notes', 'Plugin installer section title' ), ); // Sanitize HTML. foreach ( (array) $api->sections as $section_name => $content ) { $api->sections[ $section_name ] = wp_kses( $content, $plugins_allowedtags ); } foreach ( array( 'version', 'author', 'requires', 'tested', 'homepage', 'downloaded', 'slug' ) as $key ) { if ( isset( $api->$key ) ) { $api->$key = wp_kses( $api->$key, $plugins_allowedtags ); } } $_tab = esc_attr( $tab ); // Default to the Description tab, Do not translate, API returns English. $section = isset( $_REQUEST['section'] ) ? wp_unslash( $_REQUEST['section'] ) : 'description'; if ( empty( $section ) || ! isset( $api->sections[ $section ] ) ) { $section_titles = array_keys( (array) $api->sections ); $section = reset( $section_titles ); } iframe_header( __( 'Plugin Installation' ) ); $_with_banner = ''; if ( ! empty( $api->banners ) && ( ! empty( $api->banners['low'] ) || ! empty( $api->banners['high'] ) ) ) { $_with_banner = 'with-banner'; $low = empty( $api->banners['low'] ) ? $api->banners['high'] : $api->banners['low']; $high = empty( $api->banners['high'] ) ? $api->banners['low'] : $api->banners['high']; ?> '; echo "'; $compatible_php_notice_message .= __( 'Error: This plugin requires a newer version of PHP.' ); if ( current_user_can( 'update_php' ) ) { $compatible_php_notice_message .= sprintf( /* translators: %s: URL to Update PHP page. */ ' ' . __( 'Click here to learn more about updating PHP.' ), esc_url( wp_get_update_php_url() ) ) . wp_update_php_annotation( '
', '', false ); } else { $compatible_php_notice_message .= '
'; } wp_admin_notice( $compatible_php_notice_message, array( 'type' => 'error', 'additional_classes' => array( 'notice-alt' ), 'paragraph_wrap' => false, ) ); } if ( ! $tested_wp ) { wp_admin_notice( __( 'Warning: This plugin has not been tested with your current version of WordPress.' ), array( 'type' => 'warning', 'additional_classes' => array( 'notice-alt' ), ) ); } elseif ( ! $compatible_wp ) { $compatible_wp_notice_message = __( 'Error: This plugin requires a newer version of WordPress.' ); if ( current_user_can( 'update_core' ) ) { $compatible_wp_notice_message .= sprintf( /* translators: %s: URL to WordPress Updates screen. */ ' ' . __( 'Click here to update WordPress.' ), esc_url( self_admin_url( 'update-core.php' ) ) ); } wp_admin_notice( $compatible_wp_notice_message, array( 'type' => 'error', 'additional_classes' => array( 'notice-alt' ), ) ); } foreach ( (array) $api->sections as $section_name => $content ) { $content = links_add_base_url( $content, 'https://wordpress.org/plugins/' . $api->slug . '/' ); $content = links_add_target( $content, '_blank' ); $san_section = esc_attr( $section_name ); $display = ( $section_name === $section ) ? 'block' : 'none'; echo "\t$feedback
\n"; } } /** * Displays the header before the update process. * * @since 3.0.0 */ public function header() { // Nothing. This will be displayed within an iframe. } /** * Displays the footer following the update process. * * @since 3.0.0 */ public function footer() { // Nothing. This will be displayed within an iframe. } /** * Displays an error message about the update. * * @since 3.0.0 * @since 5.9.0 Renamed `$error` to `$errors` for PHP 8 named parameter support. * * @param string|WP_Error $errors Errors. */ public function error( $errors ) { if ( is_string( $errors ) && isset( $this->upgrader->strings[ $errors ] ) ) { $this->error = $this->upgrader->strings[ $errors ]; } if ( is_wp_error( $errors ) ) { $messages = array(); foreach ( $errors->get_error_messages() as $emessage ) { if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) { $messages[] = $emessage . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ); } else { $messages[] = $emessage; } } $this->error = implode( ', ', $messages ); } echo ''; } /** * Displays the header before the bulk update process. * * @since 3.0.0 */ public function bulk_header() { $this->feedback( 'skin_upgrade_start' ); } /** * Displays the footer following the bulk update process. * * @since 3.0.0 */ public function bulk_footer() { $this->feedback( 'skin_upgrade_end' ); } /** * Performs an action before a bulk update. * * @since 3.0.0 * * @param string $title */ public function before( $title = '' ) { $this->in_loop = true; printf( '' . sprintf( $this->upgrader->strings['skin_update_successful'], $title ) . ' ' . '
$msg->error
$msg->msg
' . $meta['width'] . ' × ' . $meta['height'] . '' ); ?>
' . __( 'This screen is used to customize the header section of your theme.' ) . '
' . '' . __( 'You can choose from the theme’s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.' ) . '
', ) ); get_current_screen()->add_help_tab( array( 'id' => 'set-header-image', 'title' => __( 'Header Image' ), 'content' => '
' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the “Choose Image” button.' ) . '
' . '' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you would like and click the “Save Changes” button.' ) . '
' . '' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the “Random” radio button next to the Uploaded Images or Default Images section to enable this feature.' ) . '
' . '' . __( 'If you do not want a header image to be displayed on your site at all, click the “Remove Header Image” button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click “Save Changes”.' ) . '
', ) ); get_current_screen()->add_help_tab( array( 'id' => 'set-header-text', 'title' => __( 'Header Text' ), 'content' => '' . sprintf( /* translators: %s: URL to General Settings screen. */ __( 'For most themes, the header text is your Site Title and Tagline, as defined in the General Settings section.' ), admin_url( 'options-general.php' ) ) . '
' . '' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. “#ff0000” for red, or by choosing a color using the color picker.' ) . '
' . '' . __( 'Do not forget to click “Save Changes” when you are done!' ) . '
', ) ); get_current_screen()->set_help_sidebar( '' . __( 'For more information:' ) . '
' . '' . __( 'Documentation on Custom Header' ) . '
' . '' . __( 'Support forums' ) . '
' ); } /** * Gets the current step. * * @since 2.6.0 * * @return int Current step. */ public function step() { if ( ! isset( $_GET['step'] ) ) { return 1; } $step = (int) $_GET['step']; if ( $step < 1 || 3 < $step || ( 2 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) || ( 3 === $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) ) ) { return 1; } return $step; } /** * Sets up the enqueue for the JavaScript files. * * @since 2.1.0 */ public function js_includes() { $step = $this->step(); if ( ( 1 === $step || 3 === $step ) ) { wp_enqueue_media(); wp_enqueue_script( 'custom-header' ); if ( current_theme_supports( 'custom-header', 'header-text' ) ) { wp_enqueue_script( 'wp-color-picker' ); } } elseif ( 2 === $step ) { wp_enqueue_script( 'imgareaselect' ); } } /** * Sets up the enqueue for the CSS files. * * @since 2.7.0 */ public function css_includes() { $step = $this->step(); if ( ( 1 === $step || 3 === $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) { wp_enqueue_style( 'wp-color-picker' ); } elseif ( 2 === $step ) { wp_enqueue_style( 'imgareaselect' ); } } /** * Executes custom header modification. * * @since 2.6.0 */ public function take_action() { if ( ! current_user_can( 'edit_theme_options' ) ) { return; } if ( empty( $_POST ) ) { return; } $this->updated = true; if ( isset( $_POST['resetheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $this->reset_header_image(); return; } if ( isset( $_POST['removeheader'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $this->remove_header_image(); return; } if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); set_theme_mod( 'header_textcolor', 'blank' ); } elseif ( isset( $_POST['text-color'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] ); $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); if ( strlen( $color ) === 6 || strlen( $color ) === 3 ) { set_theme_mod( 'header_textcolor', $color ); } elseif ( ! $color ) { set_theme_mod( 'header_textcolor', 'blank' ); } } if ( isset( $_POST['default-header'] ) ) { check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); $this->set_header_image( $_POST['default-header'] ); return; } } /** * Processes the default headers. * * @since 3.0.0 * * @global array $_wp_default_headers */ public function process_default_headers() { global $_wp_default_headers; if ( ! isset( $_wp_default_headers ) ) { return; } if ( ! empty( $this->default_headers ) ) { return; } $this->default_headers = $_wp_default_headers; $template_directory_uri = get_template_directory_uri(); $stylesheet_directory_uri = get_stylesheet_directory_uri(); foreach ( array_keys( $this->default_headers ) as $header ) { $this->default_headers[ $header ]['url'] = sprintf( $this->default_headers[ $header ]['url'], $template_directory_uri, $stylesheet_directory_uri ); $this->default_headers[ $header ]['thumbnail_url'] = sprintf( $this->default_headers[ $header ]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri ); } } /** * Displays UI for selecting one of several default headers. * * Shows the random image option if this theme has multiple header images. * Random image option is on by default if no header has been set. * * @since 3.0.0 * * @param string $type The header type. One of 'default' (for the Uploaded Images control) * or 'uploaded' (for the Uploaded Images control). */ public function show_header_selector( $type = 'default' ) { if ( 'default' === $type ) { $headers = $this->default_headers; } else { $headers = get_uploaded_header_images(); $type = 'uploaded'; } if ( 1 < count( $headers ) ) { echo 'admin_image_div_callback ) { call_user_func( $this->admin_image_div_callback ); } else { $custom_header = get_custom_header(); $header_image = get_header_image(); if ( $header_image ) { $header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');'; } else { $header_image_style = ''; } if ( $custom_header->width ) { $header_image_style .= 'max-width:' . $custom_header->width . 'px;'; } if ( $custom_header->height ) { $header_image_style .= 'height:' . $custom_header->height . 'px;'; } ?> | |
|
' . __( 'The active theme does not support uploading a custom header image.' ) . '
', 403 ); } if ( empty( $_POST ) && isset( $_GET['file'] ) ) { $attachment_id = absint( $_GET['file'] ); $file = get_attached_file( $attachment_id, true ); $url = wp_get_attachment_image_src( $attachment_id, 'full' ); $url = $url[0]; } elseif ( isset( $_POST ) ) { $data = $this->step_2_manage_upload(); $attachment_id = $data['attachment_id']; $file = $data['file']; $url = $data['url']; } if ( file_exists( $file ) ) { list( $width, $height, $type, $attr ) = wp_getimagesize( $file ); } else { $data = wp_get_attachment_metadata( $attachment_id ); $height = isset( $data['height'] ) ? (int) $data['height'] : 0; $width = isset( $data['width'] ) ? (int) $data['width'] : 0; unset( $data ); } $max_width = 0; // For flex, limit size of image displayed to 1500px unless theme says otherwise. if ( current_theme_supports( 'custom-header', 'flex-width' ) ) { $max_width = 1500; } if ( current_theme_supports( 'custom-header', 'max-width' ) ) { $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); } $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); // If flexible height isn't supported and the image is the exact right size. if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) && (int) get_theme_support( 'custom-header', 'width' ) === $width && (int) get_theme_support( 'custom-header', 'height' ) === $height ) { // Add the metadata. if ( file_exists( $file ) ) { wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) ); } $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); /** * Filters the attachment file path after the custom header or background image is set. * * Used for file replication. * * @since 2.1.0 * * @param string $file Path to the file. * @param int $attachment_id Attachment ID. */ $file = apply_filters( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication. return $this->finished(); } elseif ( $width > $max_width ) { $oitar = $width / $max_width; $image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) ); if ( ! $image || is_wp_error( $image ) ) { wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); } /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication. $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url ); $width = $width / $oitar; $height = $height / $oitar; } else { $oitar = 1; } ?>' . __( 'The active theme does not support uploading a custom header image.' ) . '
', 403 ); } if ( ! empty( $_POST['skip-cropping'] ) && ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { wp_die( '' . __( 'The active theme does not support a flexible sized header image.' ) . '
', 403 ); } if ( $_POST['oitar'] > 1 ) { $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; $_POST['width'] = $_POST['width'] * $_POST['oitar']; $_POST['height'] = $_POST['height'] * $_POST['oitar']; } $attachment_id = absint( $_POST['attachment_id'] ); $original = get_attached_file( $attachment_id ); $dimensions = $this->get_header_dimensions( array( 'height' => $_POST['height'], 'width' => $_POST['width'], ) ); $height = $dimensions['dst_height']; $width = $dimensions['dst_width']; if ( empty( $_POST['skip-cropping'] ) ) { $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $width, $height ); } elseif ( ! empty( $_POST['create-new-attachment'] ) ) { $cropped = _copy_image_file( $attachment_id ); } else { $cropped = get_attached_file( $attachment_id ); } if ( ! $cropped || is_wp_error( $cropped ) ) { wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); } /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. $attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, 'custom-header' ); if ( ! empty( $_POST['create-new-attachment'] ) ) { unset( $attachment['ID'] ); } // Update the attachment. $attachment_id = $this->insert_attachment( $attachment, $cropped ); $url = wp_get_attachment_url( $attachment_id ); $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); // Cleanup. $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original ); if ( file_exists( $medium ) ) { wp_delete_file( $medium ); } if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) { wp_delete_file( $original ); } return $this->finished(); } /** * Displays last step of custom header image page. * * @since 2.1.0 */ public function finished() { $this->updated = true; $this->step_1(); } /** * Displays the page based on the current step. * * @since 2.1.0 */ public function admin_page() { if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( __( 'Sorry, you are not allowed to customize headers.' ) ); } $step = $this->step(); if ( 2 === $step ) { $this->step_2(); } elseif ( 3 === $step ) { $this->step_3(); } else { $this->step_1(); } } /** * Unused since 3.5.0. * * @since 3.4.0 * * @param array $form_fields * @return array $form_fields */ public function attachment_fields_to_edit( $form_fields ) { return $form_fields; } /** * Unused since 3.5.0. * * @since 3.4.0 * * @param array $tabs * @return array $tabs */ public function filter_upload_tabs( $tabs ) { return $tabs; } /** * Chooses a header image, selected from existing uploaded and default headers, * or provides an array of uploaded header data (either new, or from media library). * * @since 3.4.0 * * @param mixed $choice Which header image to select. Allows for values of 'random-default-image', * for randomly cycling among the default images; 'random-uploaded-image', * for randomly cycling among the uploaded images; the key of a default image * registered for that theme; and the key of an image uploaded for that theme * (the attachment ID of the image). Or an array of arguments: attachment_id, * url, width, height. All are required. */ final public function set_header_image( $choice ) { if ( is_array( $choice ) || is_object( $choice ) ) { $choice = (array) $choice; if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) { return; } $choice['url'] = sanitize_url( $choice['url'] ); $header_image_data = (object) array( 'attachment_id' => $choice['attachment_id'], 'url' => $choice['url'], 'thumbnail_url' => $choice['url'], 'height' => $choice['height'], 'width' => $choice['width'], ); update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() ); set_theme_mod( 'header_image', $choice['url'] ); set_theme_mod( 'header_image_data', $header_image_data ); return; } if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) { set_theme_mod( 'header_image', $choice ); remove_theme_mod( 'header_image_data' ); return; } $uploaded = get_uploaded_header_images(); if ( $uploaded && isset( $uploaded[ $choice ] ) ) { $header_image_data = $uploaded[ $choice ]; } else { $this->process_default_headers(); if ( isset( $this->default_headers[ $choice ] ) ) { $header_image_data = $this->default_headers[ $choice ]; } else { return; } } set_theme_mod( 'header_image', sanitize_url( $header_image_data['url'] ) ); set_theme_mod( 'header_image_data', $header_image_data ); } /** * Removes a header image. * * @since 3.4.0 */ final public function remove_header_image() { $this->set_header_image( 'remove-header' ); } /** * Resets a header image to the default image for the theme. * * This method does not do anything if the theme does not have a default header image. * * @since 3.4.0 */ final public function reset_header_image() { $this->process_default_headers(); $default = get_theme_support( 'custom-header', 'default-image' ); if ( ! $default ) { $this->remove_header_image(); return; } $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); $default_data = array(); foreach ( $this->default_headers as $header => $details ) { if ( $details['url'] === $default ) { $default_data = $details; break; } } set_theme_mod( 'header_image', $default ); set_theme_mod( 'header_image_data', (object) $default_data ); } /** * Calculates width and height based on what the currently selected theme supports. * * @since 3.9.0 * * @param array $dimensions * @return array dst_height and dst_width of header image. */ final public function get_header_dimensions( $dimensions ) { $max_width = 0; $width = absint( $dimensions['width'] ); $height = absint( $dimensions['height'] ); $theme_height = get_theme_support( 'custom-header', 'height' ); $theme_width = get_theme_support( 'custom-header', 'width' ); $has_flex_width = current_theme_supports( 'custom-header', 'flex-width' ); $has_flex_height = current_theme_supports( 'custom-header', 'flex-height' ); $has_max_width = current_theme_supports( 'custom-header', 'max-width' ); $dst = array( 'dst_height' => null, 'dst_width' => null, ); // For flex, limit size of image displayed to 1500px unless theme says otherwise. if ( $has_flex_width ) { $max_width = 1500; } if ( $has_max_width ) { $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); } $max_width = max( $max_width, $theme_width ); if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) { $dst['dst_height'] = absint( $height * ( $max_width / $width ) ); } elseif ( $has_flex_height && $has_flex_width ) { $dst['dst_height'] = $height; } else { $dst['dst_height'] = $theme_height; } if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) { $dst['dst_width'] = absint( $width * ( $max_width / $width ) ); } elseif ( $has_flex_width && $has_flex_height ) { $dst['dst_width'] = $width; } else { $dst['dst_width'] = $theme_width; } return $dst; } /** * Creates an attachment 'object'. * * @since 3.9.0 * @deprecated 6.5.0 * * @param string $cropped Cropped image URL. * @param int $parent_attachment_id Attachment ID of parent image. * @return array An array with attachment object data. */ final public function create_attachment_object( $cropped, $parent_attachment_id ) { _deprecated_function( __METHOD__, '6.5.0', 'wp_copy_parent_attachment_properties()' ); $parent = get_post( $parent_attachment_id ); $parent_url = wp_get_attachment_url( $parent->ID ); $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); $size = wp_getimagesize( $cropped ); $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; $attachment = array( 'ID' => $parent_attachment_id, 'post_title' => wp_basename( $cropped ), 'post_mime_type' => $image_type, 'guid' => $url, 'context' => 'custom-header', 'post_parent' => $parent_attachment_id, ); return $attachment; } /** * Inserts an attachment and its metadata. * * @since 3.9.0 * * @param array $attachment An array with attachment object data. * @param string $cropped File path to cropped image. * @return int Attachment ID. */ final public function insert_attachment( $attachment, $cropped ) { $parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null; unset( $attachment['post_parent'] ); $attachment_id = wp_insert_attachment( $attachment, $cropped ); $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); // If this is a crop, save the original attachment ID as metadata. if ( $parent_id ) { $metadata['attachment_parent'] = $parent_id; } /** * Filters the header image attachment metadata. * * @since 3.9.0 * * @see wp_generate_attachment_metadata() * * @param array $metadata Attachment metadata. */ $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata ); wp_update_attachment_metadata( $attachment_id, $metadata ); return $attachment_id; } /** * Gets attachment uploaded by Media Manager, crops it, then saves it as a * new object. Returns JSON-encoded object details. * * @since 3.9.0 */ public function ajax_header_crop() { check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error(); } if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) { wp_send_json_error(); } $crop_details = $_POST['cropDetails']; $dimensions = $this->get_header_dimensions( array( 'height' => $crop_details['height'], 'width' => $crop_details['width'], ) ); $attachment_id = absint( $_POST['id'] ); $cropped = wp_crop_image( $attachment_id, (int) $crop_details['x1'], (int) $crop_details['y1'], (int) $crop_details['width'], (int) $crop_details['height'], (int) $dimensions['dst_width'], (int) $dimensions['dst_height'] ); if ( ! $cropped || is_wp_error( $cropped ) ) { wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) ); } /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. $attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, 'custom-header' ); $previous = $this->get_previous_crop( $attachment ); if ( $previous ) { $attachment['ID'] = $previous; } else { unset( $attachment['ID'] ); } $new_attachment_id = $this->insert_attachment( $attachment, $cropped ); $attachment['attachment_id'] = $new_attachment_id; $attachment['url'] = wp_get_attachment_url( $new_attachment_id ); $attachment['width'] = $dimensions['dst_width']; $attachment['height'] = $dimensions['dst_height']; wp_send_json_success( $attachment ); } /** * Given an attachment ID for a header image, updates its "last used" * timestamp to now. * * Triggered when the user tries adds a new header image from the * Media Manager, even if s/he doesn't save that change. * * @since 3.9.0 */ public function ajax_header_add() { check_ajax_referer( 'header-add', 'nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error(); } $attachment_id = absint( $_POST['attachment_id'] ); if ( $attachment_id < 1 ) { wp_send_json_error(); } $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); update_post_meta( $attachment_id, $key, time() ); update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); wp_send_json_success(); } /** * Given an attachment ID for a header image, unsets it as a user-uploaded * header image for the active theme. * * Triggered when the user clicks the overlay "X" button next to each image * choice in the Customizer's Header tool. * * @since 3.9.0 */ public function ajax_header_remove() { check_ajax_referer( 'header-remove', 'nonce' ); if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error(); } $attachment_id = absint( $_POST['attachment_id'] ); if ( $attachment_id < 1 ) { wp_send_json_error(); } $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); delete_post_meta( $attachment_id, $key ); delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() ); wp_send_json_success(); } /** * Updates the last-used postmeta on a header image attachment after saving a new header image via the Customizer. * * @since 3.9.0 * * @param WP_Customize_Manager $wp_customize Customize manager. */ public function customize_set_last_used( $wp_customize ) { $header_image_data_setting = $wp_customize->get_setting( 'header_image_data' ); if ( ! $header_image_data_setting ) { return; } $data = $header_image_data_setting->post_value(); if ( ! isset( $data['attachment_id'] ) ) { return; } $attachment_id = $data['attachment_id']; $key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); update_post_meta( $attachment_id, $key, time() ); } /** * Gets the details of default header images if defined. * * @since 3.9.0 * * @return array Default header images. */ public function get_default_header_images() { $this->process_default_headers(); // Get the default image if there is one. $default = get_theme_support( 'custom-header', 'default-image' ); if ( ! $default ) { // If not, easy peasy. return $this->default_headers; } $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); $already_has_default = false; foreach ( $this->default_headers as $k => $h ) { if ( $h['url'] === $default ) { $already_has_default = true; break; } } if ( $already_has_default ) { return $this->default_headers; } // If the one true image isn't included in the default set, prepend it. $header_images = array(); $header_images['default'] = array( 'url' => $default, 'thumbnail_url' => $default, 'description' => 'Default', ); // The rest of the set comes after. return array_merge( $header_images, $this->default_headers ); } /** * Gets the previously uploaded header images. * * @since 3.9.0 * * @return array Uploaded header images. */ public function get_uploaded_header_images() { $header_images = get_uploaded_header_images(); $timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet(); $alt_text_key = '_wp_attachment_image_alt'; foreach ( $header_images as &$header_image ) { $header_meta = get_post_meta( $header_image['attachment_id'] ); $header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : ''; $header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : ''; } return $header_images; } /** * Gets the ID of a previous crop from the same base image. * * @since 4.9.0 * * @param array $attachment An array with a cropped attachment object data. * @return int|false An attachment ID if one exists. False if none. */ public function get_previous_crop( $attachment ) { $header_images = $this->get_uploaded_header_images(); // Bail early if there are no header images. if ( empty( $header_images ) ) { return false; } $previous = false; foreach ( $header_images as $image ) { if ( $image['attachment_parent'] === $attachment['post_parent'] ) { $previous = $image['attachment_id']; break; } } return $previous; } } includes/class-wp-screen.php 0000644 00000110717 14717704420 0012106 0 ustar 00 post_type; /** This filter is documented in wp-admin/post.php */ $replace_editor = apply_filters( 'replace_editor', false, $post ); if ( ! $replace_editor ) { $is_block_editor = use_block_editor_for_post( $post ); } } } break; case 'edit-tags': case 'term': if ( null === $post_type && is_object_in_taxonomy( 'post', $taxonomy ? $taxonomy : 'post_tag' ) ) { $post_type = 'post'; } break; case 'upload': $post_type = 'attachment'; break; } } switch ( $base ) { case 'post': if ( null === $post_type ) { $post_type = 'post'; } // When creating a new post, use the default block editor support value for the post type. if ( empty( $post_id ) ) { $is_block_editor = use_block_editor_for_post_type( $post_type ); } $id = $post_type; break; case 'edit': if ( null === $post_type ) { $post_type = 'post'; } $id .= '-' . $post_type; break; case 'edit-tags': case 'term': if ( null === $taxonomy ) { $taxonomy = 'post_tag'; } // The edit-tags ID does not contain the post type. Look for it in the request. if ( null === $post_type ) { $post_type = 'post'; if ( isset( $_REQUEST['post_type'] ) && post_type_exists( $_REQUEST['post_type'] ) ) { $post_type = $_REQUEST['post_type']; } } $id = 'edit-' . $taxonomy; break; } if ( 'network' === $in_admin ) { $id .= '-network'; $base .= '-network'; } elseif ( 'user' === $in_admin ) { $id .= '-user'; $base .= '-user'; } if ( isset( self::$_registry[ $id ] ) ) { $screen = self::$_registry[ $id ]; if ( get_current_screen() === $screen ) { return $screen; } } else { $screen = new self(); $screen->id = $id; } $screen->base = $base; $screen->action = $action; $screen->post_type = (string) $post_type; $screen->taxonomy = (string) $taxonomy; $screen->is_user = ( 'user' === $in_admin ); $screen->is_network = ( 'network' === $in_admin ); $screen->in_admin = $in_admin; $screen->is_block_editor = $is_block_editor; self::$_registry[ $id ] = $screen; return $screen; } /** * Makes the screen object the current screen. * * @see set_current_screen() * @since 3.3.0 * * @global WP_Screen $current_screen WordPress current screen object. * @global string $typenow The post type of the current screen. * @global string $taxnow The taxonomy of the current screen. */ public function set_current_screen() { global $current_screen, $taxnow, $typenow; $current_screen = $this; $typenow = $this->post_type; $taxnow = $this->taxonomy; /** * Fires after the current screen has been set. * * @since 3.0.0 * * @param WP_Screen $current_screen Current WP_Screen object. */ do_action( 'current_screen', $current_screen ); } /** * Constructor * * @since 3.3.0 */ private function __construct() {} /** * Indicates whether the screen is in a particular admin. * * @since 3.5.0 * * @param string $admin The admin to check against (network | user | site). * If empty any of the three admins will result in true. * @return bool True if the screen is in the indicated admin, false otherwise. */ public function in_admin( $admin = null ) { if ( empty( $admin ) ) { return (bool) $this->in_admin; } return ( $admin === $this->in_admin ); } /** * Sets or returns whether the block editor is loading on the current screen. * * @since 5.0.0 * * @param bool $set Optional. Sets whether the block editor is loading on the current screen or not. * @return bool True if the block editor is being loaded, false otherwise. */ public function is_block_editor( $set = null ) { if ( null !== $set ) { $this->is_block_editor = (bool) $set; } return $this->is_block_editor; } /** * Sets the old string-based contextual help for the screen for backward compatibility. * * @since 3.3.0 * * @param WP_Screen $screen A screen object. * @param string $help Help text. */ public static function add_old_compat_help( $screen, $help ) { self::$_old_compat_help[ $screen->id ] = $help; } /** * Sets the parent information for the screen. * * This is called in admin-header.php after the menu parent for the screen has been determined. * * @since 3.3.0 * * @param string $parent_file The parent file of the screen. Typically the $parent_file global. */ public function set_parentage( $parent_file ) { $this->parent_file = $parent_file; list( $this->parent_base ) = explode( '?', $parent_file ); $this->parent_base = str_replace( '.php', '', $this->parent_base ); } /** * Adds an option for the screen. * * Call this in template files after admin.php is loaded and before admin-header.php is loaded * to add screen options. * * @since 3.3.0 * * @param string $option Option ID. * @param mixed $args Option-dependent arguments. */ public function add_option( $option, $args = array() ) { $this->_options[ $option ] = $args; } /** * Removes an option from the screen. * * @since 3.8.0 * * @param string $option Option ID. */ public function remove_option( $option ) { unset( $this->_options[ $option ] ); } /** * Removes all options from the screen. * * @since 3.8.0 */ public function remove_options() { $this->_options = array(); } /** * Gets the options registered for the screen. * * @since 3.8.0 * * @return array Options with arguments. */ public function get_options() { return $this->_options; } /** * Gets the arguments for an option for the screen. * * @since 3.3.0 * * @param string $option Option name. * @param string|false $key Optional. Specific array key for when the option is an array. * Default false. * @return string The option value if set, null otherwise. */ public function get_option( $option, $key = false ) { if ( ! isset( $this->_options[ $option ] ) ) { return null; } if ( $key ) { if ( isset( $this->_options[ $option ][ $key ] ) ) { return $this->_options[ $option ][ $key ]; } return null; } return $this->_options[ $option ]; } /** * Gets the help tabs registered for the screen. * * @since 3.4.0 * @since 4.4.0 Help tabs are ordered by their priority. * * @return array Help tabs with arguments. */ public function get_help_tabs() { $help_tabs = $this->_help_tabs; $priorities = array(); foreach ( $help_tabs as $help_tab ) { if ( isset( $priorities[ $help_tab['priority'] ] ) ) { $priorities[ $help_tab['priority'] ][] = $help_tab; } else { $priorities[ $help_tab['priority'] ] = array( $help_tab ); } } ksort( $priorities ); $sorted = array(); foreach ( $priorities as $list ) { foreach ( $list as $tab ) { $sorted[ $tab['id'] ] = $tab; } } return $sorted; } /** * Gets the arguments for a help tab. * * @since 3.4.0 * * @param string $id Help Tab ID. * @return array Help tab arguments. */ public function get_help_tab( $id ) { if ( ! isset( $this->_help_tabs[ $id ] ) ) { return null; } return $this->_help_tabs[ $id ]; } /** * Adds a help tab to the contextual help for the screen. * * Call this on the `load-$pagenow` hook for the relevant screen, * or fetch the `$current_screen` object, or use get_current_screen() * and then call the method from the object. * * You may need to filter `$current_screen` using an if or switch statement * to prevent new help tabs from being added to ALL admin screens. * * @since 3.3.0 * @since 4.4.0 The `$priority` argument was added. * * @param array $args { * Array of arguments used to display the help tab. * * @type string $title Title for the tab. Default false. * @type string $id Tab ID. Must be HTML-safe and should be unique for this menu. * It is NOT allowed to contain any empty spaces. Default false. * @type string $content Optional. Help tab content in plain text or HTML. Default empty string. * @type callable $callback Optional. A callback to generate the tab content. Default false. * @type int $priority Optional. The priority of the tab, used for ordering. Default 10. * } */ public function add_help_tab( $args ) { $defaults = array( 'title' => false, 'id' => false, 'content' => '', 'callback' => false, 'priority' => 10, ); $args = wp_parse_args( $args, $defaults ); $args['id'] = sanitize_html_class( $args['id'] ); // Ensure we have an ID and title. if ( ! $args['id'] || ! $args['title'] ) { return; } // Allows for overriding an existing tab with that ID. $this->_help_tabs[ $args['id'] ] = $args; } /** * Removes a help tab from the contextual help for the screen. * * @since 3.3.0 * * @param string $id The help tab ID. */ public function remove_help_tab( $id ) { unset( $this->_help_tabs[ $id ] ); } /** * Removes all help tabs from the contextual help for the screen. * * @since 3.3.0 */ public function remove_help_tabs() { $this->_help_tabs = array(); } /** * Gets the content from a contextual help sidebar. * * @since 3.4.0 * * @return string Contents of the help sidebar. */ public function get_help_sidebar() { return $this->_help_sidebar; } /** * Adds a sidebar to the contextual help for the screen. * * Call this in template files after admin.php is loaded and before admin-header.php is loaded * to add a sidebar to the contextual help. * * @since 3.3.0 * * @param string $content Sidebar content in plain text or HTML. */ public function set_help_sidebar( $content ) { $this->_help_sidebar = $content; } /** * Gets the number of layout columns the user has selected. * * The layout_columns option controls the max number and default number of * columns. This method returns the number of columns within that range selected * by the user via Screen Options. If no selection has been made, the default * provisioned in layout_columns is returned. If the screen does not support * selecting the number of layout columns, 0 is returned. * * @since 3.4.0 * * @return int Number of columns to display. */ public function get_columns() { return $this->columns; } /** * Gets the accessible hidden headings and text used in the screen. * * @since 4.4.0 * * @see set_screen_reader_content() For more information on the array format. * * @return string[] An associative array of screen reader text strings. */ public function get_screen_reader_content() { return $this->_screen_reader_content; } /** * Gets a screen reader text string. * * @since 4.4.0 * * @param string $key Screen reader text array named key. * @return string Screen reader text string. */ public function get_screen_reader_text( $key ) { if ( ! isset( $this->_screen_reader_content[ $key ] ) ) { return null; } return $this->_screen_reader_content[ $key ]; } /** * Adds accessible hidden headings and text for the screen. * * @since 4.4.0 * * @param array $content { * An associative array of screen reader text strings. * * @type string $heading_views Screen reader text for the filter links heading. * Default 'Filter items list'. * @type string $heading_pagination Screen reader text for the pagination heading. * Default 'Items list navigation'. * @type string $heading_list Screen reader text for the items list heading. * Default 'Items list'. * } */ public function set_screen_reader_content( $content = array() ) { $defaults = array( 'heading_views' => __( 'Filter items list' ), 'heading_pagination' => __( 'Items list navigation' ), 'heading_list' => __( 'Items list' ), ); $content = wp_parse_args( $content, $defaults ); $this->_screen_reader_content = $content; } /** * Removes all the accessible hidden headings and text for the screen. * * @since 4.4.0 */ public function remove_screen_reader_content() { $this->_screen_reader_content = array(); } /** * Renders the screen's help section. * * This will trigger the deprecated filters for backward compatibility. * * @since 3.3.0 * * @global string $screen_layout_columns */ public function render_screen_meta() { /** * Filters the legacy contextual help list. * * @since 2.7.0 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or * {@see get_current_screen()->remove_help_tab()} instead. * * @param array $old_compat_help Old contextual help. * @param WP_Screen $screen Current WP_Screen instance. */ self::$_old_compat_help = apply_filters_deprecated( 'contextual_help_list', array( self::$_old_compat_help, $this ), '3.3.0', 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' ); $old_help = isset( self::$_old_compat_help[ $this->id ] ) ? self::$_old_compat_help[ $this->id ] : ''; /** * Filters the legacy contextual help text. * * @since 2.7.0 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or * {@see get_current_screen()->remove_help_tab()} instead. * * @param string $old_help Help text that appears on the screen. * @param string $screen_id Screen ID. * @param WP_Screen $screen Current WP_Screen instance. */ $old_help = apply_filters_deprecated( 'contextual_help', array( $old_help, $this->id, $this ), '3.3.0', 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' ); // Default help only if there is no old-style block of text and no new-style help tabs. if ( empty( $old_help ) && ! $this->get_help_tabs() ) { /** * Filters the default legacy contextual help text. * * @since 2.8.0 * @deprecated 3.3.0 Use {@see get_current_screen()->add_help_tab()} or * {@see get_current_screen()->remove_help_tab()} instead. * * @param string $old_help_default Default contextual help text. */ $default_help = apply_filters_deprecated( 'default_contextual_help', array( '' ), '3.3.0', 'get_current_screen()->add_help_tab(), get_current_screen()->remove_help_tab()' ); if ( $default_help ) { $old_help = '' . $default_help . '
'; } } if ( $old_help ) { $this->add_help_tab( array( 'id' => 'old-contextual-help', 'title' => __( 'Overview' ), 'content' => $old_help, ) ); } $help_sidebar = $this->get_help_sidebar(); $help_class = 'hidden'; if ( ! $help_sidebar ) { $help_class .= ' no-sidebar'; } // Time to render! ?> get_help_tabs() && ! $this->show_screen_options() ) { return; } ?>
" . esc_html( $template ) . ''; } } /** * Prints out option HTML elements for the page parents drop-down. * * @since 1.5.0 * @since 4.4.0 `$post` argument was added. * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $default_page Optional. The default page ID to be pre-selected. Default 0. * @param int $parent_page Optional. The parent page ID. Default 0. * @param int $level Optional. Page depth level. Default 0. * @param int|WP_Post $post Post ID or WP_Post object. * @return void|false Void on success, false if the page has no children. */ function parent_dropdown( $default_page = 0, $parent_page = 0, $level = 0, $post = null ) { global $wpdb; $post = get_post( $post ); $items = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent_page ) ); if ( $items ) { foreach ( $items as $item ) { // A page cannot be its own parent. if ( $post && $post->ID && (int) $item->ID === $post->ID ) { continue; } $pad = str_repeat( ' ', $level * 3 ); $selected = selected( $default_page, $item->ID, false ); echo "\n\t'; parent_dropdown( $default_page, $item->ID, $level + 1 ); } } else { return false; } } /** * Prints out option HTML elements for role selectors. * * @since 2.1.0 * * @param string $selected Slug for the role that should be already selected. */ function wp_dropdown_roles( $selected = '' ) { $r = ''; $editable_roles = array_reverse( get_editable_roles() ); foreach ( $editable_roles as $role => $details ) { $name = translate_user_role( $details['name'] ); // Preselect specified role. if ( $selected === $role ) { $r .= "\n\t"; } else { $r .= "\n\t"; } } echo $r; } /** * Outputs the form used by the importers to accept the data to be imported. * * @since 2.0.0 * * @param string $action The action attribute for the form. */ function wp_import_upload_form( $action ) { /** * Filters the maximum allowed upload size for import files. * * @since 2.3.0 * * @see wp_max_upload_size() * * @param int $max_upload_size Allowed upload size. Default 1 MB. */ $bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() ); $size = size_format( $bytes ); $upload_dir = wp_upload_dir(); if ( ! empty( $upload_dir['error'] ) ) : $upload_directory_error = '
' . __( 'Before you can upload your import file, you will need to fix the following error:' ) . '
'; $upload_directory_error .= '' . $upload_dir['error'] . '
'; wp_admin_notice( $upload_directory_error, array( 'additional_classes' => array( 'error' ), 'paragraph_wrap' => false, ) ); else : ?> id ) ) { return; } $page = $screen->id; if ( ! isset( $wp_meta_boxes ) ) { $wp_meta_boxes = array(); } if ( ! isset( $wp_meta_boxes[ $page ] ) ) { $wp_meta_boxes[ $page ] = array(); } if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { $wp_meta_boxes[ $page ][ $context ] = array(); } foreach ( array_keys( $wp_meta_boxes[ $page ] ) as $a_context ) { foreach ( array( 'high', 'core', 'default', 'low' ) as $a_priority ) { if ( ! isset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) ) { continue; } // If a core box was previously removed, don't add. if ( ( 'core' === $priority || 'sorted' === $priority ) && false === $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ) { return; } // If a core box was previously added by a plugin, don't add. if ( 'core' === $priority ) { /* * If the box was added with default priority, give it core priority * to maintain sort order. */ if ( 'default' === $a_priority ) { $wp_meta_boxes[ $page ][ $a_context ]['core'][ $id ] = $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ]; unset( $wp_meta_boxes[ $page ][ $a_context ]['default'][ $id ] ); } return; } // If no priority given and ID already present, use existing priority. if ( empty( $priority ) ) { $priority = $a_priority; /* * Else, if we're adding to the sorted priority, we don't know the title * or callback. Grab them from the previously added context/priority. */ } elseif ( 'sorted' === $priority ) { $title = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['title']; $callback = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['callback']; $callback_args = $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ]['args']; } // An ID can be in only one priority and one context. if ( $priority !== $a_priority || $context !== $a_context ) { unset( $wp_meta_boxes[ $page ][ $a_context ][ $a_priority ][ $id ] ); } } } if ( empty( $priority ) ) { $priority = 'low'; } if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { $wp_meta_boxes[ $page ][ $context ][ $priority ] = array(); } $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = array( 'id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args, ); } /** * Renders a "fake" meta box with an information message, * shown on the block editor, when an incompatible meta box is found. * * @since 5.0.0 * * @param mixed $data_object The data object being rendered on this screen. * @param array $box { * Custom formats meta box arguments. * * @type string $id Meta box 'id' attribute. * @type string $title Meta box title. * @type callable $old_callback The original callback for this meta box. * @type array $args Extra meta box arguments. * } */ function do_block_editor_incompatible_meta_box( $data_object, $box ) { $plugin = _get_plugin_from_callback( $box['old_callback'] ); $plugins = get_plugins(); echo ''; if ( $plugin ) { /* translators: %s: The name of the plugin that generated this meta box. */ printf( __( 'This meta box, from the %s plugin, is not compatible with the block editor.' ), "{$plugin['Name']}" ); } else { _e( 'This meta box is not compatible with the block editor.' ); } echo '
'; if ( empty( $plugins['classic-editor/classic-editor.php'] ) ) { if ( current_user_can( 'install_plugins' ) ) { $install_url = wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ); echo ''; /* translators: %s: A link to install the Classic Editor plugin. */ printf( __( 'Please install the Classic Editor plugin to use this meta box.' ), esc_url( $install_url ) ); echo '
'; } } elseif ( is_plugin_inactive( 'classic-editor/classic-editor.php' ) ) { if ( current_user_can( 'activate_plugins' ) ) { $activate_url = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php' ), 'activate-plugin_classic-editor/classic-editor.php' ); echo ''; /* translators: %s: A link to activate the Classic Editor plugin. */ printf( __( 'Please activate the Classic Editor plugin to use this meta box.' ), esc_url( $activate_url ) ); echo '
'; } } elseif ( $data_object instanceof WP_Post ) { $edit_url = add_query_arg( array( 'classic-editor' => '', 'classic-editor__forget' => '', ), get_edit_post_link( $data_object ) ); echo ''; /* translators: %s: A link to use the Classic Editor plugin. */ printf( __( 'Please open the classic editor to use this meta box.' ), esc_url( $edit_url ) ); echo '
'; } } /** * Internal helper function to find the plugin from a meta box callback. * * @since 5.0.0 * * @access private * * @param callable $callback The callback function to check. * @return array|null The plugin that the callback belongs to, or null if it doesn't belong to a plugin. */ function _get_plugin_from_callback( $callback ) { try { if ( is_array( $callback ) ) { $reflection = new ReflectionMethod( $callback[0], $callback[1] ); } elseif ( is_string( $callback ) && str_contains( $callback, '::' ) ) { $reflection = new ReflectionMethod( $callback ); } else { $reflection = new ReflectionFunction( $callback ); } } catch ( ReflectionException $exception ) { // We could not properly reflect on the callable, so we abort here. return null; } // Don't show an error if it's an internal PHP function. if ( ! $reflection->isInternal() ) { // Only show errors if the meta box was registered by a plugin. $filename = wp_normalize_path( $reflection->getFileName() ); $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); if ( str_starts_with( $filename, $plugin_dir ) ) { $filename = str_replace( $plugin_dir, '', $filename ); $filename = preg_replace( '|^/([^/]*/).*$|', '\\1', $filename ); $plugins = get_plugins(); foreach ( $plugins as $name => $plugin ) { if ( str_starts_with( $name, $filename ) ) { return $plugin; } } } } return null; } /** * Meta-Box template function. * * @since 2.5.0 * * @global array $wp_meta_boxes Global meta box state. * * @param string|WP_Screen $screen The screen identifier. If you have used add_menu_page() or * add_submenu_page() to create a new screen (and hence screen_id) * make sure your menu slug conforms to the limits of sanitize_key() * otherwise the 'screen' menu may not correctly render on your page. * @param string $context The screen context for which to display meta boxes. * @param mixed $data_object Gets passed to the meta box callback function as the first parameter. * Often this is the object that's the focus of the current screen, * for example a `WP_Post` or `WP_Comment` object. * @return int Number of meta_boxes. */ function do_meta_boxes( $screen, $context, $data_object ) { global $wp_meta_boxes; static $already_sorted = false; if ( empty( $screen ) ) { $screen = get_current_screen(); } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); } $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); printf( ' '; return $i; } /** * Removes a meta box from one or more screens. * * @since 2.6.0 * @since 4.4.0 The `$screen` parameter now accepts an array of screen IDs. * * @global array $wp_meta_boxes Global meta box state. * * @param string $id Meta box ID (used in the 'id' attribute for the meta box). * @param string|array|WP_Screen $screen The screen or screens on which the meta box is shown (such as a * post type, 'link', or 'comment'). Accepts a single screen ID, * WP_Screen object, or array of screen IDs. * @param string $context The context within the screen where the box is set to display. * Contexts vary from screen to screen. Post edit screen contexts * include 'normal', 'side', and 'advanced'. Comments screen contexts * include 'normal' and 'side'. Menus meta boxes (accordion sections) * all use the 'side' context. */ function remove_meta_box( $id, $screen, $context ) { global $wp_meta_boxes; if ( empty( $screen ) ) { $screen = get_current_screen(); } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); } elseif ( is_array( $screen ) ) { foreach ( $screen as $single_screen ) { remove_meta_box( $id, $single_screen, $context ); } } if ( ! isset( $screen->id ) ) { return; } $page = $screen->id; if ( ! isset( $wp_meta_boxes ) ) { $wp_meta_boxes = array(); } if ( ! isset( $wp_meta_boxes[ $page ] ) ) { $wp_meta_boxes[ $page ] = array(); } if ( ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { $wp_meta_boxes[ $page ][ $context ] = array(); } foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { $wp_meta_boxes[ $page ][ $context ][ $priority ][ $id ] = false; } } /** * Meta Box Accordion Template Function. * * Largely made up of abstracted code from do_meta_boxes(), this * function serves to build meta boxes as list items for display as * a collapsible accordion. * * @since 3.6.0 * * @uses global $wp_meta_boxes Used to retrieve registered meta boxes. * * @param string|object $screen The screen identifier. * @param string $context The screen context for which to display accordion sections. * @param mixed $data_object Gets passed to the section callback function as the first parameter. * @return int Number of meta boxes as accordion sections. */ function do_accordion_sections( $screen, $context, $data_object ) { global $wp_meta_boxes; wp_enqueue_script( 'accordion' ); if ( empty( $screen ) ) { $screen = get_current_screen(); } elseif ( is_string( $screen ) ) { $screen = convert_to_screen( $screen ); } $page = $screen->id; $hidden = get_hidden_meta_boxes( $screen ); ?>