当前位置: 首页>>代码示例>>PHP>>正文


PHP _truncate_post_slug函数代码示例

本文整理汇总了PHP中_truncate_post_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP _truncate_post_slug函数的具体用法?PHP _truncate_post_slug怎么用?PHP _truncate_post_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_truncate_post_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: crb_wp_unique_post_slug

function crb_wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug)
{
    global $wpdb;
    $check_sql = "SELECT post_name FROM {$wpdb->posts}\n\t\tWHERE post_type IN ('post_type_name', 'page')\n\t\tAND post_name = %s\n\t\tAND post_parent = %d\n\t\tAND ID != %d\n\t\tLIMIT 1";
    $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_parent, $post_ID));
    if (!$post_name_check) {
        return $slug;
    }
    $suffix = 2;
    do {
        $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-" . $suffix;
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_parent, $post_ID));
        $suffix++;
    } while ($post_name_check);
    $slug = $alt_post_name;
    return $slug;
}
开发者ID:brutalenemy666,项目名称:wp-utils,代码行数:17,代码来源:page-permalinks-for-post-types.php

示例2: validate

 function validate()
 {
     global $wpdb, $wp_rewrite;
     $slug = $this->value;
     $feeds = $wp_rewrite->feeds;
     if (!is_array($feeds)) {
         $feeds = array();
     }
     // Post slugs must be unique across all posts.
     $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s LIMIT 1";
     $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug));
     /**
      * Filter whether the post slug would be bad as a flat slug.
      *
      * @since 3.1.0
      *
      * @param bool   $bad_slug  Whether the post slug would be bad as a flat slug.
      * @param string $slug      The post slug.
      * @param string $post_type Post type.
      */
     if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) {
         $suffix = 2;
         do {
             $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
             $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name));
             $suffix++;
         } while ($post_name_check);
         $slug = $alt_post_name;
         $this->value = isset($this->current) ? $this->current : '';
         $this->field['msg'] = sprintf($this->field['msg'], $slug);
         $this->error = $this->field;
     } else {
         if (isset($this->field['flush_permalinks']) && $this->field['flush_permalinks'] == true) {
             add_action('init', array($this, 'flush_permalinks'), 99);
         }
     }
 }
开发者ID:pedrom40,项目名称:sazoo.org,代码行数:37,代码来源:validation_unique_slug.php

示例3: wp_unique_post_slug

/**
 * Computes a unique slug for the post, when given the desired slug and some post details.
 *
 * @since 2.8.0
 *
 * @global wpdb       $wpdb WordPress database abstraction object.
 * @global WP_Rewrite $wp_rewrite
 *
 * @param string $slug        The desired slug (post_name).
 * @param int    $post_ID     Post ID.
 * @param string $post_status No uniqueness checks are made if the post is still draft or pending.
 * @param string $post_type   Post type.
 * @param int    $post_parent Post parent ID.
 * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
 */
