<?php /* * Settings class. */ if (!defined('ABSPATH')) { exit; } // Exit if accessed directly if (class_exists('WC_Settings_Page')) { TM_EPO_ADMIN_GLOBAL()->tm_load_scripts(); class TM_EPO_ADMIN_SETTINGS extends WC_Settings_Page { var $other_settings = 0; var $other_settings_headers = 0; /** * Constructor. */ public function __construct() { $this->id = TM_ADMIN_SETTINGS_ID; $this->label = __('Extra Product Options', TM_EPO_TRANSLATION); $this->tab_count = 0; add_filter('woocommerce_settings_tabs_array', array($this, 'add_settings_page'), 20); add_action('woocommerce_settings_' . $this->id, array($this, 'output')); add_action('woocommerce_settings_save_' . $this->id, array($this, 'save')); add_action('woocommerce_admin_field_tm_tabs_header', array($this, 'tm_tabs_header_setting')); add_action('woocommerce_settings_' . 'epo_page_options', array($this, 'tm_settings_hook')); add_action('woocommerce_settings_' . 'epo_page_options' . '_end', array($this, 'tm_settings_hook_end')); add_action('woocommerce_settings_' . 'epo_page_options' . '_after', array($this, 'tm_settings_hook_after')); add_action('woocommerce_settings_' . $this->id, array($this, 'tm_settings_hook_all_end'));
/** * Save our meta data */ public function tm_save_postdata($post_id, $post_object) { if (empty($_POST) || !isset($_POST['post_type']) || TM_EPO_GLOBAL_POST_TYPE != $_POST['post_type']) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if ($post_object->post_type == 'revision') { return; } check_admin_referer('update-post_' . $post_id); if (!current_user_can('edit_post', $post_id)) { return $post_id; } if (!isset($_SESSION)) { session_start(); } $import = false; if (isset($_SESSION['import_csv'])) { $import = $_SESSION['import_csv']; } if (isset($_POST['tm_meta_serialized'])) { $tm_metas = $_POST['tm_meta_serialized']; $tm_metas = stripslashes_deep($tm_metas); $tm_metas = rawurldecode($tm_metas); $tm_metas = nl2br($tm_metas); $tm_metas = json_decode($tm_metas, true); if ($tm_metas) { if (!empty($import)) { $tm_metas = $this->import_array_merge($tm_metas, $import); unset($_SESSION['import_csv']); } if (!empty($tm_metas) && is_array($tm_metas) && isset($tm_metas['tm_meta']) && is_array($tm_metas['tm_meta'])) { $tm_meta = $tm_metas['tm_meta']; $old_data = get_post_meta($post_id, 'tm_meta', true); $this->tm_save_meta($post_id, $tm_meta, $old_data, 'tm_meta'); } } } elseif (isset($_POST['tm_meta_serialized_wpml'])) { $tm_metas = $_POST['tm_meta_serialized_wpml']; $tm_metas = stripslashes_deep($tm_metas); $tm_metas = rawurldecode($tm_metas); $tm_metas = nl2br($tm_metas); $tm_metas = json_decode($tm_metas, true); if ($tm_metas) { $old_data = get_post_meta($post_id, 'tm_meta_wpml', true); if (!empty($tm_metas) && is_array($tm_metas) && isset($tm_metas['tm_meta']) && is_array($tm_metas['tm_meta'])) { $tm_meta = $tm_metas['tm_meta']; TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, $tm_meta, $old_data, 'tm_meta_wpml'); } else { TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, false, $old_data, 'tm_meta_wpml'); } } } if (isset($_POST['tm_meta_product_ids'])) { if (!is_array($_POST['tm_meta_product_ids'])) { $_POST['tm_meta_product_ids'] = explode(",", $_POST['tm_meta_product_ids']); } $old_data = get_post_meta($post_id, 'tm_meta_product_ids', true); $this->tm_save_meta($post_id, $_POST['tm_meta_product_ids'], $old_data, 'tm_meta_product_ids'); } else { $old_data = get_post_meta($post_id, 'tm_meta_product_ids', true); $this->tm_save_meta($post_id, array(), $old_data, 'tm_meta_product_ids'); } if (isset($_POST['tm_meta_disable_categories'])) { $old_data = get_post_meta($post_id, 'tm_meta_disable_categories', true); $this->tm_save_meta($post_id, $_POST['tm_meta_disable_categories'], $old_data, 'tm_meta_disable_categories'); } else { $old_data = get_post_meta($post_id, 'tm_meta_disable_categories', true); $this->tm_save_meta($post_id, 0, $old_data, 'tm_meta_disable_categories'); } // WPML fields if (TM_EPO_WPML()->is_active()) { if (isset($_POST[TM_EPO_WPML_PARENT_POSTID])) { $old_data = get_post_meta($post_id, TM_EPO_WPML_PARENT_POSTID, true); $this->tm_save_meta($post_id, $_POST[TM_EPO_WPML_PARENT_POSTID], $old_data, TM_EPO_WPML_PARENT_POSTID); } if (isset($_POST[TM_EPO_WPML_LANG_META]) && !empty($_POST[TM_EPO_WPML_LANG_META])) { $old_data = get_post_meta($post_id, TM_EPO_WPML_LANG_META, true); $this->tm_save_meta($post_id, $_POST[TM_EPO_WPML_LANG_META], $old_data, TM_EPO_WPML_LANG_META); } else { $old_data = get_post_meta($post_id, TM_EPO_WPML_LANG_META, true); $this->tm_save_meta($post_id, TM_EPO_WPML()->get_default_lang(), $old_data, TM_EPO_WPML_LANG_META); } } }
/** * Generates all hidden elements for use in jQuery. * * @since 1.0.0 * @access public */ public function print_elements($echo = 0, $wpml_is_original_product = true) { $out1 = ''; //$drag_elements=''; foreach ($this->get_elements() as $element => $settings) { if (isset($this->elements_array[$element])) { /*if(empty($settings['no_selection'])){ $drag_elements .="<div data-element='".$element."' class='ditem element-".$element."'><div class='tm-label'><i class='tmfa tcfa ".$settings["icon"]."'></i> ".$settings["name"]."</div></div>"; }*/ $_temp_option = $this->elements_array[$element]; $internal_name_input = '<input type="hidden" value="' . esc_attr($settings["name"]) . '" name="tm_meta[tmfbuilder][' . $element . '_internal_name][]" class="t tm-internal-name">'; $out1 .= "<div class='bitem element-" . $element . " " . $settings["width"] . "'>" . "<input class='builder_element_type' name='tm_meta[tmfbuilder][element_type][]' type='hidden' value='" . $element . "' />" . "<input class='div_size' name='tm_meta[tmfbuilder][div_size][]' type='hidden' value='" . $settings["width"] . "' />" . "<div class='hstc2 closed'><div class='tmicon tcfa tcfa-sort move'></div>" . "<div class='tmicon tcfa tcfa-minus minus'></div><div class='tmicon tcfa tcfa-plus plus'></div>" . "<div class='tmicon size'>" . $settings["width_display"] . "</div>" . "<div class='tmicon tcfa tcfa-pencil edit'></div><div class='tmicon tcfa tcfa-copy clone'></div><div class='tmicon tcfa tcfa-times delete'></div><span class='tm-element-label'>" . $settings["name"] . "</span>" . $internal_name_input . "<div class='tm-label-icon'><i class='tmfa tcfa " . $settings["icon"] . "'></i></div>" . "<div class='tm-label'>" . $settings["name"] . "</div><div class='inside'><div class='manager'>" . "<div class='builder_element_wrap'>"; foreach ($_temp_option as $key => $value) { $out1 .= TM_EPO_HTML()->tm_make_field($value, 0); } $out1 .= "</div></div></div></div></div>"; } } $drag_elements = TM_EPO_ADMIN_GLOBAL()->js_element_data("ditem"); $out = '<div class="builder_elements closed"><div class="tc-handle tmicon tcfa tcfa-caret-up"></div><div class="builder_hidden_elements" data-template="' . esc_html(json_encode(array("html" => $out1))) . '"></div>' . '<div class="builder_hidden_section" data-template="' . esc_html(json_encode(array("html" => $this->section_elements(0, $wpml_is_original_product)))) . '"></div>' . ($wpml_is_original_product ? '<div class="builder_drag_elements">' . $drag_elements . '</div>' : '') . ($wpml_is_original_product ? '<div class="builder_actions">' . '<a class="builder_add_section tm-button bsbb" href="#"><i class="tcfa tcfa-plus-square"></i> ' . __("Add section", TM_EPO_TRANSLATION) . '</a>' . '</div>' : '') . "</div>"; if (empty($echo)) { return $out; } else { echo $out; } }
_e('BUILDER', TM_EPO_TRANSLATION); ?> </span> <span class="button button-primary button-large tm_select_mode tm_local_select"><?php _e('LOCAL', TM_EPO_TRANSLATION); ?> </span> <span class="button button-primary button-large tm_select_mode tm_settings_select"><?php _e('SETTINGS', TM_EPO_TRANSLATION); ?> </span> </p> </div> <div class="tm_mode_builder"> <?php TM_EPO_ADMIN_GLOBAL()->tm_form_fields_builder_meta_box($post); ?> </div> <div class="tm_mode_local tm_wrapper"> <?php if (TM_EPO_WPML()->is_original_product($post_id)) { include 'html-tm-epo.php'; } else { ?> <div id="message" class="tm-inner inline woocommerce-message"> <?php echo __('To translate the strings for the local options please use WPML interface.', TM_EPO_TRANSLATION); ?> </div><?php } ?>
} add_filter('woocommerce_get_settings_pages', 'tm_add_epo_admin_settings'); /* woocommerce_bundle_rate_shipping chosen fix by removing */ add_action('admin_enqueue_scripts', 'tm_fix_woocommerce_bundle_rate_shipping_scripts', 99); function tm_fix_woocommerce_bundle_rate_shipping_scripts() { if (!(isset($_GET['page']) && isset($_GET['tab']) && $_GET['page'] == 'wc-settings' && $_GET['tab'] == 'shipping')) { wp_dequeue_script('woocommerce_bundle_rate_shipping_admin_js'); } } /* Load Globals Admin Interface */ function TM_EPO_ADMIN_GLOBAL() { return TM_EPO_ADMIN_Global_base::instance(); } TM_EPO_ADMIN_GLOBAL()->init(); /* Load Admin Interface */ function TM_EPO_ADMIN() { return TM_EPO_Admin_base::instance(); } TM_EPO_ADMIN()->init(); } /** * Load main plugin interface */ function TM_EPO() { return TM_Extra_Product_Options::instance(); } TM_EPO()->init();
public function save_meta($post_id) { global $woocommerce, $wpdb; $attributes = (array) maybe_unserialize(get_post_meta($post_id, '_product_attributes', true)); if (isset($_POST['variable_sku']) || isset($_POST['_sku'])) { $_post_id = isset($_POST['tmcp_post_id']) ? $_POST['tmcp_post_id'] : array(); $tmcp_regular_price = isset($_POST['tmcp_regular_price']) ? $_POST['tmcp_regular_price'] : array(); $tmcp_regular_price_type = isset($_POST['tmcp_regular_price_type']) ? $_POST['tmcp_regular_price_type'] : array(); $tmcp_enabled = isset($_POST['tmcp_enabled']) ? $_POST['tmcp_enabled'] : array(); $tmcp_required = isset($_POST['tmcp_required']) ? $_POST['tmcp_required'] : array(); $tmcp_hide_price = isset($_POST['tmcp_hide_price']) ? $_POST['tmcp_hide_price'] : array(); $tmcp_limit = isset($_POST['tmcp_limit']) ? $_POST['tmcp_limit'] : array(); $tmcp_menu_order = isset($_POST['tmcp_menu_order']) ? $_POST['tmcp_menu_order'] : array(); $tmcp_attribute = isset($_POST['tmcp_attribute']) ? $_POST['tmcp_attribute'] : array(); $tmcp_type = isset($_POST['tmcp_type']) ? $_POST['tmcp_type'] : array(); $tm_meta_cpf = isset($_POST['tm_meta_cpf']) ? $_POST['tm_meta_cpf'] : array(); // update custom product settings update_post_meta($post_id, 'tm_meta_cpf', $tm_meta_cpf); if (isset($_POST['tm_meta_serialized'])) { $tm_metas = $_POST['tm_meta_serialized']; $tm_metas = stripslashes_deep($tm_metas); $tm_metas = rawurldecode($tm_metas); $tm_metas = nl2br($tm_metas); $tm_metas = json_decode($tm_metas, true); if ($tm_metas || is_array($tm_metas)) { if (!isset($_SESSION)) { session_start(); } $import = false; if (isset($_SESSION['import_csv'])) { $import = $_SESSION['import_csv']; } if (!empty($import)) { $tm_metas = TM_EPO_ADMIN_GLOBAL()->import_array_merge($tm_metas, $import); unset($_SESSION['import_csv']); } $old_data = get_post_meta($post_id, 'tm_meta', true); if (!empty($tm_metas) && is_array($tm_metas) && isset($tm_metas['tm_meta']) && is_array($tm_metas['tm_meta'])) { $tm_meta = $tm_metas['tm_meta']; TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, $tm_meta, $old_data, 'tm_meta'); } else { TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, false, $old_data, 'tm_meta'); } } } elseif (isset($_POST['tm_meta_serialized_wpml'])) { $tm_metas = $_POST['tm_meta_serialized_wpml']; $tm_metas = stripslashes_deep($tm_metas); $tm_metas = rawurldecode($tm_metas); $tm_metas = nl2br($tm_metas); $tm_metas = json_decode($tm_metas, true); if ($tm_metas) { $old_data = get_post_meta($post_id, 'tm_meta_wpml', true); if (!empty($tm_metas) && is_array($tm_metas) && isset($tm_metas['tm_meta']) && is_array($tm_metas['tm_meta'])) { $tm_meta = $tm_metas['tm_meta']; TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, $tm_meta, $old_data, 'tm_meta_wpml'); } else { TM_EPO_ADMIN_GLOBAL()->tm_save_meta($post_id, false, $old_data, 'tm_meta_wpml'); } } } if (!empty($_post_id)) { global $wpdb; $max_loop = max(array_keys($_post_id)); for ($i = 0; $i <= $max_loop; $i++) { if (!isset($_post_id[$i])) { continue; } $tmcp_id = absint($_post_id[$i]); // This will always be update post if ($tmcp_id) { // Enabled or disabled $post_status = isset($tmcp_enabled[$i]) ? 'publish' : 'private'; // Generate a useful post title $post_title = sprintf(__('TM Extra Product Option #%s of %s', TM_EPO_TRANSLATION), absint($tmcp_id), esc_html(get_the_title($post_id))); /*wp_update_post( wp_slash( array( 'ID' => $tmcp_id, 'post_status' => $post_status, 'post_title' => $post_title, 'menu_order' => $tmcp_menu_order[ $i ] )));*/ $data = wp_slash(array('post_status' => $post_status, 'post_title' => $post_title, 'menu_order' => $tmcp_menu_order[$i])); $data = wp_unslash($data); $where = array('ID' => $tmcp_id); if (false === $wpdb->update($wpdb->posts, $data, $where)) { if ($wp_error) { return new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error); } else { return 0; } } // Update post meta // Price handling $clean_prices = array(); $clean_prices_type = array(); if (isset($tmcp_regular_price[$i])) { foreach ($tmcp_regular_price[$i] as $key => $value) { foreach ($value as $k => $v) { if ($v !== '') { $clean_prices[$key][$k] = wc_format_decimal($v); } } } } if (isset($tmcp_regular_price_type[$i])) { foreach ($tmcp_regular_price_type[$i] as $key => $value) { foreach ($value as $k => $v) { $clean_prices_type[$key][$k] = $v; } } } $regular_price = $clean_prices; $regular_price_type = $clean_prices_type; update_post_meta($tmcp_id, '_regular_price', $regular_price); update_post_meta($tmcp_id, '_regular_price_type', $regular_price_type); $post_required = isset($tmcp_required[$i]) ? 1 : ''; $post_hide_price = isset($tmcp_hide_price[$i]) ? 1 : ''; $post_limit = isset($tmcp_limit[$i]) ? $tmcp_limit[$i] : ''; update_post_meta($tmcp_id, 'tmcp_required', $post_required); update_post_meta($tmcp_id, 'tmcp_hide_price', $post_hide_price); update_post_meta($tmcp_id, 'tmcp_limit', $post_limit); update_post_meta($tmcp_id, 'tmcp_attribute', $tmcp_attribute[$i]); update_post_meta($tmcp_id, 'tmcp_attribute_is_taxonomy', $attributes[$tmcp_attribute[$i]]['is_taxonomy']); update_post_meta($tmcp_id, 'tmcp_type', $tmcp_type[$i]); } } } } }