[wordpress插件] Advanced Post Privacy高级帖子隐私

wordpress 插件 文章 2020-02-08 14:40 525 0 全屏看文

AI助手支持GPT4.0

评分

0

0

描述

Advanced Post Privacy takes advantage of the current underdeveloped functionality of private posts.

高级帖子隐私权利用了私人帖子当前未开发的功能。

It


allows you to make exceptions to any content types that have been marked as private.

允许您对已标记为私有的任何内容类型进行例外处理。

Possible Future Features:

未来可能的功能:

* Allowing exceptions on a per page/post basis.

*允许在每页/每篇文章的基础上例外。

* Allowing protected posts/pages to be bypassed.

*允许绕过受保护的帖子/页面。

* Integration with popular Member Plugins.

*与流行的会员插件集成。

* Integration with Pods CMS.

*与Pods CMS集成。

* Anything else requested.

*还有其他要求。

Usage

用法

The usage of this plugin varies, I created it after having to do something very simple for a

此插件的用法各不相同,我在做完一个非常简单的操作后便创建了它

project that wasn’t built in, allowing a search engine to crawl private posts while remaining

未内置的项目,允许搜索引擎在保留剩余信息的同时抓取私人信息

private.

私人的。

I was able to do it using IP address, and this made the process much easier.

我能够使用IP地址做到这一点,这使整个过程变得更加容易。

Other uses could include:
   

其他用途可能包括:
   

* Allowing certain roles (such as authors) to see private media.
   

*允许某些角色(例如作者)查看私人媒体。
   

* Allowing certain users to see all private posts based on their IP address.

*允许某些用户根据其IP地址查看所有私人帖子。

Extending

扩展

Note: At this point all additional folders that are added to the plugin will be deleted upon upgrade.
  

注意:此时,升级时将删除添加到插件的所有其他文件夹。
  

Until I figure out how I want to work around that, if you develop any modules you want to keep, they will
  

在我弄清楚如何解决此问题之前,如果您开发任何要保留的模块,它们将
  

have to be moved out of the plugin folder before upgrade and then moved back in.

必须先将其移出插件文件夹,然后再移回。

Advanced Post Privacy (APP) is built in a very modular way, that allows for extending upon

高级帖子隐私(APP)以非常模块化的方式构建,可以扩展到

via hooks/filters, or in the way of adding your own exclusion module.

通过挂钩/过滤器,或添加自己的排除模块。

Each type of exclusion

每种排除类型

is within it’s own code, so all code related to the role exclusion is found within the /codeole

在自己的代码中,因此所有与角色排除相关的代码都在/ code / role
中找到

directory.

目录。

Available Actions:

可用操作

* adv_pp_add_ip_address_exclusion (1 arg, the IP address being added)

* adv_pp_add_ip_address_exclusion(1个arg,正在添加IP地址)

* adv_pp_remove_ip_address_exclusion (2 args, the IP address, and the post type slug being removed)

* adv_pp_remove_ip_address_exclusion(2个args,IP地址和帖子类型段被删除)

* adv_pp_uninstall (No arguments, runs on uninstall)

* adv_pp_uninstall(无参数,在卸载时运行)

Available Filters:

可用过滤器

* adv_pp_applicable_post_types (Array of slug => label post types that APP can access.)

* adv_pp_applicable_post_types(数组可以是APP可以访问的标签发布类型。)

* adv_pp_post_type_labels (Array of labels for Post Types)

* adv_pp_post_type_labels(帖子类型的标签数组)

* adv_pp_bypassed_post_ids (Array of Post Ids the current user can bypass)

* adv_pp_bypassed_post_ids(当前用户可以绕过的发布ID数组)

Adding a type of Exclusion

添加排除类型

By default, Advanced Post Privacy (APP) has two types of exclusions, IP Address, and Role.

默认情况下,高级帖子隐私(APP)具有两种类型的排除,即IP地址和角色。

It’s built in a mostly modular fashion, and is a configuration based plugin, meaning after adding your functionality, you need to explicitly tell the system about your new functionality, via the config.json file.

它以一种大多数模块化的方式构建,并且是一个基于配置的插件,这意味着添加功能后,您需要通过config.json文件向系统明确告知新功能。

If you wanted to add a new type of exclusion, for example IP Address Range, you would have to do the following –
  

如果要添加新的排除类型,例如IP地址范围,则必须执行以下操作–
  

* Create a new directory inside the code folder, naming doesn’t matter much here, it could be called “ip-range”.
  

