@@ -19,96 +19,96 @@ |
||
| 19 | 19 | use Wordlift\Task\Single_Call_Task; |
| 20 | 20 | |
| 21 | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 22 | - exit; |
|
| 22 | + exit; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | define( 'WL_FOOD_KG_FILE', __FILE__ ); |
| 26 | 26 | define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
| 27 | 27 | |
| 28 | 28 | function __wl_foodkg__load() { |
| 29 | - // Autoloader for dependencies. |
|
| 30 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - // Autoloader for plugin itself. |
|
| 35 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - $container_builder = new ContainerBuilder(); |
|
| 40 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | - $loader->load( 'services.yml' ); |
|
| 42 | - $container_builder->compile(); |
|
| 43 | - |
|
| 44 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | - $notices->register_hooks(); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var Preconditions $preconditions |
|
| 49 | - */ |
|
| 50 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | - if ( ! $preconditions->pass() ) { |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Meta Box. |
|
| 56 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | - $meta_box->register_hooks(); |
|
| 58 | - |
|
| 59 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | - $module->register_hooks(); |
|
| 61 | - |
|
| 62 | - /** @var Jsonld $jsonld */ |
|
| 63 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | - $jsonld->register_hooks(); |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Ingredients API. |
|
| 68 | - */ |
|
| 69 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 70 | - $ingredients_api->register_hooks(); |
|
| 71 | - |
|
| 72 | - /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 73 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 74 | - $main_ingredient_jsonld->register_hooks(); |
|
| 75 | - |
|
| 76 | - // Main Ingredient Background Task. |
|
| 77 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 78 | - Background_Task_Factory::create( |
|
| 79 | - new All_Posts_Task( |
|
| 80 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
| 81 | - 'wprm_recipe', |
|
| 82 | - 'sync-main-ingredient' |
|
| 83 | - ), |
|
| 84 | - '/main-ingredient', |
|
| 85 | - 'sync-main-ingredient', |
|
| 86 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - // Ingredients Taxonomy Background Task. |
|
| 90 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 91 | - Background_Task_Factory::create( |
|
| 92 | - new Single_Call_Task( |
|
| 93 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 94 | - 'sync-ingredients-taxonomy' |
|
| 95 | - ), |
|
| 96 | - '/sync-ingredients-taxonomy', |
|
| 97 | - 'sync-ingredients-taxonomy', |
|
| 98 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - if ( is_admin() ) { |
|
| 102 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 103 | - $page->register_hooks(); |
|
| 104 | - |
|
| 105 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 106 | - $page->register_hooks(); |
|
| 107 | - |
|
| 108 | - // Download Ingredients Data. |
|
| 109 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 110 | - $download_ingredients_data->register_hooks(); |
|
| 111 | - } |
|
| 29 | + // Autoloader for dependencies. |
|
| 30 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | + require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + // Autoloader for plugin itself. |
|
| 35 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | + require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + $container_builder = new ContainerBuilder(); |
|
| 40 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | + $loader->load( 'services.yml' ); |
|
| 42 | + $container_builder->compile(); |
|
| 43 | + |
|
| 44 | + $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | + $notices->register_hooks(); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var Preconditions $preconditions |
|
| 49 | + */ |
|
| 50 | + $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | + if ( ! $preconditions->pass() ) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Meta Box. |
|
| 56 | + $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | + $meta_box->register_hooks(); |
|
| 58 | + |
|
| 59 | + $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | + $module->register_hooks(); |
|
| 61 | + |
|
| 62 | + /** @var Jsonld $jsonld */ |
|
| 63 | + $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | + $jsonld->register_hooks(); |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Ingredients API. |
|
| 68 | + */ |
|
| 69 | + $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 70 | + $ingredients_api->register_hooks(); |
|
| 71 | + |
|
| 72 | + /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 73 | + $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 74 | + $main_ingredient_jsonld->register_hooks(); |
|
| 75 | + |
|
| 76 | + // Main Ingredient Background Task. |
|
| 77 | + $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 78 | + Background_Task_Factory::create( |
|
| 79 | + new All_Posts_Task( |
|
| 80 | + array( $main_ingredient_recipe_lift, 'process' ), |
|
| 81 | + 'wprm_recipe', |
|
| 82 | + 'sync-main-ingredient' |
|
| 83 | + ), |
|
| 84 | + '/main-ingredient', |
|
| 85 | + 'sync-main-ingredient', |
|
| 86 | + __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + // Ingredients Taxonomy Background Task. |
|
| 90 | + $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 91 | + Background_Task_Factory::create( |
|
| 92 | + new Single_Call_Task( |
|
| 93 | + array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 94 | + 'sync-ingredients-taxonomy' |
|
| 95 | + ), |
|
| 96 | + '/sync-ingredients-taxonomy', |
|
| 97 | + 'sync-ingredients-taxonomy', |
|
| 98 | + __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + if ( is_admin() ) { |
|
| 102 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 103 | + $page->register_hooks(); |
|
| 104 | + |
|
| 105 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 106 | + $page->register_hooks(); |
|
| 107 | + |
|
| 108 | + // Download Ingredients Data. |
|
| 109 | + $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 110 | + $download_ingredients_data->register_hooks(); |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
@@ -18,98 +18,98 @@ |
||
| 18 | 18 | use Wordlift\Task\Background\Background_Task_Factory; |
| 19 | 19 | use Wordlift\Task\Single_Call_Task; |
| 20 | 20 | |
| 21 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 21 | +if ( ! defined('ABSPATH')) { |
|
| 22 | 22 | exit; |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -define( 'WL_FOOD_KG_FILE', __FILE__ ); |
|
| 26 | -define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
|
| 25 | +define('WL_FOOD_KG_FILE', __FILE__); |
|
| 26 | +define('WL_FOOD_KG_DIR_PATH', dirname(WL_FOOD_KG_FILE)); |
|
| 27 | 27 | |
| 28 | 28 | function __wl_foodkg__load() { |
| 29 | 29 | // Autoloader for dependencies. |
| 30 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 31 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 30 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php')) { |
|
| 31 | + require WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | // Autoloader for plugin itself. |
| 35 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 36 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 35 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php')) { |
|
| 36 | + require WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php'; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $container_builder = new ContainerBuilder(); |
| 40 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 41 | - $loader->load( 'services.yml' ); |
|
| 40 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 41 | + $loader->load('services.yml'); |
|
| 42 | 42 | $container_builder->compile(); |
| 43 | 43 | |
| 44 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 44 | + $notices = $container_builder->get('Wordlift\Modules\Food_Kg\Notices'); |
|
| 45 | 45 | $notices->register_hooks(); |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | 48 | * @var Preconditions $preconditions |
| 49 | 49 | */ |
| 50 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 51 | - if ( ! $preconditions->pass() ) { |
|
| 50 | + $preconditions = $container_builder->get('Wordlift\Modules\Food_Kg\Preconditions'); |
|
| 51 | + if ( ! $preconditions->pass()) { |
|
| 52 | 52 | return; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Meta Box. |
| 56 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 56 | + $meta_box = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Meta_Box'); |
|
| 57 | 57 | $meta_box->register_hooks(); |
| 58 | 58 | |
| 59 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 59 | + $module = $container_builder->get('Wordlift\Modules\Food_Kg\Module'); |
|
| 60 | 60 | $module->register_hooks(); |
| 61 | 61 | |
| 62 | 62 | /** @var Jsonld $jsonld */ |
| 63 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 63 | + $jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Jsonld'); |
|
| 64 | 64 | $jsonld->register_hooks(); |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Ingredients API. |
| 68 | 68 | */ |
| 69 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 69 | + $ingredients_api = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_API'); |
|
| 70 | 70 | $ingredients_api->register_hooks(); |
| 71 | 71 | |
| 72 | 72 | /** @var Main_Ingredient_Jsonld $jsonld */ |
| 73 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 73 | + $main_ingredient_jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld'); |
|
| 74 | 74 | $main_ingredient_jsonld->register_hooks(); |
| 75 | 75 | |
| 76 | 76 | // Main Ingredient Background Task. |
| 77 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 77 | + $main_ingredient_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy'); |
|
| 78 | 78 | Background_Task_Factory::create( |
| 79 | 79 | new All_Posts_Task( |
| 80 | - array( $main_ingredient_recipe_lift, 'process' ), |
|
| 80 | + array($main_ingredient_recipe_lift, 'process'), |
|
| 81 | 81 | 'wprm_recipe', |
| 82 | 82 | 'sync-main-ingredient' |
| 83 | 83 | ), |
| 84 | 84 | '/main-ingredient', |
| 85 | 85 | 'sync-main-ingredient', |
| 86 | - __( 'Synchronize Main Ingredient', 'wordlift' ) |
|
| 86 | + __('Synchronize Main Ingredient', 'wordlift') |
|
| 87 | 87 | ); |
| 88 | 88 | |
| 89 | 89 | // Ingredients Taxonomy Background Task. |
| 90 | - $ingredients_taxonomy_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy' ); |
|
| 90 | + $ingredients_taxonomy_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_Taxonomy_Recipe_Lift_Strategy'); |
|
| 91 | 91 | Background_Task_Factory::create( |
| 92 | 92 | new Single_Call_Task( |
| 93 | - array( $ingredients_taxonomy_recipe_lift, 'run' ), |
|
| 93 | + array($ingredients_taxonomy_recipe_lift, 'run'), |
|
| 94 | 94 | 'sync-ingredients-taxonomy' |
| 95 | 95 | ), |
| 96 | 96 | '/sync-ingredients-taxonomy', |
| 97 | 97 | 'sync-ingredients-taxonomy', |
| 98 | - __( 'Synchronize Ingredients Taxonomy', 'wordlift' ) |
|
| 98 | + __('Synchronize Ingredients Taxonomy', 'wordlift') |
|
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | - if ( is_admin() ) { |
|
| 102 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 101 | + if (is_admin()) { |
|
| 102 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Page'); |
|
| 103 | 103 | $page->register_hooks(); |
| 104 | 104 | |
| 105 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page' ); |
|
| 105 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Ingredients_Taxonomy_Page'); |
|
| 106 | 106 | $page->register_hooks(); |
| 107 | 107 | |
| 108 | 108 | // Download Ingredients Data. |
| 109 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 109 | + $download_ingredients_data = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data'); |
|
| 110 | 110 | $download_ingredients_data->register_hooks(); |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | -add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
|
| 114 | +add_action('plugins_loaded', '__wl_foodkg__load'); |
|
| 115 | 115 | |
@@ -6,63 +6,63 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Module { |
| 8 | 8 | |
| 9 | - const RUN_EVENT = 'wl_food_kg__run'; |
|
| 9 | + const RUN_EVENT = 'wl_food_kg__run'; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var Api_Service_Ext |
|
| 13 | - */ |
|
| 14 | - private $api_service; |
|
| 11 | + /** |
|
| 12 | + * @var Api_Service_Ext |
|
| 13 | + */ |
|
| 14 | + private $api_service; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var Recipe_Lift_Strategy |
|
| 18 | - */ |
|
| 19 | - private $recipe_lift_strategies; |
|
| 16 | + /** |
|
| 17 | + * @var Recipe_Lift_Strategy |
|
| 18 | + */ |
|
| 19 | + private $recipe_lift_strategies; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param Api_Service_Ext $api_service |
|
| 23 | - * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
|
| 24 | - */ |
|
| 25 | - public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 26 | - $this->api_service = $api_service; |
|
| 27 | - $this->recipe_lift_strategies = $recipe_lift_strategies; |
|
| 28 | - } |
|
| 21 | + /** |
|
| 22 | + * @param Api_Service_Ext $api_service |
|
| 23 | + * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
|
| 24 | + */ |
|
| 25 | + public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 26 | + $this->api_service = $api_service; |
|
| 27 | + $this->recipe_lift_strategies = $recipe_lift_strategies; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function register_hooks() { |
|
| 31 | - add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | - add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | - add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 34 | - } |
|
| 30 | + public function register_hooks() { |
|
| 31 | + add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | + add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | + add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function __key_updated() { |
|
| 37 | - try { |
|
| 38 | - $me_response = $this->api_service->me(); |
|
| 39 | - $has_food_kg = isset( $me_response->networks ) |
|
| 40 | - && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | - $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 36 | + public function __key_updated() { |
|
| 37 | + try { |
|
| 38 | + $me_response = $this->api_service->me(); |
|
| 39 | + $has_food_kg = isset( $me_response->networks ) |
|
| 40 | + && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | + $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 42 | 42 | |
| 43 | - // We're connected to the Food KG, but not yet scheduled. |
|
| 44 | - if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | - wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 46 | - } |
|
| 43 | + // We're connected to the Food KG, but not yet scheduled. |
|
| 44 | + if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | + wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // We're not connected to the Food KG, but we're scheduled. |
|
| 49 | - if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | - wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 51 | - } |
|
| 52 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
| 53 | - } catch ( \Exception $e ) { |
|
| 54 | - // Do nothing. |
|
| 55 | - } |
|
| 56 | - } |
|
| 48 | + // We're not connected to the Food KG, but we're scheduled. |
|
| 49 | + if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | + wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 51 | + } |
|
| 52 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
| 53 | + } catch ( \Exception $e ) { |
|
| 54 | + // Do nothing. |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function __run() { |
|
| 59 | - foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 60 | - $recipe_lift_strategy->run(); |
|
| 61 | - } |
|
| 62 | - } |
|
| 58 | + public function __run() { |
|
| 59 | + foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 60 | + $recipe_lift_strategy->run(); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - private function __has_food_kg( $carry, $item ) { |
|
| 65 | - return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
|
| 66 | - } |
|
| 64 | + private function __has_food_kg( $carry, $item ) { |
|
| 65 | + return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | } |
@@ -22,46 +22,46 @@ |
||
| 22 | 22 | * @param Api_Service_Ext $api_service |
| 23 | 23 | * @param Recipe_Lift_Strategy[] $recipe_lift_strategies |
| 24 | 24 | */ |
| 25 | - public function __construct( Api_Service_Ext $api_service, array $recipe_lift_strategies ) { |
|
| 25 | + public function __construct(Api_Service_Ext $api_service, array $recipe_lift_strategies) { |
|
| 26 | 26 | $this->api_service = $api_service; |
| 27 | 27 | $this->recipe_lift_strategies = $recipe_lift_strategies; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function register_hooks() { |
| 31 | - add_action( 'wl_key_updated', array( $this, '__key_updated' ) ); |
|
| 32 | - add_action( self::RUN_EVENT, array( $this, '__run' ) ); |
|
| 33 | - add_action( 'wp_ajax_wl_food_kg__run', array( $this, '__run' ) ); |
|
| 31 | + add_action('wl_key_updated', array($this, '__key_updated')); |
|
| 32 | + add_action(self::RUN_EVENT, array($this, '__run')); |
|
| 33 | + add_action('wp_ajax_wl_food_kg__run', array($this, '__run')); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public function __key_updated() { |
| 37 | 37 | try { |
| 38 | 38 | $me_response = $this->api_service->me(); |
| 39 | - $has_food_kg = isset( $me_response->networks ) |
|
| 40 | - && array_reduce( $me_response->networks, array( $this, '__has_food_kg' ), false ); |
|
| 41 | - $next_scheduled = wp_next_scheduled( self::RUN_EVENT ); |
|
| 39 | + $has_food_kg = isset($me_response->networks) |
|
| 40 | + && array_reduce($me_response->networks, array($this, '__has_food_kg'), false); |
|
| 41 | + $next_scheduled = wp_next_scheduled(self::RUN_EVENT); |
|
| 42 | 42 | |
| 43 | 43 | // We're connected to the Food KG, but not yet scheduled. |
| 44 | - if ( $has_food_kg && ! $next_scheduled ) { |
|
| 45 | - wp_schedule_event( time(), 'daily', self::RUN_EVENT ); |
|
| 44 | + if ($has_food_kg && ! $next_scheduled) { |
|
| 45 | + wp_schedule_event(time(), 'daily', self::RUN_EVENT); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // We're not connected to the Food KG, but we're scheduled. |
| 49 | - if ( ! $has_food_kg && $next_scheduled ) { |
|
| 50 | - wp_unschedule_event( $next_scheduled, self::RUN_EVENT ); |
|
| 49 | + if ( ! $has_food_kg && $next_scheduled) { |
|
| 50 | + wp_unschedule_event($next_scheduled, self::RUN_EVENT); |
|
| 51 | 51 | } |
| 52 | 52 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
| 53 | - } catch ( \Exception $e ) { |
|
| 53 | + } catch (\Exception $e) { |
|
| 54 | 54 | // Do nothing. |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function __run() { |
| 59 | - foreach ( $this->recipe_lift_strategies as $recipe_lift_strategy ) { |
|
| 59 | + foreach ($this->recipe_lift_strategies as $recipe_lift_strategy) { |
|
| 60 | 60 | $recipe_lift_strategy->run(); |
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - private function __has_food_kg( $carry, $item ) { |
|
| 64 | + private function __has_food_kg($carry, $item) { |
|
| 65 | 65 | return $carry || 'https://knowledge.cafemedia.com/food/' === $item->dataset_uri; |
| 66 | 66 | } |
| 67 | 67 | |