Title: OthelloBloke's Replies | WordPress.org

---

# OthelloBloke

  [  ](https://wordpress.org/support/users/othellobloke/)

 *   [Profile](https://wordpress.org/support/users/othellobloke/)
 *   [Topics Started](https://wordpress.org/support/users/othellobloke/topics/)
 *   [Replies Created](https://wordpress.org/support/users/othellobloke/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/othellobloke/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/othellobloke/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/othellobloke/engagements/)
 *   [Favorites](https://wordpress.org/support/users/othellobloke/favorites/)

 Search replies:

## Forum Replies Created

Viewing 15 replies - 1 through 15 (of 186 total)

1 [2](https://wordpress.org/support/users/othellobloke/replies/page/2/?output_format=md)
[3](https://wordpress.org/support/users/othellobloke/replies/page/3/?output_format=md)…
[11](https://wordpress.org/support/users/othellobloke/replies/page/11/?output_format=md)
[12](https://wordpress.org/support/users/othellobloke/replies/page/12/?output_format=md)
[13](https://wordpress.org/support/users/othellobloke/replies/page/13/?output_format=md)
[→](https://wordpress.org/support/users/othellobloke/replies/page/2/?output_format=md)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Error with an old plugin using count() function](https://wordpress.org/support/topic/error-with-an-old-plugin-using-count-function/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/error-with-an-old-plugin-using-count-function/#post-12072955)
 * That nailed it. Thank you.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Error with an old plugin using count() function](https://wordpress.org/support/topic/error-with-an-old-plugin-using-count-function/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/error-with-an-old-plugin-using-count-function/#post-12069211)
 * Ryan’s Useful Options.
 * I took an old plugin called is_child and integrated into a plugin that I use 
   on some client sites because I was sick and tired of copying and pasting. Figured
   I’d make a plugin.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Force User Email Change](https://wordpress.org/support/topic/force-user-email-change/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/force-user-email-change/#post-12010622)
 * [@mushmellow](https://wordpress.org/support/users/mushmellow/)
 * Hi… cheers. I don’t want to change the passwords. I want to force people to change
   their email addresses.
 * Ryan
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/page/2/#post-11659140)
 * I fixed it. I was using the ID, and just used the page slug and everything worked
   perfectly.
 * Legit appreciate your help mate.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/page/2/#post-11659082)
 * It said there was another function because when you told me to try that, I didn’t
   erase all of the other code that initially defined it.
 * Thanks for your help anyway 🙂
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/page/2/#post-11659071)
 * I did that. It showed me a bunch of errors about other random plugins, but not
   a single error about is_child.
 * I even deleted ALL of that code from the plugin, and is_child then gave me an
   undefined function error.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659040)
 * I just went through the ENTIRE plugin, and the ONLY place is_child is used or
   mentioned is here:
 *     ```
       <?php
   
       if( !function_exists( "is_child" ) ) {
   
       	function is_child( $ofParent, $doRecursive = true ) {
   
       		global $wpdb;
       		$allCats = array();
   
       		// Turn title or slug into ID if needed.
       		if( !is_int( $ofParent ) ) {
       			if( is_page() )
       				# Different handling for Pages
       				$getID = $wpdb->get_results("
       					SELECT	ID as cat_ID
       					FROM	{$wpdb->posts}
       					WHERE	post_title = '{$ofParent}'
       					OR		post_name = '{$ofParent}'
       					LIMIT	0,1
       				");
       			else
       				# Get catID
       				$getID = $wpdb->get_results("
       					SELECT	cat_ID
       					FROM	{$wpdb->terms}
       //					FROM	{$wpdb->categories}
       					WHERE	cat_name = '{$ofParent}'
       					OR		category_nicename = '{$ofParent}'
       					LIMIT	0,1
       				");
   
       			if( !$getID )
       				# Not found.
       				return false;
       			else {
       				# Found.
       				$ofParent = $getID[0]->cat_ID;
       				unset( $getID );
       			}
       		}
   
       		// Everyone's a sub zero.
       		if( $ofParent == 0 && $doRecursive )
       			return true;
   
       		// Now let's break it down to categories (or pages).
       		if( is_page() ) {
       			global $post;
       			$allCats[] = $post->ID;
       		} elseif( is_single() ) {
       			$getCats = get_the_category();
       			foreach( $getCats as $getCat )
       				$allCats[] = $getCat->cat_ID;
       			unset( $getCats );
       		} elseif( is_category ) {
       			global $cat;
       			$allCats[] = $cat;
       		}
   
       		// Already a match? Would save processing time.
       		if( in_array( $ofParent, $allCats ) )
       			return true;
   
       		// Post without recursive search ends here.
       		if( ( is_single() ) && !$doRecursive )
       			return false;
   
       		// Otherwise, let's do some genealogy.
       		while( count( $allCats ) != 0 ) {
       			if( in_array( $ofParent, $allCats ) )
       				return true;
       			else 
       				$allCats = 
       					is_child_getParents( $allCats );
       		}
   
       		// Still here? Then nothing has been found.
       		return false;
   
       	}
       }
   
       if( !function_exists( "is_child_getParents" ) ) {
   
       	function is_child_getParents( $fromChilds ) {
   
       		// As there's only get_category_parents which isn't useful 
       		// for fetching parental data, we'll have to query this
       		// directly to the DB.
       		global $wpdb;
   
       		$fromChilds = implode( ", ", $fromChilds );
       		if( !$fromChilds ) return array();
   
       		$getParents = 
       			( is_page() )
       			?	# Pages
       				$wpdb->get_results("
       					SELECT	post_parent AS category_parent
       					FROM	{$wpdb->posts}
       					WHERE	ID IN ({$fromChilds})
       				")
       			: 	# Posts / Categories
       				$wpdb->get_results("
       					SELECT	category_parent
       //					FROM	{$wpdb->categories}
       					FROM	{$wpdb->terms}
       					WHERE	cat_ID IN ({$fromChilds})
       				");
   
       		foreach( $getParents as $getParent )
       			if( $getParent->category_parent != 0 )
       				$allParents[] = $getParent->category_parent;
   
       		return $allParents;
   
       	}
       }
       ```
   
 * and then when I try to use it. I’m really stuck.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659034)
 * So why does it work if I replace my original code with:
 * if( !is_user_logged_in() && is_child(232) ) { auth_redirect(); }
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659028)
 * No I mean it’s only defined in one place in the plugin… and then I use the is_child
   function later on in the plugin in a difference place.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659023)
 * Yeah it’s being defined in the same plugin.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659018)
 * is_child already exists.
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11659003)
 * It’s not echoing anything 🙁 I’m stuck. Here’s the is_child function:
 *     ```
       <?php
   
       if( !function_exists( "is_child" ) ) {
   
       	function is_child( $ofParent, $doRecursive = true ) {
   
       		global $wpdb;
       		$allCats = array();
   
       		// Turn title or slug into ID if needed.
       		if( !is_int( $ofParent ) ) {
       			if( is_page() )
       				# Different handling for Pages
       				$getID = $wpdb->get_results("
       					SELECT	ID as cat_ID
       					FROM	{$wpdb->posts}
       					WHERE	post_title = '{$ofParent}'
       					OR		post_name = '{$ofParent}'
       					LIMIT	0,1
       				");
       			else
       				# Get catID
       				$getID = $wpdb->get_results("
       					SELECT	cat_ID
       					FROM	{$wpdb->terms}
       //					FROM	{$wpdb->categories}
       					WHERE	cat_name = '{$ofParent}'
       					OR		category_nicename = '{$ofParent}'
       					LIMIT	0,1
       				");
   
       			if( !$getID )
       				# Not found.
       				return false;
       			else {
       				# Found.
       				$ofParent = $getID[0]->cat_ID;
       				unset( $getID );
       			}
       		}
   
       		// Everyone's a sub zero.
       		if( $ofParent == 0 && $doRecursive )
       			return true;
   
       		// Now let's break it down to categories (or pages).
       		if( is_page() ) {
       			global $post;
       			$allCats[] = $post->ID;
       		} elseif( is_single() ) {
       			$getCats = get_the_category();
       			foreach( $getCats as $getCat )
       				$allCats[] = $getCat->cat_ID;
       			unset( $getCats );
       		} elseif( is_category ) {
       			global $cat;
       			$allCats[] = $cat;
       		}
   
       		// Already a match? Would save processing time.
       		if( in_array( $ofParent, $allCats ) )
       			return true;
   
       		// Post without recursive search ends here.
       		if( ( is_single() ) && !$doRecursive )
       			return false;
   
       		// Otherwise, let's do some genealogy.
       		while( count( $allCats ) != 0 ) {
       			if( in_array( $ofParent, $allCats ) )
       				return true;
       			else 
       				$allCats = 
       					is_child_getParents( $allCats );
       		}
   
       		// Still here? Then nothing has been found.
       		return false;
   
       	}
       }
   
       if( !function_exists( "is_child_getParents" ) ) {
   
       	function is_child_getParents( $fromChilds ) {
   
       		// As there's only get_category_parents which isn't useful 
       		// for fetching parental data, we'll have to query this
       		// directly to the DB.
       		global $wpdb;
   
       		$fromChilds = implode( ", ", $fromChilds );
       		if( !$fromChilds ) return array();
   
       		$getParents = 
       			( is_page() )
       			?	# Pages
       				$wpdb->get_results("
       					SELECT	post_parent AS category_parent
       					FROM	{$wpdb->posts}
       					WHERE	ID IN ({$fromChilds})
       				")
       			: 	# Posts / Categories
       				$wpdb->get_results("
       					SELECT	category_parent
       //					FROM	{$wpdb->categories}
       					FROM	{$wpdb->terms}
       					WHERE	cat_ID IN ({$fromChilds})
       				");
   
       		foreach( $getParents as $getParent )
       			if( $getParent->category_parent != 0 )
       				$allParents[] = $getParent->category_parent;
   
       		return $allParents;
   
       	}
       }
       ```
   
 *   Forum: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
   
   In reply to: [Help using a variable in a function parameter](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/help-using-a-variable-in-a-function-parameter/#post-11658966)
 * I already did that. It’s echoing the page ID number that it’s supposed to.
 * But it doesn’t work when I put the variable as the parameter 🙁
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Custom Plugin Settings Screen – Saving HTML](https://wordpress.org/support/topic/custom-plugin-settings-screen-saving-html/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/custom-plugin-settings-screen-saving-html/#post-11643951)
 * Anyone?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Contact Form 7] wpcf7_add_shortcode is deprecated](https://wordpress.org/support/topic/wpcf7_add_shortcode-is-deprecated-4/)
 *  Thread Starter [OthelloBloke](https://wordpress.org/support/users/othellobloke/)
 * (@othellobloke)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/wpcf7_add_shortcode-is-deprecated-4/#post-11534837)
 * I’m not using **wpcf7_add_shortcode** anywhere.
 * I just installed the plugin, and added **`[contact-form-7 id="50" title="Contact
   form 1"]`** to my page.
 * That post doesn’t show me how to fix the error.

Viewing 15 replies - 1 through 15 (of 186 total)

1 [2](https://wordpress.org/support/users/othellobloke/replies/page/2/?output_format=md)
[3](https://wordpress.org/support/users/othellobloke/replies/page/3/?output_format=md)…
[11](https://wordpress.org/support/users/othellobloke/replies/page/11/?output_format=md)
[12](https://wordpress.org/support/users/othellobloke/replies/page/12/?output_format=md)
[13](https://wordpress.org/support/users/othellobloke/replies/page/13/?output_format=md)
[→](https://wordpress.org/support/users/othellobloke/replies/page/2/?output_format=md)