/** * Get complete click type HTML * * @since 0.0.6 * * @param int $id Group ID * * @return string */ function ingot_click_test($id) { $html = ''; if (!is_array($id)) { $group = \ingot\testing\crud\group::read($id); } else { $group = $id; } if (!is_array($group) || 'click' !== $group['type']) { return $html; } $type = $group['sub_type']; if (in_array($type, \ingot\testing\types::allowed_click_types())) { switch ($type) { case in_array($type, \ingot\testing\types::internal_click_types()): $html = ingot_click_html_link($type, $group); break; case is_callable($type): $html = call_user_func($type, $group); break; default: $html = ''; } } return $html; }
/** * Construct object * * @since 1.1.0 * * @param string $by What to query by options are plugin or product_ID * @param int|string $value What value to use for query. Product ID or plugin slug (edd|woo) */ public function __construct($by, $value) { if ('plugin' == $by && in_array($value, types::allowed_price_types())) { $this->set_tests_by_plugin($value); } elseif ('product_ID' == $by && is_object(get_post($value))) { $this->set_tests_by_product_id($value); } }
/** * Find all price tests by plugin type * * @since 1.1.0 * * @param string $plugin Plugin -- must be allowed by ingot\testing\types::allowed_price_types() * * @return array */ public static function find_by_plugin($plugin, $skip_no_variants = false) { if (in_array($plugin, types::allowed_price_types())) { $table_name = group::get_table_name(); global $wpdb; $sql = sprintf('SELECT * FROM `%s` WHERE `sub_type` = "%s" AND `type` = "price"', $table_name, $plugin); if ($skip_no_variants) { $empty = serialize([]); $sql .= sprintf(' AND `variants` != "%s"', $empty); } return self::query($wpdb, $sql); } }
/** * Data needed in app * * @since 0.2.0 * * @access protected * * @return array */ protected function vars() { return array('api' => esc_url_raw(util::get_url()), 'nonce' => wp_create_nonce('wp_rest'), 'partials' => esc_url_raw(INGOT_URL . 'assets/admin/partials/'), 'spinner_url' => trailingslashit(INGOT_URL) . 'assets/img/loading.gif', 'edd_active' => esc_attr(ingot_is_edd_active()), 'woo_active' => esc_attr(ingot_is_woo_active()), 'price_tests_enabled' => esc_attr(ingot_enable_price_testing()), 'click_type_options' => types::allowed_click_types(true), 'price_type_options' => types::allowed_price_types(), 'destinations' => \ingot\testing\tests\click\destination\types::destination_types(true, true), 'dev_mode' => INGOT_DEV_MODE); }
/** * Set cookie property for class * * @since 0.0.9 * * @access protected * * @param array $cookie Current contents of this part of cookie * @param bool $reset Optional. Whether to rest or not, default is false */ protected function set_cookie($cookie, $reset) { if (false == $reset) { $this->cookie = $cookie; } else { $this->cookie = []; } foreach (types::allowed_price_types() as $type) { if (!isset($this->cookie[$type])) { $this->cookie[$type] = []; } } }
/** * Get price test object from the price cookie * * @since 1.1.0 * * @param string $plugin Slug of plugin edd|woo * @param int $id Product ID * @param array|null $cookie * * @return \ingot\testing\object\price\test */ public static function get_price_test_from_cookie($plugin, $id, $cookie = null) { if (in_array($plugin, types::allowed_price_types())) { if (is_null($cookie)) { $cookie = init::get_instance()->get_ingot_cookie(false)['price']; } if (isset($cookie[$plugin][$id])) { $test = $cookie[$plugin][$id]; return self::inflate_price_test($test); } } }
/** * Validate item click type * * @since 0.0.7 * * @access protected * * @param array $data Item config * * @return bool True if valid, false if not */ protected static function validate_click_type($data) { if (!in_array($data['sub_type'], types::allowed_click_types())) { return false; } return true; }
/** * Validate sub_type click type * * @since 0.4.0 * * @param $value * * @return bool */ public function allowed_sub_tupe($value, $request) { $type = $request->get_param('type'); if ('click' == $type) { return in_array($value, types::allowed_click_types()); } else { return in_array($value, types::allowed_price_types()); } }
/** * 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())); } }
/** * Set product property * * @since 1.1.0 * * @access private */ private function set_product() { if (!is_object($this->product)) { $group = group::read($this->variant['group_ID']); if (in_array($group['sub_type'], types::allowed_price_types())) { $this->product = price::get_product($group); } } }