[wordpress插件] BuddyPig好友猪

wordpress 插件 文章 2020-03-12 17:30 500 0 全屏看文

AI助手支持GPT4.0

评分
60
描述

BuddyPig is a game meant to help BuddyPress group members get to know each other better.

BuddyPig是一款旨在帮助BuddyPress组成员更好地了解彼此的游戏。

It was built during a hack day at Automattic.

它是在Automattic的黑客日期间建造的。

Since we’re a distributed company, it’s not uncommon to go months without talking to certain colleagues.

由于我们是一家分布式公司,因此几个月不与某些同事交谈的情况并不少见。

We came up with BuddyPig as a fun way to work around that.

我们想到了BuddyPig,这是解决该问题的一种有趣方式。

PIG, in case you’re curious, is an acronym for Personal Information Game.

PIG(如果您感到好奇)是“个人信息游戏”的缩写。

To use it you’ll have to write a small plugin to create questions and choose the BuddyPress group you’d like to use.

要使用它,您必须编写一个小插件来创建问题,然后选择要使用的BuddyPress组。

PIG is very hook-able, so there’s lots of other stuff you can customize if you’re so inclined.

PIG具有很强的吸引力,因此,如果您愿意的话,还可以自定义许多其他内容。

We’ll include an example plugin to setup PIG below.

我们将在下面提供一个示例插件来设置PIG。

PIG requires BuddyPress and its Activity Streams feature to be running.

PIG需要BuddyPress及其“活动流”功能正在运行。

It also requires PHP 5.3, which is slightly higher than the default requirement for WordPress.

它还需要 PHP 5.3 ,该值略高于WordPress的默认要求。

Example setup

示例设置

You have to tell PIG what profile items to use and how to ask the questions.

您必须告诉PIG使用哪些配置文件项以及如何提出问题。

We gave you a function called pig_register_question() to do just that.

我们为您提供了一个名为 pig_register_question()的函数来完成此操作。

By default, pig_register_question() takes 2 arguments, the BuddyPress profile field name and a format to use to ask the question.

默认情况下, pig_register_question()带有2个参数,BuddyPress配置文件字段名称和用于询问问题的格式。

Here’s an example:

这是一个示例:

pig_register_question( 'Address', 'Where does %s live?' );

  pig_register_question('地址','%s住在哪里?');

You’ll notice the %s in the question format, which is where we drop in the user’s name that the question is about.

您会注意到问题格式的%s ,这是我们在其中输入问题所涉及的用户名的位置。

If you’ve written PHP before, you may recognize this syntax from the sprintf() function, which is what is used behind the scenes.

如果您以前写过PHP,则可以从 sprintf()函数中识别出这种语法,这是在幕后使用的。

You’ll also have to tell PIG what BuddyPress group to use, which can be done with pig_set_group() by passing the group’s ID.

您还必须告诉PIG使用哪个BuddyPress组,这可以通过传递组ID来通过 pig_set_group()完成。

Here’s an example:

这是一个示例:

pig_set_group( 1 );

  pig_set_group(1);

pig_register_question() can take two additional arguments.

pig_register_question()可以接受两个附加参数。

The first one tells PIG whether to make the name possessive when it asks the question.

第一个告诉PIG,当问到这个问题时是否让这个名字成为所有格。

For example, "Where was Beau born?"

例如,“博在哪里出生?”

would not be possessive, but "Where is Beau's house?"

不会占有欲,而是“博的房子在哪里?”

would be.

将会。

If you want PIG to make the name possessive, you can add `true` as the third argument, like this:

如果您希望PIG使名称具有所有格,则可以将“ true”添加为第三个参数,如下所示:

pig_register_question( 'Address', 'Where is %s house?', true );

pig_register_question('Address','%s的房子在哪里?',true);

The last optional argument is a callback.

最后一个可选参数是回调。

PIG can format answers for you before displaying them.

PIG可以在显示答案之前为您格式化答案。

One use case of this is deduplicating multiple phrases that mean the same thing, like “United States” and “USA”.

这样的一个用例是对多个表示同一事物的短语进行重复数据删除,例如“美国”和“美国”。

If you use this callback, you must also make sure the function exists for PIG to call.

如果使用此回调,则还必须确保存在该函数供PIG调用。

Here’s an example:

这是一个示例:

pig_register_question( 'Address', 'Where is %s house?', 'a8c_dedupe_countries' );

  pig_register_question('地址','%s的房子在哪里?','a8c_dedupe_countries');

function a8c_pig_dedupe_countries( $country ) {    

函数a8c_pig_dedupe_countries($ country){    

$usa_versions = array( 'US', 'USA', 'United States', 'U.S.A', 'U.S.', 'America', 'United States of America' );    

$ usa_versions = array('US','USA','United States','U.S.A','U.S.','America','United States of America));    

$uk_versions = array( 'UK', 'U.K.', 'United Kingdom' );    

$ uk_versions = array('UK','U.K.','United Kingdom');    

foreach ( $usa_versions as $usa_version ) {        

foreach($ usa_versions as $ usa_version){        

if ( strtolower( $country ) == strtolower( $usa_version ) )            

如果(strtolower($ country)== strtolower($ usa_version))            

return 'United States';    

返回“美国”;    

}    

}    

foreach ( $uk_versions as $uk_version ) {        

foreach($ uk_versions as $ uk_version){        

if ( strtolower( $country ) == strtolower( $uk_version ) )            

如果(strtolower($ country)== strtolower($ uk_version))            

return 'United Kingdom';    

返回“英国”;    

}    

}    

return $country;

返回$ country;

}

}

You can put these setup calls into your own plugin and activate it just like any other.

您可以将这些设置调用放入您自己的插件中,并像其他任何插件一样激活它。

If you insist, you could also put them into your theme’s functions.php file.

如果您坚持,也可以将它们放入主题的 functions.php 文件中。

To make sure they’re loaded after PIG is setup, you can hook them to the pig_loaded action.

为了确保在设置PIG后将其加载,您可以将其挂接到 pig_loaded 操作。

安装步骤

    1. Upload the buddypig directory to your plugins directory, most likely /wp-content/plugins/
    2. buddypig 目录上传到您的插件目录,很可能是 / wp-content / plugins /

    3. Activate the plugin through the ‘Plugins’ menu in WordPress
    4. 通过WordPress中的“插件”菜单激活插件

    5. Write and activate your custom PIG setup plugin (example below)
    6. 编写并激活您的自定义PIG设置插件(以下示例)

下载地址
https://downloads.wordpress.org/plugin/buddypig.1.1.2.zip
-EOF-

AI助手支持GPT4.0