/** * Save Force SSL option to post or page * * @param int $post_id * @return int $post_id */ public function post_save($post_id) { if (array_key_exists($this->getPlugin()->getSlug(), $_POST)) { if (!wp_verify_nonce($_POST[$this->getPlugin()->getSlug()], $this->getPlugin()->getSlug())) { return $post_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } if (@$_POST['post_type'] == 'page') { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } $force_ssl = @$_POST['force_ssl'] == 1 ? true : false; if ($force_ssl) { update_post_meta($post_id, 'force_ssl', 1); } else { delete_post_meta($post_id, 'force_ssl'); } $force_ssl_children = @$_POST['force_ssl_children'] == 1 ? true : false; if ($force_ssl_children) { update_post_meta($post_id, 'force_ssl_children', 1); } else { delete_post_meta($post_id, 'force_ssl_children'); } } return $post_id; }
public function setUp() { global $wpdb; parent::setUp(); register_taxonomy('edu_test_tax_1', 'post'); register_taxonomy('edu_test_tax_2', 'post'); $t1 = wp_insert_term('Edu', 'edu_test_tax_1'); $t2 = wp_insert_term('Edu', 'edu_test_tax_2'); $t3 = wp_insert_term('Edu', 'ib_educator_category'); $t4 = wp_insert_term('Mathematics', 'ib_educator_category'); // Arbitrary term. $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t2['term_taxonomy_id']), array('%d'), array('%d')); $wpdb->update($wpdb->term_taxonomy, array('term_id' => $t1['term_id']), array('term_taxonomy_id' => $t3['term_taxonomy_id']), array('%d'), array('%d')); $t2['term_id'] = $t1['term_id']; $t3['term_id'] = $t1['term_id']; // Create membership. $post_id = wp_insert_post(array('post_type' => 'ib_edu_membership', 'post_name' => 'edu-membership-1', 'post_title' => 'edu membership 1', 'post_status' => 'publish')); $ms = Edr_Memberships::get_instance(); $meta = $ms->get_membership_meta(); $meta['price'] = '10.05'; $meta['period'] = ''; $meta['duration'] = ''; $meta['categories'] = array($t3['term_id'], $t4['term_id']); update_post_meta($post_id, '_ib_educator_membership', $meta); $this->posts[] = $post_id; $this->terms = array('term1' => $t1, 'term2' => $t2, 'term3' => $t3, 'term4' => $t4); }
/** * Adds the post to the relevant site * * @param $post * * @param $blog * * @return int|\WP_Error */ public function add_post($post, $blog) { if (!$blog || $this->post_exists($post, $blog)) { return FALSE; } $original_post_id = $post->ID; // store temp so that we can return it to the original post $source_content_id = Wpml2mlp_Helper::get_default_post_ID($post); $meta = get_post_meta($post->ID); $post->ID = NULL; // reset the post_id, new one will be created switch_to_blog((int) $blog['blog_id']); $new_post_id = wp_insert_post((array) $post); if ($new_post_id > 0) { foreach ($meta as $key => $value) { update_post_meta($new_post_id, $key, $value[0]); } } restore_current_blog(); if (0 < $new_post_id) { $this->content_relations->set_relation(Wpml2mlp_Helper::get_default_blog(), (int) $blog['blog_id'], $source_content_id, $new_post_id, $post->post_type); } $post->ID = $original_post_id; return $new_post_id; }
/** * When the post is saved, saves our custom data. * * @param int $post_id The ID of the post being saved. */ function perpageath_save_postdata($post_id) { /* * We need to verify this came from the our screen and with proper authorization, * because save_post can be triggered at other times. */ // Check if our nonce is set. if (!isset($_POST['athcontent'])) { return $post_id; } $nonce = $_POST['athcontent']; // Verify that the nonce is valid. if (!wp_verify_nonce($nonce, 'athcallback')) { return $post_id; } // If this is an autosave, our form has not been submitted, so we don't want to do anything. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check the user's permissions. if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } /* OK, its safe for us to save the data now. */ // Sanitize user input. $mydata = esc_sql(str_replace(array("\r\n", "\r", "\n"), '%BREAK%', $_POST['per-page-ath'])); // Update the meta field in the database. update_post_meta($post_id, 'per-page-ath-content', $mydata); }
/** * Runs on plugin activations * - Transfer any settings which may have been set in the Lite version of the plugin * - Creates a post type 'mc4wp-form' and enters the form mark-up from the Lite version */ function mc4wp_pro_install() { // check if PRO option exists and contains data entered by user $pro_options = get_option('mc4wp', false); if ($pro_options !== false) { return false; } $default_options = array(); $default_options['general'] = array('api_key' => '', 'license_key' => ''); $default_options['checkbox'] = array('label' => 'Sign me up for the newsletter!', 'precheck' => 1, 'css' => 0, 'show_at_comment_form' => 0, 'show_at_registration_form' => 0, 'show_at_multisite_form' => 0, 'show_at_buddypress_form' => 0, 'show_at_edd_checkout' => 0, 'show_at_woocommerce_checkout' => 0, 'show_at_bbpress_forms' => 0, 'lists' => array(), 'double_optin' => 1, 'send_welcome' => 0); $default_options['form'] = array('css' => 0, 'custom_theme_color' => '#1af', 'ajax' => 1, 'double_optin' => 1, 'update_existing' => 0, 'replace_interests' => 1, 'send_welcome' => 0, 'text_success' => 'Thank you, your sign-up request was successful! Please check your e-mail inbox.', 'text_error' => 'Oops. Something went wrong. Please try again later.', 'text_invalid_email' => 'Please provide a valid email address.', 'text_already_subscribed' => 'Given email address is already subscribed, thank you!', 'redirect' => '', 'hide_after_success' => 0, 'send_email_copy' => 0); $lite_settings = array('general' => (array) get_option('mc4wp_lite'), 'checkbox' => (array) get_option('mc4wp_lite_checkbox'), 'form' => (array) get_option('mc4wp_lite_form')); foreach ($default_options as $group_key => $options) { foreach ($options as $option_key => $option_value) { if (isset($lite_settings[$group_key][$option_key]) && !empty($lite_settings[$group_key][$option_key])) { $default_options[$group_key][$option_key] = $lite_settings[$group_key][$option_key]; } } } // Transfer form from Lite, but only if no Pro forms exist yet. $forms = get_posts(array('post_type' => 'mc4wp-form', 'post_status' => 'publish')); if (false == $forms) { // no forms found, try to transfer from lite. $form_markup = isset($lite_settings['form']['markup']) ? $lite_settings['form']['markup'] : "<p>\n\t<label for=\"mc4wp_email\">Email address: </label>\n\t<input type=\"email\" id=\"mc4wp_email\" name=\"EMAIL\" required placeholder=\"Your email address\" />\n</p>\n\n<p>\n\t<input type=\"submit\" value=\"Sign up\" />\n</p>"; $form_ID = wp_insert_post(array('post_type' => 'mc4wp-form', 'post_title' => 'Sign-Up Form #1', 'post_content' => $form_markup, 'post_status' => 'publish')); $lists = isset($lite_settings['form']['lists']) ? $lite_settings['form']['lists'] : array(); update_post_meta($form_ID, '_mc4wp_settings', array('lists' => $lists)); update_option('mc4wp_default_form_id', $form_ID); } // store options update_option('mc4wp', $default_options['general']); update_option('mc4wp_checkbox', $default_options['checkbox']); update_option('mc4wp_form', $default_options['form']); }
function save_meta_box_data($post_id) { if (!isset($_POST['portfolio_meta_box_nonce'])) { return; } // Verify that the nonce is valid. if (!wp_verify_nonce($_POST['portfolio_meta_box_nonce'], 'portfolio_meta_box')) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (isset($_POST['post_type']) && 'portfolio' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } if (!isset($_POST['publishing_year'])) { return; } $my_data = sanitize_text_field($_POST['publishing_year']); update_post_meta($post_id, 'publishing_year', $my_data); }
public function do_save($return_val, $data, $module) { if (empty($data['attachment_url'])) { return false; } $bits = file_get_contents($data['attachment_url']); $filename = $this->faker->uuid() . '.jpg'; $upload = wp_upload_bits($filename, null, $bits); $data['guid'] = $upload['url']; $data['post_mime_type'] = 'image/jpeg'; // Insert the attachment. $attach_id = wp_insert_attachment($data, $upload['file'], 0); if (!is_numeric($attach_id)) { return false; } if (!function_exists('wp_generate_attachment_metadata')) { // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. require_once ABSPATH . 'wp-admin/includes/image.php'; } // Generate the metadata for the attachment, and update the database record. update_post_meta($attach_id, '_wp_attachment_metadata', wp_generate_attachment_metadata($attach_id, $upload['file'])); // Flag the Object as FakerPress update_post_meta($attach_id, self::$flag, 1); return $attach_id; }
/** * updates the post_meta of the current object with the given value * * @param string $field * @param mixed $value * @nodoc */ function update($field, $value) { if (isset($this->ID)) { update_post_meta($this->ID, $field, $value); $this->{$field} = $value; } }
function cresta_save_meta_box_data($post_id) { if (!isset($_POST['cresta_meta_box_nonce'])) { return; } if (!wp_verify_nonce($_POST['cresta_meta_box_nonce'], 'cresta_meta_box')) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } if (isset($_POST['cresta_new_field'])) { update_post_meta($post_id, '_get_cresta_plugin', $_POST['cresta_new_field']); } else { delete_post_meta($post_id, '_get_cresta_plugin'); } }
/** * Save metabox data. * * @param int $post_id Current post type ID. * * @return void */ public function save($post_id) { // Verify nonce. if (!isset($_POST['wcboleto_metabox_nonce']) || !wp_verify_nonce($_POST['wcboleto_metabox_nonce'], basename(__FILE__))) { return $post_id; } // Verify if this is an auto save routine. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions. if ('shop_order' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } if (isset($_POST['wcboleto_expiration_date']) && !empty($_POST['wcboleto_expiration_date'])) { // Gets boleto data. $boleto_data = get_post_meta($post_id, 'wc_boleto_data', true); $boleto_data['data_vencimento'] = sanitize_text_field($_POST['wcboleto_expiration_date']); // Update boleto data. update_post_meta($post_id, 'wc_boleto_data', $boleto_data); // Gets order data. $order = new WC_Order($post_id); // Add order note. $order->add_order_note(sprintf(__('Expiration date updated to: %s', 'wcboleto'), $boleto_data['data_vencimento'])); // Send email notification. $this->email_notification($order, $boleto_data['data_vencimento']); } }
function check_three_col_table() { global $post; if (get_post_meta($post->ID, "num_three_col_tables", $single = true) == "") { update_post_meta($post->ID, 'num_three_col_tables', 0, true); } }
function kopa_click_like_button() { check_ajax_referer('kopa_click_like_button', 'ajax_nonce'); if (!empty($_POST['post_id'])) { $result = array('status' => 'disable', 'total' => 0); $post_id = (int) $_POST['post_id']; $status = $_POST['status']; $include_text = $_POST['include_text']; $public_key = KOPA_OPT_PREFIX . 'likes'; $single_key = KOPA_OPT_PREFIX . 'like_by_' . KopaUtil::get_client_IP(); $total = KopaUtil::get_likes($post_id); $is_liked = KopaUtil::is_liked($post_id); if ('enable' == $status && !$is_liked) { $total++; update_post_meta($post_id, $single_key, true); update_post_meta($post_id, $public_key, abs($total)); $result['class'] = 'kopa-button-likes-disable'; } else { $total--; delete_post_meta($post_id, $single_key); update_post_meta($post_id, $public_key, abs($total)); $result['class'] = 'kopa-button-likes-enable'; } if ($include_text) { if ($total < 2) { $total .= __(' Like', kopa_get_domain()); } else { $total .= __(' Likes', kopa_get_domain()); } } $result['total'] = $total; echo json_encode($result); } exit; }
function update_sale_price($post_id) { if (get_post_type($post_id) == $this->post_type) { $price = STRental::get_price($post_id); update_post_meta($post_id, 'sale_price', $price); } }
function ultimatum_meta_save_postdata( $post_id, $post ) { //echo '<pre>';print_r($_POST);die(); //* Verify the nonce if ( ! isset( $_POST[ 'ultimatum_additional_meta_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'ultimatum_additional_meta_nonce' ], 'ultimatum_additional_meta' ) ) return; //* Don't try to save the data under autosave, ajax, or future post. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return; if ( defined( 'DOING_CRON' ) && DOING_CRON ) return; //* Grab the post object $post = get_post( $post ); //* Don't save if WP is creating a revision (same as DOING_AUTOSAVE?) if ( 'revision' === $post->post_type ) return; //* Check that the user is allowed to edit the post if ( ! current_user_can( 'edit_post', $post->ID ) ) return; $mydata = $_POST['ultimatum_video']; update_post_meta($post->ID, 'ultimatum_video', $mydata); $mydata = $_POST['ultimatum_author']; update_post_meta($post->ID, 'ultimatum_author', $mydata); }
function linkblog_save_post($post_id) { // Ignore if doing an autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // verify data came from the linkblog meta box if (!wp_verify_nonce($_POST['linkblog_noncename'], plugin_basename(__FILE__))) { return; } // Check user permissions if ('post' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } $linkblog_data = $_POST['linkblog_url']; if ($linkblog_data == "") { return; } else { update_post_meta($post_id, 'linkblog_url', $linkblog_data); } }
function sp_update_nav_fa_icon_class($menu_id, $menu_item_db_id, $args) { $fa_icon_class = $_REQUEST['menu-item-fa-icon-class'][$menu_item_db_id] ? $_REQUEST['menu-item-fa-icon-class'][$menu_item_db_id] : ''; if (!empty($fa_icon_class)) { update_post_meta($menu_item_db_id, '_sp_menu_item_fa_icon_class', $fa_icon_class); } }
function comcon_meta_save() { global $post; $post_id = $post->ID; if (!isset($_POST['comcon-form-nonce']) || !wp_verify_nonce($_POST['comcon-form-nonce'], basename(__FILE__))) { return $post->ID; } $post_type = get_post_type_object($post->post_type); if (!current_user_can($post_type->cap->edit_post, $post_id)) { return $post->ID; } $input = array(); $input['position'] = isset($_POST['comcon-form-position']) ? $_POST['comcon-form-position'] : ''; $input['major'] = isset($_POST['comcon-form-major']) ? $_POST['comcon-form-major'] : ''; $input['order'] = str_pad($input['order'], 3, "0", STR_PAD_LEFT); foreach ($input as $field => $value) { $old = get_post_meta($post_id, 'comcon-form-' . $field, true); if ($value && '' == $old) { add_post_meta($post_id, 'comcon-form-' . $field, $value, true); } else { if ($value && $value != $old) { update_post_meta($post_id, 'comcon-form-' . $field, $value); } else { if ('' == $value && $old) { delete_post_meta($post_id, 'comcon-form-' . $field, $old); } } } } }
function save_newsletter($post_id) { // verify nonce if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if ('newsletter' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } $old = get_post_meta($post_id, "name", true); $new = $_POST["name"]; if ($new && $new != $old) { update_post_meta($post_id, "name", $new); } elseif ('' == $new && $old) { delete_post_meta($post_id, "name", $old); } }
public function meta_box() { add_action('add_meta_boxes', function () { // css id, title, cb func, page, priority, cb func arug add_meta_box("address", "Address", "address", "mjs_testimonial"); }); function address($post) { $meta_biography = get_post_meta($post->ID, 'mjs_address', true); ?> <p> <label for="gsize">Address</label> <input class="widefat" type="text" name="mjs_address" id="address" value="<?php echo $meta_biography; ?> " /> </p> <?php } add_action('save_post', function ($id) { if (isset($_POST['mjs_address'])) { update_post_meta($id, 'mjs_address', strip_tags($_POST['mjs_address'])); } }); }
function karma_post($post_id, $action = 'get') { if (!is_numeric($post_id)) { return; } $karma_count = get_post_meta($post_id, $this->option_key, true); switch ($action) { case 'get': if (!$karma_count) { $karma_count = 0; add_post_meta($post_id, $this->option_key, $karma_count, true); } return $karma_count; break; case 'update': if (isset($_COOKIE[$this->option_key . $post_id])) { return $karma_count; } $karma_count++; update_post_meta($post_id, $this->option_key, $karma_count); setcookie($this->option_key . $post_id, $post_id, time() * 20, '/'); return $karma_count; break; } }
function like_post($post_id, $action = 'get') { if (!is_numeric($post_id)) { return; } switch ($action) { case 'get': $like_count = get_post_meta($post_id, '_qode-like', true); if (!$like_count) { $like_count = 0; add_post_meta($post_id, '_qode-like', $like_count, true); } return '<span class="qode-like-count">' . $like_count . '</span>'; break; case 'update': $like_count = get_post_meta($post_id, '_qode-like', true); if (isset($_COOKIE['qode-like_' . $post_id])) { return $like_count; } $like_count++; update_post_meta($post_id, '_qode-like', $like_count); setcookie('qode-like_' . $post_id, $post_id, time() * 20, '/'); return '<span class="qode-like-count">' . $like_count . '</span>'; break; } }
/** * Save meta box data */ public static function save($post_id, $post) { if ('shop_subscription' == $post->post_type && !empty($_POST['woocommerce_meta_nonce']) && wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) { if (isset($_POST['_billing_interval'])) { update_post_meta($post_id, '_billing_interval', $_POST['_billing_interval']); } if (!empty($_POST['_billing_period'])) { update_post_meta($post_id, '_billing_period', $_POST['_billing_period']); } $subscription = wcs_get_subscription($post_id); $dates = array(); foreach (wcs_get_subscription_date_types() as $date_key => $date_label) { if ('last_payment' == $date_key) { continue; } $utc_timestamp_key = $date_key . '_timestamp_utc'; // A subscription needs a start date, even if it wasn't set if (isset($_POST[$utc_timestamp_key])) { $datetime = $_POST[$utc_timestamp_key]; } elseif ('start' === $date_key) { $datetime = current_time('timestamp', true); } else { // No date to set continue; } $dates[$date_key] = date('Y-m-d H:i:s', $datetime); } try { $subscription->update_dates($dates, 'gmt'); wp_cache_delete($post_id, 'posts'); } catch (Exception $e) { wcs_add_admin_notice($e->getMessage(), 'error'); } } }
static function savePost($post_id) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!isset($_POST[__CLASS__ . '_noncename'])) { return; } if (!wp_verify_nonce($_POST[__CLASS__ . '_noncename'], 'save_' . __CLASS__)) { return; } // Check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } // OK, we're authenticated: we need to find and save the data if (isset($_POST[__CLASS__])) { foreach ($_POST[__CLASS__] as $meta_key => $value) { update_post_meta($post_id, $meta_key, $value); } } }
function save_postdata($post_id) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (!wp_verify_nonce($_POST['aceelpress_noncename'], plugin_basename(__FILE__))) { return; } // Check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } // OK, we're authenticated: we need to find and save the data $l = new Language(); if (!($languageIDs = $_POST[$l->getFormName()])) { return; } foreach ($languageIDs as $lid => $val) { add_post_meta($post_id, 'accelpress_language_' . $lid, $val, true) or update_post_meta($post_id, 'accelpress_language_' . $lid, $val); } }
function wpex_custom_attachment_fields_to_save($post, $attachment) { if (isset($attachment['wpex_video_url'])) { update_post_meta($post['ID'], '_video_url', $attachment['wpex_video_url']); } return $post; }
public function metabox_save($post_id) { if (!isset($_POST[MI_PREFIX . 'meta_box_nonce'])) { return; } if (!wp_verify_nonce($_POST[MI_PREFIX . 'meta_box_nonce'], MI_PREFIX . 'meta_box')) { return; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return; } } else { if (!current_user_can('edit_post', $post_id)) { return; } } foreach ($_POST['metabox'] as $metabox_id) { foreach ($this->fields as $id => $field) { add_post_meta($post_id, MI_PREFIX . $id, $_POST[$id], true) or update_post_meta($post_id, MI_PREFIX . $id, $_POST[$id]); } } // foreach ( $_POST[ 'metabox' ] as $metabox_id ) { // if ( $this->boxes->$metabox_id->fields ) { // foreach ( $this->boxes->$metabox_id->fields as $id => $field ) { // add_post_meta( $post_id, MI_PREFIX . $id, $_POST[ $id ], true ) or update_post_meta( $post_id, MI_PREFIX . $id, $_POST[ $id ] ); // } // } // } }
function check_single_list_two() { global $post; if (get_post_meta($post->ID, "num_single_list_twos", $single = true) == "") { update_post_meta($post->ID, 'num_single_list_twos', 0, true); } }
function tz_save_data_page($post_id) { global $meta_box_category; // verify nonce if (!isset($_POST['tz_meta_box_nonce']) || !wp_verify_nonce($_POST['tz_meta_box_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($meta_box_category['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post_id, $field['id'], stripslashes(htmlspecialchars($new))); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } } }
function ajax_contact_form() { $response = array(); $navn = isset($_POST['navn']) ? wp_strip_all_tags($_POST['navn']) : false; $email = isset($_POST['email']) ? wp_strip_all_tags($_POST['email']) : false; $firma = isset($_POST['firma']) ? wp_strip_all_tags($_POST['firma']) : false; $telefon = isset($_POST['telefon']) ? wp_strip_all_tags($_POST['telefon']) : false; $about = isset($_POST['about']) ? wp_strip_all_tags($_POST['about']) : false; $kommentar = isset($_POST['kommentar']) ? esc_textarea($_POST['kommentar']) : false; if (!$navn) { $response['error'] = 'Indtast et navn'; } else { if (!$email) { $response['error'] = 'Indtast en email'; } } if (!isset($response['error'])) { $post_vars = array('post_title' => $navn . ' [' . $email . ']', 'post_status' => 'publish', 'post_type' => 'form'); $response['post_id'] = wp_insert_post($post_vars, true); if (is_wp_error($response['post_id'])) { $response['error'] = $return->get_error_message(); } } if (!isset($response['error'])) { update_post_meta($response['post_id'], 'form_navn', $navn); update_post_meta($response['post_id'], 'form_email', $email); update_post_meta($response['post_id'], 'form_firma', $firma); update_post_meta($response['post_id'], 'form_telefon', $telefon); update_post_meta($response['post_id'], 'form_about', $about); update_post_meta($response['post_id'], 'form_kommentar', $kommentar); $response['success'] = '<article><h2>Tak for din henvendelse</h2><p>Vi vil besvare den hurtigst muligt.</p><article>'; sendEmail(get_theme_mod('info_name'), get_theme_mod('info_email'), get_theme_mod('info_email'), 'Ny henvendelse fra ' . $navn, $kommentar); } wp_die(json_encode($response)); }
/** * @param int $order_id * @return array */ public function process_payment($order_id) { // get order object $order = new WC_Order($order_id); $cashback = isset($_POST['pos-cashback']) ? wc_format_decimal($_POST['pos-cashback']) : 0; if ($cashback !== 0) { // add order meta update_post_meta($order_id, '_pos_card_cashback', $cashback); // add cashback as fee line item // TODO: this should be handled by $order->add_fee after WC 2.2 $item_id = wc_add_order_item($order_id, array('order_item_name' => __('Cashback', 'woocommerce-pos'), 'order_item_type' => 'fee')); if ($item_id) { wc_add_order_item_meta($item_id, '_line_total', $cashback); wc_add_order_item_meta($item_id, '_line_tax', 0); wc_add_order_item_meta($item_id, '_line_subtotal', $cashback); wc_add_order_item_meta($item_id, '_line_subtotal_tax', 0); wc_add_order_item_meta($item_id, '_tax_class', 'zero-rate'); } // update the order total to include fee $order_total = get_post_meta($order_id, '_order_total', true); $order_total += $cashback; update_post_meta($order_id, '_order_total', $order_total); } // payment complete $order->payment_complete(); // success return array('result' => 'success'); }