/wp-content/plugins/wordpress-seo/admin/class-cornerstone-field.php

https://bitbucket.org/carloskikea/helpet · PHP · 57 lines · 26 code · 8 blank · 23 comment · 2 complexity · cbb59bd04c1c2fe2d4a6af62478725ed MD5 · raw file

  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. */
  7. /**
  8. * Adds a checkbox to the focus keyword section.
  9. */
  10. class WPSEO_Cornerstone_Field {
  11. /**
  12. * Returns a label with a checkbox in it. Make it possible to mark the page as cornerstone content.
  13. *
  14. * @param WP_POST $post The post object.
  15. *
  16. * @return string The HTML to show.
  17. */
  18. public function get_html( $post ) {
  19. $post_types = apply_filters( 'wpseo_cornerstone_post_types', WPSEO_Post_Type::get_accessible_post_types() );
  20. if ( ! is_array( $post_types ) || ! isset( $post_types[ get_post_type( $post ) ] ) ) {
  21. return '';
  22. }
  23. $return = '';
  24. $return .= sprintf(
  25. '<input id="%1$s" class="wpseo-cornerstone-checkbox" type="checkbox" value="1" name="%1$s" %2$s/>',
  26. WPSEO_Cornerstone::FIELD_NAME,
  27. checked( $this->get_meta_value( $post->ID ), '1', false )
  28. );
  29. $return .= sprintf( '<label for="%1$s">', WPSEO_Cornerstone::FIELD_NAME );
  30. $return .= sprintf(
  31. /* translators: 1: link open tag; 2: link close tag. */
  32. __( 'This article is %1$scornerstone content%2$s', 'wordpress-seo' ),
  33. '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/metabox-help-cornerstone' ) . '" target="_blank">',
  34. '</a>'
  35. );
  36. $return .= '</label>';
  37. return $return;
  38. }
  39. /**
  40. * Gets the meta value from the database.
  41. *
  42. * @param int $post_id The post id to get the meta value for.
  43. *
  44. * @return null|string The meta value from the database.
  45. */
  46. protected function get_meta_value( $post_id ) {
  47. return WPSEO_Meta::get_value( WPSEO_Cornerstone::META_NAME, $post_id );
  48. }
  49. }