private function _createPage($slug, $data) { $wpdb = $this->wp->getWPDB(); $slug = esc_sql(_x($slug, 'page_slug', 'jigoshop')); $page_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_status = 'publish' AND post_status <> 'trash' LIMIT 1", $slug)); if (!$page_id) { Registry::getInstance(JIGOSHOP_LOGGER)->addDebug(sprintf('Installing page "%s".', $slug)); $data['post_name'] = $slug; $page_id = $this->wp->wpInsertPost($data); } $this->options->setPageId($slug, $page_id); $this->options->update('advanced.pages.' . $slug, $page_id); }
/** * Validate and sanitize input values. * * @param array $settings Input fields. * * @return array Sanitized and validated output. * @throws ValidationException When some items are not valid. */ public function validate($settings) { // This is required when installin emails this function is used twice, // once for advanced settings and once for all jigoshop settings. if (isset($settings['general']) && is_array($settings['general'])) { return $settings; } if (isset($settings['install_emails'])) { unset($settings['install_emails']); // TODO add this to WPAL remove_all_actions('save_post_' . Types\Email::NAME); $this->di->get('jigoshop.installer')->installEmails(); $this->messages->addNotice(__('Emails created.', 'jigoshop')); } $settings['automatic_complete'] = $settings['automatic_complete'] == 'on'; $settings['automatic_reset'] = $settings['automatic_reset'] == 'on'; $settings['products_list']['variations_sku_stock'] = $settings['products_list']['variations_sku_stock'] == 'on'; if (!in_array($settings['cache'], array_keys($this->caches))) { $this->messages->addWarning(sprintf(__('Invalid cache mechanism: "%s". Value set to %s.', 'jigoshop'), $settings['cache'], $this->caches['simple'])); $settings['cache'] = 'simple'; } $settings['ignore_meta_queries'] = $settings['ignore_meta_queries'] == 'on'; if (isset($settings['api'], $settings['api']['keys'])) { $settings['api']['keys'] = array_filter($settings['api']['keys'], function ($item) { return !empty($item['key']); }); $settings['api']['keys'] = array_map(function ($item) { return array_merge(array('key' => '', 'permissions' => array()), $item); }, $settings['api']['keys']); } $pages = $this->_getPages(); if (!in_array($settings['pages']['shop'], array_keys($pages))) { $this->messages->addError(__('Invalid shop page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::SHOP, $settings['pages']['shop']); } if (!in_array($settings['pages']['cart'], array_keys($pages))) { $this->messages->addError(__('Invalid cart page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::CART, $settings['pages']['cart']); } if (!in_array($settings['pages']['checkout'], array_keys($pages))) { $this->messages->addError(__('Invalid checkout page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::CHECKOUT, $settings['pages']['checkout']); } if (!in_array($settings['pages']['checkout_thank_you'], array_keys($pages))) { $this->messages->addError(__('Invalid thank you page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::THANK_YOU, $settings['pages']['checkout_thank_you']); } if (!in_array($settings['pages']['account'], array_keys($pages))) { $this->messages->addError(__('Invalid My account page, please select again.', 'jigoshop')); } else { $this->options->setPageId(Pages::ACCOUNT, $settings['pages']['account']); } if (!empty($settings['pages']['terms']) && $settings['pages']['terms'] != 0 && !in_array($settings['pages']['terms'], array_keys($pages))) { $this->messages->addError(__('Invalid terms page, please select again.', 'jigoshop')); } return $settings; }