PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/config-ui/fields/class-field-choice-post-type.php

https://bitbucket.org/carloskikea/helpet
PHP | 81 lines | 32 code | 13 blank | 36 comment | 1 complexity | 1159dd4542238ec26a77f5e02807fc6b MD5 | raw file
 1<?php
 2/**
 3 * WPSEO plugin file.
 4 *
 5 * @package WPSEO\Admin\ConfigurationUI
 6 */
 7
 8/**
 9 * Class WPSEO_Config_Field_Choice_Post_Type
10 */
11class WPSEO_Config_Field_Choice_Post_Type extends WPSEO_Config_Field_Choice {
12
13	/** @var string Post type */
14	protected $post_type;
15
16	/**
17	 * WPSEO_Config_Field_Choice_Post_Type constructor.
18	 *
19	 * @param string $post_type The post type to add.
20	 * @param string $label     Label to show (translated post type).
21	 */
22	public function __construct( $post_type, $label ) {
23		parent::__construct( 'postType' . ucfirst( $post_type ) );
24
25		$this->post_type = $post_type;
26
27		/* Translators: %1$s expands to the name of the post type. The options given to the user are "visible" and "hidden" */
28		$this->set_property( 'label', sprintf( __( 'Search engines should show "%1$s" in search results:', 'wordpress-seo' ), $label ) );
29
30		$this->add_choice( 'true', __( 'Yes', 'wordpress-seo' ) );
31		$this->add_choice( 'false', __( 'No', 'wordpress-seo' ) );
32	}
33
34	/**
35	 * Set adapter
36	 *
37	 * @param WPSEO_Configuration_Options_Adapter $adapter Adapter to register lookup on.
38	 */
39	public function set_adapter( WPSEO_Configuration_Options_Adapter $adapter ) {
40		$adapter->add_custom_lookup(
41			$this->get_identifier(),
42			array( $this, 'get_data' ),
43			array( $this, 'set_data' )
44		);
45	}
46
47	/**
48	 * Get the post type of this field.
49	 *
50	 * @return string Post type.
51	 */
52	public function get_post_type() {
53		return $this->post_type;
54	}
55
56	/**
57	 * @return bool
58	 */
59	public function get_data() {
60		$key = 'noindex-' . $this->get_post_type();
61
62		if ( WPSEO_Options::get( $key, false ) === false ) {
63			return 'true';
64		}
65
66		return 'false';
67	}
68
69	/**
70	 * Set new data
71	 *
72	 * @param string $visible Visible (true) or hidden (false).
73	 *
74	 * @return bool
75	 */
76	public function set_data( $visible ) {
77		$post_type = $this->get_post_type();
78
79		return WPSEO_Options::set( 'noindex-' . $post_type, ( $visible === 'false' ) );
80	}
81}