Making WordPress.org

Changeset 12335


Ignore:
Timestamp:
12/15/2022 05:55:50 PM (4 years ago)
Author:
coffee2code
Message:

Plugin Directory: Add initial plugin categorization features to the plugin.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php

    r11430 r12335  
    6161 * @param array  $caps Returns the user's actual capabilities.
    6262 * @param string $cap  Capability name.
     63 * @param int    $user_id The user ID.
     64 * @param mixed  $context Adds the context to the cap. Typically the object ID.
    6365 * @return array
    6466 */
    65 function wporg_themes_map_meta_cap( $caps, $cap ) {
     67function wporg_themes_map_meta_cap( $caps, $cap, $user_id, $context ) {
    6668        switch ( $cap ) {
    6769                case 'delete_categories':
     
    8385                        unset( $caps[ array_search( $cap, $caps ) ] );
    8486                        break;
     87
     88                case 'theme_configure_categorization_options':
     89                        // Protect against a cap call without a theme context.
     90                        $post = $context ? get_post( $context[0] ) : false;
     91                        if ( ! $post ) {
     92                                return [ 'do_not_allow' ];
     93                        }
     94
     95                        // The current user instance.
     96                        $user = new \WP_User( $user_id );
     97
     98                        // Shortcut, if no user specified, we can't help.
     99                        if ( ! $user_id || ! $user->exists() ) {
     100                                return [ 'do_not_allow' ];
     101                        }
     102
     103                        // Post must be a published theme.
     104                        if ( 'publish' !== $post->post_status || 'repopackage' !== $post->post_type ) {
     105                                return [ 'do_not_allow' ];
     106                        }
     107
     108                        // User must be able to edit theme or be the theme owner.
     109                        if ( ! ( user_can( $user->ID, 'edit_post', $post ) || $user->ID === $post->post_author ) ) {
     110                                return [ 'do_not_allow' ];
     111                        }
     112
     113                        // Start over, we'll specify all caps below.
     114                        $caps = [];
     115
     116                        // At this point, user is allowed.
     117                        $caps[] = 'exist';
     118                        break;
    85119        }
    86120
    87121        return $caps;
    88122}
    89 add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 2 );
     123add_filter( 'map_meta_cap', 'wporg_themes_map_meta_cap', 10, 4 );
    90124
    91125/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-themes-api.php

    r11373 r12335  
    6565                'requires_php'       => false,
    6666                'trac_tickets'       => false,
     67                'is_commercial'      => false,
     68                'is_community'       => false,
     69                'external_repository_url' => false,
     70                'external_support_url' => false,
     71                'can_configure_categorization_options' => false,
    6772        );
    6873
     
    7277         * @var string
    7378         */
    74         private $cache_group = 'theme-info';
     79//      private $cache_group = 'theme-info';
     80private $cache_group = 'test-theme-info'; // Don't pollute production cache.
    7581
    7682        /**
     
    7985         * @var int
    8086         */
    81         private $cache_life = 600; // 10 minutes.
     87//      private $cache_life = 600; // 10 minutes.
     88private $cache_life = 1; // Disable caching.
    8289
    8390        /**
     
    460467                        $defaults['requires_php'] = true;
    461468                        $defaults['creation_time'] = true;
     469                        $defaults['is_commercial'] = true;
     470                        $defaults['is_community'] = true;
     471                        $defaults['external_repository_url'] = true;
     472                        $defaults['external_support_url'] = true;
     473                        $defaults['can_configure_categorization_options'] = true;
    462474                }
    463475
     
    526538                        $defaults['requires'] = true;
    527539                        $defaults['requires_php'] = true;
     540                        $defaults['is_commercial'] = true;
     541                        $defaults['is_community'] = true;
     542                        $defaults['external_repository_url'] = true;
     543                        $defaults['external_support_url'] = true;
     544                        $defaults['can_configure_categorization_options'] = true;
    528545                }
    529546
     
    880897                }
    881898
     899                if ( $this->fields['is_commercial'] ) {
     900                        $phil->is_commercial = has_term( 'commercial', 'theme_business_model', $theme );
     901                }
     902
     903                if ( $this->fields['external_support_url'] ) {
     904                        // Only return external_support_url value if theme is commercial.
     905                        if ( ! empty( $phil->is_commercial ) ) {
     906                                $phil->external_support_url = get_post_meta( $theme->ID, 'external_support_url', true );
     907                        } else {
     908                                $phil->external_support_url = false;
     909                        }
     910                }
     911
     912                if ( $this->fields['is_community'] ) {
     913                        $phil->is_community = has_term( 'community', 'theme_business_model', $theme );
     914                }
     915
     916                if ( $this->fields['external_repository_url'] ) {
     917                        // Only return external_repository_url value if theme is community.
     918                        if ( ! empty( $phil->is_community ) ) {
     919                                $phil->external_repository_url = get_post_meta( $theme->ID, 'external_repository_url', true );
     920                        } else {
     921                                $phil->external_repository_url = '';
     922                        }
     923                }
     924
     925                if ( $this->fields['can_configure_categorization_options'] ) {
     926                        $phil->can_configure_categorization_options = current_user_can( 'theme_configure_categorization_options', $theme );
     927                }
     928
    882929                if ( class_exists( 'GlotPress_Translate_Bridge' ) ) {
    883930                        $glotpress_project = "wp-themes/{$phil->slug}";
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api.php

    r11856 r12335  
    5454        include __DIR__ . '/rest-api/class-tags-endpoint.php';
    5555        include __DIR__ . '/rest-api/class-themes-auto-review.php';
     56        include __DIR__ . '/rest-api/class-theme-categorization.php';
    5657        include __DIR__ . '/rest-api/class-theme-review-stats.php';
    5758} );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r12311 r12335  
    905905                'requires' => true,
    906906                'requires_php' => true,
     907                'is_commercial' => true,
     908                'external_support_url' => true,
     909                'is_community' => true,
     910                'external_repository_url' => true,
     911                'can_configure_categorization_options' => true,
    907912        );
    908913
     
    946951                        'requires' => true,
    947952                        'requires_php' => true,
     953                        'is_commercial' => true,
     954                        'external_support_url' => true,
     955                        'is_community' => true,
     956                        'external_repository_url' => true,
     957                        'can_configure_categorization_model_options' => true,
    948958                )
    949959        ) );
Note: See TracChangeset for help on using the changeset viewer.