WPSEO_Config_Factory_Post_Type

Class WPSEO_Config_Factory_Post_Type.

Defined (1)

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

/admin/config-ui/factories/class-factory-post-type.php  
  1. class WPSEO_Config_Factory_Post_Type { 
  2.  
  3. /** @var WPSEO_Config_Field_Choice_Post_Type[] List of fields */ 
  4. protected static $fields = array(); 
  5.  
  6. /** 
  7. * @return WPSEO_Config_Field_Choice_Post_Type[] List of fields. 
  8. */ 
  9. public function get_fields() { 
  10.  
  11. if ( empty( self::$fields ) ) { 
  12.  
  13. $fields = array(); 
  14.  
  15. $post_types = get_post_types( array( 'public' => true ), 'objects' ); 
  16. if ( ! empty( $post_types ) ) { 
  17. foreach ( $post_types as $post_type => $post_type_object ) { 
  18. $label = $this->decode_html_entities( $post_type_object->label ); 
  19. $field = new WPSEO_Config_Field_Choice_Post_Type( $post_type, $label ); 
  20.  
  21. $this->add_custom_properties( $post_type, $field ); 
  22.  
  23. $fields[] = $field; 
  24.  
  25. self::$fields = $fields; 
  26.  
  27. return self::$fields; 
  28.  
  29. /** 
  30. * Add custom properties for specific post types 
  31. * @param string $post_type Post type of field that is being added. 
  32. * @param WPSEO_Config_Field $field Field that corresponds to the post type. 
  33. */ 
  34. private function add_custom_properties( $post_type, $field ) { 
  35. if ( 'attachment' === $post_type ) { 
  36. $field->set_property( 'explanation', __( 'WordPress automatically generates an URL for each media item in the library. Enabling this will allow for google to index the generated URL.', 'wordpress-seo' ) ); 
  37.  
  38. /** 
  39. * Replaces the HTML entity with it's actual symbol. 
  40. * Because we do not not know what consequences it will have if we convert every HTML entity,  
  41. * we will only replace the characters that we have known problems with in text's. 
  42. * @param string $text The text to decode. 
  43. * @return string String with decoded HTML entities. 
  44. */ 
  45. private function decode_html_entities( $text ) { 
  46. return str_replace( ''', '*', $text );