2013-01-20 1 views
2

d'abord je tiens à dire aux gens que je suis très faible dans wordpress, je viens de commencer, donc si je pose une question idiote, alors s'il vous plaît ignorer mon ignorance ..Chargement du fichier .php sous wordpress pugins fonction

j'ai un wordpress pugins scénario

<?php 
/* 
Plugin Name: Saswat Routroy 
Plugin URI: http://www.maheshchari.com/ 
Description: Description of my plugin 
Author URI: http://www.maheshchari.com/ 
*/ 
class new_menu { 

    function new_menu() 
    { 
     add_action('admin_menu', array(&$this, 'my_admin_menu')); 
    } 

    function my_admin_menu() 
    { //create a main admin panel 
     //create a sub admin panel link above 
     add_menu_page('CMS', 'CMS', 'administrator', 8, array(&$this,'overview')); 
     add_submenu_page(8, 'View CMS Page', 'View CMS Page', 'administrator', 1, array(&$this,'view_page')); 
     add_submenu_page(8, 'Add CMS Page', 'Add CMS Page', 'administrator', 2, array(&$this,'add_page')); 
     //These functions adds sub menu for different kinds of admin panel on back end 
     add_options_page('Pages Options', 'Saswat Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_options')); 
     add_posts_page('Pages posts', 'Saswat Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_posts')); 
     add_media_page('Pages media', 'Saswat Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_media')); 
     add_pages_page('Pages pages', 'Saswat Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_pages')); 
     add_users_page('Pages users', 'Saswat Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_users')); 
     add_management_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_tools')); 
     add_theme_page('maheshchari', 'Mahesh Plugin', 'administrator', basename(__file__),array(&$this, 'my_plugin_themes')); 

    } 


    function overview() 
    { 
     echo '<h2>My Wordpress Plugin Overview</h2>'; 
    } 

    function view_page() 
    { 
     echo '<h2>My Wordpress Plugin Settings</h2>'; 
    } 

    function add_page() 
    { 
     //echo '<h2>My Wordpress Plugin Generel</h2>'; 
     echo "<form method='POST' action=''> 
    <ul> 
     <li><label for='fname'>Family Name (Sir Name)<span> *</span>: </label> 
     <input id='fname' maxlength='45' size='10' name='fname' value='' /></li>  

     <li><label for='lname'>Last Name<span> *</span>: </label> 
     <input id='lname' maxlength='45' size='10' name='lname' value='' /></li> 
     <li><label for='lname'>Last Name<span> *</span>: </label> 
     <input type='submit' maxlength='45' size='10' name='lname' value='' /></li> 
    </ul> 
</form>"; 
    } 
    function my_plugin_options() 
    { 
     echo '<h2>My Wordpress Plugin Options</h2>'; 

    } 
    function my_plugin_posts() 
    { 
     echo '<h2>My Wordpress Plugin posts</h2>'; 
    } 
    function my_plugin_media() 
    { 
     echo '<h2>My Wordpress Plugin media</h2>'; 
    } 
    function my_plugin_pages() 
    { 
     echo '<h2>My Wordpress Plugin pages</h2>'; 
    } 
    function my_plugin_users() 
    { 
     echo '<h2>My Wordpress Plugin users</h2>'; 
    } 

    function my_plugin_tools() 
    { 
     echo '<h2>My Wordpress Plugin tools</h2>'; 
    } 

    function my_plugin_themes() 
    { 
     echo '<h2>My Wordpress Plugin themes</h2>'; 
    } 


} 


$mybackuper = &new new_menu();//instance of the plugin class 

?> 

le fichier est Kep sous \ wp-content \ plugins \ admin menu \ new_menu.php

maintenant je suis la fonction add_page() faisant écho à la html . i dnt veux faire, est-il possible que je puisse charger une page .php sous la fonction sans écho le script ..

dire quelque chose comme

<?php get_template_part('content-home');?> 

Répondre

0

j'ai obtenu la réponse

include('content-home.php'); 
+1

+1 vraiment travaillé avec ce simple 'inclure' Mate s'il vous plaît partager votre expérience. Merci! C'est très intéressant! o/\ o –

1

Je ne suis pas sûr que vous comprends bien. Voici un moyen de stocker une sortie sans écho:

public $contents_add_page = ''; 

function add_page() 
{ 
    ob_start(); 

    //echo '<h2>My Wordpress Plugin Generel</h2>'; 
    echo "<form method='POST' action=''> 
<ul> 
<li><label for='fname'>Family Name (Sir Name)<span> *</span>: </label> 
<input id='fname' maxlength='45' size='10' name='fname' value='' /></li>  
<li><label for='lname'>Last Name<span> *</span>: </label> 
<input id='lname' maxlength='45' size='10' name='lname' value='' /></li> 
<li><label for='lname'>Last Name<span> *</span>: </label> 
<input type='submit' maxlength='45' size='10' name='lname' value='' /></li> 
</ul> 
</form>"; 

    $this->contents_add_page = ob_get_contents(); 
    ob_end_clean(); 
} 

Vous pouvez inclure un fichier et stocker sa sortie dans un var aussi:

ob_start(); 
include DIR . '/content-home.php'; 
$contents   = ob_get_contents(); 
ob_end_clean(); 

En effet, j'utilise ces techniques WP à la sortie HTML via AJAX.

+0

@saswat Bon à savoir que vous avez atteint votre objectif! –

Questions connexes