如何防止用户创建新标签?

时间:2018-11-19 22:15:11

标签: php wordpress

我创建了代码以更新当前帖子中的标签。

Triple.t

但是我在编辑标签时需要

如果帖子在数据库中不包含指定的标签,

然后,而不是标签显示为“”

示例

如果输入了文本区域

现有标签,新标签,现有标签

然后它将显示

已存在标签,已存在标签

1 个答案:

答案 0 :(得分:1)

通过类似的操作,您应该能够做到(注释中解释的代码):

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define MAX 100


struct cg {
    // structure to hold x and y co-ordinates and mass
    float x, y, mass;
}masses[MAX];


int readin(void)
{
    FILE *fp;
    masses cg;
//Error saying cg is an undeclared identifier.
    fp = fopen("m.txt", "rb");
    int n = 0;

    if (fp == NULL) {
        printf("Cannot find file.");
        return 0;
    }
    else {
        fscanf(fp, "%f" &cg.x, &cg.y, &cg.mass);
//Error here too
            n++;
            fclose(fp);
            getchar();
            return n;

    }

    }
    /* Write this function to read in the data from a file */
    /* into the array masses */
    /* note that this function should return the number of */
    /* masses read in from the file */


void computecg(int n_masses)
{
    /* Write this function to compute the C of G */
    /* and print the result */
}
void main(void)
{
    int number;
    if ((number = readin()) > 0) {
        computecg(number);
    }
}

p.s。您应该通过isset()函数检查<?php if ($_POST['post_get_tags']) { // Split post_get_tags string into an array using the comma as delimiter. $tags_got_exploded = explode(',', $_POST['post_get_tags']); // Remove whitespaces from every value of the array (we want a clean tag name for each value of the array). $tags_got_exploded = array_map('trim', $tags_got_exploded); /* * Get an array with all the tags allowed to be added. * get_tags https://codex.wordpress.org/Function_Reference/get_tags * Returns a multidimensional array where the column_key "name" contains the tag name * Just return an array with tag names allowed */ $tags_allowed = array_column(get_tags(), 'name'); // Iterate over every tag got foreach ($tags_got_exploded as $key => &$tag_got) { // If the tag got is not inside the array with all the tags allowed to be added. if (!in_array($tag_got, $tags_allowed)) // Remove the tag. unset($tags_got_exploded[$key]); } // Join tag got elements (cleaned and checked). $tags_got = implode(', ', $tags_got_exploded); wp_set_post_tags($post->ID, $tags_got); } 变量集

$_POST