2013-08-30 112 views
2

我創建一個WordPress插件使用的查詢字符串,讓頁面的打印版本,我有這樣的代碼在我的插件:Wordpress打印版本|在一個插件訪問WordPress的核心功能

if(isset($_GET['print']) && $_GET['print'] == "true") { 

    // some code 

    exit(); 
} 

,但我得到了一些錯誤有關wordpress函數像the_post()等。 首先我想知道我是否正確地顯示打印版本的頁面? 第二,如果我正確的做法,我應該如何包含wordpress的核心功能? (我想我顯示包括wp-load.php)

回答

2

所有的WordPress功能都可以在插件中使用。這件事正在掛在正確的地方。

簡單的例子:

<?php 
/** 
* Plugin Name: Test Plugin 
*/ 

// This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated 
add_action('wp_loaded', 'plugin_so_18538270'); 

function plugin_so_18538270() 
{ 
    // Admin area, do nothing 
    if(is_admin()) 
     return; 

    // "true" == $var 
    // See Yoda Conditions: http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html 
    if(isset($_GET['print']) && "true" == $_GET['print']) 
    { 
     // some code 
     exit(); 
    } 
} 

參考文獻: