@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | private $configuration; |
| 23 | 23 | |
| 24 | - public function __construct( $configuration ) { |
|
| 24 | + public function __construct($configuration) { |
|
| 25 | 25 | $this->configuration = $configuration; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * Register hooks. |
| 30 | 30 | */ |
| 31 | 31 | public function register_hooks() { |
| 32 | - add_filter( 'wl_is_enabled', array( $this, 'wl_is_enabled' ) ); |
|
| 32 | + add_filter('wl_is_enabled', array($this, 'wl_is_enabled')); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,50 +39,50 @@ discard block |
||
| 39 | 39 | * |
| 40 | 40 | * @return bool|mixed |
| 41 | 41 | */ |
| 42 | - public function wl_is_enabled( $enabled ) { |
|
| 42 | + public function wl_is_enabled($enabled) { |
|
| 43 | 43 | |
| 44 | 44 | // Always enable wordlift on admin and rest api pages. |
| 45 | - if ( is_admin() || $this->is_rest_request() ) { |
|
| 45 | + if (is_admin() || $this->is_rest_request()) { |
|
| 46 | 46 | return $enabled; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
| 50 | - $options = get_option( 'wl_exclude_include_urls_settings' ); |
|
| 49 | + $path = strtok((string) $_SERVER['REQUEST_URI'], '?'); // phpcs:ignore |
|
| 50 | + $options = get_option('wl_exclude_include_urls_settings'); |
|
| 51 | 51 | |
| 52 | 52 | // Bail out if URLs are not set. |
| 53 | - if ( empty( $options['urls'] ) ) { |
|
| 53 | + if (empty($options['urls'])) { |
|
| 54 | 54 | return $enabled; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $current_url = trailingslashit( home_url( $path ) ); |
|
| 57 | + $current_url = trailingslashit(home_url($path)); |
|
| 58 | 58 | |
| 59 | - return $this->are_urls_included( $current_url ); |
|
| 59 | + return $this->are_urls_included($current_url); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public function are_urls_included( $urls ) { |
|
| 62 | + public function are_urls_included($urls) { |
|
| 63 | 63 | // Ensure we deal with an array. We `trailingslashit` all URLs to avoid issues with missing slashes. |
| 64 | - $urls = array_map( 'trailingslashit', (array) $urls ); |
|
| 64 | + $urls = array_map('trailingslashit', (array) $urls); |
|
| 65 | 65 | |
| 66 | 66 | // Set a default state. |
| 67 | - $include_by_default = ( $this->configuration->get_default() === 'include' ); |
|
| 67 | + $include_by_default = ($this->configuration->get_default() === 'include'); |
|
| 68 | 68 | |
| 69 | 69 | // Get URLs into an array from settings, trim them and make absolute if needed. |
| 70 | 70 | $configured_urls = array_map( |
| 71 | - function ( $url ) { |
|
| 72 | - $url = trim( $url ); |
|
| 73 | - if ( substr( $url, 0, 4 ) !== 'http' ) { |
|
| 74 | - return trailingslashit( home_url( $url ) ); |
|
| 71 | + function($url) { |
|
| 72 | + $url = trim($url); |
|
| 73 | + if (substr($url, 0, 4) !== 'http') { |
|
| 74 | + return trailingslashit(home_url($url)); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | // Add a trailing slash and return the url |
| 78 | - return trailingslashit( $url ); |
|
| 78 | + return trailingslashit($url); |
|
| 79 | 79 | }, |
| 80 | - explode( PHP_EOL, $this->configuration->get_urls() ) |
|
| 80 | + explode(PHP_EOL, $this->configuration->get_urls()) |
|
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | // Check if any of the provided URLs is in the configured URLs. |
| 84 | - $intersection = array_intersect( $urls, $configured_urls ); |
|
| 85 | - if ( ! empty( $intersection ) ) { |
|
| 84 | + $intersection = array_intersect($urls, $configured_urls); |
|
| 85 | + if ( ! empty($intersection)) { |
|
| 86 | 86 | return ! $include_by_default; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -95,15 +95,15 @@ discard block |
||
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | 97 | protected function is_rest_request() { |
| 98 | - if ( empty( $_SERVER['REQUEST_URI'] ) ) { |
|
| 98 | + if (empty($_SERVER['REQUEST_URI'])) { |
|
| 99 | 99 | // Probably a CLI request. |
| 100 | 100 | return false; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $rest_prefix = trailingslashit( rest_get_url_prefix() ); |
|
| 104 | - $path = strtok( (string) $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore |
|
| 103 | + $rest_prefix = trailingslashit(rest_get_url_prefix()); |
|
| 104 | + $path = strtok((string) $_SERVER['REQUEST_URI'], '?'); // phpcs:ignore |
|
| 105 | 105 | |
| 106 | - return strpos( $path, $rest_prefix ) !== false; |
|
| 106 | + return strpos($path, $rest_prefix) !== false; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | } |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | private $urls; |
| 11 | 11 | |
| 12 | 12 | protected function __construct() { |
| 13 | - $include_exclude_data = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
| 14 | - $include_exclude = isset( $include_exclude_data['include_exclude'] ) ? (array) $include_exclude_data['include_exclude'] : array(); |
|
| 13 | + $include_exclude_data = get_option('wl_exclude_include_urls_settings', array()); |
|
| 14 | + $include_exclude = isset($include_exclude_data['include_exclude']) ? (array) $include_exclude_data['include_exclude'] : array(); |
|
| 15 | 15 | |
| 16 | 16 | $this->type = in_array( |
| 17 | 17 | $include_exclude, |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public static function get_instance() { |
| 29 | - if ( ! isset( self::$instance ) ) { |
|
| 29 | + if ( ! isset(self::$instance)) { |
|
| 30 | 30 | self::$instance = new self(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | 45 | public function get_default() { |
| 46 | - return ( $this->type === 'exclude' ? 'include' : 'exclude' ); |
|
| 46 | + return ($this->type === 'exclude' ? 'include' : 'exclude'); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function get_urls() { |
@@ -7,21 +7,21 @@ |
||
| 7 | 7 | /** @var Plugin_Enabled $plugin_enabled */ |
| 8 | 8 | private $plugin_enabled; |
| 9 | 9 | |
| 10 | - public function __construct( $plugin_enabled ) { |
|
| 10 | + public function __construct($plugin_enabled) { |
|
| 11 | 11 | $this->plugin_enabled = $plugin_enabled; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function register_hooks() { |
| 15 | - add_filter( 'wl_after_get_jsonld', array( $this, 'after_get_jsonld' ) ); |
|
| 15 | + add_filter('wl_after_get_jsonld', array($this, 'after_get_jsonld')); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function after_get_jsonld( $jsonld_arr ) { |
|
| 19 | - if ( ! is_array( $jsonld_arr ) || empty( $jsonld_arr ) || ! isset( $jsonld_arr[0]['url'] ) ) { |
|
| 18 | + public function after_get_jsonld($jsonld_arr) { |
|
| 19 | + if ( ! is_array($jsonld_arr) || empty($jsonld_arr) || ! isset($jsonld_arr[0]['url'])) { |
|
| 20 | 20 | return $jsonld_arr; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | // If the URLs are included then publish them. |
| 24 | - if ( $this->plugin_enabled->are_urls_included( $jsonld_arr[0]['url'] ) ) { |
|
| 24 | + if ($this->plugin_enabled->are_urls_included($jsonld_arr[0]['url'])) { |
|
| 25 | 25 | return $jsonld_arr; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | use Wordlift\Modules\Common\Symfony\Component\DependencyInjection\ContainerBuilder; |
| 13 | 13 | use Wordlift\Modules\Common\Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
| 14 | 14 | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if ( ! defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -20,8 +20,8 @@ discard block |
||
| 20 | 20 | * This module loads very early since it needs to tell WLP whether to load itself or not. Therefore we need to load the |
| 21 | 21 | * feature settings by ourselves. |
| 22 | 22 | */ |
| 23 | -$wl_features = get_option( '_wl_features', array() ); |
|
| 24 | -if ( ! apply_filters( 'wl_feature__enable__include-exclude', isset( $wl_features['include-exclude'] ) && $wl_features['include-exclude'] ) ) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 23 | +$wl_features = get_option('_wl_features', array()); |
|
| 24 | +if ( ! apply_filters('wl_feature__enable__include-exclude', isset($wl_features['include-exclude']) && $wl_features['include-exclude'])) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -33,26 +33,26 @@ discard block |
||
| 33 | 33 | function __wl_include_exclude__load() { |
| 34 | 34 | |
| 35 | 35 | // Autoloader for plugin itself. |
| 36 | - if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 37 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
| 36 | + if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
| 37 | + require_once __DIR__.'/vendor/autoload.php'; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $container_builder = new ContainerBuilder(); |
| 41 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | - $loader->load( 'services.yml' ); |
|
| 41 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 42 | + $loader->load('services.yml'); |
|
| 43 | 43 | $container_builder->compile(); |
| 44 | 44 | |
| 45 | - $enabled = $container_builder->get( 'Wordlift\Modules\Include_Exclude\Plugin_Enabled' ); |
|
| 45 | + $enabled = $container_builder->get('Wordlift\Modules\Include_Exclude\Plugin_Enabled'); |
|
| 46 | 46 | $enabled->register_hooks(); |
| 47 | 47 | |
| 48 | - if ( apply_filters( 'wl_is_enabled', true ) ) { |
|
| 49 | - $settings = $container_builder->get( 'Wordlift\Modules\Include_Exclude\Admin\Settings' ); |
|
| 48 | + if (apply_filters('wl_is_enabled', true)) { |
|
| 49 | + $settings = $container_builder->get('Wordlift\Modules\Include_Exclude\Admin\Settings'); |
|
| 50 | 50 | $settings->register_hooks(); |
| 51 | 51 | |
| 52 | - $api = $container_builder->get( 'Wordlift\Modules\Include_Exclude\API' ); |
|
| 52 | + $api = $container_builder->get('Wordlift\Modules\Include_Exclude\API'); |
|
| 53 | 53 | $api->register_hooks(); |
| 54 | 54 | |
| 55 | - $jsonld_interceptor = $container_builder->get( 'Wordlift\Modules\Include_Exclude\Jsonld_Interceptor' ); |
|
| 55 | + $jsonld_interceptor = $container_builder->get('Wordlift\Modules\Include_Exclude\Jsonld_Interceptor'); |
|
| 56 | 56 | $jsonld_interceptor->register_hooks(); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @since 3.10.0 |
| 48 | 48 | */ |
| 49 | - public function __construct( $entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false ) { |
|
| 50 | - parent::__construct( $entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create() ); |
|
| 49 | + public function __construct($entity_type_service, $user_service, $attachment_service, $disable_convert_filters = false) { |
|
| 50 | + parent::__construct($entity_type_service, $user_service, $attachment_service, Wordlift_Property_Getter_Factory::create()); |
|
| 51 | 51 | $this->disable_convert_filters = $disable_convert_filters; |
| 52 | 52 | // Set a reference to the logger. |
| 53 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Post_To_Jsonld_Converter' ); |
|
| 53 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Post_To_Jsonld_Converter'); |
|
| 54 | 54 | |
| 55 | 55 | self::$instance = $this; |
| 56 | 56 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function new_instance_with_filters_disabled() { |
| 65 | - return new static( $this->entity_type_service, $this->user_service, $this->attachment_service, true ); |
|
| 65 | + return new static($this->entity_type_service, $this->user_service, $this->attachment_service, true); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -76,30 +76,30 @@ discard block |
||
| 76 | 76 | * @return array A JSON-LD array. |
| 77 | 77 | * @since 3.10.0 |
| 78 | 78 | */ |
| 79 | - public function convert( $post_id, &$references = array(), &$references_infos = array(), $relations = null ) { |
|
| 79 | + public function convert($post_id, &$references = array(), &$references_infos = array(), $relations = null) { |
|
| 80 | 80 | |
| 81 | 81 | // Get the post instance. |
| 82 | - $post = get_post( $post_id ); |
|
| 83 | - if ( null === $post ) { |
|
| 82 | + $post = get_post($post_id); |
|
| 83 | + if (null === $post) { |
|
| 84 | 84 | // Post not found. |
| 85 | 85 | return null; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Get the base JSON-LD and the list of entities referenced by this entity. |
| 89 | - $jsonld = parent::convert( $post_id, $references, $references_infos, $relations ); |
|
| 89 | + $jsonld = parent::convert($post_id, $references, $references_infos, $relations); |
|
| 90 | 90 | |
| 91 | 91 | // Set WebPage by default. |
| 92 | - if ( empty( $jsonld['@type'] ) ) { |
|
| 92 | + if (empty($jsonld['@type'])) { |
|
| 93 | 93 | $jsonld['@type'] = 'WebPage'; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Get the entity name. |
| 97 | 97 | $jsonld['headline'] = $post->post_title; |
| 98 | 98 | |
| 99 | - $custom_fields = $this->entity_type_service->get_custom_fields_for_post( $post_id ); |
|
| 99 | + $custom_fields = $this->entity_type_service->get_custom_fields_for_post($post_id); |
|
| 100 | 100 | |
| 101 | - if ( isset( $custom_fields ) ) { |
|
| 102 | - $this->process_type_custom_fields( $jsonld, $custom_fields, $post, $references, $references_infos ); |
|
| 101 | + if (isset($custom_fields)) { |
|
| 102 | + $this->process_type_custom_fields($jsonld, $custom_fields, $post, $references, $references_infos); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Set the published and modified dates. |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | try { |
| 114 | 114 | $default_timezone = date_default_timezone_get(); |
| 115 | - $timezone = get_option( 'timezone_string' ); |
|
| 116 | - if ( ! empty( $timezone ) ) { |
|
| 117 | - date_default_timezone_set( $timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 118 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
| 119 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i:sP', false, $post ); |
|
| 120 | - date_default_timezone_set( $default_timezone ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 115 | + $timezone = get_option('timezone_string'); |
|
| 116 | + if ( ! empty($timezone)) { |
|
| 117 | + date_default_timezone_set($timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 118 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i:sP', false, $post); |
|
| 119 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i:sP', false, $post); |
|
| 120 | + date_default_timezone_set($default_timezone); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.timezone_change_date_default_timezone_set |
|
| 121 | 121 | } else { |
| 122 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 123 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 122 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
| 123 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
| 124 | 124 | } |
| 125 | - } catch ( Exception $e ) { |
|
| 126 | - $jsonld['datePublished'] = get_post_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 127 | - $jsonld['dateModified'] = get_post_modified_time( 'Y-m-d\TH:i', true, $post, false ); |
|
| 125 | + } catch (Exception $e) { |
|
| 126 | + $jsonld['datePublished'] = get_post_time('Y-m-d\TH:i', true, $post, false); |
|
| 127 | + $jsonld['dateModified'] = get_post_modified_time('Y-m-d\TH:i', true, $post, false); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | // Get the word count for the post. |
@@ -135,8 +135,8 @@ discard block |
||
| 135 | 135 | * |
| 136 | 136 | * @since 3.20.0 |
| 137 | 137 | */ |
| 138 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
| 139 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
| 138 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
| 139 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
| 140 | 140 | $jsonld['wordCount'] = $post_adapter->word_count(); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -147,17 +147,17 @@ discard block |
||
| 147 | 147 | * |
| 148 | 148 | * @since 3.27.2 |
| 149 | 149 | */ |
| 150 | - if ( ! empty( $jsonld['@type'] ) && 'WebPage' !== $jsonld['@type'] ) { |
|
| 151 | - $post_adapter = new Wordlift_Post_Adapter( $post_id ); |
|
| 150 | + if ( ! empty($jsonld['@type']) && 'WebPage' !== $jsonld['@type']) { |
|
| 151 | + $post_adapter = new Wordlift_Post_Adapter($post_id); |
|
| 152 | 152 | $keywords = $post_adapter->keywords(); |
| 153 | 153 | $article_section = $post_adapter->article_section(); |
| 154 | 154 | $comment_count = $post_adapter->comment_count(); |
| 155 | 155 | $locale = $post_adapter->locale(); |
| 156 | 156 | |
| 157 | - if ( isset( $keywords ) ) { |
|
| 157 | + if (isset($keywords)) { |
|
| 158 | 158 | $jsonld['keywords'] = $keywords; |
| 159 | 159 | } |
| 160 | - if ( ! empty( $article_section ) ) { |
|
| 160 | + if ( ! empty($article_section)) { |
|
| 161 | 161 | $jsonld['articleSection'] = $article_section; |
| 162 | 162 | } |
| 163 | 163 | $jsonld['commentCount'] = $comment_count; |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Set the publisher. |
| 168 | - $this->set_publisher( $jsonld ); |
|
| 168 | + $this->set_publisher($jsonld); |
|
| 169 | 169 | |
| 170 | 170 | /** |
| 171 | 171 | * Call the `wl_post_jsonld_author` filter. |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $ret_val = apply_filters( |
| 189 | 189 | 'wl_jsonld_author', |
| 190 | 190 | array( |
| 191 | - 'author' => $this->get_author( $post->post_author, $references ), |
|
| 191 | + 'author' => $this->get_author($post->post_author, $references), |
|
| 192 | 192 | 'references' => $references, |
| 193 | 193 | ), |
| 194 | 194 | $post_id |
@@ -202,13 +202,13 @@ discard block |
||
| 202 | 202 | * |
| 203 | 203 | * @since 3.53.2 |
| 204 | 204 | */ |
| 205 | - if ( ! empty( $ret_val['author'] ) ) { |
|
| 205 | + if ( ! empty($ret_val['author'])) { |
|
| 206 | 206 | $jsonld['author'] = $ret_val['author']; |
| 207 | 207 | $references = $ret_val['references']; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Return the JSON-LD if filters are disabled by the client. |
| 211 | - if ( $this->disable_convert_filters ) { |
|
| 211 | + if ($this->disable_convert_filters) { |
|
| 212 | 212 | return $jsonld; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @api |
| 255 | 255 | */ |
| 256 | - return apply_filters( 'wl_post_jsonld', $jsonld, $post_id, $references ); |
|
| 256 | + return apply_filters('wl_post_jsonld', $jsonld, $post_id, $references); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | * @return string|array A JSON-LD structure. |
| 269 | 269 | * @since 3.14.0 |
| 270 | 270 | */ |
| 271 | - public function get_author( $author_id, &$references ) { |
|
| 271 | + public function get_author($author_id, &$references) { |
|
| 272 | 272 | |
| 273 | 273 | // Get the entity bound to this user. |
| 274 | - $entity_id = $this->user_service->get_entity( $author_id ); |
|
| 274 | + $entity_id = $this->user_service->get_entity($author_id); |
|
| 275 | 275 | |
| 276 | - if ( ! empty( $entity_id ) && 'publish' === get_post_status( $entity_id ) ) { |
|
| 276 | + if ( ! empty($entity_id) && 'publish' === get_post_status($entity_id)) { |
|
| 277 | 277 | // Add the author to the references. |
| 278 | - $author_uri = Wordlift_Entity_Service::get_instance()->get_uri( $entity_id ); |
|
| 278 | + $author_uri = Wordlift_Entity_Service::get_instance()->get_uri($entity_id); |
|
| 279 | 279 | $references[] = $entity_id; |
| 280 | 280 | |
| 281 | 281 | // Return the JSON-LD for the referenced entity. |
@@ -285,11 +285,11 @@ discard block |
||
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // If there's no entity bound return a simple author structure. |
| 288 | - if ( false !== get_userdata( $author_id ) ) { |
|
| 289 | - $author = get_the_author_meta( 'display_name', $author_id ); |
|
| 290 | - $author_first_name = get_the_author_meta( 'first_name', $author_id ); |
|
| 291 | - $author_last_name = get_the_author_meta( 'last_name', $author_id ); |
|
| 292 | - $author_uri = $this->user_service->get_uri( $author_id ); |
|
| 288 | + if (false !== get_userdata($author_id)) { |
|
| 289 | + $author = get_the_author_meta('display_name', $author_id); |
|
| 290 | + $author_first_name = get_the_author_meta('first_name', $author_id); |
|
| 291 | + $author_last_name = get_the_author_meta('last_name', $author_id); |
|
| 292 | + $author_uri = $this->user_service->get_uri($author_id); |
|
| 293 | 293 | |
| 294 | 294 | return array( |
| 295 | 295 | '@type' => 'Person', |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | 'name' => $author, |
| 298 | 298 | 'givenName' => $author_first_name, |
| 299 | 299 | 'familyName' => $author_last_name, |
| 300 | - 'url' => get_author_posts_url( $author_id ), |
|
| 300 | + 'url' => get_author_posts_url($author_id), |
|
| 301 | 301 | ); |
| 302 | 302 | } |
| 303 | 303 | |
@@ -312,41 +312,41 @@ discard block |
||
| 312 | 312 | * |
| 313 | 313 | * @since 3.10.0 |
| 314 | 314 | */ |
| 315 | - protected function set_publisher( &$params ) { |
|
| 315 | + protected function set_publisher(&$params) { |
|
| 316 | 316 | |
| 317 | 317 | // If the publisher id isn't set don't do anything. |
| 318 | 318 | $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
| 319 | - if ( empty( $publisher_id ) ) { |
|
| 319 | + if (empty($publisher_id)) { |
|
| 320 | 320 | return; |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // Get the post instance. |
| 324 | - $post = get_post( $publisher_id ); |
|
| 325 | - if ( ! is_a( $post, '\WP_Post' ) ) { |
|
| 324 | + $post = get_post($publisher_id); |
|
| 325 | + if ( ! is_a($post, '\WP_Post')) { |
|
| 326 | 326 | // Publisher not found. |
| 327 | 327 | return; |
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Get the item id. |
| 331 | - $id = Wordlift_Entity_Service::get_instance()->get_uri( $publisher_id ); |
|
| 331 | + $id = Wordlift_Entity_Service::get_instance()->get_uri($publisher_id); |
|
| 332 | 332 | |
| 333 | 333 | // Get the type. |
| 334 | - $type = $this->entity_type_service->get( $publisher_id ); |
|
| 334 | + $type = $this->entity_type_service->get($publisher_id); |
|
| 335 | 335 | |
| 336 | 336 | // Get the name. |
| 337 | 337 | $name = $post->post_title; |
| 338 | 338 | |
| 339 | 339 | // Set the publisher data. |
| 340 | 340 | $params['publisher'] = array( |
| 341 | - '@type' => $this->relative_to_context( $type['uri'] ), |
|
| 341 | + '@type' => $this->relative_to_context($type['uri']), |
|
| 342 | 342 | '@id' => $id, |
| 343 | 343 | 'name' => $name, |
| 344 | 344 | ); |
| 345 | 345 | |
| 346 | 346 | // Add the sameAs values associated with the publisher. |
| 347 | 347 | $storage_factory = Wordlift_Storage_Factory::get_instance(); |
| 348 | - $sameas = $storage_factory->post_meta( Wordlift_Schema_Service::FIELD_SAME_AS )->get( $publisher_id ); |
|
| 349 | - if ( ! empty( $sameas ) ) { |
|
| 348 | + $sameas = $storage_factory->post_meta(Wordlift_Schema_Service::FIELD_SAME_AS)->get($publisher_id); |
|
| 349 | + if ( ! empty($sameas)) { |
|
| 350 | 350 | $params['publisher']['sameAs'] = $sameas; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -354,15 +354,15 @@ discard block |
||
| 354 | 354 | // support the logo property. |
| 355 | 355 | // |
| 356 | 356 | // See http://schema.org/logo. |
| 357 | - if ( 1 !== preg_match( '~Organization$~', $type['uri'] ) ) { |
|
| 357 | + if (1 !== preg_match('~Organization$~', $type['uri'])) { |
|
| 358 | 358 | return; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // Get the publisher logo. |
| 362 | - $publisher_logo = $this->get_publisher_logo( $post->ID ); |
|
| 362 | + $publisher_logo = $this->get_publisher_logo($post->ID); |
|
| 363 | 363 | |
| 364 | 364 | // Bail out if the publisher logo isn't set. |
| 365 | - if ( false === $publisher_logo ) { |
|
| 365 | + if (false === $publisher_logo) { |
|
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
@@ -396,14 +396,14 @@ discard block |
||
| 396 | 396 | * @since 3.19.2 |
| 397 | 397 | * @see https://github.com/insideout10/wordlift-plugin/issues/823 related issue. |
| 398 | 398 | */ |
| 399 | - private function get_publisher_logo( $post_id ) { |
|
| 399 | + private function get_publisher_logo($post_id) { |
|
| 400 | 400 | |
| 401 | 401 | // Get the featured image for the post. |
| 402 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
| 402 | + $thumbnail_id = get_post_thumbnail_id($post_id); |
|
| 403 | 403 | |
| 404 | 404 | // Bail out if thumbnail not available. |
| 405 | - if ( empty( $thumbnail_id ) || 0 === $thumbnail_id ) { |
|
| 406 | - $this->log->info( "Featured image not set for post $post_id." ); |
|
| 405 | + if (empty($thumbnail_id) || 0 === $thumbnail_id) { |
|
| 406 | + $this->log->info("Featured image not set for post $post_id."); |
|
| 407 | 407 | |
| 408 | 408 | return false; |
| 409 | 409 | } |
@@ -412,24 +412,24 @@ discard block |
||
| 412 | 412 | $uploads_dir = wp_upload_dir(); |
| 413 | 413 | |
| 414 | 414 | // Get the attachment metadata. |
| 415 | - $metadata = wp_get_attachment_metadata( $thumbnail_id ); |
|
| 415 | + $metadata = wp_get_attachment_metadata($thumbnail_id); |
|
| 416 | 416 | |
| 417 | 417 | // Bail out if the file isn't set. |
| 418 | - if ( ! isset( $metadata['file'] ) ) { |
|
| 419 | - $this->log->warn( "Featured image file not found for post $post_id." ); |
|
| 418 | + if ( ! isset($metadata['file'])) { |
|
| 419 | + $this->log->warn("Featured image file not found for post $post_id."); |
|
| 420 | 420 | |
| 421 | 421 | return false; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | // Retrieve the relative filename, e.g. "2018/05/logo_publisher.png" |
| 425 | - $path = $uploads_dir['basedir'] . DIRECTORY_SEPARATOR . $metadata['file']; |
|
| 425 | + $path = $uploads_dir['basedir'].DIRECTORY_SEPARATOR.$metadata['file']; |
|
| 426 | 426 | |
| 427 | 427 | // Use image src, if local file does not exist. @see https://github.com/insideout10/wordlift-plugin/issues/1149 |
| 428 | - if ( ! file_exists( $path ) ) { |
|
| 429 | - $this->log->warn( "Featured image file $path doesn't exist for post $post_id." ); |
|
| 428 | + if ( ! file_exists($path)) { |
|
| 429 | + $this->log->warn("Featured image file $path doesn't exist for post $post_id."); |
|
| 430 | 430 | |
| 431 | - $attachment_image_src = wp_get_attachment_image_src( $thumbnail_id, '' ); |
|
| 432 | - if ( $attachment_image_src ) { |
|
| 431 | + $attachment_image_src = wp_get_attachment_image_src($thumbnail_id, ''); |
|
| 432 | + if ($attachment_image_src) { |
|
| 433 | 433 | return array( |
| 434 | 434 | 'url' => $attachment_image_src[0], |
| 435 | 435 | 'width' => $attachment_image_src[1], |
@@ -443,27 +443,27 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
| 446 | - $original_file_editor = wp_get_image_editor( $path ); |
|
| 447 | - if ( is_wp_error( $original_file_editor ) ) { |
|
| 448 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $path for post $post_id." ); |
|
| 446 | + $original_file_editor = wp_get_image_editor($path); |
|
| 447 | + if (is_wp_error($original_file_editor)) { |
|
| 448 | + $this->log->warn("Cannot instantiate WP Image Editor on file $path for post $post_id."); |
|
| 449 | 449 | |
| 450 | 450 | return false; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | // Generate the publisher logo filename, we cannot use the `width` and `height` because we're scaling |
| 454 | 454 | // and we don't actually know the end values. |
| 455 | - $publisher_logo_path = $original_file_editor->generate_filename( '-publisher-logo' ); |
|
| 455 | + $publisher_logo_path = $original_file_editor->generate_filename('-publisher-logo'); |
|
| 456 | 456 | |
| 457 | 457 | // If the file doesn't exist yet, create it. |
| 458 | - if ( ! file_exists( $publisher_logo_path ) ) { |
|
| 459 | - $original_file_editor->resize( 600, 60 ); |
|
| 460 | - $original_file_editor->save( $publisher_logo_path ); |
|
| 458 | + if ( ! file_exists($publisher_logo_path)) { |
|
| 459 | + $original_file_editor->resize(600, 60); |
|
| 460 | + $original_file_editor->save($publisher_logo_path); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Try to get the image editor and bail out if the editor cannot be instantiated. |
| 464 | - $publisher_logo_editor = wp_get_image_editor( $publisher_logo_path ); |
|
| 465 | - if ( is_wp_error( $publisher_logo_editor ) ) { |
|
| 466 | - $this->log->warn( "Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id." ); |
|
| 464 | + $publisher_logo_editor = wp_get_image_editor($publisher_logo_path); |
|
| 465 | + if (is_wp_error($publisher_logo_editor)) { |
|
| 466 | + $this->log->warn("Cannot instantiate WP Image Editor on file $publisher_logo_path for post $post_id."); |
|
| 467 | 467 | |
| 468 | 468 | return false; |
| 469 | 469 | } |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | // Finally return the array with data. |
| 475 | 475 | return array( |
| 476 | - 'url' => $uploads_dir['baseurl'] . substr( $publisher_logo_path, strlen( $uploads_dir['basedir'] ) ), |
|
| 476 | + 'url' => $uploads_dir['baseurl'].substr($publisher_logo_path, strlen($uploads_dir['basedir'])), |
|
| 477 | 477 | 'width' => $size['width'], |
| 478 | 478 | 'height' => $size['height'], |
| 479 | 479 | ); |