@@ -11,56 +11,56 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Wordlift_Property_Factory { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * The default {@link Wordlift_Property_Service}. |
|
| 16 | - * |
|
| 17 | - * @since 3.7.0 |
|
| 18 | - * @access private |
|
| 19 | - * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}. |
|
| 20 | - */ |
|
| 21 | - private $default_property_service; |
|
| 14 | + /** |
|
| 15 | + * The default {@link Wordlift_Property_Service}. |
|
| 16 | + * |
|
| 17 | + * @since 3.7.0 |
|
| 18 | + * @access private |
|
| 19 | + * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}. |
|
| 20 | + */ |
|
| 21 | + private $default_property_service; |
|
| 22 | 22 | |
| 23 | - private $property_services = array(); |
|
| 23 | + private $property_services = array(); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Wordlift_Property_Factory constructor. |
|
| 27 | - * |
|
| 28 | - * @since 3.7.0 |
|
| 29 | - * |
|
| 30 | - * @param \Wordlift_Property_Service $default_property_service |
|
| 31 | - */ |
|
| 32 | - public function __construct( $default_property_service ) { |
|
| 25 | + /** |
|
| 26 | + * Wordlift_Property_Factory constructor. |
|
| 27 | + * |
|
| 28 | + * @since 3.7.0 |
|
| 29 | + * |
|
| 30 | + * @param \Wordlift_Property_Service $default_property_service |
|
| 31 | + */ |
|
| 32 | + public function __construct( $default_property_service ) { |
|
| 33 | 33 | |
| 34 | - $this->default_property_service = $default_property_service; |
|
| 34 | + $this->default_property_service = $default_property_service; |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Set the {@link Wordlift_Property_Service} which handles that meta key. |
|
| 40 | - * |
|
| 41 | - * @since 3.7.0 |
|
| 42 | - * |
|
| 43 | - * @param string $meta_key WordPress' meta key. |
|
| 44 | - * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
|
| 45 | - */ |
|
| 46 | - public function register( $meta_key, $property_service ) { |
|
| 38 | + /** |
|
| 39 | + * Set the {@link Wordlift_Property_Service} which handles that meta key. |
|
| 40 | + * |
|
| 41 | + * @since 3.7.0 |
|
| 42 | + * |
|
| 43 | + * @param string $meta_key WordPress' meta key. |
|
| 44 | + * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
|
| 45 | + */ |
|
| 46 | + public function register( $meta_key, $property_service ) { |
|
| 47 | 47 | |
| 48 | - $this->property_services[ $meta_key ] = $property_service; |
|
| 48 | + $this->property_services[ $meta_key ] = $property_service; |
|
| 49 | 49 | |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get the {@link Wordlift_Property_Service} which handles the specified meta key. |
|
| 54 | - * |
|
| 55 | - * @since 3.7.0 |
|
| 56 | - * |
|
| 57 | - * @param $meta_key |
|
| 58 | - * |
|
| 59 | - * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
|
| 60 | - */ |
|
| 61 | - public function get( $meta_key ) { |
|
| 52 | + /** |
|
| 53 | + * Get the {@link Wordlift_Property_Service} which handles the specified meta key. |
|
| 54 | + * |
|
| 55 | + * @since 3.7.0 |
|
| 56 | + * |
|
| 57 | + * @param $meta_key |
|
| 58 | + * |
|
| 59 | + * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
|
| 60 | + */ |
|
| 61 | + public function get( $meta_key ) { |
|
| 62 | 62 | |
| 63 | - return $this->property_services[ $meta_key ] ?: $this->default_property_service; |
|
| 64 | - } |
|
| 63 | + return $this->property_services[ $meta_key ] ?: $this->default_property_service; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param \Wordlift_Property_Service $default_property_service |
| 31 | 31 | */ |
| 32 | - public function __construct( $default_property_service ) { |
|
| 32 | + public function __construct($default_property_service) { |
|
| 33 | 33 | |
| 34 | 34 | $this->default_property_service = $default_property_service; |
| 35 | 35 | |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * @param string $meta_key WordPress' meta key. |
| 44 | 44 | * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance. |
| 45 | 45 | */ |
| 46 | - public function register( $meta_key, $property_service ) { |
|
| 46 | + public function register($meta_key, $property_service) { |
|
| 47 | 47 | |
| 48 | - $this->property_services[ $meta_key ] = $property_service; |
|
| 48 | + $this->property_services[$meta_key] = $property_service; |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * |
| 59 | 59 | * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key. |
| 60 | 60 | */ |
| 61 | - public function get( $meta_key ) { |
|
| 61 | + public function get($meta_key) { |
|
| 62 | 62 | |
| 63 | - return $this->property_services[ $meta_key ] ?: $this->default_property_service; |
|
| 63 | + return $this->property_services[$meta_key] ?: $this->default_property_service; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * @since 3.9.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 13 | +if ( ! defined('ABSPATH')) { |
|
| 14 | 14 | exit; |
| 15 | 15 | } |
| 16 | 16 | |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | public static function get_languages() { |
| 83 | 83 | |
| 84 | 84 | // Lazily load the languages. |
| 85 | - if ( null === self::$languages ) { |
|
| 85 | + if (null === self::$languages) { |
|
| 86 | 86 | |
| 87 | 87 | // Get the language names from WP's own (multisite) function. |
| 88 | - foreach ( self::$codes as $key ) { |
|
| 89 | - self::$languages[ $key ] = self::format_code_lang( $key ); |
|
| 88 | + foreach (self::$codes as $key) { |
|
| 89 | + self::$languages[$key] = self::format_code_lang($key); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Sort by language name. |
| 93 | - asort( self::$languages ); |
|
| 93 | + asort(self::$languages); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | return self::$languages; |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | * @return string The language corresponding to $code if it exists. If it does not exist, |
| 107 | 107 | * then the first two letters of $code is returned. |
| 108 | 108 | */ |
| 109 | - private static function format_code_lang( $code = '' ) { |
|
| 110 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 109 | + private static function format_code_lang($code = '') { |
|
| 110 | + $code = strtolower(substr($code, 0, 2)); |
|
| 111 | 111 | $lang_codes = array( |
| 112 | 112 | 'aa' => 'Afar', |
| 113 | 113 | 'ab' => 'Abkhazian', |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | * @param array $lang_codes Key/value pair of language codes where key is the short version. |
| 305 | 305 | * @param string $code A two-letter designation of the language. |
| 306 | 306 | */ |
| 307 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 307 | + $lang_codes = apply_filters('lang_codes', $lang_codes, $code); |
|
| 308 | 308 | |
| 309 | - return strtr( $code, $lang_codes ); |
|
| 309 | + return strtr($code, $lang_codes); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | - exit; |
|
| 14 | + exit; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,294 +21,294 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Languages { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | - * `get_languages` function. |
|
| 27 | - * |
|
| 28 | - * @since 3.9.0 |
|
| 29 | - * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | - */ |
|
| 31 | - private static $languages = null; |
|
| 24 | + /** |
|
| 25 | + * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the |
|
| 26 | + * `get_languages` function. |
|
| 27 | + * |
|
| 28 | + * @since 3.9.0 |
|
| 29 | + * @var array|null An array of language codes => language names pairs or NULL if not initialized yet. |
|
| 30 | + */ |
|
| 31 | + private static $languages = null; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * The list of supported language codes. |
|
| 35 | - * |
|
| 36 | - * @since 3.9.0 |
|
| 37 | - * |
|
| 38 | - * @var array An array of language codes. |
|
| 39 | - */ |
|
| 40 | - private static $codes = array( |
|
| 41 | - 'ar', |
|
| 42 | - 'be', |
|
| 43 | - 'bg', |
|
| 44 | - 'ca', |
|
| 45 | - 'cs', |
|
| 46 | - 'da', |
|
| 47 | - 'de', |
|
| 48 | - 'el', |
|
| 49 | - 'en', |
|
| 50 | - 'es', |
|
| 51 | - 'et', |
|
| 52 | - 'fi', |
|
| 53 | - 'fr', |
|
| 54 | - 'hr', |
|
| 55 | - 'hu', |
|
| 56 | - 'id', |
|
| 57 | - 'is', |
|
| 58 | - 'it', |
|
| 59 | - 'lt', |
|
| 60 | - 'lv', |
|
| 61 | - 'nl', |
|
| 62 | - 'no', |
|
| 63 | - 'pl', |
|
| 64 | - 'pt', |
|
| 65 | - 'ro', |
|
| 66 | - 'ru', |
|
| 67 | - 'sk', |
|
| 68 | - 'sl', |
|
| 69 | - 'sq', |
|
| 70 | - 'sr', |
|
| 71 | - 'sv', |
|
| 72 | - 'tr', |
|
| 73 | - 'uk', |
|
| 74 | - 'zh-cn', |
|
| 75 | - ); |
|
| 33 | + /** |
|
| 34 | + * The list of supported language codes. |
|
| 35 | + * |
|
| 36 | + * @since 3.9.0 |
|
| 37 | + * |
|
| 38 | + * @var array An array of language codes. |
|
| 39 | + */ |
|
| 40 | + private static $codes = array( |
|
| 41 | + 'ar', |
|
| 42 | + 'be', |
|
| 43 | + 'bg', |
|
| 44 | + 'ca', |
|
| 45 | + 'cs', |
|
| 46 | + 'da', |
|
| 47 | + 'de', |
|
| 48 | + 'el', |
|
| 49 | + 'en', |
|
| 50 | + 'es', |
|
| 51 | + 'et', |
|
| 52 | + 'fi', |
|
| 53 | + 'fr', |
|
| 54 | + 'hr', |
|
| 55 | + 'hu', |
|
| 56 | + 'id', |
|
| 57 | + 'is', |
|
| 58 | + 'it', |
|
| 59 | + 'lt', |
|
| 60 | + 'lv', |
|
| 61 | + 'nl', |
|
| 62 | + 'no', |
|
| 63 | + 'pl', |
|
| 64 | + 'pt', |
|
| 65 | + 'ro', |
|
| 66 | + 'ru', |
|
| 67 | + 'sk', |
|
| 68 | + 'sl', |
|
| 69 | + 'sq', |
|
| 70 | + 'sr', |
|
| 71 | + 'sv', |
|
| 72 | + 'tr', |
|
| 73 | + 'uk', |
|
| 74 | + 'zh-cn', |
|
| 75 | + ); |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 79 | - * |
|
| 80 | - * @since 3.9.0 |
|
| 81 | - * |
|
| 82 | - * @return array An array with language code => language name pairs. |
|
| 83 | - */ |
|
| 84 | - public static function get_languages() { |
|
| 77 | + /** |
|
| 78 | + * Get the list of WordLift's supported languages in an array with language code => language name pairs. |
|
| 79 | + * |
|
| 80 | + * @since 3.9.0 |
|
| 81 | + * |
|
| 82 | + * @return array An array with language code => language name pairs. |
|
| 83 | + */ |
|
| 84 | + public static function get_languages() { |
|
| 85 | 85 | |
| 86 | - // Lazily load the languages. |
|
| 87 | - if ( null === self::$languages ) { |
|
| 86 | + // Lazily load the languages. |
|
| 87 | + if ( null === self::$languages ) { |
|
| 88 | 88 | |
| 89 | - // Get the language names from WP's own (multisite) function. |
|
| 90 | - foreach ( self::$codes as $key ) { |
|
| 91 | - self::$languages[ $key ] = self::format_code_lang( $key ); |
|
| 92 | - } |
|
| 89 | + // Get the language names from WP's own (multisite) function. |
|
| 90 | + foreach ( self::$codes as $key ) { |
|
| 91 | + self::$languages[ $key ] = self::format_code_lang( $key ); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - // Sort by language name. |
|
| 95 | - asort( self::$languages ); |
|
| 96 | - } |
|
| 94 | + // Sort by language name. |
|
| 95 | + asort( self::$languages ); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return self::$languages; |
|
| 99 | - } |
|
| 98 | + return self::$languages; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 103 | - * |
|
| 104 | - * @since 3.9.3 |
|
| 105 | - * |
|
| 106 | - * @param string $code Optional. The two-letter language code. Default empty. |
|
| 107 | - * |
|
| 108 | - * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 109 | - * then the first two letters of $code is returned. |
|
| 110 | - */ |
|
| 111 | - private static function format_code_lang( $code = '' ) { |
|
| 112 | - $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 113 | - $lang_codes = array( |
|
| 114 | - 'aa' => 'Afar', |
|
| 115 | - 'ab' => 'Abkhazian', |
|
| 116 | - 'af' => 'Afrikaans', |
|
| 117 | - 'ak' => 'Akan', |
|
| 118 | - 'sq' => 'Albanian', |
|
| 119 | - 'am' => 'Amharic', |
|
| 120 | - 'ar' => 'Arabic', |
|
| 121 | - 'an' => 'Aragonese', |
|
| 122 | - 'hy' => 'Armenian', |
|
| 123 | - 'as' => 'Assamese', |
|
| 124 | - 'av' => 'Avaric', |
|
| 125 | - 'ae' => 'Avestan', |
|
| 126 | - 'ay' => 'Aymara', |
|
| 127 | - 'az' => 'Azerbaijani', |
|
| 128 | - 'ba' => 'Bashkir', |
|
| 129 | - 'bm' => 'Bambara', |
|
| 130 | - 'eu' => 'Basque', |
|
| 131 | - 'be' => 'Belarusian', |
|
| 132 | - 'bn' => 'Bengali', |
|
| 133 | - 'bh' => 'Bihari', |
|
| 134 | - 'bi' => 'Bislama', |
|
| 135 | - 'bs' => 'Bosnian', |
|
| 136 | - 'br' => 'Breton', |
|
| 137 | - 'bg' => 'Bulgarian', |
|
| 138 | - 'my' => 'Burmese', |
|
| 139 | - 'ca' => 'Catalan; Valencian', |
|
| 140 | - 'ch' => 'Chamorro', |
|
| 141 | - 'ce' => 'Chechen', |
|
| 142 | - 'zh' => 'Chinese', |
|
| 143 | - 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 144 | - 'cv' => 'Chuvash', |
|
| 145 | - 'kw' => 'Cornish', |
|
| 146 | - 'co' => 'Corsican', |
|
| 147 | - 'cr' => 'Cree', |
|
| 148 | - 'cs' => 'Czech', |
|
| 149 | - 'da' => 'Danish', |
|
| 150 | - 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 151 | - 'nl' => 'Dutch; Flemish', |
|
| 152 | - 'dz' => 'Dzongkha', |
|
| 153 | - 'en' => 'English', |
|
| 154 | - 'eo' => 'Esperanto', |
|
| 155 | - 'et' => 'Estonian', |
|
| 156 | - 'ee' => 'Ewe', |
|
| 157 | - 'fo' => 'Faroese', |
|
| 158 | - 'fj' => 'Fijjian', |
|
| 159 | - 'fi' => 'Finnish', |
|
| 160 | - 'fr' => 'French', |
|
| 161 | - 'fy' => 'Western Frisian', |
|
| 162 | - 'ff' => 'Fulah', |
|
| 163 | - 'ka' => 'Georgian', |
|
| 164 | - 'de' => 'German', |
|
| 165 | - 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 166 | - 'ga' => 'Irish', |
|
| 167 | - 'gl' => 'Galician', |
|
| 168 | - 'gv' => 'Manx', |
|
| 169 | - 'el' => 'Greek, Modern', |
|
| 170 | - 'gn' => 'Guarani', |
|
| 171 | - 'gu' => 'Gujarati', |
|
| 172 | - 'ht' => 'Haitian; Haitian Creole', |
|
| 173 | - 'ha' => 'Hausa', |
|
| 174 | - 'he' => 'Hebrew', |
|
| 175 | - 'hz' => 'Herero', |
|
| 176 | - 'hi' => 'Hindi', |
|
| 177 | - 'ho' => 'Hiri Motu', |
|
| 178 | - 'hu' => 'Hungarian', |
|
| 179 | - 'ig' => 'Igbo', |
|
| 180 | - 'is' => 'Icelandic', |
|
| 181 | - 'io' => 'Ido', |
|
| 182 | - 'ii' => 'Sichuan Yi', |
|
| 183 | - 'iu' => 'Inuktitut', |
|
| 184 | - 'ie' => 'Interlingue', |
|
| 185 | - 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 186 | - 'id' => 'Indonesian', |
|
| 187 | - 'ik' => 'Inupiaq', |
|
| 188 | - 'it' => 'Italian', |
|
| 189 | - 'jv' => 'Javanese', |
|
| 190 | - 'ja' => 'Japanese', |
|
| 191 | - 'kl' => 'Kalaallisut; Greenlandic', |
|
| 192 | - 'kn' => 'Kannada', |
|
| 193 | - 'ks' => 'Kashmiri', |
|
| 194 | - 'kr' => 'Kanuri', |
|
| 195 | - 'kk' => 'Kazakh', |
|
| 196 | - 'km' => 'Central Khmer', |
|
| 197 | - 'ki' => 'Kikuyu; Gikuyu', |
|
| 198 | - 'rw' => 'Kinyarwanda', |
|
| 199 | - 'ky' => 'Kirghiz; Kyrgyz', |
|
| 200 | - 'kv' => 'Komi', |
|
| 201 | - 'kg' => 'Kongo', |
|
| 202 | - 'ko' => 'Korean', |
|
| 203 | - 'kj' => 'Kuanyama; Kwanyama', |
|
| 204 | - 'ku' => 'Kurdish', |
|
| 205 | - 'lo' => 'Lao', |
|
| 206 | - 'la' => 'Latin', |
|
| 207 | - 'lv' => 'Latvian', |
|
| 208 | - 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 209 | - 'ln' => 'Lingala', |
|
| 210 | - 'lt' => 'Lithuanian', |
|
| 211 | - 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 212 | - 'lu' => 'Luba-Katanga', |
|
| 213 | - 'lg' => 'Ganda', |
|
| 214 | - 'mk' => 'Macedonian', |
|
| 215 | - 'mh' => 'Marshallese', |
|
| 216 | - 'ml' => 'Malayalam', |
|
| 217 | - 'mi' => 'Maori', |
|
| 218 | - 'mr' => 'Marathi', |
|
| 219 | - 'ms' => 'Malay', |
|
| 220 | - 'mg' => 'Malagasy', |
|
| 221 | - 'mt' => 'Maltese', |
|
| 222 | - 'mo' => 'Moldavian', |
|
| 223 | - 'mn' => 'Mongolian', |
|
| 224 | - 'na' => 'Nauru', |
|
| 225 | - 'nv' => 'Navajo; Navaho', |
|
| 226 | - 'nr' => 'Ndebele, South; South Ndebele', |
|
| 227 | - 'nd' => 'Ndebele, North; North Ndebele', |
|
| 228 | - 'ng' => 'Ndonga', |
|
| 229 | - 'ne' => 'Nepali', |
|
| 230 | - 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 231 | - 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 232 | - 'no' => 'Norwegian', |
|
| 233 | - 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 234 | - 'oc' => 'Occitan, Provençal', |
|
| 235 | - 'oj' => 'Ojibwa', |
|
| 236 | - 'or' => 'Oriya', |
|
| 237 | - 'om' => 'Oromo', |
|
| 238 | - 'os' => 'Ossetian; Ossetic', |
|
| 239 | - 'pa' => 'Panjabi; Punjabi', |
|
| 240 | - 'fa' => 'Persian', |
|
| 241 | - 'pi' => 'Pali', |
|
| 242 | - 'pl' => 'Polish', |
|
| 243 | - 'pt' => 'Portuguese', |
|
| 244 | - 'ps' => 'Pushto', |
|
| 245 | - 'qu' => 'Quechua', |
|
| 246 | - 'rm' => 'Romansh', |
|
| 247 | - 'ro' => 'Romanian', |
|
| 248 | - 'rn' => 'Rundi', |
|
| 249 | - 'ru' => 'Russian', |
|
| 250 | - 'sg' => 'Sango', |
|
| 251 | - 'sa' => 'Sanskrit', |
|
| 252 | - 'sr' => 'Serbian', |
|
| 253 | - 'hr' => 'Croatian', |
|
| 254 | - 'si' => 'Sinhala; Sinhalese', |
|
| 255 | - 'sk' => 'Slovak', |
|
| 256 | - 'sl' => 'Slovenian', |
|
| 257 | - 'se' => 'Northern Sami', |
|
| 258 | - 'sm' => 'Samoan', |
|
| 259 | - 'sn' => 'Shona', |
|
| 260 | - 'sd' => 'Sindhi', |
|
| 261 | - 'so' => 'Somali', |
|
| 262 | - 'st' => 'Sotho, Southern', |
|
| 263 | - 'es' => 'Spanish; Castilian', |
|
| 264 | - 'sc' => 'Sardinian', |
|
| 265 | - 'ss' => 'Swati', |
|
| 266 | - 'su' => 'Sundanese', |
|
| 267 | - 'sw' => 'Swahili', |
|
| 268 | - 'sv' => 'Swedish', |
|
| 269 | - 'ty' => 'Tahitian', |
|
| 270 | - 'ta' => 'Tamil', |
|
| 271 | - 'tt' => 'Tatar', |
|
| 272 | - 'te' => 'Telugu', |
|
| 273 | - 'tg' => 'Tajik', |
|
| 274 | - 'tl' => 'Tagalog', |
|
| 275 | - 'th' => 'Thai', |
|
| 276 | - 'bo' => 'Tibetan', |
|
| 277 | - 'ti' => 'Tigrinya', |
|
| 278 | - 'to' => 'Tonga (Tonga Islands)', |
|
| 279 | - 'tn' => 'Tswana', |
|
| 280 | - 'ts' => 'Tsonga', |
|
| 281 | - 'tk' => 'Turkmen', |
|
| 282 | - 'tr' => 'Turkish', |
|
| 283 | - 'tw' => 'Twi', |
|
| 284 | - 'ug' => 'Uighur; Uyghur', |
|
| 285 | - 'uk' => 'Ukrainian', |
|
| 286 | - 'ur' => 'Urdu', |
|
| 287 | - 'uz' => 'Uzbek', |
|
| 288 | - 've' => 'Venda', |
|
| 289 | - 'vi' => 'Vietnamese', |
|
| 290 | - 'vo' => 'Volapük', |
|
| 291 | - 'cy' => 'Welsh', |
|
| 292 | - 'wa' => 'Walloon', |
|
| 293 | - 'wo' => 'Wolof', |
|
| 294 | - 'xh' => 'Xhosa', |
|
| 295 | - 'yi' => 'Yiddish', |
|
| 296 | - 'yo' => 'Yoruba', |
|
| 297 | - 'za' => 'Zhuang; Chuang', |
|
| 298 | - 'zu' => 'Zulu' |
|
| 299 | - ); |
|
| 101 | + /** |
|
| 102 | + * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`. |
|
| 103 | + * |
|
| 104 | + * @since 3.9.3 |
|
| 105 | + * |
|
| 106 | + * @param string $code Optional. The two-letter language code. Default empty. |
|
| 107 | + * |
|
| 108 | + * @return string The language corresponding to $code if it exists. If it does not exist, |
|
| 109 | + * then the first two letters of $code is returned. |
|
| 110 | + */ |
|
| 111 | + private static function format_code_lang( $code = '' ) { |
|
| 112 | + $code = strtolower( substr( $code, 0, 2 ) ); |
|
| 113 | + $lang_codes = array( |
|
| 114 | + 'aa' => 'Afar', |
|
| 115 | + 'ab' => 'Abkhazian', |
|
| 116 | + 'af' => 'Afrikaans', |
|
| 117 | + 'ak' => 'Akan', |
|
| 118 | + 'sq' => 'Albanian', |
|
| 119 | + 'am' => 'Amharic', |
|
| 120 | + 'ar' => 'Arabic', |
|
| 121 | + 'an' => 'Aragonese', |
|
| 122 | + 'hy' => 'Armenian', |
|
| 123 | + 'as' => 'Assamese', |
|
| 124 | + 'av' => 'Avaric', |
|
| 125 | + 'ae' => 'Avestan', |
|
| 126 | + 'ay' => 'Aymara', |
|
| 127 | + 'az' => 'Azerbaijani', |
|
| 128 | + 'ba' => 'Bashkir', |
|
| 129 | + 'bm' => 'Bambara', |
|
| 130 | + 'eu' => 'Basque', |
|
| 131 | + 'be' => 'Belarusian', |
|
| 132 | + 'bn' => 'Bengali', |
|
| 133 | + 'bh' => 'Bihari', |
|
| 134 | + 'bi' => 'Bislama', |
|
| 135 | + 'bs' => 'Bosnian', |
|
| 136 | + 'br' => 'Breton', |
|
| 137 | + 'bg' => 'Bulgarian', |
|
| 138 | + 'my' => 'Burmese', |
|
| 139 | + 'ca' => 'Catalan; Valencian', |
|
| 140 | + 'ch' => 'Chamorro', |
|
| 141 | + 'ce' => 'Chechen', |
|
| 142 | + 'zh' => 'Chinese', |
|
| 143 | + 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
| 144 | + 'cv' => 'Chuvash', |
|
| 145 | + 'kw' => 'Cornish', |
|
| 146 | + 'co' => 'Corsican', |
|
| 147 | + 'cr' => 'Cree', |
|
| 148 | + 'cs' => 'Czech', |
|
| 149 | + 'da' => 'Danish', |
|
| 150 | + 'dv' => 'Divehi; Dhivehi; Maldivian', |
|
| 151 | + 'nl' => 'Dutch; Flemish', |
|
| 152 | + 'dz' => 'Dzongkha', |
|
| 153 | + 'en' => 'English', |
|
| 154 | + 'eo' => 'Esperanto', |
|
| 155 | + 'et' => 'Estonian', |
|
| 156 | + 'ee' => 'Ewe', |
|
| 157 | + 'fo' => 'Faroese', |
|
| 158 | + 'fj' => 'Fijjian', |
|
| 159 | + 'fi' => 'Finnish', |
|
| 160 | + 'fr' => 'French', |
|
| 161 | + 'fy' => 'Western Frisian', |
|
| 162 | + 'ff' => 'Fulah', |
|
| 163 | + 'ka' => 'Georgian', |
|
| 164 | + 'de' => 'German', |
|
| 165 | + 'gd' => 'Gaelic; Scottish Gaelic', |
|
| 166 | + 'ga' => 'Irish', |
|
| 167 | + 'gl' => 'Galician', |
|
| 168 | + 'gv' => 'Manx', |
|
| 169 | + 'el' => 'Greek, Modern', |
|
| 170 | + 'gn' => 'Guarani', |
|
| 171 | + 'gu' => 'Gujarati', |
|
| 172 | + 'ht' => 'Haitian; Haitian Creole', |
|
| 173 | + 'ha' => 'Hausa', |
|
| 174 | + 'he' => 'Hebrew', |
|
| 175 | + 'hz' => 'Herero', |
|
| 176 | + 'hi' => 'Hindi', |
|
| 177 | + 'ho' => 'Hiri Motu', |
|
| 178 | + 'hu' => 'Hungarian', |
|
| 179 | + 'ig' => 'Igbo', |
|
| 180 | + 'is' => 'Icelandic', |
|
| 181 | + 'io' => 'Ido', |
|
| 182 | + 'ii' => 'Sichuan Yi', |
|
| 183 | + 'iu' => 'Inuktitut', |
|
| 184 | + 'ie' => 'Interlingue', |
|
| 185 | + 'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
| 186 | + 'id' => 'Indonesian', |
|
| 187 | + 'ik' => 'Inupiaq', |
|
| 188 | + 'it' => 'Italian', |
|
| 189 | + 'jv' => 'Javanese', |
|
| 190 | + 'ja' => 'Japanese', |
|
| 191 | + 'kl' => 'Kalaallisut; Greenlandic', |
|
| 192 | + 'kn' => 'Kannada', |
|
| 193 | + 'ks' => 'Kashmiri', |
|
| 194 | + 'kr' => 'Kanuri', |
|
| 195 | + 'kk' => 'Kazakh', |
|
| 196 | + 'km' => 'Central Khmer', |
|
| 197 | + 'ki' => 'Kikuyu; Gikuyu', |
|
| 198 | + 'rw' => 'Kinyarwanda', |
|
| 199 | + 'ky' => 'Kirghiz; Kyrgyz', |
|
| 200 | + 'kv' => 'Komi', |
|
| 201 | + 'kg' => 'Kongo', |
|
| 202 | + 'ko' => 'Korean', |
|
| 203 | + 'kj' => 'Kuanyama; Kwanyama', |
|
| 204 | + 'ku' => 'Kurdish', |
|
| 205 | + 'lo' => 'Lao', |
|
| 206 | + 'la' => 'Latin', |
|
| 207 | + 'lv' => 'Latvian', |
|
| 208 | + 'li' => 'Limburgan; Limburger; Limburgish', |
|
| 209 | + 'ln' => 'Lingala', |
|
| 210 | + 'lt' => 'Lithuanian', |
|
| 211 | + 'lb' => 'Luxembourgish; Letzeburgesch', |
|
| 212 | + 'lu' => 'Luba-Katanga', |
|
| 213 | + 'lg' => 'Ganda', |
|
| 214 | + 'mk' => 'Macedonian', |
|
| 215 | + 'mh' => 'Marshallese', |
|
| 216 | + 'ml' => 'Malayalam', |
|
| 217 | + 'mi' => 'Maori', |
|
| 218 | + 'mr' => 'Marathi', |
|
| 219 | + 'ms' => 'Malay', |
|
| 220 | + 'mg' => 'Malagasy', |
|
| 221 | + 'mt' => 'Maltese', |
|
| 222 | + 'mo' => 'Moldavian', |
|
| 223 | + 'mn' => 'Mongolian', |
|
| 224 | + 'na' => 'Nauru', |
|
| 225 | + 'nv' => 'Navajo; Navaho', |
|
| 226 | + 'nr' => 'Ndebele, South; South Ndebele', |
|
| 227 | + 'nd' => 'Ndebele, North; North Ndebele', |
|
| 228 | + 'ng' => 'Ndonga', |
|
| 229 | + 'ne' => 'Nepali', |
|
| 230 | + 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
| 231 | + 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
| 232 | + 'no' => 'Norwegian', |
|
| 233 | + 'ny' => 'Chichewa; Chewa; Nyanja', |
|
| 234 | + 'oc' => 'Occitan, Provençal', |
|
| 235 | + 'oj' => 'Ojibwa', |
|
| 236 | + 'or' => 'Oriya', |
|
| 237 | + 'om' => 'Oromo', |
|
| 238 | + 'os' => 'Ossetian; Ossetic', |
|
| 239 | + 'pa' => 'Panjabi; Punjabi', |
|
| 240 | + 'fa' => 'Persian', |
|
| 241 | + 'pi' => 'Pali', |
|
| 242 | + 'pl' => 'Polish', |
|
| 243 | + 'pt' => 'Portuguese', |
|
| 244 | + 'ps' => 'Pushto', |
|
| 245 | + 'qu' => 'Quechua', |
|
| 246 | + 'rm' => 'Romansh', |
|
| 247 | + 'ro' => 'Romanian', |
|
| 248 | + 'rn' => 'Rundi', |
|
| 249 | + 'ru' => 'Russian', |
|
| 250 | + 'sg' => 'Sango', |
|
| 251 | + 'sa' => 'Sanskrit', |
|
| 252 | + 'sr' => 'Serbian', |
|
| 253 | + 'hr' => 'Croatian', |
|
| 254 | + 'si' => 'Sinhala; Sinhalese', |
|
| 255 | + 'sk' => 'Slovak', |
|
| 256 | + 'sl' => 'Slovenian', |
|
| 257 | + 'se' => 'Northern Sami', |
|
| 258 | + 'sm' => 'Samoan', |
|
| 259 | + 'sn' => 'Shona', |
|
| 260 | + 'sd' => 'Sindhi', |
|
| 261 | + 'so' => 'Somali', |
|
| 262 | + 'st' => 'Sotho, Southern', |
|
| 263 | + 'es' => 'Spanish; Castilian', |
|
| 264 | + 'sc' => 'Sardinian', |
|
| 265 | + 'ss' => 'Swati', |
|
| 266 | + 'su' => 'Sundanese', |
|
| 267 | + 'sw' => 'Swahili', |
|
| 268 | + 'sv' => 'Swedish', |
|
| 269 | + 'ty' => 'Tahitian', |
|
| 270 | + 'ta' => 'Tamil', |
|
| 271 | + 'tt' => 'Tatar', |
|
| 272 | + 'te' => 'Telugu', |
|
| 273 | + 'tg' => 'Tajik', |
|
| 274 | + 'tl' => 'Tagalog', |
|
| 275 | + 'th' => 'Thai', |
|
| 276 | + 'bo' => 'Tibetan', |
|
| 277 | + 'ti' => 'Tigrinya', |
|
| 278 | + 'to' => 'Tonga (Tonga Islands)', |
|
| 279 | + 'tn' => 'Tswana', |
|
| 280 | + 'ts' => 'Tsonga', |
|
| 281 | + 'tk' => 'Turkmen', |
|
| 282 | + 'tr' => 'Turkish', |
|
| 283 | + 'tw' => 'Twi', |
|
| 284 | + 'ug' => 'Uighur; Uyghur', |
|
| 285 | + 'uk' => 'Ukrainian', |
|
| 286 | + 'ur' => 'Urdu', |
|
| 287 | + 'uz' => 'Uzbek', |
|
| 288 | + 've' => 'Venda', |
|
| 289 | + 'vi' => 'Vietnamese', |
|
| 290 | + 'vo' => 'Volapük', |
|
| 291 | + 'cy' => 'Welsh', |
|
| 292 | + 'wa' => 'Walloon', |
|
| 293 | + 'wo' => 'Wolof', |
|
| 294 | + 'xh' => 'Xhosa', |
|
| 295 | + 'yi' => 'Yiddish', |
|
| 296 | + 'yo' => 'Yoruba', |
|
| 297 | + 'za' => 'Zhuang; Chuang', |
|
| 298 | + 'zu' => 'Zulu' |
|
| 299 | + ); |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Filters the language codes. |
|
| 303 | - * |
|
| 304 | - * @since MU |
|
| 305 | - * |
|
| 306 | - * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 307 | - * @param string $code A two-letter designation of the language. |
|
| 308 | - */ |
|
| 309 | - $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 301 | + /** |
|
| 302 | + * Filters the language codes. |
|
| 303 | + * |
|
| 304 | + * @since MU |
|
| 305 | + * |
|
| 306 | + * @param array $lang_codes Key/value pair of language codes where key is the short version. |
|
| 307 | + * @param string $code A two-letter designation of the language. |
|
| 308 | + */ |
|
| 309 | + $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
| 310 | 310 | |
| 311 | - return strtr( $code, $lang_codes ); |
|
| 312 | - } |
|
| 311 | + return strtr( $code, $lang_codes ); |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | 314 | } |
@@ -173,7 +173,6 @@ discard block |
||
| 173 | 173 | * @since 3.3.0 |
| 174 | 174 | * |
| 175 | 175 | * @param int $post_id The entity post id. |
| 176 | - * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj. |
|
| 177 | 176 | * |
| 178 | 177 | * @return array An array representing the rating obj. |
| 179 | 178 | */ |
@@ -332,7 +331,7 @@ discard block |
||
| 332 | 331 | * |
| 333 | 332 | * @param int $score The rating score for a given entity. |
| 334 | 333 | * |
| 335 | - * @return string The input HTML code. |
|
| 334 | + * @return double The input HTML code. |
|
| 336 | 335 | */ |
| 337 | 336 | public function convert_raw_score_to_percentage( $score ) { |
| 338 | 337 | |
@@ -14,374 +14,374 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Wordlift_Rating_Service { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Entity rating max. |
|
| 19 | - * |
|
| 20 | - * @since 3.3.0 |
|
| 21 | - */ |
|
| 22 | - const RATING_MAX = 7; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Entity rating score meta key. |
|
| 26 | - * |
|
| 27 | - * @since 3.3.0 |
|
| 28 | - */ |
|
| 29 | - const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Entity rating warnings meta key. |
|
| 33 | - * |
|
| 34 | - * @since 3.3.0 |
|
| 35 | - */ |
|
| 36 | - const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Entity warning has related post identifier. |
|
| 40 | - * |
|
| 41 | - * @since 3.3.0 |
|
| 42 | - */ |
|
| 43 | - const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Entity warning has content post identifier. |
|
| 47 | - * |
|
| 48 | - * @since 3.3.0 |
|
| 49 | - */ |
|
| 50 | - const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Entity warning has related entities identifier. |
|
| 54 | - * |
|
| 55 | - * @since 3.3.0 |
|
| 56 | - */ |
|
| 57 | - const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Entity warning is published identifier. |
|
| 61 | - * |
|
| 62 | - * @since 3.3.0 |
|
| 63 | - */ |
|
| 64 | - const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Entity warning has thumbnail identifier. |
|
| 68 | - * |
|
| 69 | - * @since 3.3.0 |
|
| 70 | - */ |
|
| 71 | - const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Entity warning has same as identifier. |
|
| 75 | - * |
|
| 76 | - * @since 3.3.0 |
|
| 77 | - */ |
|
| 78 | - const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.'; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Entity warning has completed metadata identifier. |
|
| 82 | - * |
|
| 83 | - * @since 3.3.0 |
|
| 84 | - */ |
|
| 85 | - const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.'; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * A {@link Wordlift_Entity_Service} instance. |
|
| 89 | - * |
|
| 90 | - * @since 3.10.0 |
|
| 91 | - * @access private |
|
| 92 | - * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 93 | - */ |
|
| 94 | - private $entity_service; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 98 | - * |
|
| 99 | - * @since 3.10.0 |
|
| 100 | - * @access private |
|
| 101 | - * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 102 | - */ |
|
| 103 | - private $entity_type_service; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * The Notice service. |
|
| 107 | - * |
|
| 108 | - * @since 3.3.0 |
|
| 109 | - * @access private |
|
| 110 | - * @var \Wordlift_Notice_Service $notice_service The Notice service. |
|
| 111 | - */ |
|
| 112 | - private $notice_service; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * A {@link Wordlift_Log_Service} instance. |
|
| 116 | - * |
|
| 117 | - * @since 3.10.0 |
|
| 118 | - * @access private |
|
| 119 | - * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 120 | - */ |
|
| 121 | - private $log; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Create a {@link Wordlift_Rating_Service} instance. |
|
| 125 | - * |
|
| 126 | - * @since 3.10.0 |
|
| 127 | - * |
|
| 128 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 129 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 130 | - * @param \Wordlift_Notice_Service $notice_service A {@link Wordlift_Notice_Service} instance. |
|
| 131 | - */ |
|
| 132 | - public function __construct( $entity_service, $entity_type_service, $notice_service ) { |
|
| 133 | - |
|
| 134 | - $this->entity_service = $entity_service; |
|
| 135 | - $this->entity_type_service = $entity_type_service; |
|
| 136 | - $this->notice_service = $notice_service; |
|
| 137 | - |
|
| 138 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' ); |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Set rating for a given entity. |
|
| 144 | - * |
|
| 145 | - * @since 3.3.0 |
|
| 146 | - * |
|
| 147 | - * @param int $post_id The entity post id. |
|
| 148 | - * |
|
| 149 | - * @return array An array representing the rating obj. |
|
| 150 | - */ |
|
| 151 | - public function set_rating_for( $post_id ) { |
|
| 152 | - |
|
| 153 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 154 | - return; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Calculate rating for the given post. |
|
| 158 | - $rating = $this->calculate_rating_for( $post_id ); |
|
| 159 | - |
|
| 160 | - // Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY |
|
| 161 | - // is saved on a different meta to allow score sorting. Both meta are managed as unique. |
|
| 162 | - // |
|
| 163 | - // See https://codex.wordpress.org/Function_Reference/update_post_meta |
|
| 164 | - update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] ); |
|
| 165 | - update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] ); |
|
| 166 | - |
|
| 167 | - $this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) ); |
|
| 168 | - |
|
| 169 | - // Finally returns the rating |
|
| 170 | - return $rating; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Get or calculate rating for a given entity |
|
| 176 | - * |
|
| 177 | - * @since 3.3.0 |
|
| 178 | - * |
|
| 179 | - * @param int $post_id The entity post id. |
|
| 180 | - * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj. |
|
| 181 | - * |
|
| 182 | - * @return array An array representing the rating obj. |
|
| 183 | - */ |
|
| 184 | - public function get_rating_for( $post_id, $force_reload = false ) { |
|
| 185 | - |
|
| 186 | - // If forced reload is required or rating is missing. |
|
| 187 | - if ( $force_reload ) { |
|
| 188 | - $this->log->trace( "Force rating reload [ post_id :: $post_id ]" ); |
|
| 189 | - |
|
| 190 | - return $this->set_rating_for( $post_id ); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true ); |
|
| 194 | - |
|
| 195 | - if ( ! is_numeric( $current_raw_score ) ) { |
|
| 196 | - $this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" ); |
|
| 197 | - |
|
| 198 | - return $this->set_rating_for( $post_id ); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true ); |
|
| 202 | - |
|
| 203 | - // Finally return score and warnings |
|
| 204 | - return array( |
|
| 205 | - 'raw_score' => $current_raw_score, |
|
| 206 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ), |
|
| 207 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $current_raw_score ), |
|
| 208 | - 'warnings' => $current_warnings, |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Calculate rating for a given entity. |
|
| 215 | - * |
|
| 216 | - * Rating depends from following criteria: |
|
| 217 | - * |
|
| 218 | - * 1. Is the current entity related to at least 1 post? |
|
| 219 | - * 2. Is the current entity content post not empty? |
|
| 220 | - * 3. Is the current entity related to at least 1 entity? |
|
| 221 | - * 4. Is the entity published? |
|
| 222 | - * 5. There is a a thumbnail associated to the entity? |
|
| 223 | - * 6. Has the entity a sameas defined? |
|
| 224 | - * 7. Are all schema.org required metadata compiled? |
|
| 225 | - * |
|
| 226 | - * Each positive check means +1 in terms of rating score. |
|
| 227 | - * |
|
| 228 | - * @since 3.3.0 |
|
| 229 | - * |
|
| 230 | - * @param int $post_id The entity post id. |
|
| 231 | - * |
|
| 232 | - * @return array An array representing the rating obj. |
|
| 233 | - */ |
|
| 234 | - private function calculate_rating_for( $post_id ) { |
|
| 235 | - |
|
| 236 | - // If it's not an entity, return. |
|
| 237 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 238 | - return array(); |
|
| 239 | - } |
|
| 240 | - // Retrieve the post object. |
|
| 241 | - $post = get_post( $post_id ); |
|
| 242 | - |
|
| 243 | - // Rating value. |
|
| 244 | - $score = 0; |
|
| 245 | - |
|
| 246 | - // Store warning messages. |
|
| 247 | - $warnings = array(); |
|
| 248 | - |
|
| 249 | - // Is the current entity related to at least 1 post? |
|
| 250 | - ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ? |
|
| 251 | - $score ++ : |
|
| 252 | - array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) ); |
|
| 253 | - |
|
| 254 | - // Is the post content not empty? |
|
| 255 | - ( ! empty( $post->post_content ) ) ? |
|
| 256 | - $score ++ : |
|
| 257 | - array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) ); |
|
| 258 | - |
|
| 259 | - // Is the current entity related to at least 1 entity? |
|
| 260 | - // Was the current entity already disambiguated? |
|
| 261 | - ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ? |
|
| 262 | - $score ++ : |
|
| 263 | - array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) ); |
|
| 264 | - |
|
| 265 | - // Is the entity published? |
|
| 266 | - ( 'publish' === get_post_status( $post->ID ) ) ? |
|
| 267 | - $score ++ : |
|
| 268 | - array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) ); |
|
| 269 | - |
|
| 270 | - // Has a thumbnail? |
|
| 271 | - ( has_post_thumbnail( $post->ID ) ) ? |
|
| 272 | - $score ++ : |
|
| 273 | - array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) ); |
|
| 274 | - |
|
| 275 | - // Get all post meta keys for the current post |
|
| 276 | - global $wpdb; |
|
| 277 | - |
|
| 278 | - $query = $wpdb->prepare( |
|
| 279 | - "SELECT DISTINCT (meta_key) FROM $wpdb->postmeta WHERE post_id = %d", $post->ID |
|
| 280 | - ); |
|
| 281 | - |
|
| 282 | - // Check intersection between available meta keys and expected ones |
|
| 283 | - // arrays to detect missing values. |
|
| 284 | - $available_meta_keys = $wpdb->get_col( $query ); |
|
| 285 | - |
|
| 286 | - // If each expected key is contained in available keys array ... |
|
| 287 | - ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ? |
|
| 288 | - $score ++ : |
|
| 289 | - array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) ); |
|
| 290 | - |
|
| 291 | - $schema = $this->entity_type_service->get( $post_id ); |
|
| 292 | - |
|
| 293 | - $expected_meta_keys = ( null === $schema['custom_fields'] ) ? |
|
| 294 | - array() : |
|
| 295 | - array_keys( $schema['custom_fields'] ); |
|
| 296 | - |
|
| 297 | - $intersection = array_intersect( $expected_meta_keys, $available_meta_keys ); |
|
| 298 | - // If each expected key is contained in available keys array ... |
|
| 299 | - ( count( $intersection ) === count( $expected_meta_keys ) ) ? |
|
| 300 | - $score ++ : |
|
| 301 | - array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) ); |
|
| 302 | - |
|
| 303 | - // Finally return score and warnings |
|
| 304 | - return array( |
|
| 305 | - 'raw_score' => $score, |
|
| 306 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ), |
|
| 307 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $score ), |
|
| 308 | - 'warnings' => $warnings, |
|
| 309 | - ); |
|
| 310 | - |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Get as rating as input and convert in a traffic-light rating |
|
| 315 | - * |
|
| 316 | - * @since 3.3.0 |
|
| 317 | - * |
|
| 318 | - * @param int $score The rating score for a given entity. |
|
| 319 | - * |
|
| 320 | - * @return string The input HTML code. |
|
| 321 | - */ |
|
| 322 | - private function convert_raw_score_to_traffic_light( $score ) { |
|
| 323 | - // RATING_MAX : $score = 3 : x |
|
| 324 | - // See http://php.net/manual/en/function.round.php |
|
| 325 | - $rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 326 | - |
|
| 327 | - // If rating is 0, return 1, otherwise return rating |
|
| 328 | - return ( 0 == $rating ) ? 1 : $rating; |
|
| 329 | - |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Get as rating as input and convert in a traffic-light rating |
|
| 334 | - * |
|
| 335 | - * @since 3.3.0 |
|
| 336 | - * |
|
| 337 | - * @param int $score The rating score for a given entity. |
|
| 338 | - * |
|
| 339 | - * @return string The input HTML code. |
|
| 340 | - */ |
|
| 341 | - public function convert_raw_score_to_percentage( $score ) { |
|
| 342 | - |
|
| 343 | - // RATING_MAX : $score = 100 : x |
|
| 344 | - return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Add admin notices for the current entity depending on the current rating. |
|
| 350 | - * |
|
| 351 | - * @since 3.3.0 |
|
| 352 | - */ |
|
| 353 | - public function in_admin_header() { |
|
| 354 | - |
|
| 355 | - // Return safely if get_current_screen() is not defined (yet) |
|
| 356 | - if ( false === function_exists( 'get_current_screen' ) ) { |
|
| 357 | - return; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $screen = get_current_screen(); |
|
| 361 | - // If there is any valid screen nothing to do |
|
| 362 | - if ( null === $screen ) { |
|
| 363 | - return; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // If you're not in the entity post edit page, return. |
|
| 367 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) { |
|
| 368 | - return; |
|
| 369 | - } |
|
| 370 | - // Retrieve the current global post |
|
| 371 | - global $post; |
|
| 372 | - // If it's not an entity, return. |
|
| 373 | - if ( ! $this->entity_service->is_entity( $post->ID ) ) { |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - // Retrieve an updated rating for the current entity |
|
| 377 | - $rating = $this->get_rating_for( $post->ID, true ); |
|
| 378 | - |
|
| 379 | - // If there is at least 1 warning |
|
| 380 | - if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) { |
|
| 381 | - // TODO - Pass Wordlift_Notice_Service trough the service constructor |
|
| 382 | - $this->notice_service->add_suggestion( $rating['warnings'] ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - } |
|
| 17 | + /** |
|
| 18 | + * Entity rating max. |
|
| 19 | + * |
|
| 20 | + * @since 3.3.0 |
|
| 21 | + */ |
|
| 22 | + const RATING_MAX = 7; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Entity rating score meta key. |
|
| 26 | + * |
|
| 27 | + * @since 3.3.0 |
|
| 28 | + */ |
|
| 29 | + const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Entity rating warnings meta key. |
|
| 33 | + * |
|
| 34 | + * @since 3.3.0 |
|
| 35 | + */ |
|
| 36 | + const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Entity warning has related post identifier. |
|
| 40 | + * |
|
| 41 | + * @since 3.3.0 |
|
| 42 | + */ |
|
| 43 | + const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Entity warning has content post identifier. |
|
| 47 | + * |
|
| 48 | + * @since 3.3.0 |
|
| 49 | + */ |
|
| 50 | + const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Entity warning has related entities identifier. |
|
| 54 | + * |
|
| 55 | + * @since 3.3.0 |
|
| 56 | + */ |
|
| 57 | + const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Entity warning is published identifier. |
|
| 61 | + * |
|
| 62 | + * @since 3.3.0 |
|
| 63 | + */ |
|
| 64 | + const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Entity warning has thumbnail identifier. |
|
| 68 | + * |
|
| 69 | + * @since 3.3.0 |
|
| 70 | + */ |
|
| 71 | + const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Entity warning has same as identifier. |
|
| 75 | + * |
|
| 76 | + * @since 3.3.0 |
|
| 77 | + */ |
|
| 78 | + const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.'; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Entity warning has completed metadata identifier. |
|
| 82 | + * |
|
| 83 | + * @since 3.3.0 |
|
| 84 | + */ |
|
| 85 | + const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.'; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * A {@link Wordlift_Entity_Service} instance. |
|
| 89 | + * |
|
| 90 | + * @since 3.10.0 |
|
| 91 | + * @access private |
|
| 92 | + * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 93 | + */ |
|
| 94 | + private $entity_service; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * A {@link Wordlift_Entity_Type_Service} instance. |
|
| 98 | + * |
|
| 99 | + * @since 3.10.0 |
|
| 100 | + * @access private |
|
| 101 | + * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 102 | + */ |
|
| 103 | + private $entity_type_service; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * The Notice service. |
|
| 107 | + * |
|
| 108 | + * @since 3.3.0 |
|
| 109 | + * @access private |
|
| 110 | + * @var \Wordlift_Notice_Service $notice_service The Notice service. |
|
| 111 | + */ |
|
| 112 | + private $notice_service; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * A {@link Wordlift_Log_Service} instance. |
|
| 116 | + * |
|
| 117 | + * @since 3.10.0 |
|
| 118 | + * @access private |
|
| 119 | + * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 120 | + */ |
|
| 121 | + private $log; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Create a {@link Wordlift_Rating_Service} instance. |
|
| 125 | + * |
|
| 126 | + * @since 3.10.0 |
|
| 127 | + * |
|
| 128 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 129 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 130 | + * @param \Wordlift_Notice_Service $notice_service A {@link Wordlift_Notice_Service} instance. |
|
| 131 | + */ |
|
| 132 | + public function __construct( $entity_service, $entity_type_service, $notice_service ) { |
|
| 133 | + |
|
| 134 | + $this->entity_service = $entity_service; |
|
| 135 | + $this->entity_type_service = $entity_type_service; |
|
| 136 | + $this->notice_service = $notice_service; |
|
| 137 | + |
|
| 138 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' ); |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Set rating for a given entity. |
|
| 144 | + * |
|
| 145 | + * @since 3.3.0 |
|
| 146 | + * |
|
| 147 | + * @param int $post_id The entity post id. |
|
| 148 | + * |
|
| 149 | + * @return array An array representing the rating obj. |
|
| 150 | + */ |
|
| 151 | + public function set_rating_for( $post_id ) { |
|
| 152 | + |
|
| 153 | + if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 154 | + return; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Calculate rating for the given post. |
|
| 158 | + $rating = $this->calculate_rating_for( $post_id ); |
|
| 159 | + |
|
| 160 | + // Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY |
|
| 161 | + // is saved on a different meta to allow score sorting. Both meta are managed as unique. |
|
| 162 | + // |
|
| 163 | + // See https://codex.wordpress.org/Function_Reference/update_post_meta |
|
| 164 | + update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] ); |
|
| 165 | + update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] ); |
|
| 166 | + |
|
| 167 | + $this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) ); |
|
| 168 | + |
|
| 169 | + // Finally returns the rating |
|
| 170 | + return $rating; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Get or calculate rating for a given entity |
|
| 176 | + * |
|
| 177 | + * @since 3.3.0 |
|
| 178 | + * |
|
| 179 | + * @param int $post_id The entity post id. |
|
| 180 | + * @param $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj. |
|
| 181 | + * |
|
| 182 | + * @return array An array representing the rating obj. |
|
| 183 | + */ |
|
| 184 | + public function get_rating_for( $post_id, $force_reload = false ) { |
|
| 185 | + |
|
| 186 | + // If forced reload is required or rating is missing. |
|
| 187 | + if ( $force_reload ) { |
|
| 188 | + $this->log->trace( "Force rating reload [ post_id :: $post_id ]" ); |
|
| 189 | + |
|
| 190 | + return $this->set_rating_for( $post_id ); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true ); |
|
| 194 | + |
|
| 195 | + if ( ! is_numeric( $current_raw_score ) ) { |
|
| 196 | + $this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" ); |
|
| 197 | + |
|
| 198 | + return $this->set_rating_for( $post_id ); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true ); |
|
| 202 | + |
|
| 203 | + // Finally return score and warnings |
|
| 204 | + return array( |
|
| 205 | + 'raw_score' => $current_raw_score, |
|
| 206 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ), |
|
| 207 | + 'percentage_score' => $this->convert_raw_score_to_percentage( $current_raw_score ), |
|
| 208 | + 'warnings' => $current_warnings, |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Calculate rating for a given entity. |
|
| 215 | + * |
|
| 216 | + * Rating depends from following criteria: |
|
| 217 | + * |
|
| 218 | + * 1. Is the current entity related to at least 1 post? |
|
| 219 | + * 2. Is the current entity content post not empty? |
|
| 220 | + * 3. Is the current entity related to at least 1 entity? |
|
| 221 | + * 4. Is the entity published? |
|
| 222 | + * 5. There is a a thumbnail associated to the entity? |
|
| 223 | + * 6. Has the entity a sameas defined? |
|
| 224 | + * 7. Are all schema.org required metadata compiled? |
|
| 225 | + * |
|
| 226 | + * Each positive check means +1 in terms of rating score. |
|
| 227 | + * |
|
| 228 | + * @since 3.3.0 |
|
| 229 | + * |
|
| 230 | + * @param int $post_id The entity post id. |
|
| 231 | + * |
|
| 232 | + * @return array An array representing the rating obj. |
|
| 233 | + */ |
|
| 234 | + private function calculate_rating_for( $post_id ) { |
|
| 235 | + |
|
| 236 | + // If it's not an entity, return. |
|
| 237 | + if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 238 | + return array(); |
|
| 239 | + } |
|
| 240 | + // Retrieve the post object. |
|
| 241 | + $post = get_post( $post_id ); |
|
| 242 | + |
|
| 243 | + // Rating value. |
|
| 244 | + $score = 0; |
|
| 245 | + |
|
| 246 | + // Store warning messages. |
|
| 247 | + $warnings = array(); |
|
| 248 | + |
|
| 249 | + // Is the current entity related to at least 1 post? |
|
| 250 | + ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ? |
|
| 251 | + $score ++ : |
|
| 252 | + array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) ); |
|
| 253 | + |
|
| 254 | + // Is the post content not empty? |
|
| 255 | + ( ! empty( $post->post_content ) ) ? |
|
| 256 | + $score ++ : |
|
| 257 | + array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) ); |
|
| 258 | + |
|
| 259 | + // Is the current entity related to at least 1 entity? |
|
| 260 | + // Was the current entity already disambiguated? |
|
| 261 | + ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ? |
|
| 262 | + $score ++ : |
|
| 263 | + array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) ); |
|
| 264 | + |
|
| 265 | + // Is the entity published? |
|
| 266 | + ( 'publish' === get_post_status( $post->ID ) ) ? |
|
| 267 | + $score ++ : |
|
| 268 | + array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) ); |
|
| 269 | + |
|
| 270 | + // Has a thumbnail? |
|
| 271 | + ( has_post_thumbnail( $post->ID ) ) ? |
|
| 272 | + $score ++ : |
|
| 273 | + array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) ); |
|
| 274 | + |
|
| 275 | + // Get all post meta keys for the current post |
|
| 276 | + global $wpdb; |
|
| 277 | + |
|
| 278 | + $query = $wpdb->prepare( |
|
| 279 | + "SELECT DISTINCT (meta_key) FROM $wpdb->postmeta WHERE post_id = %d", $post->ID |
|
| 280 | + ); |
|
| 281 | + |
|
| 282 | + // Check intersection between available meta keys and expected ones |
|
| 283 | + // arrays to detect missing values. |
|
| 284 | + $available_meta_keys = $wpdb->get_col( $query ); |
|
| 285 | + |
|
| 286 | + // If each expected key is contained in available keys array ... |
|
| 287 | + ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ? |
|
| 288 | + $score ++ : |
|
| 289 | + array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) ); |
|
| 290 | + |
|
| 291 | + $schema = $this->entity_type_service->get( $post_id ); |
|
| 292 | + |
|
| 293 | + $expected_meta_keys = ( null === $schema['custom_fields'] ) ? |
|
| 294 | + array() : |
|
| 295 | + array_keys( $schema['custom_fields'] ); |
|
| 296 | + |
|
| 297 | + $intersection = array_intersect( $expected_meta_keys, $available_meta_keys ); |
|
| 298 | + // If each expected key is contained in available keys array ... |
|
| 299 | + ( count( $intersection ) === count( $expected_meta_keys ) ) ? |
|
| 300 | + $score ++ : |
|
| 301 | + array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) ); |
|
| 302 | + |
|
| 303 | + // Finally return score and warnings |
|
| 304 | + return array( |
|
| 305 | + 'raw_score' => $score, |
|
| 306 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ), |
|
| 307 | + 'percentage_score' => $this->convert_raw_score_to_percentage( $score ), |
|
| 308 | + 'warnings' => $warnings, |
|
| 309 | + ); |
|
| 310 | + |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Get as rating as input and convert in a traffic-light rating |
|
| 315 | + * |
|
| 316 | + * @since 3.3.0 |
|
| 317 | + * |
|
| 318 | + * @param int $score The rating score for a given entity. |
|
| 319 | + * |
|
| 320 | + * @return string The input HTML code. |
|
| 321 | + */ |
|
| 322 | + private function convert_raw_score_to_traffic_light( $score ) { |
|
| 323 | + // RATING_MAX : $score = 3 : x |
|
| 324 | + // See http://php.net/manual/en/function.round.php |
|
| 325 | + $rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 326 | + |
|
| 327 | + // If rating is 0, return 1, otherwise return rating |
|
| 328 | + return ( 0 == $rating ) ? 1 : $rating; |
|
| 329 | + |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Get as rating as input and convert in a traffic-light rating |
|
| 334 | + * |
|
| 335 | + * @since 3.3.0 |
|
| 336 | + * |
|
| 337 | + * @param int $score The rating score for a given entity. |
|
| 338 | + * |
|
| 339 | + * @return string The input HTML code. |
|
| 340 | + */ |
|
| 341 | + public function convert_raw_score_to_percentage( $score ) { |
|
| 342 | + |
|
| 343 | + // RATING_MAX : $score = 100 : x |
|
| 344 | + return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Add admin notices for the current entity depending on the current rating. |
|
| 350 | + * |
|
| 351 | + * @since 3.3.0 |
|
| 352 | + */ |
|
| 353 | + public function in_admin_header() { |
|
| 354 | + |
|
| 355 | + // Return safely if get_current_screen() is not defined (yet) |
|
| 356 | + if ( false === function_exists( 'get_current_screen' ) ) { |
|
| 357 | + return; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $screen = get_current_screen(); |
|
| 361 | + // If there is any valid screen nothing to do |
|
| 362 | + if ( null === $screen ) { |
|
| 363 | + return; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // If you're not in the entity post edit page, return. |
|
| 367 | + if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) { |
|
| 368 | + return; |
|
| 369 | + } |
|
| 370 | + // Retrieve the current global post |
|
| 371 | + global $post; |
|
| 372 | + // If it's not an entity, return. |
|
| 373 | + if ( ! $this->entity_service->is_entity( $post->ID ) ) { |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + // Retrieve an updated rating for the current entity |
|
| 377 | + $rating = $this->get_rating_for( $post->ID, true ); |
|
| 378 | + |
|
| 379 | + // If there is at least 1 warning |
|
| 380 | + if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) { |
|
| 381 | + // TODO - Pass Wordlift_Notice_Service trough the service constructor |
|
| 382 | + $this->notice_service->add_suggestion( $rating['warnings'] ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | 387 | } |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
| 130 | 130 | * @param \Wordlift_Notice_Service $notice_service A {@link Wordlift_Notice_Service} instance. |
| 131 | 131 | */ |
| 132 | - public function __construct( $entity_service, $entity_type_service, $notice_service ) { |
|
| 132 | + public function __construct($entity_service, $entity_type_service, $notice_service) { |
|
| 133 | 133 | |
| 134 | 134 | $this->entity_service = $entity_service; |
| 135 | 135 | $this->entity_type_service = $entity_type_service; |
| 136 | 136 | $this->notice_service = $notice_service; |
| 137 | 137 | |
| 138 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' ); |
|
| 138 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Rating_Service'); |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | |
@@ -148,23 +148,23 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @return array An array representing the rating obj. |
| 150 | 150 | */ |
| 151 | - public function set_rating_for( $post_id ) { |
|
| 151 | + public function set_rating_for($post_id) { |
|
| 152 | 152 | |
| 153 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 153 | + if ( ! $this->entity_service->is_entity($post_id)) { |
|
| 154 | 154 | return; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | // Calculate rating for the given post. |
| 158 | - $rating = $this->calculate_rating_for( $post_id ); |
|
| 158 | + $rating = $this->calculate_rating_for($post_id); |
|
| 159 | 159 | |
| 160 | 160 | // Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY |
| 161 | 161 | // is saved on a different meta to allow score sorting. Both meta are managed as unique. |
| 162 | 162 | // |
| 163 | 163 | // See https://codex.wordpress.org/Function_Reference/update_post_meta |
| 164 | - update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] ); |
|
| 165 | - update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] ); |
|
| 164 | + update_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score']); |
|
| 165 | + update_post_meta($post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings']); |
|
| 166 | 166 | |
| 167 | - $this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) ); |
|
| 167 | + $this->log->trace(sprintf("Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'])); |
|
| 168 | 168 | |
| 169 | 169 | // Finally returns the rating |
| 170 | 170 | return $rating; |
@@ -181,30 +181,30 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @return array An array representing the rating obj. |
| 183 | 183 | */ |
| 184 | - public function get_rating_for( $post_id, $force_reload = false ) { |
|
| 184 | + public function get_rating_for($post_id, $force_reload = false) { |
|
| 185 | 185 | |
| 186 | 186 | // If forced reload is required or rating is missing. |
| 187 | - if ( $force_reload ) { |
|
| 188 | - $this->log->trace( "Force rating reload [ post_id :: $post_id ]" ); |
|
| 187 | + if ($force_reload) { |
|
| 188 | + $this->log->trace("Force rating reload [ post_id :: $post_id ]"); |
|
| 189 | 189 | |
| 190 | - return $this->set_rating_for( $post_id ); |
|
| 190 | + return $this->set_rating_for($post_id); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true ); |
|
| 193 | + $current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true); |
|
| 194 | 194 | |
| 195 | - if ( ! is_numeric( $current_raw_score ) ) { |
|
| 196 | - $this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" ); |
|
| 195 | + if ( ! is_numeric($current_raw_score)) { |
|
| 196 | + $this->log->trace("Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]"); |
|
| 197 | 197 | |
| 198 | - return $this->set_rating_for( $post_id ); |
|
| 198 | + return $this->set_rating_for($post_id); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true ); |
|
| 201 | + $current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true); |
|
| 202 | 202 | |
| 203 | 203 | // Finally return score and warnings |
| 204 | 204 | return array( |
| 205 | 205 | 'raw_score' => $current_raw_score, |
| 206 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ), |
|
| 207 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $current_raw_score ), |
|
| 206 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light($current_raw_score), |
|
| 207 | + 'percentage_score' => $this->convert_raw_score_to_percentage($current_raw_score), |
|
| 208 | 208 | 'warnings' => $current_warnings, |
| 209 | 209 | ); |
| 210 | 210 | |
@@ -231,14 +231,14 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return array An array representing the rating obj. |
| 233 | 233 | */ |
| 234 | - private function calculate_rating_for( $post_id ) { |
|
| 234 | + private function calculate_rating_for($post_id) { |
|
| 235 | 235 | |
| 236 | 236 | // If it's not an entity, return. |
| 237 | - if ( ! $this->entity_service->is_entity( $post_id ) ) { |
|
| 237 | + if ( ! $this->entity_service->is_entity($post_id)) { |
|
| 238 | 238 | return array(); |
| 239 | 239 | } |
| 240 | 240 | // Retrieve the post object. |
| 241 | - $post = get_post( $post_id ); |
|
| 241 | + $post = get_post($post_id); |
|
| 242 | 242 | |
| 243 | 243 | // Rating value. |
| 244 | 244 | $score = 0; |
@@ -247,30 +247,25 @@ discard block |
||
| 247 | 247 | $warnings = array(); |
| 248 | 248 | |
| 249 | 249 | // Is the current entity related to at least 1 post? |
| 250 | - ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ? |
|
| 251 | - $score ++ : |
|
| 252 | - array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) ); |
|
| 250 | + (0 < count(wl_core_get_related_post_ids($post->ID))) ? |
|
| 251 | + $score++ : array_push($warnings, __('There are no related posts for the current entity.', 'wordlift')); |
|
| 253 | 252 | |
| 254 | 253 | // Is the post content not empty? |
| 255 | - ( ! empty( $post->post_content ) ) ? |
|
| 256 | - $score ++ : |
|
| 257 | - array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) ); |
|
| 254 | + ( ! empty($post->post_content)) ? |
|
| 255 | + $score++ : array_push($warnings, __('This entity has not description.', 'wordlift')); |
|
| 258 | 256 | |
| 259 | 257 | // Is the current entity related to at least 1 entity? |
| 260 | 258 | // Was the current entity already disambiguated? |
| 261 | - ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ? |
|
| 262 | - $score ++ : |
|
| 263 | - array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) ); |
|
| 259 | + (0 < count(wl_core_get_related_entity_ids($post->ID))) ? |
|
| 260 | + $score++ : array_push($warnings, __('There are no related entities for the current entity.', 'wordlift')); |
|
| 264 | 261 | |
| 265 | 262 | // Is the entity published? |
| 266 | - ( 'publish' === get_post_status( $post->ID ) ) ? |
|
| 267 | - $score ++ : |
|
| 268 | - array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) ); |
|
| 263 | + ('publish' === get_post_status($post->ID)) ? |
|
| 264 | + $score++ : array_push($warnings, __('This entity is not published. It will not appear within analysis results.', 'wordlift')); |
|
| 269 | 265 | |
| 270 | 266 | // Has a thumbnail? |
| 271 | - ( has_post_thumbnail( $post->ID ) ) ? |
|
| 272 | - $score ++ : |
|
| 273 | - array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) ); |
|
| 267 | + (has_post_thumbnail($post->ID)) ? |
|
| 268 | + $score++ : array_push($warnings, __('This entity has no featured image yet.', 'wordlift')); |
|
| 274 | 269 | |
| 275 | 270 | // Get all post meta keys for the current post |
| 276 | 271 | global $wpdb; |
@@ -281,30 +276,27 @@ discard block |
||
| 281 | 276 | |
| 282 | 277 | // Check intersection between available meta keys and expected ones |
| 283 | 278 | // arrays to detect missing values. |
| 284 | - $available_meta_keys = $wpdb->get_col( $query ); |
|
| 279 | + $available_meta_keys = $wpdb->get_col($query); |
|
| 285 | 280 | |
| 286 | 281 | // If each expected key is contained in available keys array ... |
| 287 | - ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ? |
|
| 288 | - $score ++ : |
|
| 289 | - array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) ); |
|
| 282 | + (in_array(Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys)) ? |
|
| 283 | + $score++ : array_push($warnings, __('There are no sameAs configured for this entity.', 'wordlift')); |
|
| 290 | 284 | |
| 291 | - $schema = $this->entity_type_service->get( $post_id ); |
|
| 285 | + $schema = $this->entity_type_service->get($post_id); |
|
| 292 | 286 | |
| 293 | - $expected_meta_keys = ( null === $schema['custom_fields'] ) ? |
|
| 294 | - array() : |
|
| 295 | - array_keys( $schema['custom_fields'] ); |
|
| 287 | + $expected_meta_keys = (null === $schema['custom_fields']) ? |
|
| 288 | + array() : array_keys($schema['custom_fields']); |
|
| 296 | 289 | |
| 297 | - $intersection = array_intersect( $expected_meta_keys, $available_meta_keys ); |
|
| 290 | + $intersection = array_intersect($expected_meta_keys, $available_meta_keys); |
|
| 298 | 291 | // If each expected key is contained in available keys array ... |
| 299 | - ( count( $intersection ) === count( $expected_meta_keys ) ) ? |
|
| 300 | - $score ++ : |
|
| 301 | - array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) ); |
|
| 292 | + (count($intersection) === count($expected_meta_keys)) ? |
|
| 293 | + $score++ : array_push($warnings, __('Schema.org metadata for this entity are not completed.', 'wordlift')); |
|
| 302 | 294 | |
| 303 | 295 | // Finally return score and warnings |
| 304 | 296 | return array( |
| 305 | 297 | 'raw_score' => $score, |
| 306 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ), |
|
| 307 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $score ), |
|
| 298 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light($score), |
|
| 299 | + 'percentage_score' => $this->convert_raw_score_to_percentage($score), |
|
| 308 | 300 | 'warnings' => $warnings, |
| 309 | 301 | ); |
| 310 | 302 | |
@@ -319,13 +311,13 @@ discard block |
||
| 319 | 311 | * |
| 320 | 312 | * @return string The input HTML code. |
| 321 | 313 | */ |
| 322 | - private function convert_raw_score_to_traffic_light( $score ) { |
|
| 314 | + private function convert_raw_score_to_traffic_light($score) { |
|
| 323 | 315 | // RATING_MAX : $score = 3 : x |
| 324 | 316 | // See http://php.net/manual/en/function.round.php |
| 325 | - $rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 317 | + $rating = round(($score * 3) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP); |
|
| 326 | 318 | |
| 327 | 319 | // If rating is 0, return 1, otherwise return rating |
| 328 | - return ( 0 == $rating ) ? 1 : $rating; |
|
| 320 | + return (0 == $rating) ? 1 : $rating; |
|
| 329 | 321 | |
| 330 | 322 | } |
| 331 | 323 | |
@@ -338,10 +330,10 @@ discard block |
||
| 338 | 330 | * |
| 339 | 331 | * @return string The input HTML code. |
| 340 | 332 | */ |
| 341 | - public function convert_raw_score_to_percentage( $score ) { |
|
| 333 | + public function convert_raw_score_to_percentage($score) { |
|
| 342 | 334 | |
| 343 | 335 | // RATING_MAX : $score = 100 : x |
| 344 | - return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP ); |
|
| 336 | + return round(($score * 100) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP); |
|
| 345 | 337 | } |
| 346 | 338 | |
| 347 | 339 | |
@@ -353,33 +345,33 @@ discard block |
||
| 353 | 345 | public function in_admin_header() { |
| 354 | 346 | |
| 355 | 347 | // Return safely if get_current_screen() is not defined (yet) |
| 356 | - if ( false === function_exists( 'get_current_screen' ) ) { |
|
| 348 | + if (false === function_exists('get_current_screen')) { |
|
| 357 | 349 | return; |
| 358 | 350 | } |
| 359 | 351 | |
| 360 | 352 | $screen = get_current_screen(); |
| 361 | 353 | // If there is any valid screen nothing to do |
| 362 | - if ( null === $screen ) { |
|
| 354 | + if (null === $screen) { |
|
| 363 | 355 | return; |
| 364 | 356 | } |
| 365 | 357 | |
| 366 | 358 | // If you're not in the entity post edit page, return. |
| 367 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) { |
|
| 359 | + if (Wordlift_Entity_Service::TYPE_NAME !== $screen->id) { |
|
| 368 | 360 | return; |
| 369 | 361 | } |
| 370 | 362 | // Retrieve the current global post |
| 371 | 363 | global $post; |
| 372 | 364 | // If it's not an entity, return. |
| 373 | - if ( ! $this->entity_service->is_entity( $post->ID ) ) { |
|
| 365 | + if ( ! $this->entity_service->is_entity($post->ID)) { |
|
| 374 | 366 | return; |
| 375 | 367 | } |
| 376 | 368 | // Retrieve an updated rating for the current entity |
| 377 | - $rating = $this->get_rating_for( $post->ID, true ); |
|
| 369 | + $rating = $this->get_rating_for($post->ID, true); |
|
| 378 | 370 | |
| 379 | 371 | // If there is at least 1 warning |
| 380 | - if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) { |
|
| 372 | + if (isset($rating['warnings']) && 0 < count($rating['warnings'])) { |
|
| 381 | 373 | // TODO - Pass Wordlift_Notice_Service trough the service constructor |
| 382 | - $this->notice_service->add_suggestion( $rating['warnings'] ); |
|
| 374 | + $this->notice_service->add_suggestion($rating['warnings']); |
|
| 383 | 375 | } |
| 384 | 376 | |
| 385 | 377 | } |
@@ -21,66 +21,66 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wordlift_Seo_Service { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @inheritdoc |
|
| 26 | - */ |
|
| 27 | - function __construct() { |
|
| 24 | + /** |
|
| 25 | + * @inheritdoc |
|
| 26 | + */ |
|
| 27 | + function __construct() { |
|
| 28 | 28 | |
| 29 | - // If we are not on the admin, run the get_term filter for entity type terms. |
|
| 30 | - add_filter( 'get_wl_entity_type', array( |
|
| 31 | - $this, |
|
| 32 | - 'get_wl_entity_type', |
|
| 33 | - ), 10, 2 ); |
|
| 29 | + // If we are not on the admin, run the get_term filter for entity type terms. |
|
| 30 | + add_filter( 'get_wl_entity_type', array( |
|
| 31 | + $this, |
|
| 32 | + 'get_wl_entity_type', |
|
| 33 | + ), 10, 2 ); |
|
| 34 | 34 | |
| 35 | - } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Filter the entity term object, and when not in admin context replace title |
|
| 39 | - * and description with whatever was set in the entity settings page. |
|
| 40 | - * |
|
| 41 | - * @since 3.11 |
|
| 42 | - * |
|
| 43 | - * @param WP_Term $term The term to filters. |
|
| 44 | - * @param string $taxonomy The taxonomy name. |
|
| 45 | - * |
|
| 46 | - * @return WP_Term The {@link WP_Term} with fields changed. |
|
| 47 | - */ |
|
| 48 | - function get_wl_entity_type( $term, $taxonomy ) { |
|
| 37 | + /** |
|
| 38 | + * Filter the entity term object, and when not in admin context replace title |
|
| 39 | + * and description with whatever was set in the entity settings page. |
|
| 40 | + * |
|
| 41 | + * @since 3.11 |
|
| 42 | + * |
|
| 43 | + * @param WP_Term $term The term to filters. |
|
| 44 | + * @param string $taxonomy The taxonomy name. |
|
| 45 | + * |
|
| 46 | + * @return WP_Term The {@link WP_Term} with fields changed. |
|
| 47 | + */ |
|
| 48 | + function get_wl_entity_type( $term, $taxonomy ) { |
|
| 49 | 49 | |
| 50 | - // Do nothing when in admin. |
|
| 51 | - if ( is_admin() ) { |
|
| 52 | - return $term; |
|
| 53 | - } |
|
| 50 | + // Do nothing when in admin. |
|
| 51 | + if ( is_admin() ) { |
|
| 52 | + return $term; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // Get the terms' settings. |
|
| 56 | - $entity_settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 55 | + // Get the terms' settings. |
|
| 56 | + $entity_settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 57 | 57 | |
| 58 | - // If we have no settings for the specified term, then return the original |
|
| 59 | - // term. |
|
| 60 | - if ( ! isset( $entity_settings[ $term->term_id ] ) ) { |
|
| 58 | + // If we have no settings for the specified term, then return the original |
|
| 59 | + // term. |
|
| 60 | + if ( ! isset( $entity_settings[ $term->term_id ] ) ) { |
|
| 61 | 61 | |
| 62 | - return $term; |
|
| 63 | - } |
|
| 62 | + return $term; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - // Get the settings for the specified term. |
|
| 66 | - $settings = $entity_settings[ $term->term_id ]; |
|
| 65 | + // Get the settings for the specified term. |
|
| 66 | + $settings = $entity_settings[ $term->term_id ]; |
|
| 67 | 67 | |
| 68 | - // Update the name. |
|
| 69 | - if ( ! empty( $settings['title'] ) ) { |
|
| 68 | + // Update the name. |
|
| 69 | + if ( ! empty( $settings['title'] ) ) { |
|
| 70 | 70 | |
| 71 | - $term->name = $settings['title']; |
|
| 71 | + $term->name = $settings['title']; |
|
| 72 | 72 | |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // Update the description. |
|
| 76 | - if ( ! empty( $settings['description'] ) ) { |
|
| 75 | + // Update the description. |
|
| 76 | + if ( ! empty( $settings['description'] ) ) { |
|
| 77 | 77 | |
| 78 | - $term->description = $settings['description']; |
|
| 78 | + $term->description = $settings['description']; |
|
| 79 | 79 | |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // Return the updated term. |
|
| 83 | - return $term; |
|
| 84 | - } |
|
| 82 | + // Return the updated term. |
|
| 83 | + return $term; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | } |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | function __construct() { |
| 28 | 28 | |
| 29 | 29 | // If we are not on the admin, run the get_term filter for entity type terms. |
| 30 | - add_filter( 'get_wl_entity_type', array( |
|
| 30 | + add_filter('get_wl_entity_type', array( |
|
| 31 | 31 | $this, |
| 32 | 32 | 'get_wl_entity_type', |
| 33 | - ), 10, 2 ); |
|
| 33 | + ), 10, 2); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -45,35 +45,35 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return WP_Term The {@link WP_Term} with fields changed. |
| 47 | 47 | */ |
| 48 | - function get_wl_entity_type( $term, $taxonomy ) { |
|
| 48 | + function get_wl_entity_type($term, $taxonomy) { |
|
| 49 | 49 | |
| 50 | 50 | // Do nothing when in admin. |
| 51 | - if ( is_admin() ) { |
|
| 51 | + if (is_admin()) { |
|
| 52 | 52 | return $term; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Get the terms' settings. |
| 56 | - $entity_settings = get_option( 'wl_entity_type_settings', array() ); |
|
| 56 | + $entity_settings = get_option('wl_entity_type_settings', array()); |
|
| 57 | 57 | |
| 58 | 58 | // If we have no settings for the specified term, then return the original |
| 59 | 59 | // term. |
| 60 | - if ( ! isset( $entity_settings[ $term->term_id ] ) ) { |
|
| 60 | + if ( ! isset($entity_settings[$term->term_id])) { |
|
| 61 | 61 | |
| 62 | 62 | return $term; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // Get the settings for the specified term. |
| 66 | - $settings = $entity_settings[ $term->term_id ]; |
|
| 66 | + $settings = $entity_settings[$term->term_id]; |
|
| 67 | 67 | |
| 68 | 68 | // Update the name. |
| 69 | - if ( ! empty( $settings['title'] ) ) { |
|
| 69 | + if ( ! empty($settings['title'])) { |
|
| 70 | 70 | |
| 71 | 71 | $term->name = $settings['title']; |
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Update the description. |
| 76 | - if ( ! empty( $settings['description'] ) ) { |
|
| 76 | + if ( ! empty($settings['description'])) { |
|
| 77 | 77 | |
| 78 | 78 | $term->description = $settings['description']; |
| 79 | 79 | |
@@ -16,26 +16,26 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | abstract class Wordlift_Widget extends WP_Widget { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @inheritdoc |
|
| 21 | - */ |
|
| 22 | - public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) { |
|
| 23 | - parent::__construct( $id_base, $name, $widget_options, $control_options ); |
|
| 19 | + /** |
|
| 20 | + * @inheritdoc |
|
| 21 | + */ |
|
| 22 | + public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) { |
|
| 23 | + parent::__construct( $id_base, $name, $widget_options, $control_options ); |
|
| 24 | 24 | |
| 25 | - // Initialize the Related Entities Cloud Widget. |
|
| 26 | - add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
| 25 | + // Initialize the Related Entities Cloud Widget. |
|
| 26 | + add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
| 27 | 27 | |
| 28 | - } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Register the related entities cloud widget |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - */ |
|
| 35 | - public function widget_init() { |
|
| 30 | + /** |
|
| 31 | + * Register the related entities cloud widget |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + */ |
|
| 35 | + public function widget_init() { |
|
| 36 | 36 | |
| 37 | - register_widget( get_class( $this ) ); |
|
| 37 | + register_widget( get_class( $this ) ); |
|
| 38 | 38 | |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @inheritdoc |
| 21 | 21 | */ |
| 22 | - public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) { |
|
| 23 | - parent::__construct( $id_base, $name, $widget_options, $control_options ); |
|
| 22 | + public function __construct($id_base, $name, array $widget_options = array(), array $control_options = array()) { |
|
| 23 | + parent::__construct($id_base, $name, $widget_options, $control_options); |
|
| 24 | 24 | |
| 25 | 25 | // Initialize the Related Entities Cloud Widget. |
| 26 | - add_action( 'widgets_init', array( $this, 'widget_init' ) ); |
|
| 26 | + add_action('widgets_init', array($this, 'widget_init')); |
|
| 27 | 27 | |
| 28 | 28 | } |
| 29 | 29 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function widget_init() { |
| 36 | 36 | |
| 37 | - register_widget( get_class( $this ) ); |
|
| 37 | + register_widget(get_class($this)); |
|
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
@@ -16,55 +16,55 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Publisher_Ajax_Adapter { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The {@link Wordlift_Publisher_Service} instance. |
|
| 21 | - * |
|
| 22 | - * @since 3.11.0 |
|
| 23 | - * @access private |
|
| 24 | - * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 25 | - */ |
|
| 26 | - private $publisher_service; |
|
| 19 | + /** |
|
| 20 | + * The {@link Wordlift_Publisher_Service} instance. |
|
| 21 | + * |
|
| 22 | + * @since 3.11.0 |
|
| 23 | + * @access private |
|
| 24 | + * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 25 | + */ |
|
| 26 | + private $publisher_service; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.11.0 |
|
| 32 | - * |
|
| 33 | - * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 34 | - */ |
|
| 35 | - function __construct( $publisher_service ) { |
|
| 28 | + /** |
|
| 29 | + * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.11.0 |
|
| 32 | + * |
|
| 33 | + * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 34 | + */ |
|
| 35 | + function __construct( $publisher_service ) { |
|
| 36 | 36 | |
| 37 | - $this->publisher_service = $publisher_service; |
|
| 37 | + $this->publisher_service = $publisher_service; |
|
| 38 | 38 | |
| 39 | - } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * The publisher AJAX action. This function is hook to the `wl_publisher` |
|
| 43 | - * action. |
|
| 44 | - * |
|
| 45 | - * @since 3.11.0 |
|
| 46 | - */ |
|
| 47 | - public function publisher() { |
|
| 41 | + /** |
|
| 42 | + * The publisher AJAX action. This function is hook to the `wl_publisher` |
|
| 43 | + * action. |
|
| 44 | + * |
|
| 45 | + * @since 3.11.0 |
|
| 46 | + */ |
|
| 47 | + public function publisher() { |
|
| 48 | 48 | |
| 49 | - // Ensure we don't have garbage before us. |
|
| 50 | - ob_clean(); |
|
| 49 | + // Ensure we don't have garbage before us. |
|
| 50 | + ob_clean(); |
|
| 51 | 51 | |
| 52 | - // Check if the current user can `manage_options`. |
|
| 53 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 54 | - wp_send_json_error( 'Access denied.' ); |
|
| 55 | - } |
|
| 52 | + // Check if the current user can `manage_options`. |
|
| 53 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 54 | + wp_send_json_error( 'Access denied.' ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - // No actual search parameter was passed, bail out. |
|
| 58 | - if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) { |
|
| 59 | - wp_send_json_error( 'The q parameter is required.' ); |
|
| 60 | - } |
|
| 57 | + // No actual search parameter was passed, bail out. |
|
| 58 | + if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) { |
|
| 59 | + wp_send_json_error( 'The q parameter is required.' ); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - // Get the response. |
|
| 63 | - $response = $this->publisher_service->query( $_POST['q'] ); |
|
| 62 | + // Get the response. |
|
| 63 | + $response = $this->publisher_service->query( $_POST['q'] ); |
|
| 64 | 64 | |
| 65 | - // Finally output the response. |
|
| 66 | - wp_send_json_success( $response ); |
|
| 65 | + // Finally output the response. |
|
| 66 | + wp_send_json_success( $response ); |
|
| 67 | 67 | |
| 68 | - } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
| 34 | 34 | */ |
| 35 | - function __construct( $publisher_service ) { |
|
| 35 | + function __construct($publisher_service) { |
|
| 36 | 36 | |
| 37 | 37 | $this->publisher_service = $publisher_service; |
| 38 | 38 | |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | ob_clean(); |
| 51 | 51 | |
| 52 | 52 | // Check if the current user can `manage_options`. |
| 53 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 54 | - wp_send_json_error( 'Access denied.' ); |
|
| 53 | + if ( ! current_user_can('manage_options')) { |
|
| 54 | + wp_send_json_error('Access denied.'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | // No actual search parameter was passed, bail out. |
| 58 | - if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) { |
|
| 59 | - wp_send_json_error( 'The q parameter is required.' ); |
|
| 58 | + if ( ! isset($_POST['q']) || empty($_POST['q'])) { |
|
| 59 | + wp_send_json_error('The q parameter is required.'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Get the response. |
| 63 | - $response = $this->publisher_service->query( $_POST['q'] ); |
|
| 63 | + $response = $this->publisher_service->query($_POST['q']); |
|
| 64 | 64 | |
| 65 | 65 | // Finally output the response. |
| 66 | - wp_send_json_success( $response ); |
|
| 66 | + wp_send_json_success($response); |
|
| 67 | 67 | |
| 68 | 68 | } |
| 69 | 69 | |
@@ -18,74 +18,74 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Category_Taxonomy_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 23 | - * |
|
| 24 | - * @since 3.11.0 |
|
| 25 | - * @access private |
|
| 26 | - * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 27 | - */ |
|
| 28 | - private $entity_post_type_service; |
|
| 21 | + /** |
|
| 22 | + * The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 23 | + * |
|
| 24 | + * @since 3.11.0 |
|
| 25 | + * @access private |
|
| 26 | + * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 27 | + */ |
|
| 28 | + private $entity_post_type_service; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Create a {@link Wordlift_Category_Taxonomy_Service} instance. |
|
| 32 | - * |
|
| 33 | - * @since 3.11.0 |
|
| 34 | - * |
|
| 35 | - * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 36 | - */ |
|
| 37 | - function __construct( $entity_post_type_service ) { |
|
| 30 | + /** |
|
| 31 | + * Create a {@link Wordlift_Category_Taxonomy_Service} instance. |
|
| 32 | + * |
|
| 33 | + * @since 3.11.0 |
|
| 34 | + * |
|
| 35 | + * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance. |
|
| 36 | + */ |
|
| 37 | + function __construct( $entity_post_type_service ) { |
|
| 38 | 38 | |
| 39 | - $this->entity_post_type_service = $entity_post_type_service; |
|
| 39 | + $this->entity_post_type_service = $entity_post_type_service; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Set the entity post types as one to be included in archive pages. |
|
| 45 | - * |
|
| 46 | - * In order to have entities show up in standard WP categories (Posts categories) |
|
| 47 | - * we configure the `entity` post type, but we also need to alter the main |
|
| 48 | - * WP query (which by default queries posts only) to include the `entities`. |
|
| 49 | - * |
|
| 50 | - * @since 3.11.0 |
|
| 51 | - * |
|
| 52 | - * @param WP_Query $query WP's {@link WP_Query} instance. |
|
| 53 | - */ |
|
| 54 | - public function pre_get_posts( $query ) { |
|
| 43 | + /** |
|
| 44 | + * Set the entity post types as one to be included in archive pages. |
|
| 45 | + * |
|
| 46 | + * In order to have entities show up in standard WP categories (Posts categories) |
|
| 47 | + * we configure the `entity` post type, but we also need to alter the main |
|
| 48 | + * WP query (which by default queries posts only) to include the `entities`. |
|
| 49 | + * |
|
| 50 | + * @since 3.11.0 |
|
| 51 | + * |
|
| 52 | + * @param WP_Query $query WP's {@link WP_Query} instance. |
|
| 53 | + */ |
|
| 54 | + public function pre_get_posts( $query ) { |
|
| 55 | 55 | |
| 56 | - // Only for the main query, avoid problems with widgets and what not. |
|
| 57 | - if ( ! $query->is_main_query() ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 56 | + // Only for the main query, avoid problems with widgets and what not. |
|
| 57 | + if ( ! $query->is_main_query() ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - // We don't want to alter the query if we're in the admin UI, if this is |
|
| 62 | - // not a category query, or if the `suppress_filters` is set. |
|
| 63 | - // |
|
| 64 | - // Note that it is unlikely for `suppress_filter` to be set on the front |
|
| 65 | - // end, but let's be safe if it is set the calling code assumes no |
|
| 66 | - // modifications of queries. |
|
| 67 | - // |
|
| 68 | - // is_admin is needed, otherwise category based post filters will show |
|
| 69 | - // both types and at the current release (4.7) it causes PHP errors. |
|
| 70 | - if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 61 | + // We don't want to alter the query if we're in the admin UI, if this is |
|
| 62 | + // not a category query, or if the `suppress_filters` is set. |
|
| 63 | + // |
|
| 64 | + // Note that it is unlikely for `suppress_filter` to be set on the front |
|
| 65 | + // end, but let's be safe if it is set the calling code assumes no |
|
| 66 | + // modifications of queries. |
|
| 67 | + // |
|
| 68 | + // is_admin is needed, otherwise category based post filters will show |
|
| 69 | + // both types and at the current release (4.7) it causes PHP errors. |
|
| 70 | + if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // Check the current post types, maybe the category archive pages |
|
| 75 | - // are already associated with other post types. |
|
| 76 | - // |
|
| 77 | - // If `post_type` isn't set, WP assumes `post` by default. |
|
| 78 | - $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' ); |
|
| 74 | + // Check the current post types, maybe the category archive pages |
|
| 75 | + // are already associated with other post types. |
|
| 76 | + // |
|
| 77 | + // If `post_type` isn't set, WP assumes `post` by default. |
|
| 78 | + $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' ); |
|
| 79 | 79 | |
| 80 | - // Add the entities post type only if the post post type is used in the query |
|
| 81 | - // since we only want `entities` to appear alongside posts. |
|
| 82 | - if ( in_array( 'post', $post_types ) ) { |
|
| 83 | - $post_types[] = $this->entity_post_type_service->get_post_type(); |
|
| 84 | - } |
|
| 80 | + // Add the entities post type only if the post post type is used in the query |
|
| 81 | + // since we only want `entities` to appear alongside posts. |
|
| 82 | + if ( in_array( 'post', $post_types ) ) { |
|
| 83 | + $post_types[] = $this->entity_post_type_service->get_post_type(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // Update the query post types. |
|
| 87 | - $query->set( 'post_type', $post_types ); |
|
| 86 | + // Update the query post types. |
|
| 87 | + $query->set( 'post_type', $post_types ); |
|
| 88 | 88 | |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance. |
| 36 | 36 | */ |
| 37 | - function __construct( $entity_post_type_service ) { |
|
| 37 | + function __construct($entity_post_type_service) { |
|
| 38 | 38 | |
| 39 | 39 | $this->entity_post_type_service = $entity_post_type_service; |
| 40 | 40 | |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @param WP_Query $query WP's {@link WP_Query} instance. |
| 53 | 53 | */ |
| 54 | - public function pre_get_posts( $query ) { |
|
| 54 | + public function pre_get_posts($query) { |
|
| 55 | 55 | |
| 56 | 56 | // Only for the main query, avoid problems with widgets and what not. |
| 57 | - if ( ! $query->is_main_query() ) { |
|
| 57 | + if ( ! $query->is_main_query()) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | // |
| 68 | 68 | // is_admin is needed, otherwise category based post filters will show |
| 69 | 69 | // both types and at the current release (4.7) it causes PHP errors. |
| 70 | - if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) { |
|
| 70 | + if (is_admin() || ! is_category() || ! empty($query->query_vars['suppress_filters'])) { |
|
| 71 | 71 | return; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -75,16 +75,16 @@ discard block |
||
| 75 | 75 | // are already associated with other post types. |
| 76 | 76 | // |
| 77 | 77 | // If `post_type` isn't set, WP assumes `post` by default. |
| 78 | - $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' ); |
|
| 78 | + $post_types = (array) ($query->get('post_type') ?: 'post'); |
|
| 79 | 79 | |
| 80 | 80 | // Add the entities post type only if the post post type is used in the query |
| 81 | 81 | // since we only want `entities` to appear alongside posts. |
| 82 | - if ( in_array( 'post', $post_types ) ) { |
|
| 82 | + if (in_array('post', $post_types)) { |
|
| 83 | 83 | $post_types[] = $this->entity_post_type_service->get_post_type(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Update the query post types. |
| 87 | - $query->set( 'post_type', $post_types ); |
|
| 87 | + $query->set('post_type', $post_types); |
|
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | - exit; |
|
| 15 | + exit; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | $term = get_term( $term_id, 'wl_entity_type' ); |
| 19 | 19 | |
| 20 | 20 | $term_settings = ! is_null( $settings ) ? $settings : array( |
| 21 | - 'title' => '', |
|
| 22 | - 'description' => '', |
|
| 21 | + 'title' => '', |
|
| 22 | + 'description' => '', |
|
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | 25 | ?> |
@@ -37,32 +37,32 @@ discard block |
||
| 37 | 37 | <tr class="form-field form-required term-name-wrap"> |
| 38 | 38 | <th scope="row"> |
| 39 | 39 | <label><?php |
| 40 | - esc_html_e( 'Name', 'wordlift' ); ?></label> |
|
| 40 | + esc_html_e( 'Name', 'wordlift' ); ?></label> |
|
| 41 | 41 | </th> |
| 42 | 42 | <td><?php |
| 43 | - echo esc_html( $term->name ) ?></td> |
|
| 43 | + echo esc_html( $term->name ) ?></td> |
|
| 44 | 44 | </tr> |
| 45 | 45 | <tr class="form-field form-required term-name-wrap"> |
| 46 | 46 | <th scope="row"> |
| 47 | 47 | <label for="title"><?php |
| 48 | - esc_html_e( 'Title', 'wordlift' ); ?></label> |
|
| 48 | + esc_html_e( 'Title', 'wordlift' ); ?></label> |
|
| 49 | 49 | </th> |
| 50 | 50 | <td><input name="title" id="title" type="text" |
| 51 | 51 | value="<?php echo esc_attr( $term_settings['title'] ) ?>" |
| 52 | 52 | size="40" /> |
| 53 | 53 | <p class="description"><?php |
| 54 | - esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 54 | + esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 55 | 55 | </td> |
| 56 | 56 | </tr> |
| 57 | 57 | <tr class="form-field term-description-wrap"> |
| 58 | 58 | <th scope="row"><label for="description"><?php |
| 59 | - esc_html_e( 'Description', 'wordlift' ); ?></label> |
|
| 59 | + esc_html_e( 'Description', 'wordlift' ); ?></label> |
|
| 60 | 60 | </th> |
| 61 | 61 | <td><textarea name="description" id="description" rows="5" |
| 62 | 62 | cols="50" class="large-text"><?php |
| 63 | - echo esc_html( $term_settings['description'] ) ?></textarea> |
|
| 63 | + echo esc_html( $term_settings['description'] ) ?></textarea> |
|
| 64 | 64 | <p class="description"><?php |
| 65 | - esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 65 | + esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 66 | 66 | </td> |
| 67 | 67 | </tr> |
| 68 | 68 | </table> |
@@ -11,61 +11,61 @@ |
||
| 11 | 11 | * |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 14 | +if ( ! defined('ABSPATH')) { |
|
| 15 | 15 | exit; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | -$term = get_term( $term_id, 'wl_entity_type' ); |
|
| 18 | +$term = get_term($term_id, 'wl_entity_type'); |
|
| 19 | 19 | |
| 20 | -$term_settings = ! is_null( $settings ) ? $settings : array( |
|
| 20 | +$term_settings = ! is_null($settings) ? $settings : array( |
|
| 21 | 21 | 'title' => '', |
| 22 | 22 | 'description' => '', |
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | 25 | ?> |
| 26 | 26 | <div class="wrap"> |
| 27 | - <h1><?php esc_html_e( 'Edit Entity Type', 'wordlift' ) ?></h1> |
|
| 27 | + <h1><?php esc_html_e('Edit Entity Type', 'wordlift') ?></h1> |
|
| 28 | 28 | |
| 29 | 29 | <form name="edittag" id="edittag" method="post" |
| 30 | - action="<?php echo admin_url( 'admin.php?page=wl_entity_type_settings' ) ?>" |
|
| 30 | + action="<?php echo admin_url('admin.php?page=wl_entity_type_settings') ?>" |
|
| 31 | 31 | class="validate"> |
| 32 | 32 | <input type="hidden" name="tag_ID" |
| 33 | - value="<?php echo esc_attr( $term_id ) ?>" /> |
|
| 33 | + value="<?php echo esc_attr($term_id) ?>" /> |
|
| 34 | 34 | <input type="hidden" name="action" value="wl_edit_entity_type_term" /> |
| 35 | - <?php wp_nonce_field( 'update-entity_type_term_' . $term_id ); ?> |
|
| 35 | + <?php wp_nonce_field('update-entity_type_term_'.$term_id); ?> |
|
| 36 | 36 | <table class="form-table"> |
| 37 | 37 | <tr class="form-field form-required term-name-wrap"> |
| 38 | 38 | <th scope="row"> |
| 39 | 39 | <label><?php |
| 40 | - esc_html_e( 'Name', 'wordlift' ); ?></label> |
|
| 40 | + esc_html_e('Name', 'wordlift'); ?></label> |
|
| 41 | 41 | </th> |
| 42 | 42 | <td><?php |
| 43 | - echo esc_html( $term->name ) ?></td> |
|
| 43 | + echo esc_html($term->name) ?></td> |
|
| 44 | 44 | </tr> |
| 45 | 45 | <tr class="form-field form-required term-name-wrap"> |
| 46 | 46 | <th scope="row"> |
| 47 | 47 | <label for="title"><?php |
| 48 | - esc_html_e( 'Title', 'wordlift' ); ?></label> |
|
| 48 | + esc_html_e('Title', 'wordlift'); ?></label> |
|
| 49 | 49 | </th> |
| 50 | 50 | <td><input name="title" id="title" type="text" |
| 51 | - value="<?php echo esc_attr( $term_settings['title'] ) ?>" |
|
| 51 | + value="<?php echo esc_attr($term_settings['title']) ?>" |
|
| 52 | 52 | size="40" /> |
| 53 | 53 | <p class="description"><?php |
| 54 | - esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 54 | + esc_html_e('The HTML title to be used in the entity type archive page.', 'wordlift'); ?></p> |
|
| 55 | 55 | </td> |
| 56 | 56 | </tr> |
| 57 | 57 | <tr class="form-field term-description-wrap"> |
| 58 | 58 | <th scope="row"><label for="description"><?php |
| 59 | - esc_html_e( 'Description', 'wordlift' ); ?></label> |
|
| 59 | + esc_html_e('Description', 'wordlift'); ?></label> |
|
| 60 | 60 | </th> |
| 61 | 61 | <td><textarea name="description" id="description" rows="5" |
| 62 | 62 | cols="50" class="large-text"><?php |
| 63 | - echo esc_html( $term_settings['description'] ) ?></textarea> |
|
| 63 | + echo esc_html($term_settings['description']) ?></textarea> |
|
| 64 | 64 | <p class="description"><?php |
| 65 | - esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p> |
|
| 65 | + esc_html_e('The description to be used in the entity type archive page.', 'wordlift'); ?></p> |
|
| 66 | 66 | </td> |
| 67 | 67 | </tr> |
| 68 | 68 | </table> |
| 69 | - <?php submit_button( __( 'Update' ) ); ?> |
|
| 69 | + <?php submit_button(__('Update')); ?> |
|
| 70 | 70 | </form> |
| 71 | 71 | </div> |
@@ -16,33 +16,33 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Related_Entities_Cloud_Widget extends Wordlift_Widget { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
| 21 | - * |
|
| 22 | - * @since 3.11.0 |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - parent::__construct( |
|
| 26 | - 'wl_related_entities_cloud', |
|
| 27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 28 | - array( |
|
| 29 | - 'classname' => 'wl_related_entities_cloud', |
|
| 30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @inheritdoc |
|
| 38 | - */ |
|
| 39 | - public function form( $instance ) { |
|
| 40 | - $title_id = $this->get_field_id( 'title' ); |
|
| 41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 42 | - ?> |
|
| 19 | + /** |
|
| 20 | + * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance. |
|
| 21 | + * |
|
| 22 | + * @since 3.11.0 |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + parent::__construct( |
|
| 26 | + 'wl_related_entities_cloud', |
|
| 27 | + __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 28 | + array( |
|
| 29 | + 'classname' => 'wl_related_entities_cloud', |
|
| 30 | + 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @inheritdoc |
|
| 38 | + */ |
|
| 39 | + public function form( $instance ) { |
|
| 40 | + $title_id = $this->get_field_id( 'title' ); |
|
| 41 | + $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 42 | + ?> |
|
| 43 | 43 | |
| 44 | 44 | <p><label for="<?php echo esc_attr( $title_id ); ?>"><?php |
| 45 | - esc_html_e( 'Title:' ); ?></label> |
|
| 45 | + esc_html_e( 'Title:' ); ?></label> |
|
| 46 | 46 | <input type="text" class="widefat" |
| 47 | 47 | id="<?php echo esc_attr( $title_id ); ?>" |
| 48 | 48 | name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
@@ -51,46 +51,46 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | <?php |
| 53 | 53 | |
| 54 | - return 'wl_related_entities_cloud_form'; |
|
| 55 | - } |
|
| 54 | + return 'wl_related_entities_cloud_form'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @inheritdoc |
|
| 59 | - */ |
|
| 60 | - public function update( $new_instance, $old_instance ) { |
|
| 57 | + /** |
|
| 58 | + * @inheritdoc |
|
| 59 | + */ |
|
| 60 | + public function update( $new_instance, $old_instance ) { |
|
| 61 | 61 | |
| 62 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 63 | - } |
|
| 62 | + return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @inheritdoc |
|
| 67 | - */ |
|
| 68 | - public function widget( $args, $instance ) { |
|
| 65 | + /** |
|
| 66 | + * @inheritdoc |
|
| 67 | + */ |
|
| 68 | + public function widget( $args, $instance ) { |
|
| 69 | 69 | |
| 70 | - /* |
|
| 70 | + /* |
|
| 71 | 71 | * Use the shortcode to calculate the HTML required to show the cloud |
| 72 | 72 | * if there is no such html do not render the widget at all. |
| 73 | 73 | */ |
| 74 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | - if ( empty( $cloud_html ) ) { |
|
| 76 | - return false; |
|
| 77 | - } |
|
| 74 | + $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | + if ( empty( $cloud_html ) ) { |
|
| 76 | + return false; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // The widget title. |
|
| 80 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 79 | + // The widget title. |
|
| 80 | + $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 81 | 81 | |
| 82 | - // Standard filter all widgets should apply |
|
| 83 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 82 | + // Standard filter all widgets should apply |
|
| 83 | + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 84 | 84 | |
| 85 | - echo $args['before_widget']; |
|
| 85 | + echo $args['before_widget']; |
|
| 86 | 86 | |
| 87 | - if ( $title ) { |
|
| 88 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 89 | - } |
|
| 87 | + if ( $title ) { |
|
| 88 | + echo $args['before_title'] . $title . $args['after_title']; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - echo $cloud_html; |
|
| 92 | - echo $args['after_widget']; |
|
| 91 | + echo $cloud_html; |
|
| 92 | + echo $args['after_widget']; |
|
| 93 | 93 | |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | 96 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | public function __construct() { |
| 25 | 25 | parent::__construct( |
| 26 | 26 | 'wl_related_entities_cloud', |
| 27 | - __( 'WordLift Entities Cloud', 'wordlift' ), |
|
| 27 | + __('WordLift Entities Cloud', 'wordlift'), |
|
| 28 | 28 | array( |
| 29 | 29 | 'classname' => 'wl_related_entities_cloud', |
| 30 | - 'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ), |
|
| 30 | + 'description' => __('Display entities related to the current post/entity in a tag cloud.', 'wordlift'), |
|
| 31 | 31 | ) |
| 32 | 32 | ); |
| 33 | 33 | |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @inheritdoc |
| 38 | 38 | */ |
| 39 | - public function form( $instance ) { |
|
| 40 | - $title_id = $this->get_field_id( 'title' ); |
|
| 41 | - $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; |
|
| 39 | + public function form($instance) { |
|
| 40 | + $title_id = $this->get_field_id('title'); |
|
| 41 | + $instance['title'] = ! empty($instance['title']) ? esc_attr($instance['title']) : ''; |
|
| 42 | 42 | ?> |
| 43 | 43 | |
| 44 | - <p><label for="<?php echo esc_attr( $title_id ); ?>"><?php |
|
| 45 | - esc_html_e( 'Title:' ); ?></label> |
|
| 44 | + <p><label for="<?php echo esc_attr($title_id); ?>"><?php |
|
| 45 | + esc_html_e('Title:'); ?></label> |
|
| 46 | 46 | <input type="text" class="widefat" |
| 47 | - id="<?php echo esc_attr( $title_id ); ?>" |
|
| 48 | - name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" |
|
| 49 | - value="<?php echo esc_attr( $instance['title'] ); ?>" /> |
|
| 47 | + id="<?php echo esc_attr($title_id); ?>" |
|
| 48 | + name="<?php echo esc_attr($this->get_field_name('title')); ?>" |
|
| 49 | + value="<?php echo esc_attr($instance['title']); ?>" /> |
|
| 50 | 50 | </p> |
| 51 | 51 | |
| 52 | 52 | <?php |
@@ -57,35 +57,35 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @inheritdoc |
| 59 | 59 | */ |
| 60 | - public function update( $new_instance, $old_instance ) { |
|
| 60 | + public function update($new_instance, $old_instance) { |
|
| 61 | 61 | |
| 62 | - return array( 'title' => sanitize_text_field( $new_instance['title'] ) ); |
|
| 62 | + return array('title' => sanitize_text_field($new_instance['title'])); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * @inheritdoc |
| 67 | 67 | */ |
| 68 | - public function widget( $args, $instance ) { |
|
| 68 | + public function widget($args, $instance) { |
|
| 69 | 69 | |
| 70 | 70 | /* |
| 71 | 71 | * Use the shortcode to calculate the HTML required to show the cloud |
| 72 | 72 | * if there is no such html do not render the widget at all. |
| 73 | 73 | */ |
| 74 | - $cloud_html = do_shortcode( '[wl_cloud]' ); |
|
| 75 | - if ( empty( $cloud_html ) ) { |
|
| 74 | + $cloud_html = do_shortcode('[wl_cloud]'); |
|
| 75 | + if (empty($cloud_html)) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // The widget title. |
| 80 | - $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title']; |
|
| 80 | + $title = empty($instance['title']) ? __('Related Entities', 'wordlift') : $instance['title']; |
|
| 81 | 81 | |
| 82 | 82 | // Standard filter all widgets should apply |
| 83 | - $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); |
|
| 83 | + $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
|
| 84 | 84 | |
| 85 | 85 | echo $args['before_widget']; |
| 86 | 86 | |
| 87 | - if ( $title ) { |
|
| 88 | - echo $args['before_title'] . $title . $args['after_title']; |
|
| 87 | + if ($title) { |
|
| 88 | + echo $args['before_title'].$title.$args['after_title']; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | echo $cloud_html; |