AuthorPageTitle.php
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace ACA\YoastSeo\Column\User;
use AC;
use AC\MetaType;
use ACA\YoastSeo\Editing;
use ACA\YoastSeo\Export;
use ACA\YoastSeo\Filtering;
use ACP;
use ACP\Editing\Service\Basic;
use ACP\Editing\Storage\Meta;
use ACP\Editing\View\Text;
class AuthorPageTitle extends AC\Column\Meta
implements ACP\Editing\Editable, ACP\Search\Searchable, ACP\Sorting\Sortable, ACP\ConditionalFormat\Formattable {
use ACP\ConditionalFormat\ConditionalFormatTrait;
public function __construct() {
$this->set_type( 'column-yoast_author_title' )
->set_group( 'yoast-seo' )
->set_label( __( 'SEO Title', 'codepress-admin-columns' ) );
}
private function get_wp_seo_author_title( $user_id ) {
$old_author = get_query_var( 'author' );
set_query_var( 'author', $user_id );
$titles = get_option( 'wpseo_titles' );
$author_title = isset( $titles['title-author-wpseo'] ) ? $titles['title-author-wpseo'] : false;
$title = wpseo_replace_vars( $author_title, (object) [] );
set_query_var( 'author', $old_author );
return $title;
}
public function get_value( $id ) {
$title = $this->get_raw_value( $id );
if ( ! $title ) {
$icon = ac_helper()->html->tooltip(
ac_helper()->icon->dashicon( [ 'icon' => 'media-text', 'class' => 'gray' ] ),
__( 'Specific title is missing. The current title is generated by Yoast SEO.', 'codepress-admin-columns' )
);
$title = sprintf( '%s %s',
$icon,
$this->get_wp_seo_author_title( $id )
);
}
return $title;
}
public function get_meta_key() {
return 'wpseo_title';
}
public function search() {
return new ACP\Search\Comparison\Meta\Text( $this->get_meta_key(), $this->get_meta_type() );
}
public function editing() {
return new Basic( new Text(), new Meta( $this->get_meta_key(), new MetaType( MetaType::USER ) ) );
}
public function sorting() {
return new ACP\Sorting\Model\User\Meta( $this->get_meta_key() );
}
}