2014-07-20 3 views
-1

Я пытаюсь сделать очень простой плагин с коротким кодом, и я хочу получить идентификатор этого короткого кода.Получите идентификатор плагина wc shortcode

Мой простой код:

<?php 
/* 
Plugin Name: DEMO 
Plugin URI: http://www.mydemo.com 
Description: DEMO 
Version: 0.1 BETA 
Author: Paul McKnight 
Author URI: http://www.mydemo.com 
*/ 

function demol_handler() { 
    $demolph_output = demoplug_function(); 
    return $demolph_output; 
} 

function demoplug_function() { 
    $demolp_output = "Hello Your Shortcode id is:"; Here i want to display my shortcodes Id 
    return $demolp_output; 
} 

add_shortcode("my_plugin", "demo_handler"); 

?> 

шорткод для этого простого плагина [my_plugin][/my_plugin] Так я хочу, чтобы получить этот идентификатор [my_plugin id=9876][/my_plugin]

ответ

3

вы собираетесь передать идентификатор из обработчика SHORTCODE в функция.

function demo_handler($atts) { 
    extract(shortcode_atts(array(
     'id' => '', 
    ), $atts, 'my_plugin')); 

    $demolph_output = demoplug_function($id); 
    return $demolph_output; 
} 
add_shortcode("my_plugin", "demo_handler"); 

function demoplug_function($id) { 
    $demolp_output = "Hello Your Shortcode id is: " . $id; 
    return $demolp_output; 
} 

Использование:

[my_plugin id="1"] 
Смежные вопросы