function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent)
{
    if (in_array($post_status, array('draft', 'pending', 'auto-draft')) || 'inherit' == $post_status && 'revision' == $post_type) {
        return $slug;
    }
    global $wpdb, $wp_rewrite;
    $original_slug = $slug;
    $feeds = $wp_rewrite->feeds;
    if (!is_array($feeds)) {
        $feeds = array();
    }
    if ('attachment' == $post_type) {
        // Attachment slugs must be unique across all types.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID));
        /**
         * Filter whether the post slug would make a bad attachment slug.
         *
         * @since 3.1.0
         *
         * @param bool   $bad_slug Whether the slug would be bad as an attachment slug.
         * @param string $slug     The post slug.
         */
        if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } elseif (is_post_type_hierarchical($post_type)) {
        if ('nav_menu_item' == $post_type) {
            return $slug;
        }
        /*
         * Page slugs must be unique within their own trees. Pages are in a separate
         * namespace than posts so page slugs are allowed to overlap post slugs.
         */
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
        /**
         * Filter whether the post slug would make a bad hierarchical post slug.
         *
         * @since 3.1.0
         *
         * @param bool   $bad_slug    Whether the post slug would be bad in a hierarchical post context.
         * @param string $slug        The post slug.
         * @param string $post_type   Post type.
         * @param int    $post_parent Post parent ID.
         */
        if ($post_name_check || in_array($slug, $feeds) || preg_match("@^({$wp_rewrite->pagination_base})?\\d+\$@", $slug) || apply_filters('wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } else {
        // Post slugs must be unique across all posts.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID));
        // Prevent new post slugs that could result in URLs that conflict with date archives.
        $post = get_post($post_ID);
        $conflicts_with_date_archive = false;
        if ('post' === $post_type && (!$post || $post->post_name !== $slug) && preg_match('/^[0-9]+$/', $slug) && ($slug_num = intval($slug))) {
            $permastructs = array_values(array_filter(explode('/', get_option('permalink_structure'))));
            $postname_index = array_search('%postname%', $permastructs);
            /*
             * Potential date clashes are as follows:
             *
             * - Any integer in the first permastruct position could be a year.
             * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
             * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
             */
            if (0 === $postname_index || $postname_index && '%year%' === $permastructs[$postname_index - 1] && 13 > $slug_num || $postname_index && '%monthnum%' === $permastructs[$postname_index - 1] && 32 > $slug_num) {
                $conflicts_with_date_archive = true;
            }
        }
        /**
         * Filter whether the post slug would be bad as a flat slug.
         *
//.........这里部分代码省略.........
开发者ID:SayenkoDesign,项目名称:ividf,代码行数:101,代码来源:post.php

示例4: wp_unique_post_slug

/**
 * Computes a unique slug for the post, when given the desired slug and some post details.
 *
 * @since 2.8.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 * @global WP_Rewrite $wp_rewrite
 *
 * @param string $slug        The desired slug (post_name).
 * @param int    $post_ID     Post ID.
 * @param string $post_status No uniqueness checks are made if the post is still draft or pending.
 * @param string $post_type   Post type.
 * @param int    $post_parent Post parent ID.
 * @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
 */
function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent)
{
    if (in_array($post_status, array('draft', 'pending', 'auto-draft')) || 'inherit' == $post_status && 'revision' == $post_type) {
        return $slug;
    }
    global $wpdb, $wp_rewrite;
    $original_slug = $slug;
    $feeds = $wp_rewrite->feeds;
    if (!is_array($feeds)) {
        $feeds = array();
    }
    if ('attachment' == $post_type) {
        // Attachment slugs must be unique across all types.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID));
        /**
         * Filter whether the post slug would make a bad attachment slug.
         *
         * @since 3.1.0
         *
         * @param bool   $bad_slug Whether the slug would be bad as an attachment slug.
         * @param string $slug     The post slug.
         */
        if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } elseif (is_post_type_hierarchical($post_type)) {
        if ('nav_menu_item' == $post_type) {
            return $slug;
        }
        /*
         * Page slugs must be unique within their own trees. Pages are in a separate
         * namespace than posts so page slugs are allowed to overlap post slugs.
         */
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
        /**
         * Filter whether the post slug would make a bad hierarchical post slug.
         *
         * @since 3.1.0
         *
         * @param bool   $bad_slug    Whether the post slug would be bad in a hierarchical post context.
         * @param string $slug        The post slug.
         * @param string $post_type   Post type.
         * @param int    $post_parent Post parent ID.
         */
        if ($post_name_check || in_array($slug, $feeds) || preg_match("@^({$wp_rewrite->pagination_base})?\\d+\$@", $slug) || apply_filters('wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } else {
        // Post slugs must be unique across all posts.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID));
        /**
         * Filter whether the post slug would be bad as a flat slug.
         *
         * @since 3.1.0
         *
         * @param bool   $bad_slug  Whether the post slug would be bad as a flat slug.
         * @param string $slug      The post slug.
         * @param string $post_type Post type.
         */
        if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    }
    /**
//.........这里部分代码省略.........
开发者ID:venizeng,项目名称:pintimes-wordpress,代码行数:101,代码来源:post.php

示例5: geodir_update_term_slug

/**
 * Update term slug.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global string $table_prefix WordPress Database Table prefix.
 * @param int|string $term_id The term ID.
 * @param int $tt_id term Taxonomy ID.
 * @param string $taxonomy Taxonomy slug.
 */
function geodir_update_term_slug($term_id, $tt_id, $taxonomy)
{
    global $wpdb, $plugin_prefix, $table_prefix;
    $tern_data = get_term_by('id', $term_id, $taxonomy);
    $slug = $tern_data->slug;
    /**
     * Filter if a term slug exists.
     *
     * @since 1.0.0
     * @package GeoDirectory
     * @param bool $bool Default: false.
     * @param string $slug The term slug.
     * @param int $term_id The term ID.
     */
    $slug_exists = apply_filters('geodir_term_slug_is_exists', false, $slug, $term_id);
    if ($slug_exists) {
        $suffix = 1;
        do {
            $new_slug = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
            /** This action is documented in geodirectory_hooks_actions.php */
            $term_slug_check = apply_filters('geodir_term_slug_is_exists', false, $new_slug, $term_id);
            $suffix++;
        } while ($term_slug_check && $suffix < 100);
        $slug = $new_slug;
        //wp_update_term( $term_id, $taxonomy, array('slug' => $slug) );
        $wpdb->query($wpdb->prepare("UPDATE " . $table_prefix . "terms SET slug=%s WHERE term_id=%d", array($slug, $term_id)));
    }
}
开发者ID:bangjojo,项目名称:wp,代码行数:40,代码来源:geodirectory_hooks_actions.php

示例6: wp_add_trashed_suffix_to_post_name_for_post

/**
 * For a given post, add a trashed suffix.
 *
 * Store its desired (i.e. current) slug so it can try to reclaim it
 * if the post is untrashed.
 *
 * For internal use.
 *
 * @since 4.5.0
 *
 * @param WP_Post $post The post.
 */
function wp_add_trashed_suffix_to_post_name_for_post($post)
{
    global $wpdb;
    $post = get_post($post);
    if (strpos($post->post_name, '-%trashed%')) {
        return $post->post_name;
    }
    add_post_meta($post->ID, '_wp_desired_post_slug', $post->post_name);
    $post_name = _truncate_post_slug($post->post_name, 190) . '-%trashed%';
    $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
    clean_post_cache($post->ID);
    return $post_name;
}
开发者ID:akalipetis,项目名称:WordPress,代码行数:25,代码来源:post.php

示例7: qtranxf_slug_unique

function qtranxf_slug_unique($slug, $lang, $name)
{
    global $wpdb;
    //$wpdb->show_errors(); @set_time_limit(0);
    $slug = sanitize_key($slug);
    $check_sql = 'SELECT name FROM ' . $wpdb->prefix . 'i18n_slugs WHERE slug = %s AND (lang != %s OR name != %s)';
    $query = $wpdb->prepare($check_sql, $slug, $lang, $name);
    $post_name_check = $wpdb->get_var($query);
    //qtranxf_dbg_log('qtranxf_slug_unique: $slug="'.$slug.'"; $lang="'.$lang.'"; $name='.$name.'; $post_name_check: ', $post_name_check);
    if (!$post_name_check) {
        return $slug;
    }
    $sfx = '-' . $lang;
    if (substr($slug, -3) != $sfx) {
        $alt_post_name = _truncate_post_slug($slug, 200 - 3) . $sfx;
        //qtranxf_dbg_log('qtranxf_slug_unique: $slug="'.$alt_post_name.'"; $lang="'.$lang.'"; $name='.$name.'; $post_name_check: ', $post_name_check);
        $query = $wpdb->prepare($check_sql, $alt_post_name, $lang, $name);
        $post_name_check = $wpdb->get_var($query);
        if (!$post_name_check) {
            return $alt_post_name;
        }
    }
    $suffix = 2;
    do {
        $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . '-' . $suffix;
        $query = $wpdb->prepare($check_sql, $alt_post_name, $lang, $name);
        $post_name_check = $wpdb->get_var($query);
        //qtranxf_dbg_log('qtranxf_slug_unique: $slug="'.$alt_post_name.'"; $lang="'.$lang.'"; $name='.$name.'; $post_name_check: ', $post_name_check);
        $suffix++;
    } while ($post_name_check);
    return $alt_post_name;
}
开发者ID:vallsargente,项目名称:qtranslate-x,代码行数:32,代码来源:qtx_admin_slug.php

示例8: wp_unique_post_slug

/**
 * Computes a unique slug for the post, when given the desired slug and some post details.
 *
 * @since 2.8.0
 *
 * @global wpdb $wpdb
 * @global WP_Rewrite $wp_rewrite
 * @param string $slug the desired slug (post_name)
 * @param integer $post_ID
 * @param string $post_status no uniqueness checks are made if the post is still draft or pending
 * @param string $post_type
 * @param integer $post_parent
 * @return string unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
 */
function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent)
{
    if (in_array($post_status, array('draft', 'pending', 'auto-draft')) || 'inherit' == $post_status && 'revision' == $post_type) {
        return $slug;
    }
    global $wpdb, $wp_rewrite;
    $original_slug = $slug;
    $feeds = $wp_rewrite->feeds;
    if (!is_array($feeds)) {
        $feeds = array();
    }
    $hierarchical_post_types = get_post_types(array('hierarchical' => true));
    if ('attachment' == $post_type) {
        // Attachment slugs must be unique across all types.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID));
        if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } elseif (in_array($post_type, $hierarchical_post_types)) {
        if ('nav_menu_item' == $post_type) {
            return $slug;
        }
        // Page slugs must be unique within their own trees. Pages are in a separate
        // namespace than posts so page slugs are allowed to overlap post slugs.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type IN ( '" . implode("', '", esc_sql($hierarchical_post_types)) . "' ) AND ID != %d AND post_parent = %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent));
        if ($post_name_check || in_array($slug, $feeds) || preg_match("@^({$wp_rewrite->pagination_base})?\\d+\$@", $slug) || apply_filters('wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID, $post_parent));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    } else {
        // Post slugs must be unique across all posts.
        $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
        $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID));
        if ($post_name_check || in_array($slug, $feeds) || apply_filters('wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type)) {
            $suffix = 2;
            do {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID));
                $suffix++;
            } while ($post_name_check);
            $slug = $alt_post_name;
        }
    }
    return apply_filters('wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug);
}
开发者ID:palimadra,项目名称:bubblegraphics-wpsite,代码行数:72,代码来源:post.php

示例9: prevent_slug_conflict

 public static function prevent_slug_conflict($slug)
 {
     global $wpdb;
     // slugs must be unique within their own trees
     $check_sql = "SELECT post_name FROM {$wpdb->posts} WHERE post_name = %s AND post_parent = 0 LIMIT 1";
     $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug));
     if ($slug_check) {
         $suffix = 2;
         do {
             $alt_slug = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
             $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_slug));
             $suffix++;
         } while ($slug_check);
         $slug = $alt_slug;
     }
     return $slug;
 }
开发者ID:subharanjanm,项目名称:testimonials-widget,代码行数:17,代码来源:class-testimonials-widget-settings.php

示例10: save_status

 function save_status()
 {
     global $wpdb;
     $table = $wpdb->prefix . "wc_crm_statuses";
     extract($_POST);
     if (!isset($status_slug) || empty($status_slug)) {
         $status_slug = sanitize_title($status_name);
     } else {
         $status_slug = sanitize_title($status_slug);
     }
     $filter = '';
     if (isset($status_id) && !empty($status_id)) {
         $filter = " AND status_id != {$status_id}";
     }
     $check_sql = "SELECT status_slug FROM {$table} WHERE status_slug = '%s' {$filter} LIMIT 1";
     $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $status_slug));
     if ($slug_check) {
         $suffix = 2;
         do {
             $alt_slug = _truncate_post_slug($status_slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
             $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_slug));
             $suffix++;
         } while ($slug_check);
         $status_slug = $alt_slug;
     }
     $data = array('status_name' => $status_name, 'status_slug' => $status_slug, 'status_icon' => $status_icon, 'status_colour' => $status_colour);
     if (isset($status_id) && !empty($status_id)) {
         $wpdb->update($table, $data, array('status_id' => $status_id));
     } else {
         $wpdb->insert($table, $data);
     }
 }
