/** * Get plugins we can use for price tests * * @since 0.2.0 * * @param \WP_REST_Request $request Full data about the request. * @return \WP_Error|\WP_REST_Response */ public function get_plugins($request) { $allowed = ingot_accepted_plugins_for_price_tests(true); if (!empty($allowed)) { foreach ($allowed as $value => $label) { if (ingot_check_ecommerce_active($value)) { $plugins[] = array('value' => $value, 'label' => $label); } } return rest_ensure_response($plugins); } else { return rest_ensure_response('', 404); } }
/** * Get plugins we can use for price tests * * @since 0.2.0 * * @param \WP_REST_Request $request Full data about the request. * @return \WP_Error|\WP_REST_Response */ public function get_plugins($request) { if ('list' == $request->get_param('context')) { $plugins = ingot_ecommerce_plugins_list(); return ingot_rest_response($plugins); } $plugins = []; $allowed = ingot_accepted_plugins_for_price_tests(true); if (!empty($allowed)) { foreach ($allowed as $value => $label) { if (ingot_check_ecommerce_active($value)) { $plugins[] = array('value' => $value, 'label' => $label); } } return ingot_rest_response($plugins); } else { return ingot_rest_response('', 404); } }
/** * Allowed price test types * * @todo deprecate this or ingot_accepted_plugins_for_price_tests() * @since 0.0.7 * * @param bool $with_labels Optional. If true labels as values. Default is false * * @return array $types The allowed click test types */ public static function allowed_price_types($with_labels = false) { return ingot_accepted_plugins_for_price_tests($with_labels); }
/** * Check if price tests are allowed * * @since 0.0.9 * * @return bool */ function ingot_enable_price_testing() { $enable = false; foreach (ingot_accepted_plugins_for_price_tests() as $plugin) { $func = "ingot_is_{$plugin}_active"; if (function_exists($func)) { $active = call_user_func($func); if ($active) { $enable = true; break; } } } /** * Ovveride the enable/disable of price tests, based on active checks * * @since 0.0.9 * * @param bool $enable True to allow, false to not allow. */ return (bool) apply_filters('ingot_enable_price_testing', $enable); }
/** * Test checking validity of price sub_type with filter * * @since 1.1.0 * * @group price * @group helpers * * @covers ingot_acceptable_plugin_for_price_test() * @covers ingot_accepted_plugins_for_price_tests() * @covers \ingot\testing\types::allowed_price_types() */ public function testAllowedSubTypesFilter() { add_filter('ingot_accepted_plugins_for_price_tests', function ($plugins) { $plugins['roy2020'] = 'Roy!'; return $plugins; }); $this->assertTrue(in_array('roy2020', \ingot\testing\types::allowed_price_types())); $this->assertTrue(ingot_acceptable_plugin_for_price_test('roy2020')); $this->assertTrue(in_array('roy2020', ingot_accepted_plugins_for_price_tests())); foreach (['woo', 'edd'] as $plugin) { $this->assertTrue(in_array($plugin, \ingot\testing\types::allowed_price_types())); $this->assertTrue(ingot_acceptable_plugin_for_price_test($plugin)); $this->assertTrue(in_array($plugin, ingot_accepted_plugins_for_price_tests())); } }