Making WordPress.org


Ignore:
Timestamp:
04/12/2023 05:24:19 AM (12 months ago)
Author:
dd32
Message:

Plugin Directory: Store required plugins as an array, and an additional flag for when dependencies are not met by published WordPress.org-hosted plugins.

See #6921, [12532].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/cli/class-import.php

    r12532 r12533  
    4242    // Plugin headers that are stored in plugin meta
    4343    public $plugin_headers = array(
    44         // Header         => meta_key
    45         'Name'            => 'header_name',
    46         'PluginURI'       => 'header_plugin_uri',
    47         'Author'          => 'header_author',
    48         'AuthorURI'       => 'header_author_uri',
    49         'TextDomain'      => 'header_textdomain',
    50         'RequiresPlugins' => 'requires_plugins'
     44        // Header    => meta_key
     45        'Name'       => 'header_name',
     46        'PluginURI'  => 'header_plugin_uri',
     47        'Author'     => 'header_author',
     48        'AuthorURI'  => 'header_author_uri',
     49        'TextDomain' => 'header_textdomain',
    5150
    5251        // These headers are stored in these fields, but are handled separately.
    53         // 'Version'     => 'version',
    54         // 'RequiresWP'  => 'requires',
    55         // 'RequiresPHP' => 'requires_php',
     52        // 'Version'         => 'version',
     53        // 'RequiresWP'      => 'requires',
     54        // 'RequiresPHP'     => 'requires_php',
     55        // 'RequiresPlugins' => 'requires_plugins'
    5656    );
    5757
     
    240240            $plugin_names[ $headers->Name ] = $headers->Version;
    241241            update_post_meta( $plugin->ID, 'plugin_name_history', wp_slash( $plugin_names ) );
     242        }
     243
     244        // Validate whether the dependencies are met by WordPress.org-hosted plugins.
     245        $requires_plugins       = array_map( 'trim', explode( ',', $headers->RequiresPlugins ) );
     246        $requires_plugins_unmet = false;
     247        foreach ( $requires_plugins as $requires_plugin_slug ) {
     248            // TODO: Add support for premium plugins.
     249            $requires_plugin_post = Plugin_Directory::get_plugin_post( $requires_plugin_slug );
     250            if (
     251                ! $requires_plugin_post ||
     252                'publish' !== $requires_plugin_post->post_status
     253            ) {
     254                $requires_plugins_unmet = true;
     255                break;
     256            }
     257        }
     258
     259        update_post_meta( $plugin->ID, 'requires_plugins', wp_slash( $requires_plugins ) );
     260        if ( $requires_plugins_unmet ) {
     261            update_post_meta( $plugin->ID, '_requires_plugins_unmet', true );
     262        } else {
     263            delete_post_meta( $plugin->ID, '_requires_plugins_unmet' );
    242264        }
    243265
Note: See TracChangeset for help on using the changeset viewer.