开发者ID:sajidshah,项目名称:le-dolci,代码行数:32,代码来源:wc-crm-settings-statuses.php

示例11: geodir_update_term_slug

/**
 * Update term slug.
 *
 * @since 1.0.0
 * @since 1.5.3 Modified to update tag in detail table when tag updated.
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global string $plugin_prefix Geodirectory plugin table prefix.
 * @global string $table_prefix WordPress Database Table prefix.
 * @param int|string $term_id The term ID.
 * @param int $tt_id term Taxonomy ID.
 * @param string $taxonomy Taxonomy slug.
 */
function geodir_update_term_slug($term_id, $tt_id, $taxonomy)
{
    global $wpdb, $plugin_prefix, $table_prefix;
    $tern_data = get_term_by('id', $term_id, $taxonomy);
    $slug = $tern_data->slug;
    /**
     * Filter if a term slug exists.
     *
     * @since 1.0.0
     * @package GeoDirectory
     * @param bool $bool Default: false.
     * @param string $slug The term slug.
     * @param int $term_id The term ID.
     */
    $slug_exists = apply_filters('geodir_term_slug_is_exists', false, $slug, $term_id);
    if ($slug_exists) {
        $suffix = 1;
        do {
            $new_slug = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
            /** This action is documented in geodirectory_hooks_actions.php */
            $term_slug_check = apply_filters('geodir_term_slug_is_exists', false, $new_slug, $term_id);
            $suffix++;
        } while ($term_slug_check && $suffix < 100);
        $slug = $new_slug;
        //wp_update_term( $term_id, $taxonomy, array('slug' => $slug) );
        $wpdb->query($wpdb->prepare("UPDATE " . $table_prefix . "terms SET slug=%s WHERE term_id=%d", array($slug, $term_id)));
    }
    // Update tag in detail table.
    $taxonomy_obj = get_taxonomy($taxonomy);
    $post_type = !empty($taxonomy_obj) ? $taxonomy_obj->object_type[0] : NULL;
    $post_types = geodir_get_posttypes();
    if ($post_type && in_array($post_type, $post_types) && $post_type . '_tags' == $taxonomy) {
        $posts_obj = $wpdb->get_results($wpdb->prepare("SELECT object_id FROM " . $wpdb->term_relationships . " WHERE term_taxonomy_id = %d", array($tt_id)));
        if (!empty($posts_obj)) {
            foreach ($posts_obj as $post_obj) {
                $post_id = $post_obj->object_id;
                $raw_tags = wp_get_object_terms($post_id, $post_type . '_tags', array('fields' => 'names'));
                $post_tags = !empty($raw_tags) ? implode(',', $raw_tags) : '';
                $listing_table = $plugin_prefix . $post_type . '_detail';
                $wpdb->query($wpdb->prepare("UPDATE " . $listing_table . " SET post_tags=%s WHERE post_id =%d", array($post_tags, $post_id)));
            }
        }
    }
}
开发者ID:kkoppenhaver,项目名称:geodirectory,代码行数:57,代码来源:geodirectory_hooks_actions.php

