WPSEO_Taxonomy_Social_Fields

This class parses all the values for the social tab in the Yoast SEO settings metabox.

Defined (1)

The class is defined in the following location(s).

/admin/taxonomy/class-taxonomy-social-fields.php  
  1. class WPSEO_Taxonomy_Social_Fields extends WPSEO_Taxonomy_Fields { 
  2.  
  3. /** 
  4. * Setting the class properties 
  5. * @param stdClass|WP_Term $term The current taxonomy. 
  6. * @param array $options The options. 
  7. */ 
  8. public function __construct( $term, array $options = null ) { 
  9. parent::__construct( $term, $options ); 
  10. $this->networks = $this->get_social_networks(); 
  11.  
  12. /** 
  13. * When this method returns false, the social tab in the meta box will be hidden 
  14. * @return bool 
  15. */ 
  16. public function show_social() { 
  17. return ( $this->options['opengraph'] === true || $this->options['twitter'] === true ); 
  18.  
  19. /** 
  20. * Gets the social meta fields by social network for the taxonomy. 
  21. * @param string $network The social network for which to fetch the fields. 
  22. * @return array 
  23. */ 
  24. public function get_by_network( $network ) { 
  25. $settings = $this->networks[ $network ]; 
  26.  
  27. return array( 
  28. $settings['network'] . '-title' => $this->get_field_config( 
  29. /** translators: %s expands to the social network name */ 
  30. sprintf( __( '%s Title', 'wordpress-seo' ), $settings['label'] ),  
  31. /** translators: %1$s expands to the social network name */ 
  32. sprintf( esc_html__( 'If you don\'t want to use the title for sharing on %1$s but instead want another title there, write it here.', 'wordpress-seo' ), $settings['label'] ),  
  33. 'text',  
  34. array( 'class' => 'large-text' ) 
  35. ),  
  36. $settings['network'] . '-description' => $this->get_field_config( 
  37. /** translators: %s expands to the social network name */ 
  38. sprintf( __( '%s Description', 'wordpress-seo' ), $settings['label'] ),  
  39. /** translators: %1$s expands to the social network name */ 
  40. sprintf( esc_html__( 'If you don\'t want to use the meta description for sharing on %1$s but want another description there, write it here.', 'wordpress-seo' ), $settings['label'] ),  
  41. 'textarea' 
  42. ),  
  43. $settings['network'] . '-image' => $this->get_field_config( 
  44. /** translators: %s expands to the social network name */ 
  45. sprintf( __( '%s Image', 'wordpress-seo' ), $settings['label'] ),  
  46. /** translators: %1$s expands to the social network name */ 
  47. sprintf( esc_html__( 'If you want to use an image for sharing on %1$s, you can upload / choose an image or add the image URL here.', 'wordpress-seo' ), $settings['label'] ) . '<br />' . 
  48. /** translators: %1$s expands to the social network name, %2$s expands to the image size */ 
  49. sprintf( __( 'The recommended image size for %1$s is %2$s pixels.', 'wordpress-seo' ), $settings['label'], $settings['size'] ),  
  50. 'upload' 
  51. ),  
  52. ); 
  53.  
  54. /** 
  55. * Returning the fields for the social media tab 
  56. * @return array 
  57. */ 
  58. public function get() { 
  59. $fields = array(); 
  60. foreach ( $this->networks as $option => $settings ) { 
  61. $fields_to_push = $this->get_by_network( $option ); 
  62.  
  63. $fields = array_merge( $fields, $fields_to_push ); 
  64.  
  65. return $this->filter_hidden_fields( $fields ); 
  66.  
  67. /** 
  68. * Getting array with the social networks 
  69. * @return array 
  70. */ 
  71. private function get_social_networks() { 
  72. $social_networks = array( 
  73. // Source: https://developers.facebook.com/docs/sharing/best-practices#images. 
  74. 'opengraph' => $this->social_network( 'opengraph', __( 'Facebook', 'wordpress-seo' ), sprintf( 
  75. /** translators: %1$s expands to the image recommended width, %2$s to its height. */ 
  76. __( '%1$s by %2$s', 'wordpress-seo' ), '1200', '630' 
  77. ) ),  
  78. 'twitter' => $this->social_network( 'twitter', __( 'Twitter', 'wordpress-seo' ), sprintf( 
  79. /** translators: %1$s expands to the image recommended width, %2$s to its height. */ 
  80. __( '%1$s by %2$s', 'wordpress-seo' ), '1024', '512' 
  81. ) ),  
  82. ); 
  83. $social_networks = $this->filter_social_networks( $social_networks ); 
  84.  
  85. return $social_networks; 
  86.  
  87. /** 
  88. * Returns array with the config fields for the social network 
  89. * @param string $network The name of the social network. 
  90. * @param string $label The label for the social network. 
  91. * @param string $image_size The image dimensions. 
  92. * @return array 
  93. */ 
  94. private function social_network( $network, $label, $image_size ) { 
  95. return array( 
  96. 'network' => $network,  
  97. 'label' => $label,  
  98. 'size' => $image_size,  
  99. ); 
  100.  
  101. /** 
  102. * Filter the social networks which are disabled in the configuration 
  103. * @param array $social_networks Array with the social networks that have to be filtered. 
  104. * @return array 
  105. */ 
  106. private function filter_social_networks( array $social_networks ) { 
  107. foreach ( $social_networks as $social_network => $settings ) { 
  108. if ( empty( $this->options[ $social_network ] ) ) { 
  109. unset( $social_networks[ $social_network ] ); 
  110.  
  111. return $social_networks;