*在代码文件夹中创建一个新目录,这里的命名没什么关系,它可以称为“ ip-range”。
  

* Create a file called exclusion.php, this will be a class which could be called “ipRangeExclusions”, this class must implement the “appExclusions” interface, and should (for posterity) extend the primary “advancedPostPrivacy” class.

*创建一个名为exclusion.php的文件,这将是一个可以称为“ ipRangeExclusions”的类,该类必须实现“ appExclusions”接口,并且(为了后代)应该扩展主要的“ advancedPostPrivacy”类。

This will force the class to have 5 static methods, broken down as:
  

这将迫使该类具有5个静态方法,细分为:
  

* optionName() – Takes no arguments, and returns the name of the option in which all the exclusions will be stored in the database.

* optionName()–不接受任何参数,并返回将所有排除项存储在数据库中的选项的名称。

This should be prefixed with the “APP_PREFIX” constant for uniqueness.

为了唯一起见,应在其前面加上“ APP_PREFIX”常量。

This option will be completely removed on the uninstall (deletion) of the plugin.
  

此选项将在插件的卸载(删除)中完全删除。
  

* getExclusion() – Takes an optional $identifier argument, without that argument it should contain the code that gets all exclusions of the IP Range type, with it, it will return exclusions for that specific IP Range.
  

* getExclusion()–接受一个可选的$ identifier参数,不带该参数的参数应包含获取IP范围类型的所有排除项的代码,它将返回该特定IP范围的排除项。
  

* setExclusion() – Takes an array of data that will set a single exclusion of that type.

setExclusion()–接收一组数据,该数据将设置该类型的单个排除。

To comply with the other types, your code should contain a similar snippet on a successful added exclusion:
         

为了符合其他类型,您的代码应在成功添加排除项后包含类似的代码段:
         

do_action(APP_PREFIX .
                               

do_action(APP_PREFIX。
                               

‘add_’ .
                               

‘add_’。
                               

self::getExclusionModuleData(CLASS, ‘singular’) .
                               

self :: getExclusionModuleData( CLASS ,'singular')。
                               

‘_exclusion’, $exclusionData[‘excluded_ip’]);
  

‘_exclusion’,$ exclusionData [‘excluded_ip’]));
  

This will create a hook for when an exclusion of your type is created.

这将为创建排除类型时创建一个钩子。

This method should also ignore any entries that already exist, just for good practice.
  

出于良好实践,此方法还应忽略任何已存在的条目。
  

* removeExclusion() – This takes two arguments, the exclusions unique identifier (in this case it would be the IP Range), and the post type slug (“post”, “page”, etc).

* removeExclusion()–这有两个参数,排除唯一标识符(在这种情况下,它将是IP范围)和帖子类型slug(“ post”,“ page”等)。

This code should remove the exclusion, and create an identical hook to the one in setExclusion(), only with the term remove instead of add.
  

此代码应删除排除项,并在setExclusion()中创建与该挂钩相同的钩子,仅使用术语remove而不是add。
  

* getExcludedPostIds() – This is the function that makes your exclusion type work, you do whatever checking you would need to here, in this case it would be checking if the users IP address (constant “VIEWER_IP_ADDRESS”) falls within any of the ranges

* getExcludedPostIds()–这是使排除类型起作用的功能,您需要在此处进行任何检查,在这种情况下,它将检查用户的IP地址(常数“ VIEWER_IP_ADDRESS”)是否在任何范围内

in the database.

在数据库中。

It should return an array of private post Ids, that can be obtained by using:
               

它应该返回一个私有帖子ID数组,可以使用以下方法获得:
               

self::getPrivatePostIdsFromPostTypes($arrayOfPostTypes)
  

self :: getPrivatePostIdsFromPostTypes($ arrayOfPostTypes)
  

Ideally the array of post types would be obtained by calling self::getExclusion() with the IP range passed.
  

理想情况下,可以通过调用具有IP范围的self :: getExclusion()获得帖子类型数组。
  

* Now, ajax files for the interface must be created, create a folder called ajax within the code folder, and create files called action.php, and js.php.
  

*现在,必须创建该接口的ajax文件,在代码文件夹中创建一个名为ajax的文件夹,并创建一个名为action.php和js.php的文件。
  

* With action.php, this will store the functionality of your ajax calls, the class should extend appAjaxAction, and actions should be added to the wp_ajax_action_name method, refer to the WordPress Ajax API for more information.
  