示例12: add_customer_status

 function add_customer_status($status)
 {
     global $wpdb;
     $table = $wpdb->prefix . "wc_crm_statuses";
     $status_name = $status;
     $status_slug = sanitize_title($status);
     $check_sql = "SELECT status_slug FROM {$table} WHERE status_slug = '%s' LIMIT 1";
     $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $status_slug));
     if ($slug_check) {
         $suffix = 2;
         do {
             $alt_slug = _truncate_post_slug($status_slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
             $slug_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_slug));
             $suffix++;
         } while ($slug_check);
         $status_slug = $alt_slug;
     }
     $data = array('status_name' => $status_name, 'status_slug' => $status_slug, 'status_icon' => '57545', 'status_colour' => '#8224e3');
     $wpdb->insert($table, $data);
     $this->statuses_added[] = $status_name;
     return $status_slug;
 }
开发者ID:sajidshah,项目名称:le-dolci,代码行数:22,代码来源:wc_crm_importer.php

示例13: create_user

 public static function create_user()
 {
     if (empty($_POST['user_email'])) {
         wc_crm_add_notice(__('Please enter an e-mail address.', 'wc_crm'), 'error');
     } elseif (!is_email($_POST['user_email'])) {
         wc_crm_add_notice(__("The email address isn't correct.", 'wc_crm'), 'error');
     } elseif (email_exists($_POST['user_email'])) {
         wc_crm_add_notice(__("This email is already registered, please choose another one.", 'wc_crm'), 'error');
     }
     if (wc_crm_notice_count('error') > 0) {
         return;
     }
     global $wpdb;
     $nickname = str_replace(' ', '', ucfirst(strtolower($_POST['first_name']))) . str_replace(' ', '', ucfirst(strtolower($_POST['last_name'])));
     $username_opt = get_option('wc_crm_username_add_customer');
     switch ($username_opt) {
         case 2:
             $username = str_replace(' ', '', strtolower($_POST['first_name'])) . '-' . str_replace(' ', '', strtolower($_POST['last_name']));
             break;
         case 3:
             $username = $_POST['user_email'];
             break;
         default:
             $username = strtolower($nickname);
             break;
     }
     $username = _truncate_post_slug($username, 60);
     $check_sql = "SELECT user_login FROM {$wpdb->users} WHERE user_login = '%s' LIMIT 1";
     $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $username));
     if ($user_name_check) {
         $suffix = 1;
         do {
             $alt_user_name = _truncate_post_slug($username, 60 - (strlen($suffix) + 1)) . "-{$suffix}";
             $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_user_name));
             $suffix++;
         } while ($user_name_check);
         $username = $alt_user_name;
     }
     add_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
     $user_id = wc_create_new_customer($_POST['user_email'], $username);
     remove_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
     do_action('wc_crm_create_customer', $user_id);
     if (!is_wp_error($user_id)) {
         update_user_meta($user_id, 'nickname', $nickname);
         wp_update_user(array('ID' => $user_id, 'role' => 'customer'));
         $customer_id = $wpdb->get_var("SELECT c_id FROM {$wpdb->prefix}wc_crm_customer_list WHERE user_id = {$user_id} ");
         if ($customer_id) {
             WC_CRM_Screen_Customers_Edit::save($customer_id, true);
         }
         wc_crm_add_notice(__("Customer created.", 'wc_crm'), 'success');
         wp_safe_redirect(admin_url() . 'admin.php?page=' . WC_CRM_TOKEN);
     } else {
         wc_crm_add_notice($user_id->get_error_message(), 'error');
     }
 }
