admin管理员组文章数量:1431420
I don´t why for some reasons, my callback function is not called for this url :
https://my-site/?post_type=foo-login&p=11
In the database is like this :
+----+---------------------------------------------------------------------------+------------+-------------+-----------+-----------+
| ID | post_content | post_title | post_status | post_name | post_type |
+----+---------------------------------------------------------------------------+------------+-------------+-----------+-----------+
| 19 | <!-- wp:paragraph --><p>[foo-plans][/foo-plans]</p><!-- /wp:paragraph --> | Plans | published | plans | page |
| 11 | [foo-login][/foo-login] | Login | published | sign-in | foo-login |
+----+---------------------------------------------------------------------------+------------+-------------+-----------+-----------+
Php classes
Shortcode abstract class
abstract class Shortcode{
public $tag;
public $attrs;
public $function;
public function __construct( $tag ) {
$this->attrs = array();
$this->tag = $tag;
$this->function = get_called_class().'::getCallBack';
add_shortcode( $this->tag, $this->function );
$this->init();
}
protected function init(){
if( !is_admin() ){
//Front-end
add_action('wp', array( $this , 'check_page' ) );
}
}
abstract public function check_page();
public static function page_template( $template = "" ) {
if( empty( $template ) ){
$template = locate_template( array( 'page.php' ) );
}
return $template;
}
}
Login Shortcode Class
class LoginShortcode extends Shortcode {
private $post_type;
public function __construct( $tag ) {
parent::__construct( $tag );
$this->post_type = $tag;
}
public function check_page(){
$login_post = get_unique_post_by_content( "[foo-login][/foo-login]", ["foo-login"] );
if( get_post_type() === $this->post_type || ( isset($_GET['p']) && (int) $_GET['p'] === $login_post->ID ) ){
add_filter( 'template_include', array( get_called_class(), 'page_template' ), 99 );
add_action( "template_redirect", array( $this, "is_redirection") );
add_action( "wp_enqueue_scripts", array( $this, "set_styles" ) );
add_action( "wp_enqueue_scripts", array( $this, "set_scripts" ) );
}
}
/**
* @throws \Exception
*/
public static function is_redirection() {
CALLED
...
return;
}
public static function getCallBack( $attrs = null ){
NEVER CALLED !!!
}
public function set_styles() {
...
}
public function set_scripts() {
...
}
}
For the shortcode [foo-plans][/foo-plans]
that works with the right url but for [foo-login][/foo-login]
the callback function is never called.
When I display the list of shortcodes, foo-login
is in the list.
global $shortcode_tags;
var_dump( $shortcode_tags );
/*output = array (
'wp_caption' => 'img_caption_shortcode',
'caption' => 'img_caption_shortcode',
'gallery' => 'gallery_shortcode',
'playlist' => 'wp_playlist_shortcode',
'audio' => 'wp_audio_shortcode',
'video' => 'wp_video_shortcode',
'embed' => '__return_false',
'foo-plans' => 'Shortcodes\\PlansListShortcode::getCallBack',
'foo-login' => 'Shortcodes\\LoginShortcode::getCallBack'
)*/
One differnce between foo-plans
abd foo-login
is the post type but I don´t know if it´s the key to find a solution.
本文标签: Shortcode callback not called
版权声明:本文标题:Shortcode callback not called 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745530834a2662052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论