@@ -7,6 +7,6 @@ |
||
| 7 | 7 | exit(1); |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | -require_once __DIR__ . '/composer/autoload_real.php'; |
|
| 10 | +require_once __DIR__.'/composer/autoload_real.php'; |
|
| 11 | 11 | |
| 12 | 12 | return ComposerAutoloaderInitbaaf547b24d2757395578581da934187::getLoader(); |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | public static function loadClassLoader($class) |
| 10 | 10 | { |
| 11 | 11 | if ('Wordlift_Modules_Food_Kg_Composer\Autoload\ClassLoader' === $class) { |
| 12 | - require __DIR__ . '/ClassLoader.php'; |
|
| 12 | + require __DIR__.'/ClassLoader.php'; |
|
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | self::$loader = $loader = new \Wordlift_Modules_Food_Kg_Composer\Autoload\ClassLoader(\dirname(__DIR__)); |
| 27 | 27 | spl_autoload_unregister(array('ComposerAutoloaderInitbaaf547b24d2757395578581da934187', 'loadClassLoader')); |
| 28 | 28 | |
| 29 | - require __DIR__ . '/autoload_static.php'; |
|
| 29 | + require __DIR__.'/autoload_static.php'; |
|
| 30 | 30 | call_user_func(\Wordlift_Modules_Food_Kg_Composer\Autoload\ComposerStaticInitbaaf547b24d2757395578581da934187::getInitializer($loader)); |
| 31 | 31 | |
| 32 | 32 | $loader->setClassMapAuthoritative(true); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getPrefixes() |
| 115 | 115 | { |
| 116 | - if (!empty($this->prefixesPsr0)) { |
|
| 116 | + if ( ! empty($this->prefixesPsr0)) { |
|
| 117 | 117 | return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); |
| 118 | 118 | } |
| 119 | 119 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function add($prefix, $paths, $prepend = false) |
| 185 | 185 | { |
| 186 | - if (!$prefix) { |
|
| 186 | + if ( ! $prefix) { |
|
| 187 | 187 | if ($prepend) { |
| 188 | 188 | $this->fallbackDirsPsr0 = array_merge( |
| 189 | 189 | (array) $paths, |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $first = $prefix[0]; |
| 203 | - if (!isset($this->prefixesPsr0[$first][$prefix])) { |
|
| 203 | + if ( ! isset($this->prefixesPsr0[$first][$prefix])) { |
|
| 204 | 204 | $this->prefixesPsr0[$first][$prefix] = (array) $paths; |
| 205 | 205 | |
| 206 | 206 | return; |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function addPsr4($prefix, $paths, $prepend = false) |
| 234 | 234 | { |
| 235 | - if (!$prefix) { |
|
| 235 | + if ( ! $prefix) { |
|
| 236 | 236 | // Register directories for the root namespace. |
| 237 | 237 | if ($prepend) { |
| 238 | 238 | $this->fallbackDirsPsr4 = array_merge( |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | (array) $paths |
| 246 | 246 | ); |
| 247 | 247 | } |
| 248 | - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { |
|
| 248 | + } elseif ( ! isset($this->prefixDirsPsr4[$prefix])) { |
|
| 249 | 249 | // Register directories for a new namespace. |
| 250 | 250 | $length = strlen($prefix); |
| 251 | 251 | if ('\\' !== $prefix[$length - 1]) { |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | public function set($prefix, $paths) |
| 281 | 281 | { |
| 282 | - if (!$prefix) { |
|
| 282 | + if ( ! $prefix) { |
|
| 283 | 283 | $this->fallbackDirsPsr0 = (array) $paths; |
| 284 | 284 | } else { |
| 285 | 285 | $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | */ |
| 300 | 300 | public function setPsr4($prefix, $paths) |
| 301 | 301 | { |
| 302 | - if (!$prefix) { |
|
| 302 | + if ( ! $prefix) { |
|
| 303 | 303 | $this->fallbackDirsPsr4 = (array) $paths; |
| 304 | 304 | } else { |
| 305 | 305 | $length = strlen($prefix); |
@@ -493,18 +493,18 @@ discard block |
||
| 493 | 493 | private function findFileWithExtension($class, $ext) |
| 494 | 494 | { |
| 495 | 495 | // PSR-4 lookup |
| 496 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
| 496 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
| 497 | 497 | |
| 498 | 498 | $first = $class[0]; |
| 499 | 499 | if (isset($this->prefixLengthsPsr4[$first])) { |
| 500 | 500 | $subPath = $class; |
| 501 | 501 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
| 502 | 502 | $subPath = substr($subPath, 0, $lastPos); |
| 503 | - $search = $subPath . '\\'; |
|
| 503 | + $search = $subPath.'\\'; |
|
| 504 | 504 | if (isset($this->prefixDirsPsr4[$search])) { |
| 505 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
| 505 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
| 506 | 506 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
| 507 | - if (file_exists($file = $dir . $pathEnd)) { |
|
| 507 | + if (file_exists($file = $dir.$pathEnd)) { |
|
| 508 | 508 | return $file; |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | // PSR-4 fallback dirs |
| 516 | 516 | foreach ($this->fallbackDirsPsr4 as $dir) { |
| 517 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
| 517 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
| 518 | 518 | return $file; |
| 519 | 519 | } |
| 520 | 520 | } |
@@ -526,14 +526,14 @@ discard block |
||
| 526 | 526 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
| 527 | 527 | } else { |
| 528 | 528 | // PEAR-like class name |
| 529 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
| 529 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | if (isset($this->prefixesPsr0[$first])) { |
| 533 | 533 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
| 534 | 534 | if (0 === strpos($class, $prefix)) { |
| 535 | 535 | foreach ($dirs as $dir) { |
| 536 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 536 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 537 | 537 | return $file; |
| 538 | 538 | } |
| 539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | |
| 544 | 544 | // PSR-0 fallback dirs |
| 545 | 545 | foreach ($this->fallbackDirsPsr0 as $dir) { |
| 546 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
| 546 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
| 547 | 547 | return $file; |
| 548 | 548 | } |
| 549 | 549 | } |
@@ -10,9 +10,9 @@ |
||
| 10 | 10 | </div> |
| 11 | 11 | <?php |
| 12 | 12 | |
| 13 | - // Prepare Table of elements |
|
| 14 | - $main_ingredient_list_table = new Main_Ingredient_List_Table(); |
|
| 15 | - $main_ingredient_list_table->prepare_items(); |
|
| 16 | - $main_ingredient_list_table->display(); |
|
| 17 | - ?> |
|
| 13 | + // Prepare Table of elements |
|
| 14 | + $main_ingredient_list_table = new Main_Ingredient_List_Table(); |
|
| 15 | + $main_ingredient_list_table->prepare_items(); |
|
| 16 | + $main_ingredient_list_table->display(); |
|
| 17 | + ?> |
|
| 18 | 18 | </div> |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | ?> |
| 6 | 6 | <div class="wrap"> |
| 7 | 7 | <div class="wl-ingredients"> |
| 8 | - <h1><?php esc_attr_e( 'Main Ingredients', 'wordlift' ); ?></h1> |
|
| 9 | - <button class="wl-ingredients__btn-copy-table"><?php esc_attr_e( 'Copy Table', 'wordlift' ); ?></button> |
|
| 8 | + <h1><?php esc_attr_e('Main Ingredients', 'wordlift'); ?></h1> |
|
| 9 | + <button class="wl-ingredients__btn-copy-table"><?php esc_attr_e('Copy Table', 'wordlift'); ?></button> |
|
| 10 | 10 | </div> |
| 11 | 11 | <?php |
| 12 | 12 | |
@@ -4,16 +4,16 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Full_Page_Delegate implements Page_Delegate { |
| 6 | 6 | |
| 7 | - public function render() { |
|
| 8 | - include WL_FOOD_KG_DIR_PATH . '/includes/admin/partials/main_ingredient.php'; |
|
| 9 | - } |
|
| 7 | + public function render() { |
|
| 8 | + include WL_FOOD_KG_DIR_PATH . '/includes/admin/partials/main_ingredient.php'; |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function admin_enqueue_scripts() { |
|
| 12 | - wp_enqueue_style( 'thickbox' ); |
|
| 13 | - wp_enqueue_script( 'plugin-install' ); |
|
| 11 | + public function admin_enqueue_scripts() { |
|
| 12 | + wp_enqueue_style( 'thickbox' ); |
|
| 13 | + wp_enqueue_script( 'plugin-install' ); |
|
| 14 | 14 | |
| 15 | - wp_enqueue_style( 'wl-ingredients', plugin_dir_url( __FILE__ ) . '/assets/css/ingredients.css', array(), WORDLIFT_VERSION ); |
|
| 16 | - wp_enqueue_script( 'wl-ingredients', WL_DIR_URL . 'js/dist/ingredients.js', array(), WORDLIFT_VERSION, true ); |
|
| 17 | - } |
|
| 15 | + wp_enqueue_style( 'wl-ingredients', plugin_dir_url( __FILE__ ) . '/assets/css/ingredients.css', array(), WORDLIFT_VERSION ); |
|
| 16 | + wp_enqueue_script( 'wl-ingredients', WL_DIR_URL . 'js/dist/ingredients.js', array(), WORDLIFT_VERSION, true ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | 19 | } |
@@ -5,15 +5,15 @@ |
||
| 5 | 5 | class Full_Page_Delegate implements Page_Delegate { |
| 6 | 6 | |
| 7 | 7 | public function render() { |
| 8 | - include WL_FOOD_KG_DIR_PATH . '/includes/admin/partials/main_ingredient.php'; |
|
| 8 | + include WL_FOOD_KG_DIR_PATH.'/includes/admin/partials/main_ingredient.php'; |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | public function admin_enqueue_scripts() { |
| 12 | - wp_enqueue_style( 'thickbox' ); |
|
| 13 | - wp_enqueue_script( 'plugin-install' ); |
|
| 12 | + wp_enqueue_style('thickbox'); |
|
| 13 | + wp_enqueue_script('plugin-install'); |
|
| 14 | 14 | |
| 15 | - wp_enqueue_style( 'wl-ingredients', plugin_dir_url( __FILE__ ) . '/assets/css/ingredients.css', array(), WORDLIFT_VERSION ); |
|
| 16 | - wp_enqueue_script( 'wl-ingredients', WL_DIR_URL . 'js/dist/ingredients.js', array(), WORDLIFT_VERSION, true ); |
|
| 15 | + wp_enqueue_style('wl-ingredients', plugin_dir_url(__FILE__).'/assets/css/ingredients.css', array(), WORDLIFT_VERSION); |
|
| 16 | + wp_enqueue_script('wl-ingredients', WL_DIR_URL.'js/dist/ingredients.js', array(), WORDLIFT_VERSION, true); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | } |
@@ -4,39 +4,39 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Preconditions { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var Notices |
|
| 9 | - */ |
|
| 10 | - private $notices; |
|
| 11 | - |
|
| 12 | - public function __construct( Notices $notices ) { |
|
| 13 | - $this->notices = $notices; |
|
| 14 | - } |
|
| 15 | - |
|
| 16 | - public function pass() { |
|
| 17 | - return $this->has_prerequisites() && $this->check_version(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - private function has_prerequisites() { |
|
| 21 | - return defined( 'WPRM_VERSION' ) |
|
| 22 | - && class_exists( 'WP_Recipe_Maker' ) |
|
| 23 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 24 | - && apply_filters( 'wl_feature__enable__food-kg', false ); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - private function check_version() { |
|
| 28 | - $check = version_compare( WPRM_VERSION, '8.1.0', '>=' ) |
|
| 29 | - && version_compare( WPRM_VERSION, '8.6.0', '<' ); |
|
| 30 | - |
|
| 31 | - if ( ! $check ) { |
|
| 32 | - $this->notices->queue( |
|
| 33 | - 'warning', |
|
| 34 | - /* translators: %s: Detected WP Recipe Maker version. */ |
|
| 35 | - sprintf( __( 'WordLift Food KG support requires WP Recipe Maker 8.1-8.5, %s found.', 'wordlift' ), WPRM_VERSION ) |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return $check; |
|
| 40 | - } |
|
| 7 | + /** |
|
| 8 | + * @var Notices |
|
| 9 | + */ |
|
| 10 | + private $notices; |
|
| 11 | + |
|
| 12 | + public function __construct( Notices $notices ) { |
|
| 13 | + $this->notices = $notices; |
|
| 14 | + } |
|
| 15 | + |
|
| 16 | + public function pass() { |
|
| 17 | + return $this->has_prerequisites() && $this->check_version(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + private function has_prerequisites() { |
|
| 21 | + return defined( 'WPRM_VERSION' ) |
|
| 22 | + && class_exists( 'WP_Recipe_Maker' ) |
|
| 23 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 24 | + && apply_filters( 'wl_feature__enable__food-kg', false ); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + private function check_version() { |
|
| 28 | + $check = version_compare( WPRM_VERSION, '8.1.0', '>=' ) |
|
| 29 | + && version_compare( WPRM_VERSION, '8.6.0', '<' ); |
|
| 30 | + |
|
| 31 | + if ( ! $check ) { |
|
| 32 | + $this->notices->queue( |
|
| 33 | + 'warning', |
|
| 34 | + /* translators: %s: Detected WP Recipe Maker version. */ |
|
| 35 | + sprintf( __( 'WordLift Food KG support requires WP Recipe Maker 8.1-8.5, %s found.', 'wordlift' ), WPRM_VERSION ) |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return $check; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | private $notices; |
| 11 | 11 | |
| 12 | - public function __construct( Notices $notices ) { |
|
| 12 | + public function __construct(Notices $notices) { |
|
| 13 | 13 | $this->notices = $notices; |
| 14 | 14 | } |
| 15 | 15 | |
@@ -18,21 +18,21 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | private function has_prerequisites() { |
| 21 | - return defined( 'WPRM_VERSION' ) |
|
| 22 | - && class_exists( 'WP_Recipe_Maker' ) |
|
| 21 | + return defined('WPRM_VERSION') |
|
| 22 | + && class_exists('WP_Recipe_Maker') |
|
| 23 | 23 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 24 | - && apply_filters( 'wl_feature__enable__food-kg', false ); |
|
| 24 | + && apply_filters('wl_feature__enable__food-kg', false); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | private function check_version() { |
| 28 | - $check = version_compare( WPRM_VERSION, '8.1.0', '>=' ) |
|
| 29 | - && version_compare( WPRM_VERSION, '8.6.0', '<' ); |
|
| 28 | + $check = version_compare(WPRM_VERSION, '8.1.0', '>=') |
|
| 29 | + && version_compare(WPRM_VERSION, '8.6.0', '<'); |
|
| 30 | 30 | |
| 31 | - if ( ! $check ) { |
|
| 31 | + if ( ! $check) { |
|
| 32 | 32 | $this->notices->queue( |
| 33 | 33 | 'warning', |
| 34 | 34 | /* translators: %s: Detected WP Recipe Maker version. */ |
| 35 | - sprintf( __( 'WordLift Food KG support requires WP Recipe Maker 8.1-8.5, %s found.', 'wordlift' ), WPRM_VERSION ) |
|
| 35 | + sprintf(__('WordLift Food KG support requires WP Recipe Maker 8.1-8.5, %s found.', 'wordlift'), WPRM_VERSION) |
|
| 36 | 36 | ); |
| 37 | 37 | } |
| 38 | 38 | |
@@ -4,67 +4,67 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Main_Ingredient_Recipe_Lift_Strategy implements Recipe_Lift_Strategy { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var Ingredients_Client |
|
| 9 | - */ |
|
| 10 | - private $ingredients_client; |
|
| 7 | + /** |
|
| 8 | + * @var Ingredients_Client |
|
| 9 | + */ |
|
| 10 | + private $ingredients_client; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var Notices |
|
| 14 | - */ |
|
| 15 | - private $notices; |
|
| 12 | + /** |
|
| 13 | + * @var Notices |
|
| 14 | + */ |
|
| 15 | + private $notices; |
|
| 16 | 16 | |
| 17 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 18 | - $this->ingredients_client = $ingredients_client; |
|
| 19 | - $this->notices = $notices; |
|
| 20 | - } |
|
| 17 | + public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 18 | + $this->ingredients_client = $ingredients_client; |
|
| 19 | + $this->notices = $notices; |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function get_json_ld_data( $ingredient ) { |
|
| 23 | - // Get JSON LD Data. |
|
| 24 | - $json_ld = $this->ingredients_client->main_ingredient( $ingredient ); |
|
| 25 | - return $json_ld; |
|
| 26 | - } |
|
| 22 | + public function get_json_ld_data( $ingredient ) { |
|
| 23 | + // Get JSON LD Data. |
|
| 24 | + $json_ld = $this->ingredients_client->main_ingredient( $ingredient ); |
|
| 25 | + return $json_ld; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function run() { |
|
| 29 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 28 | + public function run() { |
|
| 29 | + $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 30 | 30 | |
| 31 | - $recipes = get_posts( |
|
| 32 | - array( |
|
| 33 | - 'post_type' => 'wprm_recipe', |
|
| 34 | - 'numberposts' => - 1, |
|
| 35 | - ) |
|
| 36 | - ); |
|
| 37 | - $count = count( $recipes ); |
|
| 31 | + $recipes = get_posts( |
|
| 32 | + array( |
|
| 33 | + 'post_type' => 'wprm_recipe', |
|
| 34 | + 'numberposts' => - 1, |
|
| 35 | + ) |
|
| 36 | + ); |
|
| 37 | + $count = count( $recipes ); |
|
| 38 | 38 | |
| 39 | - $count_lifted = 0; |
|
| 40 | - foreach ( $recipes as $recipe ) { |
|
| 41 | - /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
|
| 42 | - $this->notices->queue( 'info', sprintf( __( 'WordLift is adding the main ingredient to recipes. So far it lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 39 | + $count_lifted = 0; |
|
| 40 | + foreach ( $recipes as $recipe ) { |
|
| 41 | + /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
|
| 42 | + $this->notices->queue( 'info', sprintf( __( 'WordLift is adding the main ingredient to recipes. So far it lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 43 | 43 | |
| 44 | - // Emit something to keep the connection alive. |
|
| 45 | - echo esc_html( "$count_lifted\n" ); |
|
| 44 | + // Emit something to keep the connection alive. |
|
| 45 | + echo esc_html( "$count_lifted\n" ); |
|
| 46 | 46 | |
| 47 | - // Skip posts with existing data. |
|
| 48 | - $existing = get_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', true ); |
|
| 49 | - if ( ! empty( $existing ) ) { |
|
| 50 | - $count_lifted ++; |
|
| 51 | - continue; |
|
| 52 | - } |
|
| 47 | + // Skip posts with existing data. |
|
| 48 | + $existing = get_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', true ); |
|
| 49 | + if ( ! empty( $existing ) ) { |
|
| 50 | + $count_lifted ++; |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - $jsonld = $this->ingredients_client->main_ingredient( $recipe->post_title ); |
|
| 55 | - if ( ! empty( $jsonld ) ) { |
|
| 56 | - add_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', $jsonld ); |
|
| 57 | - $count_lifted ++; |
|
| 58 | - } else { |
|
| 59 | - delete_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld' ); |
|
| 60 | - } |
|
| 61 | - } |
|
| 54 | + $jsonld = $this->ingredients_client->main_ingredient( $recipe->post_title ); |
|
| 55 | + if ( ! empty( $jsonld ) ) { |
|
| 56 | + add_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', $jsonld ); |
|
| 57 | + $count_lifted ++; |
|
| 58 | + } else { |
|
| 59 | + delete_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld' ); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 65 | - * total items |
|
| 66 | - */ |
|
| 67 | - /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
|
| 68 | - $this->notices->queue( 'info', sprintf( __( 'WordLift lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 69 | - } |
|
| 63 | + /** |
|
| 64 | + * @@todo add notification that procedure is complete, with information about the number of processed items vs |
|
| 65 | + * total items |
|
| 66 | + */ |
|
| 67 | + /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
|
| 68 | + $this->notices->queue( 'info', sprintf( __( 'WordLift lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 69 | + } |
|
| 70 | 70 | } |
@@ -14,49 +14,49 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | private $notices; |
| 16 | 16 | |
| 17 | - public function __construct( Ingredients_Client $ingredients_client, Notices $notices ) { |
|
| 17 | + public function __construct(Ingredients_Client $ingredients_client, Notices $notices) { |
|
| 18 | 18 | $this->ingredients_client = $ingredients_client; |
| 19 | 19 | $this->notices = $notices; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | - public function get_json_ld_data( $ingredient ) { |
|
| 22 | + public function get_json_ld_data($ingredient) { |
|
| 23 | 23 | // Get JSON LD Data. |
| 24 | - $json_ld = $this->ingredients_client->main_ingredient( $ingredient ); |
|
| 24 | + $json_ld = $this->ingredients_client->main_ingredient($ingredient); |
|
| 25 | 25 | return $json_ld; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function run() { |
| 29 | - $this->notices->queue( 'info', __( 'WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift' ) ); |
|
| 29 | + $this->notices->queue('info', __('WordLift detected WP Recipe Maker and, it is lifting the ingredients...', 'wordlift')); |
|
| 30 | 30 | |
| 31 | 31 | $recipes = get_posts( |
| 32 | 32 | array( |
| 33 | 33 | 'post_type' => 'wprm_recipe', |
| 34 | - 'numberposts' => - 1, |
|
| 34 | + 'numberposts' => -1, |
|
| 35 | 35 | ) |
| 36 | 36 | ); |
| 37 | - $count = count( $recipes ); |
|
| 37 | + $count = count($recipes); |
|
| 38 | 38 | |
| 39 | 39 | $count_lifted = 0; |
| 40 | - foreach ( $recipes as $recipe ) { |
|
| 40 | + foreach ($recipes as $recipe) { |
|
| 41 | 41 | /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
| 42 | - $this->notices->queue( 'info', sprintf( __( 'WordLift is adding the main ingredient to recipes. So far it lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 42 | + $this->notices->queue('info', sprintf(__('WordLift is adding the main ingredient to recipes. So far it lifted %1$d of %2$d recipe(s).', 'wordlift'), $count_lifted, $count)); |
|
| 43 | 43 | |
| 44 | 44 | // Emit something to keep the connection alive. |
| 45 | - echo esc_html( "$count_lifted\n" ); |
|
| 45 | + echo esc_html("$count_lifted\n"); |
|
| 46 | 46 | |
| 47 | 47 | // Skip posts with existing data. |
| 48 | - $existing = get_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', true ); |
|
| 49 | - if ( ! empty( $existing ) ) { |
|
| 50 | - $count_lifted ++; |
|
| 48 | + $existing = get_post_meta($recipe->ID, '_wl_main_ingredient_jsonld', true); |
|
| 49 | + if ( ! empty($existing)) { |
|
| 50 | + $count_lifted++; |
|
| 51 | 51 | continue; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $jsonld = $this->ingredients_client->main_ingredient( $recipe->post_title ); |
|
| 55 | - if ( ! empty( $jsonld ) ) { |
|
| 56 | - add_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld', $jsonld ); |
|
| 57 | - $count_lifted ++; |
|
| 54 | + $jsonld = $this->ingredients_client->main_ingredient($recipe->post_title); |
|
| 55 | + if ( ! empty($jsonld)) { |
|
| 56 | + add_post_meta($recipe->ID, '_wl_main_ingredient_jsonld', $jsonld); |
|
| 57 | + $count_lifted++; |
|
| 58 | 58 | } else { |
| 59 | - delete_post_meta( $recipe->ID, '_wl_main_ingredient_jsonld' ); |
|
| 59 | + delete_post_meta($recipe->ID, '_wl_main_ingredient_jsonld'); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
@@ -65,6 +65,6 @@ discard block |
||
| 65 | 65 | * total items |
| 66 | 66 | */ |
| 67 | 67 | /* translators: 1: The number of lifted recipes, 2: The total number of recipes. */ |
| 68 | - $this->notices->queue( 'info', sprintf( __( 'WordLift lifted %1$d of %2$d recipe(s).', 'wordlift' ), $count_lifted, $count ) ); |
|
| 68 | + $this->notices->queue('info', sprintf(__('WordLift lifted %1$d of %2$d recipe(s).', 'wordlift'), $count_lifted, $count)); |
|
| 69 | 69 | } |
| 70 | 70 | } |
@@ -16,87 +16,87 @@ discard block |
||
| 16 | 16 | * @subpackage Wordlift/admin/WL_Metabox |
| 17 | 17 | */ |
| 18 | 18 | class Wl_Abstract_Metabox { |
| 19 | - /** |
|
| 20 | - * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | - * |
|
| 22 | - * @since 3.1.0 |
|
| 23 | - * @access public |
|
| 24 | - * @var array $fields The metabox custom fields. |
|
| 25 | - */ |
|
| 26 | - public $fields; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * A {@link Wordlift_Log_Service} instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.15.4 |
|
| 32 | - * |
|
| 33 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | - */ |
|
| 35 | - private $log; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * WL_Metabox constructor. |
|
| 39 | - * |
|
| 40 | - * @since 3.1.0 |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Add a callback to print the metabox in page. |
|
| 49 | - * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | - */ |
|
| 51 | - public function add_main_metabox() { |
|
| 52 | - |
|
| 53 | - // Build the fields we need to print. |
|
| 54 | - $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | - |
|
| 56 | - // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | - if ( empty( $this->fields ) ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Add main metabox (will print also the inner fields). |
|
| 62 | - $id = uniqid( 'wl-metabox-' ); |
|
| 63 | - $title = __( 'WordLift', 'wordlift' ); |
|
| 64 | - |
|
| 65 | - // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | - add_meta_box( |
|
| 68 | - $id, |
|
| 69 | - esc_html( $title ), |
|
| 70 | - array( |
|
| 71 | - $this, |
|
| 72 | - 'html', |
|
| 73 | - ), |
|
| 74 | - $screen, |
|
| 75 | - 'normal', |
|
| 76 | - 'high' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Add filter to change the metabox CSS class. |
|
| 81 | - // |
|
| 82 | - // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | - // dynamically according to the `get_current_screen()` function. |
|
| 84 | - $current_screen = get_current_screen(); |
|
| 85 | - $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | - add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Render the metabox html. |
|
| 92 | - * |
|
| 93 | - * @since 3.1.0 |
|
| 94 | - */ |
|
| 95 | - public function html() { |
|
| 96 | - |
|
| 97 | - // HTML Code Before MetaBox Content. |
|
| 98 | - do_action( 'wl_metabox_before_html' ); |
|
| 99 | - ?> |
|
| 19 | + /** |
|
| 20 | + * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | + * |
|
| 22 | + * @since 3.1.0 |
|
| 23 | + * @access public |
|
| 24 | + * @var array $fields The metabox custom fields. |
|
| 25 | + */ |
|
| 26 | + public $fields; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * A {@link Wordlift_Log_Service} instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.15.4 |
|
| 32 | + * |
|
| 33 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | + */ |
|
| 35 | + private $log; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * WL_Metabox constructor. |
|
| 39 | + * |
|
| 40 | + * @since 3.1.0 |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Add a callback to print the metabox in page. |
|
| 49 | + * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | + */ |
|
| 51 | + public function add_main_metabox() { |
|
| 52 | + |
|
| 53 | + // Build the fields we need to print. |
|
| 54 | + $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | + |
|
| 56 | + // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | + if ( empty( $this->fields ) ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Add main metabox (will print also the inner fields). |
|
| 62 | + $id = uniqid( 'wl-metabox-' ); |
|
| 63 | + $title = __( 'WordLift', 'wordlift' ); |
|
| 64 | + |
|
| 65 | + // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | + add_meta_box( |
|
| 68 | + $id, |
|
| 69 | + esc_html( $title ), |
|
| 70 | + array( |
|
| 71 | + $this, |
|
| 72 | + 'html', |
|
| 73 | + ), |
|
| 74 | + $screen, |
|
| 75 | + 'normal', |
|
| 76 | + 'high' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Add filter to change the metabox CSS class. |
|
| 81 | + // |
|
| 82 | + // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | + // dynamically according to the `get_current_screen()` function. |
|
| 84 | + $current_screen = get_current_screen(); |
|
| 85 | + $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | + add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Render the metabox html. |
|
| 92 | + * |
|
| 93 | + * @since 3.1.0 |
|
| 94 | + */ |
|
| 95 | + public function html() { |
|
| 96 | + |
|
| 97 | + // HTML Code Before MetaBox Content. |
|
| 98 | + do_action( 'wl_metabox_before_html' ); |
|
| 99 | + ?> |
|
| 100 | 100 | <div class="wl-metabox-tabs"> |
| 101 | 101 | <ul> |
| 102 | 102 | <li class="active"> |
@@ -109,317 +109,317 @@ discard block |
||
| 109 | 109 | <div class="wl-metabox-tabs__content"> |
| 110 | 110 | <div id="wl-metabox-tab-properties"> |
| 111 | 111 | <?php |
| 112 | - // Loop over the fields. |
|
| 113 | - foreach ( $this->fields as $field ) { |
|
| 112 | + // Loop over the fields. |
|
| 113 | + foreach ( $this->fields as $field ) { |
|
| 114 | 114 | |
| 115 | - // load data from DB (values will be available in $field->data). |
|
| 116 | - $field->get_data(); |
|
| 115 | + // load data from DB (values will be available in $field->data). |
|
| 116 | + $field->get_data(); |
|
| 117 | 117 | |
| 118 | - // print field HTML (nonce included). |
|
| 119 | - echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`. |
|
| 120 | - } |
|
| 121 | - ?> |
|
| 118 | + // print field HTML (nonce included). |
|
| 119 | + echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`. |
|
| 120 | + } |
|
| 121 | + ?> |
|
| 122 | 122 | </div> |
| 123 | 123 | <div id="wl-metabox-tab-ingredient"> |
| 124 | 124 | <form></form> |
| 125 | 125 | <?php |
| 126 | - do_action( 'wl_ingredient_metabox_html' ); |
|
| 127 | - ?> |
|
| 126 | + do_action( 'wl_ingredient_metabox_html' ); |
|
| 127 | + ?> |
|
| 128 | 128 | </div> |
| 129 | 129 | </div> |
| 130 | 130 | </div> |
| 131 | 131 | <?php |
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 136 | - * |
|
| 137 | - * Note: the first function that calls this method will instantiate the fields. |
|
| 138 | - * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 139 | - * |
|
| 140 | - * @param int $id | $term_id The post id or term id. |
|
| 141 | - * |
|
| 142 | - * @param $type int Post or Term |
|
| 143 | - * |
|
| 144 | - * @since 3.1.0 |
|
| 145 | - */ |
|
| 146 | - public function instantiate_fields( $id, $type ) { |
|
| 147 | - |
|
| 148 | - $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 149 | - |
|
| 150 | - // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 151 | - if ( isset( $this->fields ) ) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 155 | - $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 156 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 157 | - $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 158 | - $term_entity_types = array_map( |
|
| 159 | - function ( $term ) { |
|
| 160 | - return get_term_by( |
|
| 161 | - 'slug', |
|
| 162 | - $term, |
|
| 163 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 164 | - ); |
|
| 165 | - }, |
|
| 166 | - $term_entity_types |
|
| 167 | - ); |
|
| 168 | - $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 169 | - } |
|
| 170 | - if ( isset( $entity_type ) ) { |
|
| 171 | - |
|
| 172 | - /* |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 136 | + * |
|
| 137 | + * Note: the first function that calls this method will instantiate the fields. |
|
| 138 | + * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 139 | + * |
|
| 140 | + * @param int $id | $term_id The post id or term id. |
|
| 141 | + * |
|
| 142 | + * @param $type int Post or Term |
|
| 143 | + * |
|
| 144 | + * @since 3.1.0 |
|
| 145 | + */ |
|
| 146 | + public function instantiate_fields( $id, $type ) { |
|
| 147 | + |
|
| 148 | + $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 149 | + |
|
| 150 | + // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 151 | + if ( isset( $this->fields ) ) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + if ( Object_Type_Enum::POST === $type ) { |
|
| 155 | + $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 156 | + } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 157 | + $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 158 | + $term_entity_types = array_map( |
|
| 159 | + function ( $term ) { |
|
| 160 | + return get_term_by( |
|
| 161 | + 'slug', |
|
| 162 | + $term, |
|
| 163 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 164 | + ); |
|
| 165 | + }, |
|
| 166 | + $term_entity_types |
|
| 167 | + ); |
|
| 168 | + $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 169 | + } |
|
| 170 | + if ( isset( $entity_type ) ) { |
|
| 171 | + |
|
| 172 | + /* |
|
| 173 | 173 | * Might not have any relevant meta box field, for example for articles, |
| 174 | 174 | * therefor make sure fields are at least an empty array to help the considered |
| 175 | 175 | * in other functions using it. |
| 176 | 176 | */ |
| 177 | - $this->fields = array(); |
|
| 177 | + $this->fields = array(); |
|
| 178 | 178 | |
| 179 | - /** |
|
| 180 | - * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 181 | - * We must divide fields in two groups: |
|
| 182 | - * - simple: accept values for one property |
|
| 183 | - * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 184 | - */ |
|
| 185 | - $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 186 | - $simple_metaboxes = $metaboxes[0]; |
|
| 187 | - $grouped_metaboxes = $metaboxes[1]; |
|
| 188 | - |
|
| 189 | - // Loop over simple entity properties. |
|
| 190 | - foreach ( $simple_metaboxes as $key => $property ) { |
|
| 191 | - |
|
| 192 | - // Info passed to the metabox. |
|
| 193 | - $info = array(); |
|
| 194 | - $info[ $key ] = $property; |
|
| 179 | + /** |
|
| 180 | + * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 181 | + * We must divide fields in two groups: |
|
| 182 | + * - simple: accept values for one property |
|
| 183 | + * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 184 | + */ |
|
| 185 | + $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 186 | + $simple_metaboxes = $metaboxes[0]; |
|
| 187 | + $grouped_metaboxes = $metaboxes[1]; |
|
| 195 | 188 | |
| 196 | - // Build the requested field as WL_Metabox_Field_ object. |
|
| 197 | - $this->add_field( $info, false, $type, $id ); |
|
| 189 | + // Loop over simple entity properties. |
|
| 190 | + foreach ( $simple_metaboxes as $key => $property ) { |
|
| 198 | 191 | |
| 199 | - } |
|
| 192 | + // Info passed to the metabox. |
|
| 193 | + $info = array(); |
|
| 194 | + $info[ $key ] = $property; |
|
| 200 | 195 | |
| 201 | - // Loop over grouped properties. |
|
| 202 | - foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 196 | + // Build the requested field as WL_Metabox_Field_ object. |
|
| 197 | + $this->add_field( $info, false, $type, $id ); |
|
| 203 | 198 | |
| 204 | - // Info passed to the metabox. |
|
| 205 | - $info = array(); |
|
| 206 | - $info[ $key ] = $property; |
|
| 199 | + } |
|
| 207 | 200 | |
| 208 | - // Build the requested field group as WL_Metabox_Field_ object. |
|
| 209 | - $this->add_field( $info, true, $type, $id ); |
|
| 201 | + // Loop over grouped properties. |
|
| 202 | + foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 210 | 203 | |
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - } |
|
| 204 | + // Info passed to the metabox. |
|
| 205 | + $info = array(); |
|
| 206 | + $info[ $key ] = $property; |
|
| 215 | 207 | |
| 216 | - /** |
|
| 217 | - * Separates metaboxes in simple and grouped. |
|
| 218 | - * |
|
| 219 | - * @param array $custom_fields Information on the entity type. |
|
| 220 | - * |
|
| 221 | - * @return array |
|
| 222 | - */ |
|
| 223 | - public function group_properties_by_input_field( $custom_fields ) { |
|
| 224 | - |
|
| 225 | - $simple_properties = array(); |
|
| 226 | - $grouped_properties = array(); |
|
| 227 | - |
|
| 228 | - // Loop over possible entity properties. |
|
| 229 | - foreach ( $custom_fields as $key => $property ) { |
|
| 230 | - |
|
| 231 | - // Check presence of predicate and type. |
|
| 232 | - if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 233 | - |
|
| 234 | - // Check if input_field is defined. |
|
| 235 | - if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 236 | - |
|
| 237 | - $grouped_key = $property['input_field']; |
|
| 238 | - |
|
| 239 | - // Update list of grouped properties. |
|
| 240 | - $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 241 | - |
|
| 242 | - } else { |
|
| 243 | - |
|
| 244 | - // input_field not defined, add simple metabox. |
|
| 245 | - $simple_properties[ $key ] = $property; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return array( $simple_properties, $grouped_properties ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Add a Field to the current Metabox, based on the description of the Field. |
|
| 255 | - * This method is a rude factory for Field objects. |
|
| 256 | - * |
|
| 257 | - * @param array $args The field's information. |
|
| 258 | - * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 259 | - * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 260 | - * @param int $id Identifier for the type. |
|
| 261 | - */ |
|
| 262 | - public function add_field( $args, $grouped, $type, $id ) { |
|
| 263 | - |
|
| 264 | - if ( $grouped ) { |
|
| 265 | - |
|
| 266 | - // Special fields (sameas, coordinates, etc.). |
|
| 267 | - // |
|
| 268 | - // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 269 | - $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 270 | - |
|
| 271 | - } else { |
|
| 272 | - |
|
| 273 | - // Simple fields (string, uri, boolean, etc.). |
|
| 274 | - // |
|
| 275 | - // Which field? We want to use the class that is specific for the field. |
|
| 276 | - $meta = key( $args ); |
|
| 277 | - $this_meta = $args[ $meta ]; |
|
| 278 | - |
|
| 279 | - // If the field declares what metabox it wants, use that one. |
|
| 280 | - if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 281 | - |
|
| 282 | - $field_class = $this_meta['metabox']['class']; |
|
| 283 | - |
|
| 284 | - } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 285 | - |
|
| 286 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 287 | - // When they will remove this. |
|
| 288 | - // |
|
| 289 | - // Use default Wl_Metabox_Field (manages strings). |
|
| 290 | - $field_class = 'Wl_Metabox_Field'; |
|
| 291 | - |
|
| 292 | - } else { |
|
| 293 | - |
|
| 294 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 295 | - // When they will remove this. |
|
| 296 | - // |
|
| 297 | - // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 298 | - $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 299 | - |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - /** |
|
| 303 | - * @since 3.31.6 |
|
| 304 | - * Add namespace to initialize class. |
|
| 305 | - */ |
|
| 306 | - /** |
|
| 307 | - * @since 3.31.6 |
|
| 308 | - * Add namespace to initialize class. |
|
| 309 | - */ |
|
| 310 | - if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 311 | - $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 312 | - // End if(). |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - if ( class_exists( $field_class ) ) { |
|
| 316 | - // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 317 | - $instance = new $field_class( $args, $id, $type ); |
|
| 318 | - // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 319 | - $this->fields[] = $instance; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 326 | - * |
|
| 327 | - * @param int $id The entity's {@link WP_Post}'s id. |
|
| 328 | - * |
|
| 329 | - * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 330 | - * |
|
| 331 | - * @param $type int Post or term |
|
| 332 | - * |
|
| 333 | - * @since 3.5.4 |
|
| 334 | - */ |
|
| 335 | - public function save_form_data( $id, $type ) { |
|
| 336 | - |
|
| 337 | - $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 338 | - |
|
| 339 | - // Skip saving if the save is called for a different post. |
|
| 340 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 341 | - if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 342 | - $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Build Field objects. |
|
| 347 | - $this->instantiate_fields( $id, $type ); |
|
| 348 | - |
|
| 349 | - // Check if WL metabox form was posted. |
|
| 350 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 351 | - if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 352 | - $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 353 | - |
|
| 354 | - return; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 358 | - $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 359 | - $posted_data = $posted_data['wl_metaboxes']; |
|
| 360 | - foreach ( $this->fields as $field ) { |
|
| 361 | - |
|
| 362 | - // Verify nonce. |
|
| 363 | - $valid_nonce = $field->verify_nonce(); |
|
| 364 | - |
|
| 365 | - if ( $valid_nonce ) { |
|
| 366 | - $field_name = $field->meta_name; |
|
| 367 | - // Each Filed only deals with its values. |
|
| 368 | - if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 369 | - |
|
| 370 | - $values = $posted_data[ $field_name ]; |
|
| 371 | - if ( ! is_array( $values ) ) { |
|
| 372 | - $values = array( $values ); |
|
| 373 | - } |
|
| 374 | - // Save data permanently |
|
| 375 | - $field->save_data( $values ); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 382 | - * before the triples are pushed to the linked dataset. |
|
| 383 | - * |
|
| 384 | - * @param int $id The entity id. |
|
| 385 | - * @param int $id The post data. |
|
| 386 | - * |
|
| 387 | - * @since 3.18.2 |
|
| 388 | - */ |
|
| 389 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 390 | - do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 391 | - |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Enqueue scripts and styles. |
|
| 396 | - * |
|
| 397 | - * @since 3.0.0 |
|
| 398 | - */ |
|
| 399 | - public function enqueue_scripts_and_styles() { |
|
| 400 | - |
|
| 401 | - // Use the minified version if PW_DEBUG isn't set. |
|
| 402 | - $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 403 | - |
|
| 404 | - // CSS For Meta Box. |
|
| 405 | - wp_enqueue_style( 'wl-meta-box', WL_DIR_URL . 'css/wl-meta-box.css', array(), WORDLIFT_VERSION ); |
|
| 406 | - |
|
| 407 | - // Load the jquery-ui-timepicker-addon library. |
|
| 408 | - wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 409 | - wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 410 | - |
|
| 411 | - wl_enqueue_leaflet(); |
|
| 412 | - |
|
| 413 | - // Add AJAX autocomplete to facilitate metabox editing. |
|
| 414 | - wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 415 | - wp_localize_script( |
|
| 416 | - 'wl-entity-metabox-utility', |
|
| 417 | - 'wlEntityMetaboxParams', |
|
| 418 | - array( |
|
| 419 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 420 | - 'action' => 'entity_by_title', |
|
| 421 | - ) |
|
| 422 | - ); |
|
| 423 | - |
|
| 424 | - } |
|
| 208 | + // Build the requested field group as WL_Metabox_Field_ object. |
|
| 209 | + $this->add_field( $info, true, $type, $id ); |
|
| 210 | + |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Separates metaboxes in simple and grouped. |
|
| 218 | + * |
|
| 219 | + * @param array $custom_fields Information on the entity type. |
|
| 220 | + * |
|
| 221 | + * @return array |
|
| 222 | + */ |
|
| 223 | + public function group_properties_by_input_field( $custom_fields ) { |
|
| 224 | + |
|
| 225 | + $simple_properties = array(); |
|
| 226 | + $grouped_properties = array(); |
|
| 227 | + |
|
| 228 | + // Loop over possible entity properties. |
|
| 229 | + foreach ( $custom_fields as $key => $property ) { |
|
| 230 | + |
|
| 231 | + // Check presence of predicate and type. |
|
| 232 | + if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 233 | + |
|
| 234 | + // Check if input_field is defined. |
|
| 235 | + if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 236 | + |
|
| 237 | + $grouped_key = $property['input_field']; |
|
| 238 | + |
|
| 239 | + // Update list of grouped properties. |
|
| 240 | + $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 241 | + |
|
| 242 | + } else { |
|
| 243 | + |
|
| 244 | + // input_field not defined, add simple metabox. |
|
| 245 | + $simple_properties[ $key ] = $property; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return array( $simple_properties, $grouped_properties ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Add a Field to the current Metabox, based on the description of the Field. |
|
| 255 | + * This method is a rude factory for Field objects. |
|
| 256 | + * |
|
| 257 | + * @param array $args The field's information. |
|
| 258 | + * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 259 | + * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 260 | + * @param int $id Identifier for the type. |
|
| 261 | + */ |
|
| 262 | + public function add_field( $args, $grouped, $type, $id ) { |
|
| 263 | + |
|
| 264 | + if ( $grouped ) { |
|
| 265 | + |
|
| 266 | + // Special fields (sameas, coordinates, etc.). |
|
| 267 | + // |
|
| 268 | + // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 269 | + $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 270 | + |
|
| 271 | + } else { |
|
| 272 | + |
|
| 273 | + // Simple fields (string, uri, boolean, etc.). |
|
| 274 | + // |
|
| 275 | + // Which field? We want to use the class that is specific for the field. |
|
| 276 | + $meta = key( $args ); |
|
| 277 | + $this_meta = $args[ $meta ]; |
|
| 278 | + |
|
| 279 | + // If the field declares what metabox it wants, use that one. |
|
| 280 | + if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 281 | + |
|
| 282 | + $field_class = $this_meta['metabox']['class']; |
|
| 283 | + |
|
| 284 | + } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 285 | + |
|
| 286 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 287 | + // When they will remove this. |
|
| 288 | + // |
|
| 289 | + // Use default Wl_Metabox_Field (manages strings). |
|
| 290 | + $field_class = 'Wl_Metabox_Field'; |
|
| 291 | + |
|
| 292 | + } else { |
|
| 293 | + |
|
| 294 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 295 | + // When they will remove this. |
|
| 296 | + // |
|
| 297 | + // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 298 | + $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 299 | + |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + /** |
|
| 303 | + * @since 3.31.6 |
|
| 304 | + * Add namespace to initialize class. |
|
| 305 | + */ |
|
| 306 | + /** |
|
| 307 | + * @since 3.31.6 |
|
| 308 | + * Add namespace to initialize class. |
|
| 309 | + */ |
|
| 310 | + if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 311 | + $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 312 | + // End if(). |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + if ( class_exists( $field_class ) ) { |
|
| 316 | + // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 317 | + $instance = new $field_class( $args, $id, $type ); |
|
| 318 | + // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 319 | + $this->fields[] = $instance; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 326 | + * |
|
| 327 | + * @param int $id The entity's {@link WP_Post}'s id. |
|
| 328 | + * |
|
| 329 | + * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 330 | + * |
|
| 331 | + * @param $type int Post or term |
|
| 332 | + * |
|
| 333 | + * @since 3.5.4 |
|
| 334 | + */ |
|
| 335 | + public function save_form_data( $id, $type ) { |
|
| 336 | + |
|
| 337 | + $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 338 | + |
|
| 339 | + // Skip saving if the save is called for a different post. |
|
| 340 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 341 | + if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 342 | + $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Build Field objects. |
|
| 347 | + $this->instantiate_fields( $id, $type ); |
|
| 348 | + |
|
| 349 | + // Check if WL metabox form was posted. |
|
| 350 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 351 | + if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 352 | + $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 353 | + |
|
| 354 | + return; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 358 | + $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 359 | + $posted_data = $posted_data['wl_metaboxes']; |
|
| 360 | + foreach ( $this->fields as $field ) { |
|
| 361 | + |
|
| 362 | + // Verify nonce. |
|
| 363 | + $valid_nonce = $field->verify_nonce(); |
|
| 364 | + |
|
| 365 | + if ( $valid_nonce ) { |
|
| 366 | + $field_name = $field->meta_name; |
|
| 367 | + // Each Filed only deals with its values. |
|
| 368 | + if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 369 | + |
|
| 370 | + $values = $posted_data[ $field_name ]; |
|
| 371 | + if ( ! is_array( $values ) ) { |
|
| 372 | + $values = array( $values ); |
|
| 373 | + } |
|
| 374 | + // Save data permanently |
|
| 375 | + $field->save_data( $values ); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 382 | + * before the triples are pushed to the linked dataset. |
|
| 383 | + * |
|
| 384 | + * @param int $id The entity id. |
|
| 385 | + * @param int $id The post data. |
|
| 386 | + * |
|
| 387 | + * @since 3.18.2 |
|
| 388 | + */ |
|
| 389 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 390 | + do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 391 | + |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Enqueue scripts and styles. |
|
| 396 | + * |
|
| 397 | + * @since 3.0.0 |
|
| 398 | + */ |
|
| 399 | + public function enqueue_scripts_and_styles() { |
|
| 400 | + |
|
| 401 | + // Use the minified version if PW_DEBUG isn't set. |
|
| 402 | + $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 403 | + |
|
| 404 | + // CSS For Meta Box. |
|
| 405 | + wp_enqueue_style( 'wl-meta-box', WL_DIR_URL . 'css/wl-meta-box.css', array(), WORDLIFT_VERSION ); |
|
| 406 | + |
|
| 407 | + // Load the jquery-ui-timepicker-addon library. |
|
| 408 | + wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 409 | + wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 410 | + |
|
| 411 | + wl_enqueue_leaflet(); |
|
| 412 | + |
|
| 413 | + // Add AJAX autocomplete to facilitate metabox editing. |
|
| 414 | + wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 415 | + wp_localize_script( |
|
| 416 | + 'wl-entity-metabox-utility', |
|
| 417 | + 'wlEntityMetaboxParams', |
|
| 418 | + array( |
|
| 419 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 420 | + 'action' => 'entity_by_title', |
|
| 421 | + ) |
|
| 422 | + ); |
|
| 423 | + |
|
| 424 | + } |
|
| 425 | 425 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function __construct() { |
| 43 | 43 | |
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -51,22 +51,22 @@ discard block |
||
| 51 | 51 | public function add_main_metabox() { |
| 52 | 52 | |
| 53 | 53 | // Build the fields we need to print. |
| 54 | - $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 54 | + $this->instantiate_fields(get_the_ID(), Object_Type_Enum::POST); |
|
| 55 | 55 | |
| 56 | 56 | // Bailout if there are no actual fields, we do not need a metabox in that case. |
| 57 | - if ( empty( $this->fields ) ) { |
|
| 57 | + if (empty($this->fields)) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Add main metabox (will print also the inner fields). |
| 62 | - $id = uniqid( 'wl-metabox-' ); |
|
| 63 | - $title = __( 'WordLift', 'wordlift' ); |
|
| 62 | + $id = uniqid('wl-metabox-'); |
|
| 63 | + $title = __('WordLift', 'wordlift'); |
|
| 64 | 64 | |
| 65 | 65 | // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
| 66 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 66 | + foreach (Wordlift_Entity_Service::valid_entity_post_types() as $screen) { |
|
| 67 | 67 | add_meta_box( |
| 68 | 68 | $id, |
| 69 | - esc_html( $title ), |
|
| 69 | + esc_html($title), |
|
| 70 | 70 | array( |
| 71 | 71 | $this, |
| 72 | 72 | 'html', |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | // dynamically according to the `get_current_screen()` function. |
| 84 | 84 | $current_screen = get_current_screen(); |
| 85 | 85 | $screen = $current_screen ? $current_screen->post_type : 'entity'; |
| 86 | - add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 86 | + add_filter("postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class'); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,22 +95,22 @@ discard block |
||
| 95 | 95 | public function html() { |
| 96 | 96 | |
| 97 | 97 | // HTML Code Before MetaBox Content. |
| 98 | - do_action( 'wl_metabox_before_html' ); |
|
| 98 | + do_action('wl_metabox_before_html'); |
|
| 99 | 99 | ?> |
| 100 | 100 | <div class="wl-metabox-tabs"> |
| 101 | 101 | <ul> |
| 102 | 102 | <li class="active"> |
| 103 | - <a href="#wl-metabox-tab-properties"><?php esc_html_e( 'Properties', 'wordlift' ); ?></a> |
|
| 103 | + <a href="#wl-metabox-tab-properties"><?php esc_html_e('Properties', 'wordlift'); ?></a> |
|
| 104 | 104 | </li> |
| 105 | 105 | <li> |
| 106 | - <a href="#wl-metabox-tab-ingredient"><?php esc_html_e( 'Main Ingredient', 'wordlift' ); ?></a> |
|
| 106 | + <a href="#wl-metabox-tab-ingredient"><?php esc_html_e('Main Ingredient', 'wordlift'); ?></a> |
|
| 107 | 107 | </li> |
| 108 | 108 | </ul> |
| 109 | 109 | <div class="wl-metabox-tabs__content"> |
| 110 | 110 | <div id="wl-metabox-tab-properties"> |
| 111 | 111 | <?php |
| 112 | 112 | // Loop over the fields. |
| 113 | - foreach ( $this->fields as $field ) { |
|
| 113 | + foreach ($this->fields as $field) { |
|
| 114 | 114 | |
| 115 | 115 | // load data from DB (values will be available in $field->data). |
| 116 | 116 | $field->get_data(); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | <div id="wl-metabox-tab-ingredient"> |
| 124 | 124 | <form></form> |
| 125 | 125 | <?php |
| 126 | - do_action( 'wl_ingredient_metabox_html' ); |
|
| 126 | + do_action('wl_ingredient_metabox_html'); |
|
| 127 | 127 | ?> |
| 128 | 128 | </div> |
| 129 | 129 | </div> |
@@ -143,20 +143,20 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @since 3.1.0 |
| 145 | 145 | */ |
| 146 | - public function instantiate_fields( $id, $type ) { |
|
| 146 | + public function instantiate_fields($id, $type) { |
|
| 147 | 147 | |
| 148 | - $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 148 | + $this->log->trace("Instantiating fields for entity post $id..."); |
|
| 149 | 149 | |
| 150 | 150 | // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
| 151 | - if ( isset( $this->fields ) ) { |
|
| 151 | + if (isset($this->fields)) { |
|
| 152 | 152 | return; |
| 153 | 153 | } |
| 154 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 155 | - $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 156 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 157 | - $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 154 | + if (Object_Type_Enum::POST === $type) { |
|
| 155 | + $entity_type = wl_entity_taxonomy_get_custom_fields($id); |
|
| 156 | + } elseif (Object_Type_Enum::TERM === $type) { |
|
| 157 | + $term_entity_types = get_term_meta($id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 158 | 158 | $term_entity_types = array_map( |
| 159 | - function ( $term ) { |
|
| 159 | + function($term) { |
|
| 160 | 160 | return get_term_by( |
| 161 | 161 | 'slug', |
| 162 | 162 | $term, |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | }, |
| 166 | 166 | $term_entity_types |
| 167 | 167 | ); |
| 168 | - $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 168 | + $entity_type = wl_get_custom_fields_by_entity_type($term_entity_types); |
|
| 169 | 169 | } |
| 170 | - if ( isset( $entity_type ) ) { |
|
| 170 | + if (isset($entity_type)) { |
|
| 171 | 171 | |
| 172 | 172 | /* |
| 173 | 173 | * Might not have any relevant meta box field, for example for articles, |
@@ -182,31 +182,31 @@ discard block |
||
| 182 | 182 | * - simple: accept values for one property |
| 183 | 183 | * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
| 184 | 184 | */ |
| 185 | - $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 185 | + $metaboxes = $this->group_properties_by_input_field($entity_type); |
|
| 186 | 186 | $simple_metaboxes = $metaboxes[0]; |
| 187 | 187 | $grouped_metaboxes = $metaboxes[1]; |
| 188 | 188 | |
| 189 | 189 | // Loop over simple entity properties. |
| 190 | - foreach ( $simple_metaboxes as $key => $property ) { |
|
| 190 | + foreach ($simple_metaboxes as $key => $property) { |
|
| 191 | 191 | |
| 192 | 192 | // Info passed to the metabox. |
| 193 | 193 | $info = array(); |
| 194 | - $info[ $key ] = $property; |
|
| 194 | + $info[$key] = $property; |
|
| 195 | 195 | |
| 196 | 196 | // Build the requested field as WL_Metabox_Field_ object. |
| 197 | - $this->add_field( $info, false, $type, $id ); |
|
| 197 | + $this->add_field($info, false, $type, $id); |
|
| 198 | 198 | |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Loop over grouped properties. |
| 202 | - foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 202 | + foreach ($grouped_metaboxes as $key => $property) { |
|
| 203 | 203 | |
| 204 | 204 | // Info passed to the metabox. |
| 205 | 205 | $info = array(); |
| 206 | - $info[ $key ] = $property; |
|
| 206 | + $info[$key] = $property; |
|
| 207 | 207 | |
| 208 | 208 | // Build the requested field group as WL_Metabox_Field_ object. |
| 209 | - $this->add_field( $info, true, $type, $id ); |
|
| 209 | + $this->add_field($info, true, $type, $id); |
|
| 210 | 210 | |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -220,34 +220,34 @@ discard block |
||
| 220 | 220 | * |
| 221 | 221 | * @return array |
| 222 | 222 | */ |
| 223 | - public function group_properties_by_input_field( $custom_fields ) { |
|
| 223 | + public function group_properties_by_input_field($custom_fields) { |
|
| 224 | 224 | |
| 225 | 225 | $simple_properties = array(); |
| 226 | 226 | $grouped_properties = array(); |
| 227 | 227 | |
| 228 | 228 | // Loop over possible entity properties. |
| 229 | - foreach ( $custom_fields as $key => $property ) { |
|
| 229 | + foreach ($custom_fields as $key => $property) { |
|
| 230 | 230 | |
| 231 | 231 | // Check presence of predicate and type. |
| 232 | - if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 232 | + if (isset($property['predicate']) && isset($property['type'])) { |
|
| 233 | 233 | |
| 234 | 234 | // Check if input_field is defined. |
| 235 | - if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 235 | + if (isset($property['input_field']) && '' !== $property['input_field']) { |
|
| 236 | 236 | |
| 237 | 237 | $grouped_key = $property['input_field']; |
| 238 | 238 | |
| 239 | 239 | // Update list of grouped properties. |
| 240 | - $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 240 | + $grouped_properties[$grouped_key][$key] = $property; |
|
| 241 | 241 | |
| 242 | 242 | } else { |
| 243 | 243 | |
| 244 | 244 | // input_field not defined, add simple metabox. |
| 245 | - $simple_properties[ $key ] = $property; |
|
| 245 | + $simple_properties[$key] = $property; |
|
| 246 | 246 | } |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - return array( $simple_properties, $grouped_properties ); |
|
| 250 | + return array($simple_properties, $grouped_properties); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -259,29 +259,29 @@ discard block |
||
| 259 | 259 | * @param int $type Post or Term, based on the correct decorator would be selected. |
| 260 | 260 | * @param int $id Identifier for the type. |
| 261 | 261 | */ |
| 262 | - public function add_field( $args, $grouped, $type, $id ) { |
|
| 262 | + public function add_field($args, $grouped, $type, $id) { |
|
| 263 | 263 | |
| 264 | - if ( $grouped ) { |
|
| 264 | + if ($grouped) { |
|
| 265 | 265 | |
| 266 | 266 | // Special fields (sameas, coordinates, etc.). |
| 267 | 267 | // |
| 268 | 268 | // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
| 269 | - $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 269 | + $field_class = 'Wl_Metabox_Field_'.key($args); |
|
| 270 | 270 | |
| 271 | 271 | } else { |
| 272 | 272 | |
| 273 | 273 | // Simple fields (string, uri, boolean, etc.). |
| 274 | 274 | // |
| 275 | 275 | // Which field? We want to use the class that is specific for the field. |
| 276 | - $meta = key( $args ); |
|
| 277 | - $this_meta = $args[ $meta ]; |
|
| 276 | + $meta = key($args); |
|
| 277 | + $this_meta = $args[$meta]; |
|
| 278 | 278 | |
| 279 | 279 | // If the field declares what metabox it wants, use that one. |
| 280 | - if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 280 | + if (isset($this_meta['metabox']['class'])) { |
|
| 281 | 281 | |
| 282 | 282 | $field_class = $this_meta['metabox']['class']; |
| 283 | 283 | |
| 284 | - } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 284 | + } elseif ( ! isset($this_meta['type']) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type']) { |
|
| 285 | 285 | |
| 286 | 286 | // TODO: all fields should explicitly declare the required WL_Metabox. |
| 287 | 287 | // When they will remove this. |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | // When they will remove this. |
| 296 | 296 | // |
| 297 | 297 | // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
| 298 | - $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 298 | + $field_class = 'Wl_Metabox_Field_'.$this_meta['type']; |
|
| 299 | 299 | |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -307,14 +307,14 @@ discard block |
||
| 307 | 307 | * @since 3.31.6 |
| 308 | 308 | * Add namespace to initialize class. |
| 309 | 309 | */ |
| 310 | - if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 311 | - $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 310 | + if (substr($field_class, 0, 1) !== '\\') { |
|
| 311 | + $field_class = 'Wordlift\Metabox\Field\\'.$field_class; |
|
| 312 | 312 | // End if(). |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - if ( class_exists( $field_class ) ) { |
|
| 315 | + if (class_exists($field_class)) { |
|
| 316 | 316 | // Get decorator and use it as wrapper for save_data and get_data methods. |
| 317 | - $instance = new $field_class( $args, $id, $type ); |
|
| 317 | + $instance = new $field_class($args, $id, $type); |
|
| 318 | 318 | // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
| 319 | 319 | $this->fields[] = $instance; |
| 320 | 320 | } |
@@ -332,47 +332,47 @@ discard block |
||
| 332 | 332 | * |
| 333 | 333 | * @since 3.5.4 |
| 334 | 334 | */ |
| 335 | - public function save_form_data( $id, $type ) { |
|
| 335 | + public function save_form_data($id, $type) { |
|
| 336 | 336 | |
| 337 | - $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 337 | + $this->log->trace("Saving form data for entity post $id..."); |
|
| 338 | 338 | |
| 339 | 339 | // Skip saving if the save is called for a different post. |
| 340 | 340 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 341 | - if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 342 | - $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 341 | + if (isset($_POST['post_ID']) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type) { |
|
| 342 | + $this->log->debug('`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.'); |
|
| 343 | 343 | return; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Build Field objects. |
| 347 | - $this->instantiate_fields( $id, $type ); |
|
| 347 | + $this->instantiate_fields($id, $type); |
|
| 348 | 348 | |
| 349 | 349 | // Check if WL metabox form was posted. |
| 350 | 350 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 351 | - if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 352 | - $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 351 | + if ( ! isset($_POST['wl_metaboxes'])) { |
|
| 352 | + $this->log->debug('`wl_metaboxes`, skipping...'); |
|
| 353 | 353 | |
| 354 | 354 | return; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 358 | - $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 358 | + $posted_data = filter_var_array($_POST, array('wl_metaboxes' => array('flags' => FILTER_REQUIRE_ARRAY))); |
|
| 359 | 359 | $posted_data = $posted_data['wl_metaboxes']; |
| 360 | - foreach ( $this->fields as $field ) { |
|
| 360 | + foreach ($this->fields as $field) { |
|
| 361 | 361 | |
| 362 | 362 | // Verify nonce. |
| 363 | 363 | $valid_nonce = $field->verify_nonce(); |
| 364 | 364 | |
| 365 | - if ( $valid_nonce ) { |
|
| 365 | + if ($valid_nonce) { |
|
| 366 | 366 | $field_name = $field->meta_name; |
| 367 | 367 | // Each Filed only deals with its values. |
| 368 | - if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 368 | + if (isset($posted_data[$field_name])) { |
|
| 369 | 369 | |
| 370 | - $values = $posted_data[ $field_name ]; |
|
| 371 | - if ( ! is_array( $values ) ) { |
|
| 372 | - $values = array( $values ); |
|
| 370 | + $values = $posted_data[$field_name]; |
|
| 371 | + if ( ! is_array($values)) { |
|
| 372 | + $values = array($values); |
|
| 373 | 373 | } |
| 374 | 374 | // Save data permanently |
| 375 | - $field->save_data( $values ); |
|
| 375 | + $field->save_data($values); |
|
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | } |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | * @since 3.18.2 |
| 388 | 388 | */ |
| 389 | 389 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 390 | - do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 390 | + do_action('wl_save_form_pre_push_entity', $id, $_POST); |
|
| 391 | 391 | |
| 392 | 392 | } |
| 393 | 393 | |
@@ -399,24 +399,24 @@ discard block |
||
| 399 | 399 | public function enqueue_scripts_and_styles() { |
| 400 | 400 | |
| 401 | 401 | // Use the minified version if PW_DEBUG isn't set. |
| 402 | - $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 402 | + $min = ! defined('WP_DEBUG') || ! WP_DEBUG ? '.min' : ''; |
|
| 403 | 403 | |
| 404 | 404 | // CSS For Meta Box. |
| 405 | - wp_enqueue_style( 'wl-meta-box', WL_DIR_URL . 'css/wl-meta-box.css', array(), WORDLIFT_VERSION ); |
|
| 405 | + wp_enqueue_style('wl-meta-box', WL_DIR_URL.'css/wl-meta-box.css', array(), WORDLIFT_VERSION); |
|
| 406 | 406 | |
| 407 | 407 | // Load the jquery-ui-timepicker-addon library. |
| 408 | - wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 409 | - wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 408 | + wp_enqueue_style('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6'); |
|
| 409 | + wp_enqueue_script('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.js", array('jquery'), '3.0.6', true); |
|
| 410 | 410 | |
| 411 | 411 | wl_enqueue_leaflet(); |
| 412 | 412 | |
| 413 | 413 | // Add AJAX autocomplete to facilitate metabox editing. |
| 414 | - wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 414 | + wp_enqueue_script('wl-entity-metabox-utility', dirname(dirname(plugin_dir_url(__FILE__))).'/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false); |
|
| 415 | 415 | wp_localize_script( |
| 416 | 416 | 'wl-entity-metabox-utility', |
| 417 | 417 | 'wlEntityMetaboxParams', |
| 418 | 418 | array( |
| 419 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 419 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 420 | 420 | 'action' => 'entity_by_title', |
| 421 | 421 | ) |
| 422 | 422 | ); |
@@ -6,43 +6,43 @@ discard block |
||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | // Set the temporary files folder. |
| 9 | -defined( 'WL_TEMP_DIR' ) || define( 'WL_TEMP_DIR', wl_temp_dir() ); |
|
| 9 | +defined('WL_TEMP_DIR') || define('WL_TEMP_DIR', wl_temp_dir()); |
|
| 10 | 10 | |
| 11 | 11 | // Define the meta name used to store the entity URL. |
| 12 | -define( 'WL_ENTITY_URL_META_NAME', 'entity_url' ); |
|
| 12 | +define('WL_ENTITY_URL_META_NAME', 'entity_url'); |
|
| 13 | 13 | |
| 14 | 14 | // WordLift Directory URL. |
| 15 | -defined( 'WL_DIR_URL' ) || define( 'WL_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
| 15 | +defined('WL_DIR_URL') || define('WL_DIR_URL', plugin_dir_url(__FILE__)); |
|
| 16 | 16 | |
| 17 | 17 | // Use the WordLift API URL set on the command line. |
| 18 | -if ( ! defined( 'WORDLIFT_API_URL' ) && false !== getenv( 'WORDLIFT_API_URL' ) ) { |
|
| 19 | - define( 'WORDLIFT_API_URL', getenv( 'WORDLIFT_API_URL' ) ); |
|
| 18 | +if ( ! defined('WORDLIFT_API_URL') && false !== getenv('WORDLIFT_API_URL')) { |
|
| 19 | + define('WORDLIFT_API_URL', getenv('WORDLIFT_API_URL')); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // 3.13.0, we use by default WLS 1.11 which provides us with the new, faster |
| 23 | 23 | // chunked analysis. |
| 24 | -define( 'WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined( 'WORDLIFT_API_URL' ) ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/' ); |
|
| 24 | +define('WL_CONFIG_WORDLIFT_API_URL_DEFAULT_VALUE', defined('WORDLIFT_API_URL') ? WORDLIFT_API_URL . '/' : 'https://api.wordlift.io/'); |
|
| 25 | 25 | |
| 26 | 26 | // @since 3.29.0 we do not use https://developers.google.com/structured-data/testing-tool/?url= |
| 27 | -define( 'WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://search.google.com/test/rich-results?url=' ); |
|
| 27 | +define('WL_CONFIG_TEST_GOOGLE_RICH_SNIPPETS_URL', 'https://search.google.com/test/rich-results?url='); |
|
| 28 | 28 | |
| 29 | 29 | // If is set to true, there will be additional button in 'Download Your Data' page |
| 30 | 30 | // that will allow users to download their data in JSON-LD format. |
| 31 | -defined( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA' ) || define( 'WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false ); |
|
| 31 | +defined('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA') || define('WL_CONFIG_DOWNLOAD_GA_CONTENT_DATA', false); |
|
| 32 | 32 | |
| 33 | 33 | /* |
| 34 | 34 | * Define the default scope for autocomplete requests. |
| 35 | 35 | * |
| 36 | 36 | * @see https://github.com/insideout10/wordlift-plugin/issues/839 |
| 37 | 37 | */ |
| 38 | -defined( 'WL_AUTOCOMPLETE_SCOPE' ) || define( 'WL_AUTOCOMPLETE_SCOPE', 'cloud' ); |
|
| 38 | +defined('WL_AUTOCOMPLETE_SCOPE') || define('WL_AUTOCOMPLETE_SCOPE', 'cloud'); |
|
| 39 | 39 | |
| 40 | 40 | /* |
| 41 | 41 | * Enable/disable the `all entity types` feature. Initially we keep the feature disabled to enture proper Q/A. |
| 42 | 42 | * |
| 43 | 43 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 44 | 44 | */ |
| 45 | -defined( 'WL_ALL_ENTITY_TYPES' ) || define( 'WL_ALL_ENTITY_TYPES', false ); |
|
| 45 | +defined('WL_ALL_ENTITY_TYPES') || define('WL_ALL_ENTITY_TYPES', false); |
|
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * Get a site unique directory under the system or WordPress temporary directory. |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function wl_temp_dir() { |
| 58 | 58 | $tempdir = get_temp_dir(); |
| 59 | - $unique = md5( site_url() . get_current_blog_id() ); |
|
| 60 | - $unique_temp_dir = $tempdir . 'wl_' . $unique; // $tempdir should have a trailing slash. |
|
| 59 | + $unique = md5(site_url().get_current_blog_id()); |
|
| 60 | + $unique_temp_dir = $tempdir.'wl_'.$unique; // $tempdir should have a trailing slash. |
|
| 61 | 61 | |
| 62 | 62 | // If directory do not exist, create it. |
| 63 | - if ( ! file_exists( $unique_temp_dir ) ) { |
|
| 63 | + if ( ! file_exists($unique_temp_dir)) { |
|
| 64 | 64 | // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
| 65 | - @mkdir( $unique_temp_dir ); |
|
| 65 | + @mkdir($unique_temp_dir); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - return $unique_temp_dir . '/'; |
|
| 68 | + return $unique_temp_dir.'/'; |
|
| 69 | 69 | } |