• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AxeWP / wp-graphql-rank-math / 6257335822

21 Sep 2023 04:53AM UTC coverage: 92.176%. First build
6257335822

Pull #59

github

web-flow
Merge e6916cad3 into a7f39383c
Pull Request #59: chore: Update dev-deps and lint

24 of 24 new or added lines in 11 files covered. (100.0%)

2533 of 2748 relevant lines covered (92.18%)

11.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.38
/src/Type/WPObject/Settings/Meta/ContentTypeMeta.php
1
<?php
2
/**
3
 * The ContentTypeMeta GraphQL object.
4
 *
5
 * @package WPGraphQL\RankMath\Type\WPObject\Settings\Meta
6
 */
7

8
namespace WPGraphQL\RankMath\Type\WPObject\Settings\Meta;
9

10
use GraphQL\Error\UserError;
11
use RankMath\Helper;
12
use WPGraphQL\AppContext;
13
use WPGraphQL\RankMath\Type\Enum\ArticleTypeEnum;
14
use WPGraphQL\RankMath\Type\Enum\BulkEditingTypeEnum;
15
use WPGraphQL\RankMath\Type\Enum\SnippetTypeEnum;
16
use WPGraphQL\RankMath\Type\WPInterface\MetaSettingWithArchive;
17
use WPGraphQL\RankMath\Type\WPInterface\MetaSettingWithRobots;
18
use WPGraphQL\RankMath\Vendor\AxeWP\GraphQL\Abstracts\ObjectType;
19

20
/**
21
 * Class - ContentTypeMeta
22
 */
