PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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