__( 'Facebook', 'wordpress-seo' ), 'twitter' => __( 'Twitter', 'wordpress-seo' ), ]; // Source: https://blog.bufferapp.com/ideal-image-sizes-social-media-posts. $recommended_image_sizes = [ /* translators: %1$s expands to the image recommended width, %2$s to its height. */ 'opengraph' => sprintf( __( '%1$s by %2$s', 'wordpress-seo' ), '1200', '630' ), // Source: https://developers.facebook.com/docs/sharing/best-practices#images. /* translators: %1$s expands to the image recommended width, %2$s to its height. */ 'twitter' => sprintf( __( '%1$s by %2$s', 'wordpress-seo' ), '1024', '512' ), ]; foreach ( $social_networks as $network => $label ) { if ( WPSEO_Options::get( $network, false ) === true ) { /* translators: %s expands to the name of a social network. */ WPSEO_Meta::$meta_fields['social'][ $network . '-title' ]['title'] = sprintf( __( '%s Title', 'wordpress-seo' ), $label ); WPSEO_Meta::$meta_fields['social'][ $network . '-title' ]['description'] = sprintf( $title_text, $label ); /* translators: %s expands to the name of a social network. */ WPSEO_Meta::$meta_fields['social'][ $network . '-description' ]['title'] = sprintf( __( '%s Description', 'wordpress-seo' ), $label ); WPSEO_Meta::$meta_fields['social'][ $network . '-description' ]['description'] = sprintf( $description_text, $label ); /* translators: %s expands to the name of a social network. */ WPSEO_Meta::$meta_fields['social'][ $network . '-image' ]['title'] = sprintf( __( '%s Image', 'wordpress-seo' ), $label ); WPSEO_Meta::$meta_fields['social'][ $network . '-image' ]['description'] = sprintf( $image_text, $label ) . ' ' . sprintf( $image_size_text, $label, $recommended_image_sizes[ $network ] ); } } } /** * Returns the metabox section for the social settings. * * @return WPSEO_Metabox_Collapsibles_Sections */ public function get_meta_section() { $tabs = []; $social_meta_fields = WPSEO_Meta::get_meta_field_defs( 'social' ); $opengraph = WPSEO_Options::get( 'opengraph' ); $twitter = WPSEO_Options::get( 'twitter' ); if ( $opengraph === true && $twitter === true ) { $single = null; } wp_nonce_field( 'yoast_free_metabox_social', 'yoast_free_metabox_social_nonce' ); if ( $opengraph === true ) { $tabs[] = new WPSEO_Metabox_Collapsible( 'facebook', $this->get_social_tab_content( 'opengraph', $social_meta_fields ), __( 'Facebook', 'wordpress-seo' ) ); } if ( $twitter === true ) { $tabs[] = new WPSEO_Metabox_Collapsible( 'twitter', $this->get_social_tab_content( 'twitter', $social_meta_fields ), __( 'Twitter', 'wordpress-seo' ) ); } return new WPSEO_Metabox_Collapsibles_Sections( 'social', '' . __( 'Social', 'wordpress-seo' ), $tabs ); } /** * Generates the html for a social settings tab for one of the supported social media. * * @param string $medium Medium. Can be 'opengraph' or 'twitter'. * @param array $meta_field_defs The social meta field definitions. * * @return string */ private function get_social_tab_content( $medium, $meta_field_defs ) { $field_names = [ $medium . '-title', $medium . '-description', $medium . '-image', $medium . '-image-id', ]; $tab_content = $this->get_premium_notice( $medium ); foreach ( $field_names as $field_name ) { $tab_content .= $this->do_meta_box( $meta_field_defs[ $field_name ], $field_name ); } /** * If premium hide the form to show the social preview instead, we still need the fields to be output because * the values of the social preview are saved in the hidden field. */ $features = new WPSEO_Features(); if ( $features->is_premium() ) { return $this->hide_form( $tab_content ); } return $tab_content; } /** * Hides the given output when rendered to HTML. * * @param string $tab_content The social tab content. * * @return string The content. */ private function hide_form( $tab_content ) { return '
%1$s