/**
 * AJAX: upgrade old database to new system
 *
 * @package Qtranslate Slug
 * @subpackage Settings
 * @version 1.0
 *
 * @return boolean
 */
function qts_process_old_data($old_data = null, $type = 'post')
{
    global $wpdb, $qtranslate_slug;
    if (is_null($old_data) || empty($old_data)) {
        return 0;
    }
    foreach ($old_data as $row) {
        switch ($row->qts_type) {
            case 1:
            case 2:
                update_post_meta($row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
                break;
            case 3:
            case 4:
                update_term_meta($row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
                break;
            case 5:
                if ($type == 'post') {
                    update_post_meta($row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
                }
                if ($type == 'term') {
                    update_term_meta($row->qts_id, $qtranslate_slug->get_meta_key($row->qts_lang), $row->qts_slug);
                }
                break;
        }
    }
    $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}qtranslate_slug");
    return 1;
}
 public static function save_category_meta($term_id)
 {
     if (!isset($_POST['xi_category_meta_nonce']) || !wp_verify_nonce($_POST['xi_category_meta_nonce'], 'save_category_meta')) {
         return;
     }
     update_term_meta($term_id, 'xi_category_color', $_POST['xi_category_color']);
 }
 /**
  * Save Category meta data
  */
 function save_category_meta($term_id)
 {
     if (!get_term_meta($term_id, 'ac_category_featured_image')) {
         add_term_meta($term_id, 'ac_category_featured_image', '', true);
     }
     if (!get_term_meta($term_id, 'ac_category_color')) {
         add_term_meta($term_id, 'ac_category_color', '', true);
     }
     if (!get_term_meta($term_id, 'ac_category_icon')) {
         add_term_meta($term_id, 'ac_category_icon', '', true);
     }
     if (!get_term_meta($term_id, 'ac_category_icon_url')) {
         add_term_meta($term_id, 'ac_category_icon_url', '', true);
     }
     if (isset($_POST['ac_category_featured_image'])) {
         $ac_category_featured_image = esc_url($_POST['ac_category_featured_image']);
         update_term_meta($term_id, 'ac_category_featured_image', $ac_category_featured_image);
     }
     if (isset($_POST['ac_category_color'])) {
         $ac_category_color = esc_attr($_POST['ac_category_color']);
         update_term_meta($term_id, 'ac_category_color', $ac_category_color);
     }
     if (isset($_POST['ac_category_icon'])) {
         $ac_category_icon = $_POST['ac_category_icon'];
         update_term_meta($term_id, 'ac_category_icon', $ac_category_icon);
     }
     if (isset($_POST['ac_category_icon_url'])) {
         $ac_category_icon_url = esc_url($_POST['ac_category_icon_url']);
         update_term_meta($term_id, 'ac_category_icon_url', $ac_category_icon_url);
     }
 }
 function handle_new_taxonomy_save($term_id, $tt_id)
 {
     require_once "taxonomy-metadata.php";
     $new_meta = isset($_POST["{$this->taxonomy}_meta"]) && is_array($_POST["{$this->taxonomy}_meta"]) ? $_POST["{$this->taxonomy}_meta"] : false;
     if (false !== $new_meta) {
         foreach ($new_meta as $meta_key => $meta_value) {
             update_term_meta($term_id, $meta_key, $meta_value);
         }
     }
 }
Example #5
1
function wp_term_like_callback()
{
    $id = $_POST['actionId'];
    $num = get_term_meta($id, '_term_like', true) ? get_term_meta($id, '_term_like', true) : 0;
    $domain = $_SERVER['HTTP_HOST'] != 'localhost' ? $_SERVER['HTTP_HOST'] : false;
    // make cookies work with localhost
    setcookie('_term_like_' . $id, $id, $expire, '/', $domain, false);
    update_term_meta($id, '_term_like', $num + 1);
    echo json_encode(array('status' => 200, 'data' => $num + 1));
    die;
}
Example #6
0
 function save_category_form_fields($term_id)
 {
     if (isset($_POST['category_order'])) {
         update_term_meta($term_id, 'order', $_POST['category_order']);
     }
     do_action('asgarosforum_action_save_category_form_fields', $term_id);
 }
Example #7
0
function fifu_cat_save_properties($term_id)
{
    if (isset($_POST['fifu_input_url'])) {
        update_term_meta($term_id, 'fifu_image_url', esc_url($_POST['fifu_input_url']));
    }
    if (isset($_POST['fifu_input_alt'])) {
        update_term_meta($term_id, 'fifu_image_alt', wp_strip_all_tags($_POST['fifu_input_alt']));
    }
}
 /**
  * @ticket 37568
  */
 public function test_meta_query_args_only()
 {
     register_taxonomy('wptests_tax', 'post', array('hierarchical' => true));
     $term1 = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     $term2 = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     $post = self::factory()->post->create(array('post_type' => 'post'));
     update_term_meta($term1, 'somekey', 'thevalue');
     wp_set_post_terms($post, array($term1, $term2), 'wptests_tax');
     $found = get_terms(array('meta_key' => 'somekey', 'meta_value' => 'thevalue'));
     $this->assertEqualSets(array($term1), wp_list_pluck($found, 'term_id'));
 }
Example #9
0
 function save_taxonomy_custom_meta($term_id)
 {
     if (isset($_POST['term_meta'])) {
         $t_id = $term_id;
         $cat_keys = array_keys($_POST['term_meta']);
         foreach ($cat_keys as $key) {
             if (isset($_POST['term_meta'][$key])) {
                 $term_meta[$key] = $_POST['term_meta'][$key];
             }
         }
         // Save the option array.
         update_term_meta($term_id, 'cat_meta', $term_meta);
     }
 }
 public function init(array $args = array())
 {
     $result = $this->get($args);
     if (is_wp_error($result) || !$result) {
         return false;
     }
     foreach ($result as $id => $data) {
         if (!$data) {
             continue;
         }
         foreach ($data as $k => $v) {
             update_term_meta($id, $k, $v);
         }
     }
     return true;
 }
Example #11
0
 /**
  */
 private function get_terms($post, $site)
 {
     $terms = wp_get_post_terms($post->ID);
     $remote_terms = array();
     foreach ($terms as $term) {
         $mapping = get_term_meta($term->term_id, MAPPING_META_KEY, true);
         if (!isset($mapping[$site])) {
             $remote_id = $this->client->xmlrpc_new_term($site, $term);
             $metadata = get_term_meta($term->term_id);
             $this->client->xmlrpc_add_term_meta($site, $remote_id, $metadata);
             $mapping[$site] = $remote_id;
             update_term_meta($term->term_id, MAPPING_META_KEY, $mapping);
             $remote_terms[$term->taxonomy][] = $remote_id;
         }
     }
     return $remote_terms;
 }
 /**
  * Upgrade from version 1.0.7 to 1.1.0
  * Move data from options table to termmeta
  */
 public function avfr_upgrade_107_to_110()
 {
     if ('1' != get_option('avfr_tax_option_moved')) {
         $allgroups = get_terms('groups', array('hide_empty' => 0));
         $moved = array();
         foreach ($allgroups as $group) {
             $max_votes = avfr_get_option('avfr_vote_limit_' . $group->slug, 'avfr_settings_groups');
             $total_votes = avfr_get_option('avfr_total_vote_limit_' . $group->slug, 'avfr_settings_groups');
             $comments_disabled = avfr_get_option('avfr_disable_comment_for' . $group->slug, 'avfr_settings_groups');
             $new_disabled = avfr_get_option('avfr_disable_new_for' . $group->slug, 'avfr_settings_groups');
             $term_id = $group->term_id;
             update_term_meta($term_id, 'avfr_max_votes', $max_votes);
             update_term_meta($term_id, 'avfr_total_votes', $total_votes);
             update_term_meta($term_id, 'avfr_comments_disabled', $comments_disabled);
             update_term_meta($term_id, 'avfr_new_disabled', $new_disabled);
         }
         update_option('avfr_tax_option_moved', '1');
         delete_option('avfr_settings_groups');
     }
 }
 /**
  * Maybe migrate to WP 4.4's own table
  */
 function maybe_migrate()
 {
     global $wpdb;
     $table_name = $wpdb->prefix . $this->table;
     $exists = $wpdb->query("SHOW TABLES LIKE '{$table_name}'");
     if ($exists) {
         // Migrate data to WP
         $rows = $wpdb->get_results("SELECT * FROM {$table_name}");
         if (0 < count($rows)) {
             foreach ($rows as $row) {
                 update_term_meta($row->term_taxonomy_id, $row->meta_key, maybe_unserialize($row->meta_value));
             }
         }
         // Check if all data has been migrated
         $newRows = $wpdb->get_results("SELECT * FROM {$wpdb->termmeta}");
         if (count($newRows) == count($rows)) {
             $wpdb->query("DROP TABLE IF EXISTS {$table_name}");
         }
     }
 }
function add_color_to_category()
{
    if (is_user_logged_in()) {
        if (isset($_POST['cat_id']) && !empty($_POST['cat_id']) && isset($_POST['hex_color']) && !empty($_POST['hex_color'])) {
            $cat_id = esc_html($_POST['cat_id']);
            $hex_color = esc_html($_POST['hex_color']);
            $has_been_set = update_term_meta($cat_id, 'hex-color', $hex_color);
            if ($has_been_set) {
                $returner = array('success' => true, 'reason' => '');
            } else {
                $returner = array('success' => false, 'reason' => "Term Meta could not be set. {$cat_id} - {$hex_color}");
            }
        } else {
            $returner = array('success' => false, 'reason' => 'Post values not set.');
        }
    } else {
        $returner = array('success' => false, 'reason' => 'User not logged in.');
    }
    echo json_encode($returner);
    exit;
}
/**
 * WooCommerce Term Meta API
 *
 * WC tables for storing term meta are @deprecated from WordPress 4.4 since 4.4 has its own table.
 * This function serves as a wrapper, using the new table if present, or falling back to the WC table.
 *
 * @todo These functions should be deprecated with notices in a future WC version, allowing users a chance to upgrade WordPress.
 *
 * @param mixed $term_id
 * @param string $meta_key
 * @param mixed $meta_value
 * @param string $prev_value (default: '')
 * @return bool
 */
function update_woocommerce_term_meta($term_id, $meta_key, $meta_value, $prev_value = '')
{
    return function_exists('update_term_meta') ? update_term_meta($term_id, $meta_key, $meta_value, $prev_value) : update_metadata('woocommerce_term', $term_id, $meta_key, $meta_value, $prev_value);
}
Example #16
0
/**
 * Set taxonomy type to a term.
 *
 * @param  mixed  $term_id
 * @param  string $taxonomy_type
 *
 * @return bool
 */
function papi_set_taxonomy_type_id($term_id, $taxonomy_type)
{
    if (papi_entry_type_exists($taxonomy_type)) {
        return update_term_meta(papi_get_term_id($term_id), papi_get_page_type_key(), $taxonomy_type);
    }
    return false;
}
Example #17
0
 /**
  * Display multiple input fields, one per language
  * 
  * @param $term_id the term id
  * @param $tt_id the term taxonomy id
  * @param $taxonomy the term object
  *
  * @since 1.0
  */
 public function save_term($term_id, $tt_id, $taxonomy)
 {
     global $q_config;
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !current_user_can('edit_posts')) {
         // check permission
         return $term_id;
     }
     $term = get_term($term_id, $taxonomy);
     foreach ($q_config['enabled_languages'] as $lang) {
         $meta_name = $this->get_meta_key($lang);
         $meta_value = apply_filters('qts_validate_term_slug', $_POST["qts_{$lang}_slug"], $term, $lang);
         delete_term_meta($term_id, $meta_name);
         update_term_meta($term_id, $meta_name, $meta_value);
     }
 }
Example #18
0
 function thb_save_taxonomy_custom_meta($term_id)
 {
     if (isset($_POST['term_meta'])) {
         $t_id = $term_id;
         $term_meta = get_term_meta($t_id, 'cat_meta');
         $cat_keys = array_keys($_POST['term_meta']);
         foreach ($cat_keys as $key) {
             if (isset($_POST['term_meta'][$key])) {
                 $term_meta[$key] = $_POST['term_meta'][$key];
             }
         }
         update_term_meta($term_id, 'cat_meta', $term_meta);
     }
 }
Example #19
0
function update_feature_meta($term_id, $tt_id)
{
    if (isset($_POST['meta-keywords']) && '' !== $_POST['meta-keywords']) {
        $keywords = esc_attr($_POST['meta-keywords']);
        update_term_meta($term_id, 'meta-keywords', $keywords);
    }
    if (isset($_POST['meta-title']) && '' !== $_POST['meta-title']) {
        $title = esc_attr($_POST['meta-title']);
        update_term_meta($term_id, 'meta-title', $title);
    }
    if (isset($_POST['meta-description']) && '' !== $_POST['meta-description']) {
        $description = esc_attr($_POST['meta-description']);
        update_term_meta($term_id, 'meta-description', $description);
    }
}
 /**
  * Saving the post oder for later use
  *
  * @author Ronald Huereca <*****@*****.**>
  * @since Reorder 1.0
  * @access public
  * @global object $wpdb  The primary global database object used internally by WordPress
  */
 public function ajax_term_sort()
 {
     global $wpdb;
     if (!current_user_can('edit_pages')) {
         die('');
     }
     // Verify nonce value, for security purposes
     if (!wp_verify_nonce($_POST['nonce'], 'sortnonce')) {
         die('');
     }
     //Get Ajax Vars
     $post_parent = isset($_POST['post_parent']) ? absint($_POST['post_parent']) : 0;
     $menu_order_start = isset($_POST['start']) ? absint($_POST['start']) : 0;
     $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0;
     $post_menu_order = isset($_POST['menu_order']) ? absint($_POST['menu_order']) : 0;
     $posts_to_exclude = isset($_POST['excluded']) ? array_filter($_POST['excluded'], 'absint') : array();
     $post_type = isset($_POST['post_type']) ? sanitize_text_field($_POST['post_type']) : false;
     $attributes = isset($_POST['attributes']) ? $_POST['attributes'] : array();
     $taxonomy = $term_slug = false;
     //Get the tax and term slug
     foreach ($attributes as $attribute_name => $attribute_value) {
         if ('data-taxonomy' == $attribute_name) {
             $taxonomy = sanitize_text_field($attribute_value);
         }
         if ('data-term' == $attribute_name) {
             $term_slug = sanitize_text_field($attribute_value);
         }
         if ('data-parent' == $attribute_name) {
             $term_parent = absint($attribute_value);
         }
         if ('data-id' == $attribute_name) {
             $term_id = absint($attribute_value);
         }
     }
     $term_count = wp_count_terms($taxonomy, array('hide_empty' => false, 'parent' => $post_parent));
     if (!$post_type || !$taxonomy || !$term_slug) {
         die('');
     }
     //Build Initial Return
     $return = array();
     $return['more_posts'] = false;
     $return['action'] = 'reorder_terms_only_sort';
     $return['post_parent'] = $post_parent;
     $return['nonce'] = sanitize_text_field($_POST['nonce']);
     $return['post_id'] = $post_id;
     $return['menu_order'] = $post_menu_order;
     $return['post_type'] = $post_type;
     $return['attributes'] = $attributes;
     $return['starts'] = array();
     $post_type_slug = $post_type . '_order';
     //Update post if passed - Should run only on beginning of first iteration
     if ($post_id > 0 && !isset($_POST['more_posts'])) {
         update_term_meta($post_id, $post_type_slug, $post_menu_order);
         wp_update_term($post_id, $taxonomy, array('parent' => $post_parent));
         $posts_to_exclude[] = $post_id;
     }
     //Build Query
     $selected_terms_args = array('orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array('relation' => 'OR', array('key' => $post_type_slug, 'compare' => 'NOT EXISTS'), array('key' => $post_type_slug, 'value' => 0, 'compare' => '>=')), 'exclude' => $posts_to_exclude, 'hide_empty' => false, 'number' => 50, 'parent' => $post_parent);
     $terms = get_terms($taxonomy, $selected_terms_args);
     $start = $menu_order_start;
     if (!empty($terms)) {
         foreach ($terms as $term) {
             //Increment start if matches menu_order and there is a post to change
             if ($start == $post_menu_order && $post_id > 0) {
                 $start++;
             }
             if ($post_id != $term->term_id) {
                 //Update post and counts
                 update_term_meta($term->term_id, $post_type_slug, $start);
             }
             $posts_to_exclude[] = $term->term_id;
             $start++;
         }
         $return['excluded'] = $posts_to_exclude;
         $return['start'] = $start;
         if ($term_count > count($return['excluded'])) {
             $return['more_posts'] = true;
         } else {
             $return['more_posts'] = false;
         }
         die(json_encode($return));
     } else {
         die(json_encode($return));
     }
 }
Example #21
0
 /**
  * Save usermeta field.
  *
  *
  * @param type $value
  */
 function termmeta_save($value = null)
 {
     // If $value null, look for submitted data
     if (is_null($value)) {
         $value = $this->get_submitted_data();
     }
     /*
      *
      *
      * Since Types 1.2
      * We completely rewrite meta.
      * It has no impact on frontend and covers a lot of cases
      * (e.g. user change mode from single to repetitive)
      */
     delete_term_meta($this->term_id, $this->slug);
     // Save
     if (!empty($value) || is_numeric($value)) {
         // Trim
         if (is_string($value)) {
             $value = trim($value);
         }
         // Apply filters
         $_value = $this->_filter_save_termmeta_value($value);
         $_value = $this->_filter_save_value($_value);
         if (!empty($_value) || is_numeric($_value)) {
             // Save field
             $mid = update_term_meta($this->term_id, $this->slug, $_value);
             $this->_action_save($this->cf, $_value, $mid, $value);
         }
     }
 }
function amt_taxonomy_extra_fields_save($term_id, $taxonomy_id)
{
    /* Verify the nonce before proceeding. */
    // Verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (!isset($_POST['amt_noncename']) || !wp_verify_nonce($_POST['amt_noncename'], plugin_basename(AMT_PLUGIN_FILE))) {
        return;
    }
    // Get the Metadata metabox permissions (filtered)
    $metabox_permissions = amt_get_metadata_metabox_permissions();
    // Global Metadata metabox permission check (can be user customized via filter).
    if (!current_user_can($metabox_permissions['global_metabox_capability'])) {
        return;
    }
    // Get the Add-Meta-Tags options.
    $options = amt_get_options();
    // Check if the current user has permission to edit the post.
    if (!current_user_can('edit_published_posts')) {
        return;
    }
    // OK, we're authenticated: we need to find and save the data
    //
    // Sanitize user input
    //
    // Full metatags - We allow only <meta> elements.
    if (isset($_POST['amt_custom_full_metatags'])) {
        $full_metatags_value = esc_textarea(wp_kses(stripslashes($_POST['amt_custom_full_metatags']), amt_get_allowed_html_kses()));
    }
    // Image URL
    if (isset($_POST['amt_custom_image_url'])) {
        $image_url_value = amt_esc_id_or_url_notation(stripslashes($_POST['amt_custom_image_url']));
    }
    // If a value has not been entered we try to delete existing data from the database
    // If the user has entered data, store it in the database.
    // Add-Meta-Tags custom field names
    $amt_full_metatags_field_name = '_amt_term_full_metatags';
    $amt_image_url_field_name = '_amt_term_image_url';
    // As an extra security measure, here we also check the user-defined per box
    // permissions before we save any data in the database.
    // per term full meta tags
    if ($options['metabox_term_enable_full_metatags'] == '1' && current_user_can($metabox_permissions['term_full_metatags_box_capability'])) {
        if (empty($full_metatags_value)) {
            delete_term_meta($term_id, $amt_full_metatags_field_name);
        } else {
            update_term_meta($term_id, $amt_full_metatags_field_name, $full_metatags_value);
        }
    }
    // Image URL
    if ($options['metabox_term_enable_image_url'] == '1' && current_user_can($metabox_permissions['term_image_url_box_capability'])) {
        if (empty($image_url_value)) {
            delete_term_meta($term_id, $amt_image_url_field_name);
        } else {
            update_term_meta($term_id, $amt_image_url_field_name, $image_url_value);
        }
    }
}
 function save($term_id)
 {
     // Verify nonce
     if (!isset($_POST['termMetaBox_nonce']) || !wp_verify_nonce($_POST['termMetaBox_nonce'], basename(__FILE__))) {
         return;
     }
     // Check permissions
     if (!current_user_can('manage_categories')) {
         return;
     }
     // Validate fields before updating
     // If there is no validate in the array, nothing will save
     foreach ($this->_termMetaBox['fields'] as $field) {
         if (in_array($field['type'], ['multitext', 'multicheck'])) {
             foreach ($field['options'] as $option) {
                 $old = get_term_meta($term_id, $option['id'], true);
                 $new = isset($_POST[$option['id']]) ? $field['validate']($_POST[$option['id']]) : '';
                 if ($field['validate'] != '') {
                     if ($new && $new != $old || $new === '0') {
                         update_term_meta($term_id, $option['id'], $new);
                     } elseif ('' == $new && $old || $old === '0') {
                         delete_term_meta($term_id, $option['id'], $old);
                     }
                 }
             }
         } else {
             $old = get_term_meta($term_id, $field['id'], true);
             $new = isset($_POST[$field['id']]) ? $field['validate']($_POST[$field['id']]) : '';
             if ($field['validate'] != '') {
                 if ($new && $new != $old || $new === '0') {
                     update_term_meta($term_id, $field['id'], $new);
                 } elseif ('' == $new && $old || $old === '0') {
                     delete_term_meta($term_id, $field['id'], $old);
                 }
             }
         }
     }
 }
Example #24
0
 function test_existing_term_meta_is_pushed_when_new_term_is_created_on_remote_wp()
 {
     $master = new Master();
     $taxonomy = 'post_tag';
     $term = wp_insert_term('test_term', $taxonomy, array('description' => 'test description'));
     $term_id = $term['term_id'];
     $meta_id = update_term_meta($term_id, "test_meta_key", "dummy");
     if (is_wp_error($term)) {
         var_dump($term);
         throw new Exception("Error in wp_insert_term");
     }
     $result = wp_set_post_terms($this->ID, array($term_id), $taxonomy);
     $master->push($this->post, $this->site);
     $mapping = get_term_meta($term_id, MAPPING_META_KEY, true);
     $remote_id = $mapping[$this->site];
     $this->assertEquals("dummy", get_term_meta($remote_id, "test_meta_key", true));
 }
 public function SetMultipleOfForCategory($category_id, $multiple_of)
 {
     $multiple_of = intval($multiple_of);
     if ($multiple_of) {
         update_term_meta($category_id, 'cat_multiple_of', $multiple_of);
     } else {
         delete_term_meta($category_id, 'cat_multiple_of');
     }
 }
Example #26
0
 /**
  * Import settings and data from standard input.
  * 
  * ## OPTIONS
  * 
  * <what>
  * : The type of data to be imported. Supported: settings|postdata|userdata|termdata
  * 
  * ## EXAMPLES
  * 
  *     wp amt import settings < amt-settings.json
  *     wp amt import postdata < amt-postdata.json
  *     wp amt import userdata < amt-userdata.json
  *     wp amt import termdata < amt-termdata.json
  *
  * @synopsis <settings|postdata|userdata|termdata>
  */
 function import($args, $assoc_args)
 {
     list($what) = $args;
     if (!in_array($what, array('settings', 'postdata', 'userdata', 'termdata'))) {
         WP_CLI::error('Invalid argument: ' . $what . ' (valid: settings|postdata|userdata|termdata)');
     }
     // Import AMT settings
     if ($what == 'settings') {
         $data = json_decode(file_get_contents('php://stdin'), true);
         // true converts to associative array
         //var_dump($data);
         if (empty($data) || !is_array($data)) {
             WP_CLI::error('No data found.');
         }
         // Since all other options might come and go, we only check for the 'settings_version' key.
         if (!array_key_exists('settings_version', $data)) {
             WP_CLI::error('Invalid data: not option data');
         }
         //var_dump( $options );
         update_option("add_meta_tags_opts", $data);
         amt_plugin_upgrade();
         WP_CLI::success('Add-Meta-Tags settings imported successfully.');
     } elseif ($what == 'postdata') {
         $data = json_decode(file_get_contents('php://stdin'));
         if (empty($data) || !is_array($data) || empty($data[0])) {
             WP_CLI::error('No data found.');
         }
         $amt_post_fields = amt_get_post_custom_field_names();
         foreach ($data as $post_meta_info) {
             // Format: array( <id>, <field_name>, <field_value> )
             if (!is_array($post_meta_info) || count($post_meta_info) != 3 || !in_array($post_meta_info[1], $amt_post_fields) || !is_numeric($post_meta_info[0])) {
                 WP_CLI::error('Invalid data: not post custom field data');
             }
             update_post_meta($post_meta_info[0], $post_meta_info[1], $post_meta_info[2]);
         }
         WP_CLI::success('Add-Meta-Tags post data was imported successfully.');
     } elseif ($what == 'userdata') {
         $data = json_decode(file_get_contents('php://stdin'));
         if (empty($data) || !is_array($data) || empty($data[0])) {
             WP_CLI::error('No data found.');
         }
         $amt_user_fields = amt_get_user_custom_field_names();
         foreach ($data as $user_meta_info) {
             // Format: array( <id>, <field_name>, <field_value> )
             if (!is_array($user_meta_info) || count($user_meta_info) != 3 || !in_array($user_meta_info[1], $amt_user_fields) || !is_numeric($user_meta_info[0])) {
                 WP_CLI::error('Invalid data: not user contact infos');
             }
             update_user_meta($user_meta_info[0], $user_meta_info[1], $user_meta_info[2]);
         }
         WP_CLI::success('Add-Meta-Tags user data was imported successfully.');
     } elseif ($what == 'termdata') {
         $data = json_decode(file_get_contents('php://stdin'));
         if (empty($data) || !is_array($data) || empty($data[0])) {
             WP_CLI::error('No data found.');
         }
         $amt_term_fields = amt_get_term_custom_field_names();
         foreach ($data as $term_meta_info) {
             // Format: array( <id>, <field_name>, <field_value> )
             if (!is_array($term_meta_info) || count($term_meta_info) != 3 || !in_array($term_meta_info[1], $amt_term_fields) || !is_numeric($term_meta_info[0])) {
                 WP_CLI::error('Invalid data: not term contact infos');
             }
             update_term_meta($term_meta_info[0], $term_meta_info[1], $term_meta_info[2]);
         }
         WP_CLI::success('Add-Meta-Tags term data was imported successfully.');
     }
 }
 /**
  * Save the image uploaded
  * @param  string $term_id term slug
  */
 function impress_agents_save_term_image($term_id)
 {
     if (!isset($_POST['impa_term_image_nonce']) || !wp_verify_nonce($_POST['impa_term_image_nonce'], basename(__FILE__))) {
         return;
     }
     $old_image = $this->impress_agents_get_term_image($term_id);
     $new_image = isset($_POST['impa-term-image']) ? $_POST['impa-term-image'] : '';
     if ($old_image && '' === $new_image) {
         delete_term_meta($term_id, 'impa_term_image');
     } else {
         if ($old_image !== $new_image) {
             update_term_meta($term_id, 'impa_term_image', $new_image);
         }
     }
     return $term_id;
 }
Example #28
-1
 public function save($term_id)
 {
     foreach ($this->fields as $id => $field) {
         if ($field) {
             add_term_meta($term_id, MI_PREFIX . $id, $_POST[$id], true) or update_term_meta($term_id, MI_PREFIX . $id, $_POST[$id], get_term_meta($term_id, MI_PREFIX . $id, true));
         }
     }
 }
    /**
     * 
     * Creates a post type
     * 
     */
    function avfr_post_type()
    {
        $domain = avfr_get_option('avfr_domain', 'avfr_settings_main', 'suggestions');
        $labels = array('name' => _x('Features', 'feature-request'), 'singular_name' => _x('Feature', 'feature-request'), 'menu_name' => __('Feature Request', 'feature-request'), 'name_admin_bar' => _x('Feature', 'add new on admin bar', 'feature-request'), 'add_new' => __('New Feature', 'feature-request'), 'add_new_item' => __('Add New Feature', 'feature-request'), 'new_item' => __('New Feature', 'feature-request'), 'edit_item' => __('Edit Feature', 'feature-request'), 'view_item' => __('View Feature', 'feature-request'), 'all_items' => __('All Features', 'feature-request'), 'search_items' => __('Search Feature', 'feature-request'), 'update_item' => __('Update Feature', 'feature-request'), 'parent_item_colon' => __('Parent Feature:', 'feature-request'), 'not_found' => __('No Feature found', 'feature-request'), 'not_found_in_trash' => __('No Feature found in Trash', 'feature-request'));
        $args = array('labels' => $labels, 'label' => __('Feature', 'feature-request'), 'description' => __('Create votes', 'feature-request'), 'labels' => $labels, 'supports' => array('editor', 'title', 'comments', 'author', 'thumbnail'), 'rewrite' => array('slug' => 'suggestions', 'pages' => true), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'suggestions', 'pages' => true), 'capability_type' => 'post', 'has_archive' => $domain, 'menu_icon' => 'dashicons-megaphone', 'can_export' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'));
        register_post_type('avfr', apply_filters('avfr_type_args', $args));
        // Hierarchical taxonomy for features
        $labels = array('name' => _x('Groups', 'taxonomy general name'), 'singular_name' => _x('Groups', 'taxonomy singular name'), 'search_items' => __('Search groups'), 'all_items' => __('All Groups'), 'parent_items' => __('Parent group'), 'parent_item_colon' => __('Parent groups'), 'edit_item' => __('Edit group'), 'update_item' => __('Update group'), 'add_new_item' => __('Add group'), 'update_count_callback' => '_update_post_term_count', 'menu_name' => __('Groups'));
        $args = array('hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array('slug' => 'groups'), 'update_count_callback' => '_update_post_term_count');
        register_taxonomy('groups', array('avfr'), $args);
        // Non hierarchical taxonomy for features
        $labels = array('name' => _x('Feature tags', 'taxonomy general name'), 'singular_name' => _x('Feature tags', 'taxonomy singular name'), 'search_items' => __('Search tags'), 'all_items' => __('All tags'), 'edit_item' => __('Edit tag'), 'update_item' => __('Update tag'), 'add_new_item' => __('Add New tag'), 'new_item_name' => __('New tag Name'), 'separate_items_with_commas' => __('Separate tags with commas'), 'add_or_remove_items' => __('Add or remove tag'), 'choose_from_most_used' => __('Choose from the most used tags'), 'not_found' => __('No tag found.'), 'update_item' => __('Update tags'), 'add_new_item' => __('Add tag'), 'menu_name' => __('Tags'));
        $args = array('hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'rewrite' => array('slug' => 'avfrtags'));
        register_taxonomy('featureTags', array('avfr'), $args);
        // Check that this plugin was installed before this or not
        if ('' == get_option('avfr_installed_before')) {
            // Defaults for adding post (feature request)
            $default_post = array('post_type' => 'avfr', 'post_title' => wp_strip_all_tags(__('New feature request', 'feature-request')), 'post_status' => 'publish', 'post_content' => __('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh
				 		euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud 
				 		exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
				 		dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at
				 		vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
				 		feugait nulla facilisi.', 'feature-request'));
            // Insert post
            $entry_id = wp_insert_post($default_post);
            //Insert group (category)
            $group_term_id = wp_set_object_terms($entry_id, __('Example group 1', 'feature-request'), 'groups');
            $term_id = $group_term_id[0];
            // Insert tags (featureTags)
            $tag_term_id = wp_set_object_terms($entry_id, __('Example tag 1', 'feature-request'), 'featureTags');
            // Set default post status as Open
            update_post_meta($entry_id, '_avfr_status', 'open');
            // Defaults for page with shortcode
            $avfr_page_def = array('post_title' => 'Sample Feature Request', 'post_status' => 'publish', 'post_type' => 'page', 'post_content' => '[feature_request hide_submit="off" hide_votes="off" hide_voting="off"]');
            // Insert as page
            $page_id = wp_insert_post($avfr_page_def);
            /**
             * Use term meta instead of site option for default group settings
             * @since    1.1.0 
             */
            update_term_meta($term_id, 'avfr_max_votes', 3);
            update_term_meta($term_id, 'avfr_total_votes', 30);
            update_term_meta($term_id, 'avfr_comments_disabled', 'off');
            update_term_meta($term_id, 'avfr_new_disabled', 'off');
            //Update this option from 0 to 1, so the codes will runs only 1 time.
            add_option('avfr_installed_before', '1', '', 'no');
        }
        // Flush rewrite rules and update option.
        // The option will be checked to flushing again.
        if ('0' === get_option('avfr_post_registered') || '' == get_option('avfr_post_registered')) {
            flush_rewrite_rules(false);
            update_option('avfr_post_registered', '1', 'no');
        }
    }
Example #30
-2
function hocwp_term_update_meta($term_id, $meta_key, $meta_value)
{
    $version = hocwp_get_wp_version();
    if (version_compare($version, '4.4', '>=')) {
        return update_term_meta($term_id, $meta_key, $meta_value);
    }
    hocwp_term_register_termmeta_table();
    return update_metadata('term', $term_id, $meta_key, $meta_value);
}