Making WordPress.org

Ticket #2303: social_meta_data.5.diff

File social_meta_data.5.diff, 2.2 KB (added by joostdevalk, 8 years ago)

Patch that does actually fix the new metadata

  • class-plugin-directory.php

     
    4141                add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
    4242                add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    4343                add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
     44                add_action( 'wp_head', array( $this, 'social_meta_data' ) );
    4445
    4546                // Cron tasks.
    4647                add_action( 'admin_init', array( $this, 'register_cron_tasks' ) );
     
    527528        }
    528529
    529530        /**
     531         * Output social metadata
     532         */
     533        public function social_meta_data() {
     534                if ( ! is_singular( 'plugin' ) ) {
     535                        return;
     536                }
     537
     538                $post_id = get_the_ID();
     539                $plugin = get_post( $post_id );
     540                $banner = Template::get_plugin_banner( $plugin, 'raw' );
     541                if ( ! isset ( $banner['banner_2x'] ) ) {
     542                        $banner['banner_2x'] = isset( $banner['banner'] ) ? $banner['banner'] : false;
     543                }
     544                $icon = Template::get_plugin_icon( $plugin, 'raw' );
     545                if ( ! isset ( $icon['icon_2x'] ) ) {
     546                        $icon['icon_2x'] = isset( $icon['icon'] ) ? $icon['icon'] : false;
     547                }
     548
     549                printf( '<meta property="og:title" content="%s" />', esc_attr( get_the_title( $post_id ) ) );
     550                printf( '<meta property="og:description" content="%s" />', esc_attr( get_the_excerpt( $post_id ) ) );
     551                printf( '<meta property="og:site_name" content="WordPress.org" />' );
     552                printf( '<meta property="og:type" content="website" />' );
     553                printf( '<meta property="og:url" content="%s" />', esc_url( get_permalink( $post_id ) ) );
     554                printf( '<meta name="twitter:card" content="summary_large_image">' );
     555                printf( '<meta name="twitter:site" content="@WordPress">' );
     556                if ( $banner['banner_2x'] ) {
     557                        printf( '<meta name="twitter:image" content="%s" />', esc_url( $banner['banner_2x'] ) );
     558                }
     559                if ( isset( $banner['banner'] ) ) {
     560                        printf( '<meta property="og:image" content="%s" />', esc_url( $banner['banner'] ) );
     561                }
     562                if ( $icon['icon_2x'] ) {
     563                        printf( '<meta name="thumbnail" content="%s" />', esc_url( $icon['icon_2x'] ) );
     564                }
     565        }
     566
     567        /**
    530568         * @param \WP_Query $wp_query The WordPress Query object.
    531569         */
    532570        public function pre_get_posts( $wp_query ) {