Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin refactor with Interfaces. #125

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .distignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/.git
/.github
/node_modules
/vendor
/phpstan
.prettierrc
.distignore
.gitignore
yarn.lock
phpcs.xml
phpstan.neon.dist
yarn.lock

9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ node_modules/
*.zip
.idea*
wp-content/
vendor/
notes.md
!vendor
vendor/*
!vendor/autoload.php
!vendor/composer
vendor/composer/installed.json
vendor/composer/*/
notes.md
102 changes: 102 additions & 0 deletions access-functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* This file contains access functions for various class methods.
*
* @todo Maybe move these into the plugin namespace?
*
* @since @todo
* @package .
*/

if ( ! function_exists( 'wp_gql_seo_format_string' ) ) {
/**
* Sanitizes and formats a string.
*
* @param string $string .
*/
function wp_gql_seo_format_string( string $string ) : ?string {
return ! empty( $string ) ? html_entity_decode( trim( $string ) ) : null;
}
}

if ( ! function_exists( 'wp_gql_seo_get_og_image' ) ) {
/**
* Get postID for og image.
*
* @param array $images
* @return string|int|false
*/
function wp_gql_seo_get_og_image( array $images ) {
if ( empty( $images ) ) {
return '';
}

$image = reset( $images );

if ( empty( $image['url'] ) ) {
return '';
}

// Remove image sizes from url.
$url = preg_replace(
'/(.*)-\d+x\d+\.(jpg|png|gif)$/',
'$1.$2',
(string) $image['url']
);

return null !== $url ? wpcom_vip_attachment_url_to_postid( $url ) : '';
}


if ( ! function_exists( 'wp_gql_seo_get_field_key' ) ) {
function wp_gql_seo_get_field_key( string $field_key ) : string {
$field_key = lcfirst( preg_replace( '[^a-zA-Z0-9 -]', ' ', $field_key ) ?: '' );
$field_key = lcfirst( str_replace( '_', ' ', ucwords( $field_key, '_' ) ?: '' ) );
$field_key = lcfirst( str_replace( '-', ' ', ucwords( $field_key, '_' ) ?: '' ) );
$field_key = lcfirst( str_replace( ' ', '', ucwords( $field_key, ' ' ) ?: '' ) );

return $field_key;
}
}

if ( ! function_exists( 'wpcom_vip_attachment_url_to_postid' ) ) {
function wpcom_vip_attachment_cache_key( string $url ) : string {
return 'wpcom_vip_attachment_url_post_id_' . md5( $url );
}
}

if ( ! function_exists( 'wpcom_vip_attachment_url_to_postid' ) ) {
/**
* Get the cached post from an attachment URL.
*
* @param string $url .
* @return int|false
*/
function wpcom_vip_attachment_url_to_postid( string $url ) {
$cache_key = wpcom_vip_attachment_cache_key( $url );
$id = wp_cache_get( $cache_key );
if ( false === $id ) {
$id = attachment_url_to_postid( $url );
if ( empty( $id ) ) {
wp_cache_set(
$cache_key,
'not_found',
'default',
12 * HOUR_IN_SECONDS + mt_rand(0, 4 * HOUR_IN_SECONDS) // phpcs:ignore
);
} else {
wp_cache_set(
$cache_key,
$id,
'default',
24 * HOUR_IN_SECONDS + mt_rand(0, 12 * HOUR_IN_SECONDS) // phpcs:ignore
);
}
} elseif ( 'not_found' === $id ) {
return false;
}

return $id;
}
}
}
82 changes: 60 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
{
"name": "ashhitch/wp-graphql-yoast-seo",
"description": "Query Yoast SEO data with wp-graphql",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Ash Hitchcock",
"email": "[email protected]"
}
],
"suggest": {
"wp-graphql/wp-graphql": "Required to return data via GraphQl",
"yoast/wordpress-seo": "Required to provide SEO data to this plugin"
},
"require-dev": {
"automattic/vipwpcs": "^2.2",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"squizlabs/php_codesniffer": "^3.5"
},
"require": {
"phpcompatibility/phpcompatibility-wp": "^2.1"
}
"name": "ashhitch/wp-graphql-yoast-seo",
"description": "Query Yoast SEO data with wp-graphql",
"type": "wordpress-plugin",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Ash Hitchcock",
"email": "[email protected]"
}
],
"suggest": {
"wp-graphql/wp-graphql": "Required to return data via GraphQl",
"yoast/wordpress-seo": "Required to provide SEO data to this plugin"
},
"require": {
"php": ">=7.4 || ^8.0"
},
"require-dev": {
"automattic/vipwpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.2",
"poolshark/wp-graphql-stubs": "^0.0.2",
"squizlabs/php_codesniffer": "^3.6",
"szepeviktor/phpstan-wordpress": "^1.0",
"wp-coding-standards/wpcs": "^2.3",
"php-stubs/wordpress-seo-stubs": "^17.2"
},
"config": {
"optimize-autoloader": true,
"process-timeout": 0,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"autoload": {
"files": [
"access-functions.php"
],
"psr-4": {
"WPGraphQL\\YoastSEO\\": "src/"
}
},
"scripts": {
"lint": "vendor/bin/phpcs",
"phpcs-i": [
"php ./vendor/bin/phpcs -i"
],
"check-cs": [
"php ./vendor/bin/phpcs"
],
"fix-cs": [
"php ./vendor/bin/phpcbf"
],
"phpstan": [
"phpstan analyze --ansi --memory-limit=1G"
]
}
}
Loading