WordPress.org

Making WordPress.org

Changeset 5163


Ignore:
Timestamp:
03/22/2017 07:23:39 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Support Theme: Add "Search this forum" form to plugin- and theme-specific views.

Use the plugin or theme name as intext parameter in the search query passed to Google.

See #7.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/functions.php

    r5159 r5163  
    259259
    260260    return in_array( $view_id, wporg_support_get_compat_views() );
     261}
     262
     263/**
     264 * Get current plugin or theme object in plugin- or theme-specific views.
     265 *
     266 * @return object|null Plugin or theme object on success, null on failure.
     267 */
     268function wporg_support_get_compat_object() {
     269    if ( ! class_exists( 'WordPressdotorg\Forums\Plugin' ) ) {
     270        return null;
     271    }
     272
     273    $object          = null;
     274    $plugin_instance = WordPressdotorg\Forums\Plugin::get_instance();
     275
     276    if ( ! empty( $plugin_instance->plugins->plugin ) ) {
     277        $object = $plugin_instance->plugins->plugin;
     278
     279        /* translators: %s: link to plugin support or review forum */
     280        $object->prefixed_title = sprintf( __( 'Plugin: %s', 'wporg-forums' ), $object->post_title );
     281        $object->type           = 'plugin';
     282    } elseif ( ! empty( $plugin_instance->themes->theme ) ) {
     283        $object = $plugin_instance->themes->theme;
     284
     285        /* translators: %s: link to theme support or review forum */
     286        $object->prefixed_title = sprintf( __( 'Theme: %s', 'wporg-forums' ), $object->post_title );
     287        $object->type           = 'theme';
     288    }
     289
     290    return $object;
    261291}
    262292
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php

    r5022 r5163  
    1616<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
    1717    <label for="s" class="screen-reader-text"><?php _ex( 'Search for:', 'label', 'wporg-forums' ); ?></label>
    18     <input type="search" id="s" class="search-field" placeholder="<?php echo esc_attr_x( 'Search forums', 'placeholder', 'wporg-forums' ); ?>" value="<?php the_search_query(); ?>" name="s" />
     18    <?php
     19        if ( 'wporg_compat_before_single_view' === current_action() ) {
     20            $placeholder = _x( 'Search this forum', 'placeholder', 'wporg-forums' );
     21            $project     = wporg_support_get_compat_object();
     22        } else {
     23            $placeholder = _x( 'Search forums', 'placeholder', 'wporg-forums' );
     24            $project     = null;
     25        }
     26    ?>
     27    <input type="search" id="s" class="search-field" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php the_search_query(); ?>" name="s" />
     28    <?php if ( $project ) : ?>
     29    <input type="hidden" name="intext" value="<?php echo esc_attr( $project->prefixed_title ); ?>" />
     30    <?php endif; ?>
    1931    <button class="button button-primary button-search"><i class="dashicons dashicons-search"></i><span class="screen-reader-text"><?php _e( 'Search forums', 'wporg-forums' ); ?></span></button>
    2032</form>
Note: See TracChangeset for help on using the changeset viewer.