/** * tfuse_count_post_visits. * * To override tfuse_count_post_visits() in a child theme, add your own tfuse_count_post_visits() * to your child theme's theme_config/theme_includes/THEME_FUNCTIONS.php file. */ function tfuse_count_post_visits() { if (!is_single()) { return; } global $post; $views = get_post_meta($post->ID, TF_THEME_PREFIX . '_post_viewed', true); $views = intval($views); tf_update_post_meta($post->ID, TF_THEME_PREFIX . '_post_viewed', ++$views); }
function save_post_options_init($post_id, $post) { // To prevent duplicate entries when using save_post action global $save_post_flag; $tfuse_post_options = array(); if ($save_post_flag == 0) { // Verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times // if (!wp_verify_nonce($this->request->POST('_tfuse_noncename'), '_tfuse_meta_box')) // return; $options = $this->get->options($post->post_type); foreach ($options as $option) { if ($option['type'] == 'metabox') { } elseif ($this->optisave->has_method("post_{$option['type']}")) { $this->optisave->{"post_{$option['type']}"}($option, $tfuse_post_options); } else { $this->optisave->post_text($option, $tfuse_post_options); } } do_action('tf_save_post_options_extra_processing', $tfuse_post_options, $post_id, $post->post_type); tf_update_post_meta($post_id, TF_THEME_PREFIX . '_tfuse_post_options', $tfuse_post_options); } $save_post_flag = 1; }
/** * Update _thumbnail_id meta to new, imported attachment IDs */ function remap_featured_images() { // cycle through posts that have a featured image foreach ($this->featured_images as $post_id => $value) { if (isset($this->processed_posts[$value])) { $new_id = $this->processed_posts[$value]; // only update if there's a difference if ($new_id != $value) { tf_update_post_meta($post_id, '_thumbnail_id', $new_id); } } } }
function backfill_attachment_urls() { global $wpdb; // TFUSE: mai intii procesam optiunile din framework $this->tfuse_process_options(); $rows = $wpdb->get_results($wpdb->prepare("SELECT post_id, meta_value FROM {$wpdb->postmeta} WHERE meta_key='%s'", TF_THEME_PREFIX . '_tfuse_post_options')); foreach ($rows as $row) { $new_val = tfuse_unpk($row->meta_value); if ($new_val === false) { $new_val = $row->meta_value; } if (is_array($new_val)) { array_walk_recursive($new_val, array($this, 'tfuse_change_link')); } tf_update_post_meta($row->post_id, TF_THEME_PREFIX . '_tfuse_post_options', $new_val); $this->tfuse_post_options[$row->post_id] = $new_val; } $this->url_remap[$this->base_url] = network_home_url(); // make sure we do the longest urls first, in case one is a substring of another uksort($this->url_remap, array($this, 'cmpr_strlen')); // append this to the end of array to be executed last (after 'cmpr_strlen' that changes the order) if ($this->wrong_replace) { $this->url_remap[$this->wrong_replace] = network_home_url(); } foreach ($this->url_remap as $from_url => $to_url) { // remap urls in post_content $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url)); // remap enclosure urls $result = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url)); } }
private function create_attachments($post_id, $attachments) { /** @var WPDB $wpdb */ global $wpdb; do { // you must first include the image.php file // for the function wp_generate_attachment_metadata() to work require_once ABSPATH . 'wp-admin/includes/image.php'; $wp_upload_dir = wp_upload_dir(); if ($wp_upload_dir['error']) { break; } $menu_order = 1; foreach ($attachments as $attachment) { $url = $attachment['url']; $rel_path = explode('/wp-content/uploads/', $url); array_shift($rel_path); $rel_path = array_pop($rel_path); if (empty($rel_path)) { continue; } $path = $wp_upload_dir['basedir'] . '/' . $rel_path; $url = $wp_upload_dir['baseurl'] . '/' . $rel_path; if (!file_exists($path)) { continue; } $wp_filetype = wp_check_filetype(basename($path), null); $alt = $attachment['alt']; $attachment = array('guid' => $url, 'post_mime_type' => $wp_filetype['type'], 'post_title' => $attachment['title'] ? $attachment['title'] : preg_replace('/\\.[^.]+$/', '', basename($path)), 'post_excerpt' => $attachment['caption'], 'post_content' => $attachment['desc'], 'post_status' => 'inherit', 'menu_order' => $menu_order++); $attach_id = $wpdb->get_var($wpdb->prepare("SELECT\r\n ID\r\n FROM {$wpdb->posts}\r\n WHERE guid = '%s' AND\r\n post_type = 'attachment'\r\n LIMIT 1", $attachment['guid'])); if ($attach_id) { wp_update_post(array('ID' => $attach_id, 'post_parent' => $post_id)); unset($attachPost); } else { $attach_id = wp_insert_attachment($attachment, $path, $post_id); } tf_update_post_meta($attach_id, '_wp_attachment_image_alt', $alt); $attach_data = wp_generate_attachment_metadata($attach_id, $path); wp_update_attachment_metadata($attach_id, $attach_data); } } while (false); return false; }
/** * Saves megamenu data to postmeta table * * @param int $menu_id The menu id * @param int $nav_item_id The menu item item * @param array $args The data that comes with the nav item before saving */ public function save_megamenu_options($menu_id, $nav_item_id, $args) { /* echo "menu id: " . $menu_id; echo "<br/>"; echo "nav_item_id: " . $nav_item_id; tf_print($this->request->POST(), true); */ // if the nav item doesn't have megamenu options do nothing if (!$this->request->isset_POST('tf_megamenu_options.' . $nav_item_id)) { tf_delete_post_meta($nav_item_id, 'tf_megamenu_options'); return; } // if we have a depth 0 nav item and tf_is_mega option is selected // or we have a depth 1 nav item and it's parent's tf_is_mega option is selected // then we save the megamenu data to post_meta table // if not we delete the megamenu tf_megamenu_options metadata if it exists $needs_to_be_saved = $args['menu-item-parent-id'] == 0 && $this->request->POST('tf_megamenu_options.' . $nav_item_id . '.tf_megamenu_is_mega') == 'true' || $this->request->isset_POST('tf_megamenu_options.' . $args['menu-item-parent-id']) && $this->request->POST('tf_megamenu_options.' . $args['menu-item-parent-id'] . '.tf_megamenu_is_mega') == 'true'; if ($needs_to_be_saved) { tf_update_post_meta($nav_item_id, 'tf_megamenu_options', $this->request->POST('tf_megamenu_options.' . $nav_item_id)); } else { tf_delete_post_meta($nav_item_id, 'tf_megamenu_options'); } }
/** * Set post tfuse option ** * @param string $option_name Without prefix * @param mixed $value * @param null $post_id */ function tfuse_set_page_option($option_name, $value, $post_id = null) { global $post, $tfuse_options; $max_cache_size = 100; if (!isset($post_id) && isset($post)) { $post_id = $post->ID; } if (!isset($post_id)) { return; } // optiunile sunt slavate cu PREFIX in fata, dar extragem scrim fara PREFIX // pentru a obtine PREFIX_logo vom folosi tfuse_page_options('logo') $option_name = TF_THEME_PREFIX . '_' . $option_name; if (!isset($tfuse_options['post'][$post_id])) { if (!empty($tfuse_options['post']) && count($tfuse_options['post']) > $max_cache_size) { // if cache limit exceeded, remove first element from cache array_shift($tfuse_options['post']); } $tfuse_options['post'][$post_id] = decode_tfuse_options(get_post_meta($post_id, TF_THEME_PREFIX . '_tfuse_post_options', true)); } $tfuse_options['post'][$post_id][$option_name] = $value; tf_update_post_meta($post_id, TF_THEME_PREFIX . '_tfuse_post_options', encode_tfuse_options($tfuse_options['post'][$post_id])); }