jquery - Issue to include wp-config.php file in wordpress plugin file -


i working on plugin, in plugin create ajax (in plugin index file) when user write in search bar related posts title shows in drop down , result create other file "foo_get_posts.php" in plugin root directory. here code:

function foo_search_form(){ ?>     <div class="foo_search_field">         <form role="search" method="get" id="searchform" class="clearfix" action="<?php echo home_url( '/' ); ?>" autocomplete="off">             <input type="text" onfocus="if (this.value == '<?php _e("search posts...", "foo") ?>') {this.value = '';}" onblur="if (this.value == '')  {this.value = '<?php _e("search posts...", "foo") ?>';}" value="<?php _e("search posts...", "foo") ?>" name="s" id="s" />             <ul id="foo_search_dropdown"></ul>             <input type="hidden" name="post_type" value="foo_base" />         </form>     </div> <?php }  add_action('wp_head', 'foo_search_drop'); function foo_search_drop(){ ?> <script type="text/javascript">     jquery(document).ready(function() {         jquery('#s').keyup(function() {             jquery('#foo_search_dropdown').slidedown("slow");             // data             var foo_search_term = jquery(this).val();              // sending data through ajax process             jquery.post('<?php echo plugin_dir_url(__file__) ?>foo_get_posts.php', {foo_search_key: foo_search_term}, function(data) {                 jquery('#foo_search_dropdown').html(data);             });         });     }); </script> <?php } 

foo_get_posts.php file code:

<?php require_once( str_replace('//','/',dirname(__file__).'/') .'../../../wp-config.php');  global $wpdb; $foo_search_key = $_post['foo_search_key']; $tbl_posts = $wpdb->prefix."posts"; $tbl_relation = $wpdb->prefix."term_relationships"; $tbl_taxonomy = $wpdb->prefix."term_taxonomy"; $tbl_terms = $wpdb->prefix."terms";  if(!empty($foo_search_key)){     $foo_search_sql = $wpdb->get_results(" // sql query goes here");      if($foo_search_sql){         foreach ($foo_search_sql $search_result) {         ?>             <li>                 <a href="<?php echo site_url()."/".foo_plugin_slug."/".$search_result->post_name ?>">                     <?php echo $search_result->post_title; ?>                 </a>             </li>             <?php         }     } else {         ?>             <span>search result not found......</span> <?php     } } ?> 

first don't call require_once( str_replace('//','/',dirname(__file__).'/') .'../../../wp-config.php'); in file, don't results, ask question , work goes perfectly.

problem

now plugin complete , send wordpress , reject it, say:

## calling core loading files directly  you're calling in foo_get_posts.php  require_once( str_replace('//','/',dirname(__file__).'/') .'../../../wp-config.php');  including wp-config.php, wp-blog-header.php, wp-load.php, or pretty other wordpress core file have call directly via include not idea , cannot approve plugin unless has reason load file(s). prone failure since not wordpress installs have exact same file structure.  plugins include wp-config.php or wp-load.php in order gain access core wordpress functions, there better ways this. it's best if tie processing functions (the ones need don't have access core functions) action hook, such "init" or "admin_init". 

i try move file "foo_get_posts.php" in theme , call header , footer gives me error, reverted work.

if remove line require_once( str_replace('//','/',dirname(__file__).'/') .'../../../wp-config.php'); file don't db results, neccessry me.

so please tell me how can resolve issue, please me.

as per wordpress document,, if plugin called "fabulous functionality", might call php file fabulous-functionality.php. first create file , include other files


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -