@@ -6,36 +6,36 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitbaaf547b24d2757395578581da934187 |
| 8 | 8 | { |
| 9 | - public static $classMap = array ( |
|
| 10 | - 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => __DIR__ . '/..' . '/composer/autoload_real.php', |
|
| 11 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
| 12 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => __DIR__ . '/../..' . '/admin/Download_Ingredients_Data.php', |
|
| 13 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => __DIR__ . '/../..' . '/admin/Full_Page_Delegate.php', |
|
| 14 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => __DIR__ . '/../..' . '/admin/Ingredients_List_Table.php', |
|
| 15 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => __DIR__ . '/../..' . '/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 16 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => __DIR__ . '/../..' . '/admin/Main_Ingredient_List_Table.php', |
|
| 17 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => __DIR__ . '/../..' . '/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 18 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => __DIR__ . '/../..' . '/admin/Meta_Box.php', |
|
| 19 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => __DIR__ . '/../..' . '/admin/Page.php', |
|
| 20 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => __DIR__ . '/../..' . '/admin/Page_Delegate.php', |
|
| 21 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients' => __DIR__ . '/../..' . '/Ingredients.php', |
|
| 22 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => __DIR__ . '/../..' . '/Ingredients_API.php', |
|
| 23 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => __DIR__ . '/../..' . '/Ingredients_Client.php', |
|
| 24 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 25 | - 'Wordlift\\Modules\\Food_Kg\\Jsonld' => __DIR__ . '/../..' . '/Jsonld.php', |
|
| 26 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => __DIR__ . '/../..' . '/Main_Ingredient_Jsonld.php', |
|
| 27 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 28 | - 'Wordlift\\Modules\\Food_Kg\\Module' => __DIR__ . '/../..' . '/Module.php', |
|
| 29 | - 'Wordlift\\Modules\\Food_Kg\\Notices' => __DIR__ . '/../..' . '/Notices.php', |
|
| 30 | - 'Wordlift\\Modules\\Food_Kg\\Preconditions' => __DIR__ . '/../..' . '/Preconditions.php', |
|
| 31 | - 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => __DIR__ . '/../..' . '/Recipe_Lift_Strategy.php', |
|
| 32 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => __DIR__ . '/..' . '/composer/ClassLoader.php', |
|
| 33 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => __DIR__ . '/..' . '/composer/autoload_static.php', |
|
| 9 | + public static $classMap = array( |
|
| 10 | + 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => __DIR__.'/..'.'/composer/autoload_real.php', |
|
| 11 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
| 12 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => __DIR__.'/../..'.'/admin/Download_Ingredients_Data.php', |
|
| 13 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => __DIR__.'/../..'.'/admin/Full_Page_Delegate.php', |
|
| 14 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => __DIR__.'/../..'.'/admin/Ingredients_List_Table.php', |
|
| 15 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => __DIR__.'/../..'.'/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 16 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => __DIR__.'/../..'.'/admin/Main_Ingredient_List_Table.php', |
|
| 17 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => __DIR__.'/../..'.'/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 18 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => __DIR__.'/../..'.'/admin/Meta_Box.php', |
|
| 19 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => __DIR__.'/../..'.'/admin/Page.php', |
|
| 20 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => __DIR__.'/../..'.'/admin/Page_Delegate.php', |
|
| 21 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients' => __DIR__.'/../..'.'/Ingredients.php', |
|
| 22 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => __DIR__.'/../..'.'/Ingredients_API.php', |
|
| 23 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => __DIR__.'/../..'.'/Ingredients_Client.php', |
|
| 24 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 25 | + 'Wordlift\\Modules\\Food_Kg\\Jsonld' => __DIR__.'/../..'.'/Jsonld.php', |
|
| 26 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => __DIR__.'/../..'.'/Main_Ingredient_Jsonld.php', |
|
| 27 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 28 | + 'Wordlift\\Modules\\Food_Kg\\Module' => __DIR__.'/../..'.'/Module.php', |
|
| 29 | + 'Wordlift\\Modules\\Food_Kg\\Notices' => __DIR__.'/../..'.'/Notices.php', |
|
| 30 | + 'Wordlift\\Modules\\Food_Kg\\Preconditions' => __DIR__.'/../..'.'/Preconditions.php', |
|
| 31 | + 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => __DIR__.'/../..'.'/Recipe_Lift_Strategy.php', |
|
| 32 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => __DIR__.'/..'.'/composer/ClassLoader.php', |
|
| 33 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => __DIR__.'/..'.'/composer/autoload_static.php', |
|
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | 36 | public static function getInitializer(ClassLoader $loader) |
| 37 | 37 | { |
| 38 | - return \Closure::bind(function () use ($loader) { |
|
| 38 | + return \Closure::bind(function() use ($loader) { |
|
| 39 | 39 | $loader->classMap = ComposerStaticInitbaaf547b24d2757395578581da934187::$classMap; |
| 40 | 40 | |
| 41 | 41 | }, null, ClassLoader::class); |
@@ -6,28 +6,28 @@ |
||
| 6 | 6 | $baseDir = dirname($vendorDir); |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => $vendorDir . '/composer/autoload_real.php', |
|
| 10 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
| 11 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => $baseDir . '/admin/Download_Ingredients_Data.php', |
|
| 12 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => $baseDir . '/admin/Full_Page_Delegate.php', |
|
| 13 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => $baseDir . '/admin/Ingredients_List_Table.php', |
|
| 14 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => $baseDir . '/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 15 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => $baseDir . '/admin/Main_Ingredient_List_Table.php', |
|
| 16 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => $baseDir . '/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 17 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => $baseDir . '/admin/Meta_Box.php', |
|
| 18 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => $baseDir . '/admin/Page.php', |
|
| 19 | - 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => $baseDir . '/admin/Page_Delegate.php', |
|
| 20 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients' => $baseDir . '/Ingredients.php', |
|
| 21 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => $baseDir . '/Ingredients_API.php', |
|
| 22 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => $baseDir . '/Ingredients_Client.php', |
|
| 23 | - 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => $baseDir . '/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 24 | - 'Wordlift\\Modules\\Food_Kg\\Jsonld' => $baseDir . '/Jsonld.php', |
|
| 25 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => $baseDir . '/Main_Ingredient_Jsonld.php', |
|
| 26 | - 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => $baseDir . '/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 27 | - 'Wordlift\\Modules\\Food_Kg\\Module' => $baseDir . '/Module.php', |
|
| 28 | - 'Wordlift\\Modules\\Food_Kg\\Notices' => $baseDir . '/Notices.php', |
|
| 29 | - 'Wordlift\\Modules\\Food_Kg\\Preconditions' => $baseDir . '/Preconditions.php', |
|
| 30 | - 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => $baseDir . '/Recipe_Lift_Strategy.php', |
|
| 31 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => $vendorDir . '/composer/ClassLoader.php', |
|
| 32 | - 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => $vendorDir . '/composer/autoload_static.php', |
|
| 9 | + 'ComposerAutoloaderInitbaaf547b24d2757395578581da934187' => $vendorDir.'/composer/autoload_real.php', |
|
| 10 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
| 11 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Download_Ingredients_Data' => $baseDir.'/admin/Download_Ingredients_Data.php', |
|
| 12 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Full_Page_Delegate' => $baseDir.'/admin/Full_Page_Delegate.php', |
|
| 13 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_List_Table' => $baseDir.'/admin/Ingredients_List_Table.php', |
|
| 14 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Ingredients_Modal_Page_Delegate' => $baseDir.'/admin/Ingredients_Modal_Page_Delegate.php', |
|
| 15 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_List_Table' => $baseDir.'/admin/Main_Ingredient_List_Table.php', |
|
| 16 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Main_Ingredient_Modal_Page_Delegate' => $baseDir.'/admin/Main_Ingredient_Modal_Page_Delegate.php', |
|
| 17 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Meta_Box' => $baseDir.'/admin/Meta_Box.php', |
|
| 18 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page' => $baseDir.'/admin/Page.php', |
|
| 19 | + 'Wordlift\\Modules\\Food_Kg\\Admin\\Page_Delegate' => $baseDir.'/admin/Page_Delegate.php', |
|
| 20 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients' => $baseDir.'/Ingredients.php', |
|
| 21 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_API' => $baseDir.'/Ingredients_API.php', |
|
| 22 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Client' => $baseDir.'/Ingredients_Client.php', |
|
| 23 | + 'Wordlift\\Modules\\Food_Kg\\Ingredients_Taxonomy_Recipe_Lift_Strategy' => $baseDir.'/Ingredients_Taxonomy_Recipe_Lift_Strategy.php', |
|
| 24 | + 'Wordlift\\Modules\\Food_Kg\\Jsonld' => $baseDir.'/Jsonld.php', |
|
| 25 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Jsonld' => $baseDir.'/Main_Ingredient_Jsonld.php', |
|
| 26 | + 'Wordlift\\Modules\\Food_Kg\\Main_Ingredient_Recipe_Lift_Strategy' => $baseDir.'/Main_Ingredient_Recipe_Lift_Strategy.php', |
|
| 27 | + 'Wordlift\\Modules\\Food_Kg\\Module' => $baseDir.'/Module.php', |
|
| 28 | + 'Wordlift\\Modules\\Food_Kg\\Notices' => $baseDir.'/Notices.php', |
|
| 29 | + 'Wordlift\\Modules\\Food_Kg\\Preconditions' => $baseDir.'/Preconditions.php', |
|
| 30 | + 'Wordlift\\Modules\\Food_Kg\\Recipe_Lift_Strategy' => $baseDir.'/Recipe_Lift_Strategy.php', |
|
| 31 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ClassLoader' => $vendorDir.'/composer/ClassLoader.php', |
|
| 32 | + 'Wordlift_Modules_Food_Kg_Composer\\Autoload\\ComposerStaticInitbaaf547b24d2757395578581da934187' => $vendorDir.'/composer/autoload_static.php', |
|
| 33 | 33 | ); |
@@ -20,83 +20,83 @@ |
||
| 20 | 20 | use Wordlift\Task\Background\Background_Task_Route; |
| 21 | 21 | |
| 22 | 22 | if ( ! defined( 'ABSPATH' ) ) { |
| 23 | - exit; |
|
| 23 | + exit; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | define( 'WL_FOOD_KG_FILE', __FILE__ ); |
| 27 | 27 | define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
| 28 | 28 | |
| 29 | 29 | function __wl_foodkg__load() { |
| 30 | - // Autoloader for dependencies. |
|
| 31 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - // Autoloader for plugin itself. |
|
| 36 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $container_builder = new ContainerBuilder(); |
|
| 41 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | - $loader->load( 'services.yml' ); |
|
| 43 | - $container_builder->compile(); |
|
| 44 | - |
|
| 45 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 46 | - $notices->register_hooks(); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var Preconditions $preconditions |
|
| 50 | - */ |
|
| 51 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | - if ( ! $preconditions->pass() ) { |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Meta Box. |
|
| 57 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 58 | - $meta_box->register_hooks(); |
|
| 59 | - |
|
| 60 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 61 | - $module->register_hooks(); |
|
| 62 | - |
|
| 63 | - /** @var Jsonld $jsonld */ |
|
| 64 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 65 | - $jsonld->register_hooks(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Ingredients API. |
|
| 69 | - */ |
|
| 70 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 71 | - $ingredients_api->register_hooks(); |
|
| 72 | - |
|
| 73 | - /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 74 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 75 | - $main_ingredient_jsonld->register_hooks(); |
|
| 76 | - |
|
| 77 | - /** Prepare the background task. */ |
|
| 78 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 79 | - $task = new All_Posts_Task( |
|
| 80 | - array( |
|
| 81 | - $main_ingredient_recipe_lift, |
|
| 82 | - 'process', |
|
| 83 | - ), |
|
| 84 | - 'wprm_recipe', |
|
| 85 | - 'sync-main-ingredient' |
|
| 86 | - ); |
|
| 87 | - $background_task = Background_Task::create( $task ); |
|
| 88 | - $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 89 | - Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 90 | - |
|
| 91 | - if ( is_admin() ) { |
|
| 92 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 93 | - $page->register_hooks(); |
|
| 94 | - |
|
| 95 | - // Download Ingredients Data. |
|
| 96 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 97 | - $download_ingredients_data->register_hooks(); |
|
| 98 | - |
|
| 99 | - } |
|
| 30 | + // Autoloader for dependencies. |
|
| 31 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | + require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + // Autoloader for plugin itself. |
|
| 36 | + if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | + require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $container_builder = new ContainerBuilder(); |
|
| 41 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | + $loader->load( 'services.yml' ); |
|
| 43 | + $container_builder->compile(); |
|
| 44 | + |
|
| 45 | + $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 46 | + $notices->register_hooks(); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var Preconditions $preconditions |
|
| 50 | + */ |
|
| 51 | + $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | + if ( ! $preconditions->pass() ) { |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Meta Box. |
|
| 57 | + $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 58 | + $meta_box->register_hooks(); |
|
| 59 | + |
|
| 60 | + $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 61 | + $module->register_hooks(); |
|
| 62 | + |
|
| 63 | + /** @var Jsonld $jsonld */ |
|
| 64 | + $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 65 | + $jsonld->register_hooks(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Ingredients API. |
|
| 69 | + */ |
|
| 70 | + $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 71 | + $ingredients_api->register_hooks(); |
|
| 72 | + |
|
| 73 | + /** @var Main_Ingredient_Jsonld $jsonld */ |
|
| 74 | + $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 75 | + $main_ingredient_jsonld->register_hooks(); |
|
| 76 | + |
|
| 77 | + /** Prepare the background task. */ |
|
| 78 | + $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 79 | + $task = new All_Posts_Task( |
|
| 80 | + array( |
|
| 81 | + $main_ingredient_recipe_lift, |
|
| 82 | + 'process', |
|
| 83 | + ), |
|
| 84 | + 'wprm_recipe', |
|
| 85 | + 'sync-main-ingredient' |
|
| 86 | + ); |
|
| 87 | + $background_task = Background_Task::create( $task ); |
|
| 88 | + $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 89 | + Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 90 | + |
|
| 91 | + if ( is_admin() ) { |
|
| 92 | + $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 93 | + $page->register_hooks(); |
|
| 94 | + |
|
| 95 | + // Download Ingredients Data. |
|
| 96 | + $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 97 | + $download_ingredients_data->register_hooks(); |
|
| 98 | + |
|
| 99 | + } |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
@@ -19,63 +19,63 @@ discard block |
||
| 19 | 19 | use Wordlift\Task\Background\Background_Task_Page; |
| 20 | 20 | use Wordlift\Task\Background\Background_Task_Route; |
| 21 | 21 | |
| 22 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 22 | +if ( ! defined('ABSPATH')) { |
|
| 23 | 23 | exit; |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | -define( 'WL_FOOD_KG_FILE', __FILE__ ); |
|
| 27 | -define( 'WL_FOOD_KG_DIR_PATH', dirname( WL_FOOD_KG_FILE ) ); |
|
| 26 | +define('WL_FOOD_KG_FILE', __FILE__); |
|
| 27 | +define('WL_FOOD_KG_DIR_PATH', dirname(WL_FOOD_KG_FILE)); |
|
| 28 | 28 | |
| 29 | 29 | function __wl_foodkg__load() { |
| 30 | 30 | // Autoloader for dependencies. |
| 31 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php' ) ) { |
|
| 32 | - require WL_FOOD_KG_DIR_PATH . '/third-party/vendor/scoper-autoload.php'; |
|
| 31 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php')) { |
|
| 32 | + require WL_FOOD_KG_DIR_PATH.'/third-party/vendor/scoper-autoload.php'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | // Autoloader for plugin itself. |
| 36 | - if ( file_exists( WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php' ) ) { |
|
| 37 | - require WL_FOOD_KG_DIR_PATH . '/includes/vendor/autoload.php'; |
|
| 36 | + if (file_exists(WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php')) { |
|
| 37 | + require WL_FOOD_KG_DIR_PATH.'/includes/vendor/autoload.php'; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $container_builder = new ContainerBuilder(); |
| 41 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 42 | - $loader->load( 'services.yml' ); |
|
| 41 | + $loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 42 | + $loader->load('services.yml'); |
|
| 43 | 43 | $container_builder->compile(); |
| 44 | 44 | |
| 45 | - $notices = $container_builder->get( 'Wordlift\Modules\Food_Kg\Notices' ); |
|
| 45 | + $notices = $container_builder->get('Wordlift\Modules\Food_Kg\Notices'); |
|
| 46 | 46 | $notices->register_hooks(); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * @var Preconditions $preconditions |
| 50 | 50 | */ |
| 51 | - $preconditions = $container_builder->get( 'Wordlift\Modules\Food_Kg\Preconditions' ); |
|
| 52 | - if ( ! $preconditions->pass() ) { |
|
| 51 | + $preconditions = $container_builder->get('Wordlift\Modules\Food_Kg\Preconditions'); |
|
| 52 | + if ( ! $preconditions->pass()) { |
|
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Meta Box. |
| 57 | - $meta_box = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Meta_Box' ); |
|
| 57 | + $meta_box = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Meta_Box'); |
|
| 58 | 58 | $meta_box->register_hooks(); |
| 59 | 59 | |
| 60 | - $module = $container_builder->get( 'Wordlift\Modules\Food_Kg\Module' ); |
|
| 60 | + $module = $container_builder->get('Wordlift\Modules\Food_Kg\Module'); |
|
| 61 | 61 | $module->register_hooks(); |
| 62 | 62 | |
| 63 | 63 | /** @var Jsonld $jsonld */ |
| 64 | - $jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Jsonld' ); |
|
| 64 | + $jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Jsonld'); |
|
| 65 | 65 | $jsonld->register_hooks(); |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Ingredients API. |
| 69 | 69 | */ |
| 70 | - $ingredients_api = $container_builder->get( 'Wordlift\Modules\Food_Kg\Ingredients_API' ); |
|
| 70 | + $ingredients_api = $container_builder->get('Wordlift\Modules\Food_Kg\Ingredients_API'); |
|
| 71 | 71 | $ingredients_api->register_hooks(); |
| 72 | 72 | |
| 73 | 73 | /** @var Main_Ingredient_Jsonld $jsonld */ |
| 74 | - $main_ingredient_jsonld = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld' ); |
|
| 74 | + $main_ingredient_jsonld = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Jsonld'); |
|
| 75 | 75 | $main_ingredient_jsonld->register_hooks(); |
| 76 | 76 | |
| 77 | 77 | /** Prepare the background task. */ |
| 78 | - $main_ingredient_recipe_lift = $container_builder->get( 'Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy' ); |
|
| 78 | + $main_ingredient_recipe_lift = $container_builder->get('Wordlift\Modules\Food_Kg\Main_Ingredient_Recipe_Lift_Strategy'); |
|
| 79 | 79 | $task = new All_Posts_Task( |
| 80 | 80 | array( |
| 81 | 81 | $main_ingredient_recipe_lift, |
@@ -84,20 +84,20 @@ discard block |
||
| 84 | 84 | 'wprm_recipe', |
| 85 | 85 | 'sync-main-ingredient' |
| 86 | 86 | ); |
| 87 | - $background_task = Background_Task::create( $task ); |
|
| 88 | - $background_task_route = Background_Task_Route::create( $background_task, '/main-ingredient' ); |
|
| 89 | - Background_Task_Page::create( __( 'Synchronize Main Ingredient', 'wordlift' ), 'sync-main-ingredient', $background_task_route ); |
|
| 87 | + $background_task = Background_Task::create($task); |
|
| 88 | + $background_task_route = Background_Task_Route::create($background_task, '/main-ingredient'); |
|
| 89 | + Background_Task_Page::create(__('Synchronize Main Ingredient', 'wordlift'), 'sync-main-ingredient', $background_task_route); |
|
| 90 | 90 | |
| 91 | - if ( is_admin() ) { |
|
| 92 | - $page = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Page' ); |
|
| 91 | + if (is_admin()) { |
|
| 92 | + $page = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Page'); |
|
| 93 | 93 | $page->register_hooks(); |
| 94 | 94 | |
| 95 | 95 | // Download Ingredients Data. |
| 96 | - $download_ingredients_data = $container_builder->get( 'Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data' ); |
|
| 96 | + $download_ingredients_data = $container_builder->get('Wordlift\Modules\Food_Kg\Admin\Download_Ingredients_Data'); |
|
| 97 | 97 | $download_ingredients_data->register_hooks(); |
| 98 | 98 | |
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | -add_action( 'plugins_loaded', '__wl_foodkg__load' ); |
|
| 102 | +add_action('plugins_loaded', '__wl_foodkg__load'); |
|
| 103 | 103 | |
@@ -4,60 +4,60 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Ingredients_API { |
| 6 | 6 | |
| 7 | - public function register_hooks() { |
|
| 8 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
| 9 | - } |
|
| 10 | - |
|
| 11 | - public function register_routes() { |
|
| 12 | - register_rest_route( |
|
| 13 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 14 | - '/ingredients', |
|
| 15 | - array( |
|
| 16 | - 'methods' => \WP_REST_Server::READABLE, |
|
| 17 | - 'callback' => array( $this, 'get_ingredients' ), |
|
| 18 | - 'permission_callback' => function () { |
|
| 19 | - return current_user_can( 'manage_options' ); |
|
| 20 | - }, |
|
| 21 | - 'args' => array( |
|
| 22 | - 'per_page' => array( |
|
| 23 | - 'type' => 'integer', |
|
| 24 | - 'validate_callback' => 'rest_validate_request_arg', |
|
| 25 | - 'default' => 20, |
|
| 26 | - 'minimum' => 1, |
|
| 27 | - 'maximum' => 100, |
|
| 28 | - 'sanitize_callback' => 'absint', |
|
| 29 | - ), |
|
| 30 | - 'page' => array( |
|
| 31 | - 'type' => 'integer', |
|
| 32 | - 'validate_callback' => 'rest_validate_request_arg', |
|
| 33 | - 'default' => 1, |
|
| 34 | - 'sanitize_callback' => 'absint', |
|
| 35 | - ), |
|
| 36 | - 'offset' => array( |
|
| 37 | - 'type' => 'integer', |
|
| 38 | - 'validate_callback' => 'rest_validate_request_arg', |
|
| 39 | - 'sanitize_callback' => 'absint', |
|
| 40 | - ), |
|
| 41 | - ), |
|
| 42 | - ) |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function get_ingredients( \WP_REST_Request $request ) { |
|
| 47 | - $per_page = $request['per_page']; |
|
| 48 | - $page = $request['page']; |
|
| 49 | - $offset = $request['offset']; |
|
| 50 | - |
|
| 51 | - global $wpdb; |
|
| 52 | - |
|
| 53 | - if ( isset( $offset ) ) { |
|
| 54 | - $offset = (int) $offset; |
|
| 55 | - } else { |
|
| 56 | - $offset = ( $page - 1 ) * $per_page; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $sql = |
|
| 60 | - "SELECT p1.ID AS recipe_ID, |
|
| 7 | + public function register_hooks() { |
|
| 8 | + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
| 9 | + } |
|
| 10 | + |
|
| 11 | + public function register_routes() { |
|
| 12 | + register_rest_route( |
|
| 13 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
| 14 | + '/ingredients', |
|
| 15 | + array( |
|
| 16 | + 'methods' => \WP_REST_Server::READABLE, |
|
| 17 | + 'callback' => array( $this, 'get_ingredients' ), |
|
| 18 | + 'permission_callback' => function () { |
|
| 19 | + return current_user_can( 'manage_options' ); |
|
| 20 | + }, |
|
| 21 | + 'args' => array( |
|
| 22 | + 'per_page' => array( |
|
| 23 | + 'type' => 'integer', |
|
| 24 | + 'validate_callback' => 'rest_validate_request_arg', |
|
| 25 | + 'default' => 20, |
|
| 26 | + 'minimum' => 1, |
|
| 27 | + 'maximum' => 100, |
|
| 28 | + 'sanitize_callback' => 'absint', |
|
| 29 | + ), |
|
| 30 | + 'page' => array( |
|
| 31 | + 'type' => 'integer', |
|
| 32 | + 'validate_callback' => 'rest_validate_request_arg', |
|
| 33 | + 'default' => 1, |
|
| 34 | + 'sanitize_callback' => 'absint', |
|
| 35 | + ), |
|
| 36 | + 'offset' => array( |
|
| 37 | + 'type' => 'integer', |
|
| 38 | + 'validate_callback' => 'rest_validate_request_arg', |
|
| 39 | + 'sanitize_callback' => 'absint', |
|
| 40 | + ), |
|
| 41 | + ), |
|
| 42 | + ) |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function get_ingredients( \WP_REST_Request $request ) { |
|
| 47 | + $per_page = $request['per_page']; |
|
| 48 | + $page = $request['page']; |
|
| 49 | + $offset = $request['offset']; |
|
| 50 | + |
|
| 51 | + global $wpdb; |
|
| 52 | + |
|
| 53 | + if ( isset( $offset ) ) { |
|
| 54 | + $offset = (int) $offset; |
|
| 55 | + } else { |
|
| 56 | + $offset = ( $page - 1 ) * $per_page; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $sql = |
|
| 60 | + "SELECT p1.ID AS recipe_ID, |
|
| 61 | 61 | p1.post_title AS recipe_name, |
| 62 | 62 | p2.ID AS post_ID, |
| 63 | 63 | p2.post_title, |
@@ -66,69 +66,69 @@ discard block |
||
| 66 | 66 | INNER JOIN {$wpdb->postmeta} pm1 ON pm1.post_ID = p1.ID |
| 67 | 67 | AND pm1.meta_key = '_wl_main_ingredient_jsonld' |
| 68 | 68 | INNER JOIN {$wpdb->posts} p2" |
| 69 | - // The following ignore rule is used against the `LIKE CONCAT`. We only have const values. |
|
| 70 | - // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery |
|
| 71 | - . " ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
|
| 69 | + // The following ignore rule is used against the `LIKE CONCAT`. We only have const values. |
|
| 70 | + // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery |
|
| 71 | + . " ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
|
| 72 | 72 | AND p2.post_status = 'publish' |
| 73 | 73 | WHERE p1.post_type = 'wprm_recipe'" . $this->limit( $per_page ) . $this->offset( $offset ); |
| 74 | 74 | |
| 75 | - $ingredients = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 76 | - |
|
| 77 | - if ( empty( $ingredients ) ) { |
|
| 78 | - return new \WP_Error( 'no_ingredients', __( 'No ingredients found.', 'wordlift' ), array( 'status' => 404 ) ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $data = array(); |
|
| 82 | - foreach ( $ingredients as $ingredient ) { |
|
| 83 | - $recipe_json_ld = get_post_meta( $ingredient->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 84 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 85 | - |
|
| 86 | - // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 87 | - $data[] = array( |
|
| 88 | - 'ingredient_id' => '', // TODO: get the ingredient id. |
|
| 89 | - 'ingredient_name' => $recipe ? $recipe['name'] : 'null', |
|
| 90 | - 'recipe_id' => $ingredient->recipe_ID, |
|
| 91 | - 'recipe_name' => $ingredient->recipe_name, |
|
| 92 | - 'post_id' => $ingredient->post_ID, |
|
| 93 | - 'post_name' => $ingredient->post_title, |
|
| 94 | - 'post_url' => esc_url( get_the_permalink( $ingredient->post_ID ) ), |
|
| 95 | - ); |
|
| 96 | - // phpcs:enable |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return rest_ensure_response( $data ); |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Add the limit clause if specified. |
|
| 105 | - * |
|
| 106 | - * @param null|int $limit The maximum number of results. |
|
| 107 | - * |
|
| 108 | - * @return string The limit clause (empty if no limit has been specified). |
|
| 109 | - */ |
|
| 110 | - private function limit( $limit = null ) { |
|
| 111 | - |
|
| 112 | - if ( null === $limit || ! is_numeric( $limit ) ) { |
|
| 113 | - return ''; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return " LIMIT $limit"; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Add the OFFSET clause if specified. |
|
| 121 | - * |
|
| 122 | - * @param null|int $offset The number of results to skip. |
|
| 123 | - * |
|
| 124 | - * @return string The offset clause (empty if no offset has been specified). |
|
| 125 | - */ |
|
| 126 | - private function offset( $offset = null ) { |
|
| 127 | - |
|
| 128 | - if ( null === $offset || ! is_numeric( $offset ) ) { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return " OFFSET $offset"; |
|
| 133 | - } |
|
| 75 | + $ingredients = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 76 | + |
|
| 77 | + if ( empty( $ingredients ) ) { |
|
| 78 | + return new \WP_Error( 'no_ingredients', __( 'No ingredients found.', 'wordlift' ), array( 'status' => 404 ) ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $data = array(); |
|
| 82 | + foreach ( $ingredients as $ingredient ) { |
|
| 83 | + $recipe_json_ld = get_post_meta( $ingredient->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 84 | + $recipe = json_decode( $recipe_json_ld, true ); |
|
| 85 | + |
|
| 86 | + // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 87 | + $data[] = array( |
|
| 88 | + 'ingredient_id' => '', // TODO: get the ingredient id. |
|
| 89 | + 'ingredient_name' => $recipe ? $recipe['name'] : 'null', |
|
| 90 | + 'recipe_id' => $ingredient->recipe_ID, |
|
| 91 | + 'recipe_name' => $ingredient->recipe_name, |
|
| 92 | + 'post_id' => $ingredient->post_ID, |
|
| 93 | + 'post_name' => $ingredient->post_title, |
|
| 94 | + 'post_url' => esc_url( get_the_permalink( $ingredient->post_ID ) ), |
|
| 95 | + ); |
|
| 96 | + // phpcs:enable |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return rest_ensure_response( $data ); |
|
| 100 | + |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Add the limit clause if specified. |
|
| 105 | + * |
|
| 106 | + * @param null|int $limit The maximum number of results. |
|
| 107 | + * |
|
| 108 | + * @return string The limit clause (empty if no limit has been specified). |
|
| 109 | + */ |
|
| 110 | + private function limit( $limit = null ) { |
|
| 111 | + |
|
| 112 | + if ( null === $limit || ! is_numeric( $limit ) ) { |
|
| 113 | + return ''; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return " LIMIT $limit"; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Add the OFFSET clause if specified. |
|
| 121 | + * |
|
| 122 | + * @param null|int $offset The number of results to skip. |
|
| 123 | + * |
|
| 124 | + * @return string The offset clause (empty if no offset has been specified). |
|
| 125 | + */ |
|
| 126 | + private function offset( $offset = null ) { |
|
| 127 | + |
|
| 128 | + if ( null === $offset || ! is_numeric( $offset ) ) { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return " OFFSET $offset"; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | class Ingredients_API { |
| 6 | 6 | |
| 7 | 7 | public function register_hooks() { |
| 8 | - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
|
| 8 | + add_action('rest_api_init', array($this, 'register_routes')); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | public function register_routes() { |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | '/ingredients', |
| 15 | 15 | array( |
| 16 | 16 | 'methods' => \WP_REST_Server::READABLE, |
| 17 | - 'callback' => array( $this, 'get_ingredients' ), |
|
| 18 | - 'permission_callback' => function () { |
|
| 19 | - return current_user_can( 'manage_options' ); |
|
| 17 | + 'callback' => array($this, 'get_ingredients'), |
|
| 18 | + 'permission_callback' => function() { |
|
| 19 | + return current_user_can('manage_options'); |
|
| 20 | 20 | }, |
| 21 | 21 | 'args' => array( |
| 22 | 22 | 'per_page' => array( |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | ); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - public function get_ingredients( \WP_REST_Request $request ) { |
|
| 46 | + public function get_ingredients(\WP_REST_Request $request) { |
|
| 47 | 47 | $per_page = $request['per_page']; |
| 48 | 48 | $page = $request['page']; |
| 49 | 49 | $offset = $request['offset']; |
| 50 | 50 | |
| 51 | 51 | global $wpdb; |
| 52 | 52 | |
| 53 | - if ( isset( $offset ) ) { |
|
| 53 | + if (isset($offset)) { |
|
| 54 | 54 | $offset = (int) $offset; |
| 55 | 55 | } else { |
| 56 | - $offset = ( $page - 1 ) * $per_page; |
|
| 56 | + $offset = ($page - 1) * $per_page; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $sql = |
@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.LikeWildcardsInQuery |
| 71 | 71 | . " ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
| 72 | 72 | AND p2.post_status = 'publish' |
| 73 | - WHERE p1.post_type = 'wprm_recipe'" . $this->limit( $per_page ) . $this->offset( $offset ); |
|
| 73 | + WHERE p1.post_type = 'wprm_recipe'" . $this->limit($per_page).$this->offset($offset); |
|
| 74 | 74 | |
| 75 | - $ingredients = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 75 | + $ingredients = $wpdb->get_results($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
| 76 | 76 | |
| 77 | - if ( empty( $ingredients ) ) { |
|
| 78 | - return new \WP_Error( 'no_ingredients', __( 'No ingredients found.', 'wordlift' ), array( 'status' => 404 ) ); |
|
| 77 | + if (empty($ingredients)) { |
|
| 78 | + return new \WP_Error('no_ingredients', __('No ingredients found.', 'wordlift'), array('status' => 404)); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $data = array(); |
| 82 | - foreach ( $ingredients as $ingredient ) { |
|
| 83 | - $recipe_json_ld = get_post_meta( $ingredient->recipe_ID, '_wl_main_ingredient_jsonld', true ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 84 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 82 | + foreach ($ingredients as $ingredient) { |
|
| 83 | + $recipe_json_ld = get_post_meta($ingredient->recipe_ID, '_wl_main_ingredient_jsonld', true); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
|
| 84 | + $recipe = json_decode($recipe_json_ld, true); |
|
| 85 | 85 | |
| 86 | 86 | // phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase |
| 87 | 87 | $data[] = array( |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | 'recipe_name' => $ingredient->recipe_name, |
| 92 | 92 | 'post_id' => $ingredient->post_ID, |
| 93 | 93 | 'post_name' => $ingredient->post_title, |
| 94 | - 'post_url' => esc_url( get_the_permalink( $ingredient->post_ID ) ), |
|
| 94 | + 'post_url' => esc_url(get_the_permalink($ingredient->post_ID)), |
|
| 95 | 95 | ); |
| 96 | 96 | // phpcs:enable |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - return rest_ensure_response( $data ); |
|
| 99 | + return rest_ensure_response($data); |
|
| 100 | 100 | |
| 101 | 101 | } |
| 102 | 102 | |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | * |
| 108 | 108 | * @return string The limit clause (empty if no limit has been specified). |
| 109 | 109 | */ |
| 110 | - private function limit( $limit = null ) { |
|
| 110 | + private function limit($limit = null) { |
|
| 111 | 111 | |
| 112 | - if ( null === $limit || ! is_numeric( $limit ) ) { |
|
| 112 | + if (null === $limit || ! is_numeric($limit)) { |
|
| 113 | 113 | return ''; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @return string The offset clause (empty if no offset has been specified). |
| 125 | 125 | */ |
| 126 | - private function offset( $offset = null ) { |
|
| 126 | + private function offset($offset = null) { |
|
| 127 | 127 | |
| 128 | - if ( null === $offset || ! is_numeric( $offset ) ) { |
|
| 128 | + if (null === $offset || ! is_numeric($offset)) { |
|
| 129 | 129 | return ''; |
| 130 | 130 | } |
| 131 | 131 | |