*使用action.php,它将存储您的ajax调用的功能,该类应扩展appAjaxAction,并将操作添加到wp_ajax_action_name方法,有关更多信息,请参阅WordPress Ajax API。
  

* With js.php, this will store the javascript that triggers your ajax calls, the class should extend appAjaxJs, and all methods should be added to the admin_head hook.

*使用js.php,它将存储触发您的ajax调用的javascript,该类应扩展appAjaxJs,并且应将所有方法添加到admin_head挂钩中。

Again, following the practices of the WordPress Ajax API.
  

同样,遵循WordPress Ajax API的做法。
  

* Now you can create the user interface “widget” (in the non-WP sense) to your exclusion type, this will be a php file in your directory named settings.php.

*现在,您可以为排除类型创建用户界面“ widget”(非WP含义),这将是您目录中名为settings.php的php文件。

This will be included on the settings page.
  

这将包含在设置页面中。
  

* Finally, all of this is done, but the system still doesn’t know your exclusion module exists, but once you tell it it’s there, it will function seamlessly with the rest of the system (configuration based ftw).

*最后,所有步骤都已完成,但是系统仍然不知道您的排除模块存在,但是一旦您知道该模块存在,它将与系统的其余部分无缝运行(基于配置的ftw)。

We do this by modifying the config.json in the root directory, you may want to back it up since it’s easy to mess up the syntax.

我们通过修改根目录中的config.json来完成此操作,您可能希望对其进行备份,因为这样很容易弄乱语法。

You’ll want to add 3 lines of json under the “exclusionModules” array item, this would be an example:
               

您需要在“ exclusionModules”数组项下添加3行json,这将是一个示例:
               

“ipAddressExclusions”: {
                       

“ ipAddressExclusions”:{
                       

“singular”: “ip_address”,
                       

“单数”:“ ip_address”,
                       

“directory”: “code/ip-address”
                        

“目录”:“代码/ ip地址”
                        

}

}

ipAddressExclusions must match the class name used in your exclusions.php file, the singular name is what will be used in hooks (and probably other places later), the directory is simply where your code lives from the plugin path, in this

ipAddressExclusions必须与您的exclusions.php文件中使用的类名匹配,单数名称是将在钩子(以及以后可能在其他地方)中使用的名称,在该目录中,代码仅位于插件路径中

example it would be “code/ip-range”.

例如“代码/ ip范围”。

Refresh your settings page, and you should see your system in effect!

刷新您的设置页面,您应该会看到系统生效!

Data available to your Exclusion Module

排除模块可用的数据

If you followed the conventions, all of your classes will ultimately extend the core advancedPostPrivacy class,

如果遵循这些约定,则所有类最终都会扩展核心的AdvancedPostPrivacy类,

meaning you have access to all the methods within the class, however most of them may be made private in the

表示您可以访问该类中的所有方法,但是大多数方法可以在
中设为私有

future as they are really for the core.

未来,因为它们确实是核心。

The protected static property of $_json_config is stored here,

$ _json_config的受保护静态属性存储在此处,

and has the complete array of the loaded json configuration file.

并具有已加载的json配置文件的完整数组。

Assets Available

可用资产

jQuery chosen js, and css, is enqueued via APP, and can be called on any pages as it is normally called.

jQuery选择的js和css通过APP入队,并且可以像通常那样在任何页面上调用。

Constants

常量

APP_PREFIX (adv_pp_)

APP_PREFIX(adv_pp_)

APP_PATH

APP_PATH

APP_CODE_PATH

APP_CODE_PATH

APP_DESIGN_PATH

APP_DESIGN_PATH

APP_PLUGIN_URL

APP_PLUGIN_URL

APP_DESIGN_URL

APP_DESIGN_URL

APP_CONFIG_FILE (path to the config.json file)

APP_CONFIG_FILE(config.json文件的路径)

VIEWER_IP_ADDRESS (users REMOTE_ADDR from $_SERVER)

VIEWER_IP_ADDRESS($ _ SERVER中的用户REMOTE_ADDR)

安装步骤

    1. Download the plugin and extract the files to the /wp-content/plugins/ directory.
    2. 下载插件并将文件解压缩到/ wp-content / plugins /目录。

    3. Activate the plugin through the Plugins menu.
    4. 通过“插件”菜单激活插件。

下载地址

https://downloads.wordpress.org/plugin/advanced-post-privacy.zip

https://downloads.wordpress.org/plugin/advanced-post-privacy.zip

-EOF-

AI助手支持GPT4.0