varunsridharan/wp-endpoint

一个用于处理WordPress中自定义端点或重写的简单库

1.5 2021-04-11 07:14 UTC

This package is auto-updated.

Last update: 2024-08-29 05:06:23 UTC


README

一个用于处理WordPress中自定义端点或重写的简单库

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock available

安装

通过Composer安装此扩展是首选方式。

要安装WP_EndPoint库,只需

$ composer require Varunsridharan/WP_Endpoint

之前的命令只会安装必要的文件,如果您想下载整个源代码,可以使用

$ composer require Varunsridharan/WP_Endpoint --prefer-source

您还可以使用Git 克隆完整的仓库

$ git clone https://github.com/varunsridharan/wp-endpoint.git

手动安装

下载WP_Endpoint.php:

$ wget https://raw.githubusercontent.com/varunsridharan/wp-endpoint/master/class-endpoint.php

用法

$vs_wp_endpoint = new \Varunsridharan\WordPress\Endpoint('customprefix');

添加端点 [ add_endpoint( $endpoint, $endpoint_type, $callback) ]

/**
 * Adds Custom Endpoints To Endpoints Array.
 *
 * @param string       $endpoint
 * @param int          $endpoint_type
 * @param array|string $callback 
 *                     if callback is a string and no function with the name then it will be triggered as action
 *
 * @example add_endpoint('hello/',EP_PAGES,'my_page_calback')
 * @example add_endpoint('world/',EP_PAGES,array(&$this,'page_callback'))
 *
 * @return $this
 */
 
 // With Action Trigger
 $vs_wp_endpoint->add_endpoint('myendpoint',EP_ROOT,'myendpoint_action');
 
 // With Function Callback
 $vs_wp_endpoint->add_endpoint('myendpoint2',EP_ROOT,'myendpoint_callback');
 
 // With Class Callback
 $vs_wp_endpoint->add_endpoint('myendpoint3',EP_ROOT,array('VS_CALLBACK_HANDLER','render'));


add_action('myendpoint_action','render_endpoint_page');

function render_endpoint_page($wp){
	var_dump($wp->query_vars);
}

function myendpoint_callback($wp){
	var_dump($wp->query_vars);
}

class VS_CALLBACK_HANDLER{
	public static function render($wp){
		echo 'Hi';
	}
}

添加重写规则 [ add_rewrite_rule( $path, $after ) ]

/**
 * Adds Custom Rewrite Rules.
 *
 * @param string $path
 * @param string $after
 *
 * @return $this
 */
 
// Below Will Be Converted into **http://example.com/mypath/22/xxx/
$vs_wp_endpoint->add_rewrite_rule('mypath/{user_id}/{user_name}','top');

// Below Will Be Converted into **http://example.com/welcome/EICAUTPPWICAASJEJNCA/
$vs_wp_endpoint->add_rewrite_rule('welcome/{verify_id}','top');

📝 更新日志

此项目的所有重大变更都将记录在此文件中。

格式基于Keep a Changelog,并且本项目遵循语义化版本控制

查看CHANGELOG.md

🤝 贡献

如果您想帮忙,请查看问题列表

📜 许可证 & 行为准则

📣 反馈

  • ⭐ 如果此项目对您有所帮助! 😉
  • 如果您需要帮助/发现错误,请创建一个问题

💰 赞助

我在2013年爱上了开源,从那以后就没有回头路了!您可以在这里了解更多关于我的信息这里。如果您或您的公司使用了我的任何项目,或者喜欢我所做的事情,请考虑支持我。我打算长期坚持下去。

  • ☕ 咖啡时间?只需$9.99
  • ☕️☕️ 每月买我两杯咖啡怎么样?您只需支付$9.99
  • 🔰 我们热爱改进开源项目。支持一次性的开源维护时间,只需 $24.99
  • 🚀 喜欢开源工具?我也是!支持一次性的开源开发时间,只需 $49.99

连接 & 问候 👋

Varun Sridharan 使用 制作