开发者ID:daanbakker1995,项目名称:vanteun,代码行数:55,代码来源:class-wc-crm-screen-customers-edit.php

示例14: create_user

 function create_user()
 {
     global $wpdb;
     extract($_POST);
     $user_email = trim($user_email);
     if (empty($user_email)) {
         $this->error[] = __('<p><strong>ERROR</strong>: The email address isn’t correct.</p>');
     } else {
         if (!email_exists($user_email)) {
             //$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
             $nickname = str_replace(' ', '', ucfirst(strtolower($_POST['first_name']))) . str_replace(' ', '', ucfirst(strtolower($_POST['last_name'])));
             $username_opt = get_option('woocommerce_crm_username_add_customer');
             switch ($username_opt) {
                 case 2:
                     $username = str_replace(' ', '', strtolower($_POST['first_name'])) . '-' . str_replace(' ', '', strtolower($_POST['last_name']));
                     break;
                 case 3:
                     $username = $user_email;
                     break;
                 default:
                     $username = strtolower($nickname);
                     break;
             }
             $username = _truncate_post_slug($username, 60);
             $check_sql = "SELECT user_login FROM {$wpdb->users} WHERE user_login = '%s' LIMIT 1";
             $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $username));
             if ($user_name_check) {
                 $suffix = 1;
                 do {
                     $alt_user_name = _truncate_post_slug($username, 60 - (strlen($suffix) + 1)) . "-{$suffix}";
                     $user_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_user_name));
                     $suffix++;
                 } while ($user_name_check);
                 $username = $alt_user_name;
             }
             add_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
             $user_id = wc_create_new_customer($user_email, $username);
             remove_filter('pre_option_woocommerce_registration_generate_password', 'wcrm_enable_generate_password');
             do_action('wc_crm_create_customer', $user_id);
             $this->save($user_id, true);
             if (!is_wp_error($user_id)) {
                 update_user_meta($user_id, 'nickname', $nickname);
                 wp_update_user(array('ID' => $user_id, 'role' => 'customer'));
             }
         } else {
             $errors = new WP_Error();
             $errors->add('invalid_email', __('<strong>ERROR</strong>: User already exists.'), array('form-field' => 'user_email'));
             $_SESSION['customer_save_errors'] = $errors;
         }
     }
 }