23
class ContentTypeMeta extends ObjectType {
24
        /**
25
         * {@inheritDoc}
26
         */
27
        protected static function type_name(): string {
28
                return 'ContentTypeMetaSettings';
18✔
29
        }
30

31
        /**
32
         * {@inheritDoc}
33
         */
34
        public static function get_description(): string {
35
                return __( 'The RankMath SEO Post Type settings.', 'wp-graphql-rank-math' );
18✔
36
        }
37

38
        /**
39
         * {@inheritDoc}
40
         */
41
        public static function register(): void {
42
                /** @var \WP_Post_Type[] */
43
                $allowed_post_types = \WPGraphQL::get_allowed_post_types( 'objects', [ 'public' => true ] );
18✔
44

45
                foreach ( $allowed_post_types as $post_type_object ) {
18✔
46
                        // Skip attachment meta if redirection is enabled.
47
                        if ( 'attachment' === $post_type_object->name && Helper::get_settings( 'general.attachment_redirect_urls', true ) ) {
18✔
48
                                continue;
18✔
49
                        }
50

51
                        $interfaces = [
18✔
52
                                MetaSettingWithRobots::get_type_name(),
18✔
53
                        ];
18✔
54
                        if ( $post_type_object->has_archive ) {
18✔
55
                                $interfaces[] = MetaSettingWithArchive::get_type_name();
×
56
                        }
57

58
                        register_graphql_object_type(
18✔
59
                                ucfirst( $post_type_object->graphql_single_name ) . 'MetaSettings',
18✔
60
                                [
18✔
61
                                        'description' => sprintf(
18✔
62
                                        // translators: post type name.
63
                                                __( 'The RankMath SEO meta settings for %s.', 'wp-graphql-rank-math' ),
18✔
64
                                                $post_type_object->label,
18✔
65
                                        ),
18✔
66
                                        'interfaces'  => $interfaces,
18✔
67
                                        'fields'      => self::get_child_type_fields( $post_type_object ),
18✔
68
                                ]
18✔
69
                        );
18✔
70
                }
71

72
                parent::register();
18✔
73
        }
74

75
        /**
76
         * {@inheritDoc}
77
         */
78
        public static function get_fields(): array {
79
                /** @var \WP_Post_Type[] */
80
                $allowed_post_types = \WPGraphQL::get_allowed_post_types( 'objects', [ 'public' => true ] );
18✔
81

82
                $fields = [];
18✔
83

84
                foreach ( $allowed_post_types as $post_type_object ) {
18✔
85

86
                        // Skip attachment meta if redirection is enabled.
87
                        if ( 'attachment' === $post_type_object->name && Helper::get_settings( 'general.attachment_redirect_urls', true ) ) {
18✔
88
                                continue;
18✔
89
                        }
90

91
                        $fields[ lcfirst( $post_type_object->graphql_single_name ) ] = [
18✔
92
                                'type'        => $post_type_object->graphql_single_name . 'MetaSettings',
18✔
93
                                'description' => sprintf(
18✔
94
                                        // translators: post type name.
95
                                        __( 'The RankMath SEO meta settings for %s.', 'wp-graphql-rank-math' ),
18✔
96
                                        $post_type_object->label,
18✔
97
                                ),
18✔
98
                        ];
18✔
99
                }
100

101
                return $fields;
18✔
102
        }
103

104
        /**
105
         * Get the fields for the provided content type.
106
         *
107
         * @param \WP_Post_Type $post_type_object .
108
         *
109
         * @return array<string, array<string, mixed>>
110
         */
111
        public static function get_child_type_fields( \WP_Post_Type $post_type_object ): array {
112
                $fields = [
18✔
113
                        'title'                   => [
18✔
114
                                'type'        => 'String',
18✔
115
                                'description' => sprintf(
18✔
116
                                        // translators: post type label.
117
                                        __( 'Default title tag for single %s pages.', 'wp-graphql-rank-math' ),
18✔
118
                                        $post_type_object->label,
18✔
119
                                ),
18✔
120
                        ],
18✔
121
                        'description'             => [
18✔
122
                                'type'        => 'String',
18✔
123
                                'description' => sprintf(
18✔
124
                                        // translators: post type label.
125
                                        __( 'Default description for single %s pages.', 'wp-graphql-rank-math' ),
18✔
126
                                        $post_type_object->label,
18✔
127
                                ),
18✔
128
                        ],
18✔
129
                        'snippetType'             => [
18✔
130
                                'type'        => SnippetTypeEnum::get_type_name(),
18✔
131
                                'description' => sprintf(
18✔
132
                                        // translators: post type label.
133
                                        __( 'Default rich snippet select when creating a new %s.', 'wp-graphql-rank-math' ),
18✔
134
                                        $post_type_object->label,
18✔
135
                                ),
18✔
136
                        ],
18✔
137
                        'articleType'             => [
18✔
138
                                'type'        => ArticleTypeEnum::get_type_name(),
18✔
139
                                'description' => sprintf(
18✔
140
                                        // translators: post type label.
141
                                        __( 'Default article type when creating a new %s.', 'wp-graphql-rank-math' ),
18✔
142
                                        $post_type_object->label,
18✔
143
                                ),
18✔
144
                        ],
18✔
145
                        'snippetHeadline'         => [
18✔
146
                                'type'        => 'String',
18✔
147
                                'description' => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
18✔
148
                        ],
18✔
149
                        'snippetDescription'      => [
18✔
150
                                'type'        => 'String',
18✔
151
                                'description' => __( 'Default rich snippet headline.', 'wp-graphql-rank-math' ),
18✔
152
                        ],
18✔
153
                        'hasCustomRobotsMeta'     => [
18✔
154
                                'type'        => 'Boolean',
18✔
155
                                'description' => __( 'Whether custom robots meta for author page are set. Otherwise the default meta will be used, as set in the Global Meta tab.', 'wp-graphql-rank-math' ),
18✔
156
                        ],
18✔
157
                        'hasLinkSuggestions'      => [
18✔
158
                                'type'        => 'Boolean',
18✔
159
                                'description' => __( 'Whether Link Suggestions meta box and the Pillar Content featured are enabled for this post type.', 'wp-graphql-rank-math' ),
18✔
160
                        ],
18✔
161
                        'shouldUseFocusKeyword'   => [
18✔
162
                                'type'        => 'Boolean',
18✔
163
                                'description' => __( 'Whether to use the Focus Keyword as the default text for the links instead of the post titles.', 'wp-graphql-rank-math' ),
18✔
164
                        ],
18✔
165
                        'hasBulkEditing'          => [
18✔
166
                                'type'        => BulkEditingTypeEnum::get_type_name(),
18✔
167
                                'description' => __( 'Whether to list bulk editing columns to the post listing screen.', 'wp-graphql-rank-math' ),
18✔
168
                        ],
18✔
169
                        'socialImage'             => [
18✔
170
                                'type'        => 'MediaItem',
18✔
171
                                'description' => __( 'The default image to display when sharing this post type on social media', 'wp-graphql-rank-math' ),
18✔
172
                                'resolve'     => static function ( $source, array $args, AppContext $context ) {
18✔
173
                                        return ! empty( $source['socialImage'] ) ? $context->get_loader( 'post' )->load_deferred( $source['socialImage'] ) : null;
1✔
174
                                },
18✔
175
                        ],
18✔
176
                        'hasSlackEnhancedSharing' => [
18✔
177
                                'type'        => 'Boolean',
18✔
178
                                'description' => __( 'Whether to show additional information (name & total number of posts) when an author archive is shared on Slack.', 'wp-graphql-rank-math' ),
18✔
179
                        ],
18✔
180
                        'hasSeoControls'          => [
18✔
181
                                'type'        => 'Boolean',
18✔
182
                                'description' => __( 'Whether the SEO Controls meta box for user profile pages is enabled.', 'wp-graphql-rank-math' ),
18✔
183
                        ],
18✔
184
                        'analyzedFields'          => [
18✔
185
                                'type'        => [ 'list_of' => 'String' ],
18✔
186
                                'description' => __( 'List of custom fields name to include in the Page analysis', 'wp-graphql-rank-math' ),
18✔
187
                        ],
18✔
188
                ];
18✔
189

190
                $all_taxonomies = Helper::get_object_taxonomies( $post_type_object->name );
18✔
191
                $all_taxonomies = is_array( $all_taxonomies ) && ! empty( $all_taxonomies ) ? $all_taxonomies : [];
18✔
192

193
                $allowed_taxonomies = \WPGraphQL::get_allowed_taxonomies( 'names', [ 'public' => true ] );
18✔
194

195
                $taxonomies = array_intersect( $all_taxonomies, $allowed_taxonomies );
18✔
196

197
                if ( ! empty( $taxonomies ) ) {
18✔
198
                        $fields['primaryTaxonomy'] = [
×
199
                                'type'        => 'TaxonomyEnum',
×
200
                                'description' => __( 'The taxonomy used with the Primary Term Feature and displayed in the Breadcrumbs.', 'wp-graphql-rank-math' ),
×
201
                                'resolve'     => static function ( $source ) use ( $allowed_taxonomies ) {
×
202
                                        if ( ! in_array( $source, $allowed_taxonomies, true ) ) {
×
203
                                                throw new UserError(
×
204
                                                        sprintf(
×
205
                                                                // translators: taxonomy name.
206
                                                                esc_html__( 'The %s post type is not available in WPGraphQL', 'wp-graphql-rank-math' ),
×
207
                                                                esc_html( $source )
×
208
                                                        )
×
209
                                                );
×
210
                                        }
211
                                },
×
212
                        ];
×
213
                }
214

215
                if ( $post_type_object->has_archive ) {
18✔
216
                        unset( $fields['socialImage'] );
×
217
                }
218

219
                if ( in_array( $post_type_object->name, [ 'product', 'download', 'rank_math_locations' ], true ) ) {
18✔
220
                        unset( $fields['snippetDescription'] );
×
221
                        unset( $fields['snippetHeadline'] );
×
222
                }
223

224
                if ( 'attachment' === $post_type_object->name ) {
18✔
225
                        unset( $fields['hasLinkSuggestions'] );
×
226
                        unset( $fields['shouldUseFocusKeyword'] );
×
227
                        unset( $fields['hasSlackEnhancedSharing'] );
×
228
                }
229

230
                if ( defined( 'WEBSTORIES_VERSION' ) && 'web-story' === $post_type_object->name ) {
18✔
231
                        unset( $fields['snippetDescription'] );
×
232
                        unset( $fields['description'] );
×
233
                        unset( $fields['hasLinkSuggestions'] );
×
234
                        unset( $fields['shouldUseFocusKeyword'] );
×
235
                        unset( $fields['analyzedFields'] );
×
236
                        unset( $fields['hasBulkEditing'] );
×
237
                        unset( $fields['hasSeoControls'] );
×
238
                }
239

240
                return $fields;
18✔
241
        }
242
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc