Jump to content

[SOLVED] How to stop a function from calling another function


atticus

Recommended Posts

Alright, here is the issue. I have written a  wordpress plugin: http://www.mywebtronics.com/atlanta-seo/seo-header-plugin/

 

Wordpress uses hooks or filters to call functions. My plugin looks for the calling of the wordpress core function "the_title()" and allows the user to replace that title with something of their choosing without changing the page title.

 

The problem lies in that another core Wordpress function "wp_list_pages()" uses "the_title()". So basically, not only does the plugin change headline the title of the page, if the user is on the actual page, the navigation also shows that title. That is a problem if for example, you want your navigation to say "Home" but you want your headline to say "Welcome to PHP Freaks".

 

Is there a way to say "If (This function is running do not execute this)"

 

Here is my script?

 

<?php
//heading function
function heading($h1){
//get the id of the current post
$id = get_the_ID();

//find out the title of the current post, because get_the_title() cannot be used and the value passed from the filter will not be the same
global $table_prefix;
$sql = "SELECT `post_title` FROM `".$table_prefix."posts` WHERE `ID` = '$id';";
$query = mysql_query($sql) or die('Error, insert query failed' . mysql_error());
$row = mysql_fetch_array($query);
$title = $row['post_title']; 

//SQL to determine site URL, so we can make sure not to change the title in the admin section
$sql = " SELECT option_value
FROM `".$table_prefix."options`
where option_name = 'siteurl'";
$query = mysql_query($sql) or die('Error, insert query failed' . mysql_error());
$row = mysql_fetch_array($query);
$siteurl = $row['option_value'];
$domain = $_SERVER['HTTP_HOST'];
$path = $_SERVER['SCRIPT_NAME'];

$url = "http://" . $domain . $path . "";



if ($url != "".$siteurl."/wp-admin/edit.php" ) 
{
   if ($url != "".$siteurl."/wp-admin/edit-pages.php") {
        //make sure that the title of the current page is the only thing changed, keeps links to pages or posts that use the_title() from being set to our meta value
        if ($h1 == $title) {
           
	       //check and see if the post has any meta data using SEO_heading
          if (get_post_meta($id, "SEO_heading", true) != '') {
          //if it does, lets get the value and assign it to the title
          $h1 = get_post_meta($id, "SEO_heading", true);
          }

        } 
    }	 
}
return ($h1);
}

 

Link to comment
Share on other sites

Why not create a similar function that does not use "the_title" or pass a parameter into "the_title" telling it which operation to execute?

 

That sounds like a plan, but I have nothing. I guess you could call it "writers block" or maybe, "programmers block".

 

Hmmm...unless I use "post_request" filter, search for the title string and replace it with the new title...

 

That may work, I wonder if the wp_list_pages() is included in it?

Link to comment
Share on other sites

I do not know word press at all.

 

Here is an example of how you could setup the function:

 

function the_title($do="") {
    if ($do != "") {
          // return your custom title
    }else {
         // return the original title
    }
}

 

That way just calling the_title() defaults it to the original, but calling the_title(1) would show your code.

Link to comment
Share on other sites

premiso, thanks for the advice! You have given me something to work with...I would suggest taking a look at Wordpress, the plugins and the way they interact with Wordpress are genius :)

 

I will in the future, going to create a site using Wordpress MU and try and make some money off of ads. As far as hacking it, I probably will not look into that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.