Making WordPress.org

Ticket #2303: social_meta_data.diff

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

First stab at patch

  • 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 ( get_post_type() !== 'plugin' ) {
     535                        return;
     536                }
     537
     538                $post_id = get_the_ID();
     539                $banner = Template::get_plugin_banner( $post_id, 'raw' );
     540                $icon = Template::get_plugin_icon( $post_id, 'raw' );
     541
     542                printf( "<meta property='og:title' content='%s' />", get_the_title( $post_id ) );
     543                printf( "<meta property='og:description' content='%s' />", get_the_excerpt( $post_id ) );
     544                printf( "<meta property='og:site_name' content='WordPress.org' />" );
     545                printf( "<meta property='og:type' content='website' />" );
     546                printf( "<meta property='og:url' content='%s' />", esc_url( get_permalink( $post_id ) ) );
     547                printf( '<meta name="twitter:card" content="summary_large_image">' );
     548                printf( '<meta name="twitter:site" content="@WordPress">' );
     549                printf( '<meta name="twitter:image" content="%s', $banner['banner_2x'] );
     550                printf( '<meta property="og:image" content="%s" />', $banner['banner'] );
     551                printf( "<meta name='thumbnail' content='%s' />", $icon['icon_2x'] );
     552        }
     553
     554        /**
    530555         * @param \WP_Query $wp_query The WordPress Query object.
    531556         */
    532557        public function pre_get_posts( $wp_query ) {