/** * Create a product. * * @param array $args * * @return int|WP_Error */ function create_object($args) { $args['post_type'] = 'it_exchange_prod'; $args['post_status'] = 'publish'; $product_id = parent::create_object($args); if (is_wp_error($product_id) || !$product_id) { return $product_id; } $defaults = array('product_type' => 'digital-downloads-product-type', 'show_in_store' => true, 'limit' => 2, 'key-type' => 'random', 'version' => '1.0', 'base-price' => '99.00', 'update-file' => ''); $args = wp_parse_args($args, $defaults); if (empty($args['update-file'])) { $name = get_the_title($product_id); $name .= '.zip'; $attachment_factory = new WP_UnitTest_Factory_For_Attachment(); $attachment_id = $attachment_factory->create_object($name, $product_id, array('post_mime_type' => 'application/zip')); $download_id = parent::create_object(array('post_type' => 'it_exchange_download')); update_post_meta($download_id, '_it-exchange-download-info', array('source' => wp_get_attachment_url($attachment_id), 'product_id' => $product_id, 'download_id' => $download_id, 'name' => $name)); $args['update-file'] = $download_id; } if (!empty($args['product_type'])) { update_post_meta($product_id, '_it_exchange_product_type', $args['product_type']); } update_post_meta($product_id, '_it-exchange-visibility', empty($args['show_in_store']) ? 'hidden' : 'visible'); it_exchange_update_product_feature($product_id, 'licensing', array('enabled' => true, 'limit' => $args['limit'], 'key-type' => $args['key-type'], 'version' => $args['version'], 'update-file' => $args['update-file'])); if (isset($args['interval'])) { it_exchange_update_product_feature($product_id, 'recurring-payments', 'on'); it_exchange_update_product_feature($product_id, 'recurring-payments', $args['interval'], array('setting' => 'interval')); it_exchange_update_product_feature($product_id, 'recurring-payments', $args['interval-count'], array('setting' => 'interval-count')); } return $product_id; }
/** * This saves the values. * * @since 1.5 * * @return void */ public function save_feature_on_product_save() { // Abort if we don't have a product ID $product_id = empty($_POST['ID']) ? false : $_POST['ID']; if (!$product_id) { return; } $data = array('rate' => sanitize_text_field($_POST['_affwp_it-exchange_product_rate']), 'disabled' => (bool) isset($_POST['_affwp_it-exchange_referrals_disabled']) ? 1 : false); it_exchange_update_product_feature($product_id, $this->slug, $data); }
/** * This saves the value. * * @since 1.0 */ public function save_feature_on_product_save() { // Abort if we don't have a product ID $product_id = empty($_POST['ID']) ? false : $_POST['ID']; if (!$product_id) { return; } $data = $_POST['itelic_upgrade']; $data['enable'] = isset($data['enable']) ? it_exchange_str_true($data['enable']) : false; it_exchange_update_product_feature($product_id, $this->slug, $data); }
/** * This saves the value. * * @since 1.0 */ public function save_feature_on_product_save() { // Abort if we don't have a product ID $product_id = empty($_POST['ID']) ? false : $_POST['ID']; if (!$product_id) { return; } $prev = it_exchange_get_product_feature($product_id, $this->slug); $data = $_POST['itelic']; $data['enabled'] = isset($data['enabled']) ? it_exchange_str_true($data['enabled']) : false; $data['enabled_variant_activations'] = isset($data['enabled_variant_activations']) ? it_exchange_str_true($data['enabled_variant_activations']) : false; $data['online-software'] = isset($data['online-software']) ? it_exchange_str_true($data['online-software']) : false; if (!empty($prev['version'])) { unset($data['version']); } $first_release = get_post_meta($product_id, '_itelic_first_release', true); if (!$first_release && isset($data['update-file']) && $data['update-file']) { $download = $data['update-file']; $download_meta = get_post_meta($download, '_it-exchange-download-info', true); if (empty($download_meta)) { return; } $url = $download_meta['source']; /** * @var \wpdb $wpdb */ global $wpdb; $ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE guid = %s", $url)); $file = get_post($ID); if ($file->post_type == 'attachment') { $product = itelic_get_product($product_id); if (isset($data['version'])) { $version = $data['version']; } elseif (isset($prev['version'])) { $version = $prev['version']; } else { $version = ''; } $type = Release::TYPE_MAJOR; $status = get_post_status($product_id) == 'publish' ? Release::STATUS_ACTIVE : Release::STATUS_DRAFT; $changelog = '<ul><li>' . __("Initial release.", Plugin::SLUG) . '</li></ul>'; if ($version) { try { $args = array('product' => $product, 'file' => $file, 'version' => $version, 'type' => $type, 'status' => $status, 'changelog' => $changelog); $release = itelic_create_release($args); if ($release && !is_wp_error($release)) { update_post_meta($product_id, '_itelic_first_release', $release->get_pk()); } } catch (\Exception $e) { } } } } it_exchange_update_product_feature($product_id, $this->slug, $data); }
/** * This saves the value. * * @since 1.0 */ public function save_feature_on_product_save() { // Abort if we don't have a product ID $product_id = empty($_POST['ID']) ? false : $_POST['ID']; if (!$product_id) { return; } $data = $_POST['itelic_readme']; $data['enable'] = isset($data['enable']) ? it_exchange_str_true($data['enable']) : false; $last_updated = \ITELIC\make_local_time($data['last_updated']); $data['last_updated'] = $last_updated->getTimestamp(); it_exchange_update_product_feature($product_id, $this->slug, $data); }
/** * Update a product feature. * * @since 1.0 * * @param string $feature * @param mixed $data * @param array $options * * @return bool */ public function update_feature($feature, $data, $options = array()) { return it_exchange_update_product_feature($this->ID, $feature, $data, $options); }