2014-07-20 49 views
-1

我正在嘗試使用簡碼創建一個非常簡單的插件,並且希望獲得此簡碼的標識。獲取簡碼wp插件的編號

我簡單的代碼是:

<?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] 所以我想這個ID [my_plugin id=9876][/my_plugin]

回答

3

你會從你的簡碼處理器通過ID來功能。

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"]