Forum Replies Created

Viewing 15 replies - 1 through 15 (of 186 total)
  • Thread Starter OthelloBloke

    (@othellobloke)

    That nailed it. Thank you.

    Thread Starter OthelloBloke

    (@othellobloke)

    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.

    Thread Starter OthelloBloke

    (@othellobloke)

    @mushmellow

    Hi… cheers. I don’t want to change the passwords. I want to force people to change their email addresses.

    Ryan

    Thread Starter OthelloBloke

    (@othellobloke)

    I fixed it. I was using the ID, and just used the page slug and everything worked perfectly.

    Legit appreciate your help mate.

    Thread Starter OthelloBloke

    (@othellobloke)

    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 🙂

    Thread Starter OthelloBloke

    (@othellobloke)

    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.

    Thread Starter OthelloBloke

    (@othellobloke)

    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.

    Thread Starter OthelloBloke

    (@othellobloke)

    So why does it work if I replace my original code with:

    if( !is_user_logged_in() && is_child(232) ) { auth_redirect(); }

    Thread Starter OthelloBloke

    (@othellobloke)

    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.

    Thread Starter OthelloBloke

    (@othellobloke)

    Yeah it’s being defined in the same plugin.

    Thread Starter OthelloBloke

    (@othellobloke)

    is_child already exists.

    Thread Starter OthelloBloke

    (@othellobloke)

    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;
    
    	}
    }
    
    Thread Starter OthelloBloke

    (@othellobloke)

    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 🙁

    Thread Starter OthelloBloke

    (@othellobloke)

    Anyone?

    Thread Starter OthelloBloke

    (@othellobloke)

    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)