开发者ID:sajidshah,项目名称:le-dolci,代码行数:51,代码来源:wc_crm_customer_details.php

示例15: unset

            unset($query_args['pagename']);
        }
        $suffix = 2;
        $alt_post_name = $slug;
        // Search for a good slug, adding an appended numeric string if necessary.
        while (true) {
            $query = new WP_Query($query_args);
            $use_slug = true;
            // If there's a post at this URL already, bail.
            if ($query->have_posts()) {
                $use_slug = false;
            }
            // Avoid collision with `tag/tagname` even if there are no posts in the taxonomy.
            if ($query->get_queried_object()) {
                $use_slug = false;
            }
            if ($post_type === 'attachment' && apply_filters('wp_unique_post_slug_is_bad_attachment_slug', false, $slug)) {
                $use_slug = false;
            }
            if ($use_slug) {
                break;
            } else {
                $alt_post_name = _truncate_post_slug($slug, 200 - (strlen($suffix) + 1)) . "-{$suffix}";
                $query_args['name'] = $alt_post_name;
                $suffix++;
            }
        }
        $slug = $alt_post_name;
    }
    return $slug;
}, 10, 6);
开发者ID:ericandrewlewis,项目名称:wp-cool-slugs,代码行数:31,代码来源:index.php


注:本文中的_truncate_post_slug函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。