php - WordPress plugin adds the number 1 to content if activated -


If the plugin is active, then my wp plugin adds numeric 1 to the content.

  add_filters ('the_content', 'poc_shop_cart_button_filter'); Function poc_shop_cart_button_filter ($ the_content) {$ new_content = $ the_content; $ New_content = Include (WP_CONTENT_DIR. "/custom_php/shop-cart-button.php"); Return $ New_content; }   

This is the page in which I am including the plugin:

  if (isset ($ _ cookie ['_ abs_34287GjNW'])) {$ CookieID = htmlspecialchars ($ _COOKIE ['_ _ _ _ _ _ _ _]' ', ETAQUOTES,' UTF-8 '); } And {$ cookieID = ''; } $ SupplierID = get_bloginfo ('name'); Required (Abospace. 'Wp-content / custom_php / included / connect db.fp'); Try {$ Conn = new PDO ("mysql: host = $ host; dbname = $ dbname", $ user, $ pass}; $ Conn- & gt; exec ("SET CHARACTER SET utf8"); Calculate as $ Sql ​​= "SELECT COUNT (*) with` shopping cart` where supplierID =: supplierID and cookieID =: cookie id "; $ Sqlprep = $ conn- & gt; Ready ($ sql); $ Ar_val = array (': supplierID' => $ supplierID, ': cookie id ='> & gt; $ cookieID); If ($ sqlprep-> Execute ($ ar_val)) {when ($ row = $ sqlprep-> get (PDF :: FETCH_OBJ)) {if ($ row-> count == '' || $ row- & gt; counts == 0) {$ count = '0'; } And {$ count = $ row- & gt; Count; }}} If ($ count == 1) {$ items = "item"; } And {$ item = "item"; } If (is_page (array (48)) $ count & lt; 1) {echo '& lt; Div class = "shopCartNoButton" & gt; '; Echo "& lt; img src = '" Get_template_directory_uri () "/images/cart-icon.png' alt = '' & gt;"; Echo "& lt; b & gt; $ count $ items & lt; / b & gt;"; Echo & lt; / Div & gt; & Lt; div class = "clearFix" & gt; & Lt; / Div & gt; '; } Else {echo & lt; Div class = "shopCartButton" & gt; '; Echo "& lt; img src = '" Get_template_directory_uri () "/images/cart-icon.png' alt = '' & gt;"; Echo "& lt; b & gt; $ count $ items & lt; / b & gt;"; Echo "& amp; nbsp; & lt; a href = 'office-sit / checkout /' class = 'btn btn-warning' & gt; checkout & gt; & gt; & lt; / a & gt;"; Echo & lt; / Div & gt; & Lt; div class = "clearFix" & gt; & Lt; / Div & gt; '; }} Hold (PDOException $ e) {echo $ e-> getMessage (); }   

Enter image details here

Therefore, after many Googling, the solution is as follows:

  $ filename = get_include_contents ('somefile.php'); Function get_include_contents ($ filename) {if (is_file ($ filename)) {ob_start (); Include $ Filename; Return ob_get_clean (); } return false; }   

Code:

 Include  ($ filename);   

Contains the included file + value 1 because someone was successful in joining the output buffering and should not return value 1 with returned file content.

I had the same trouble. The reason for this is that include represents the value of the call, i.e. "true" or 1 when wordpress echo Just use file_get_contents , this will help.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -