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

quetzalrojo on "Where to begin"

$
0
0

Hi everyone,
This is my first-time on WP forum. I was looking for an open-source project to work on and though I would contribute to WP. My question is, where is a good place to begin learning about back-end WP issues? I'm a computer science major, I use Linux (Debian/crunchbang), and I'm hoping to build up some WP skills along the way to possibly do some freelance work. Any help is much appreciated. Thanks in advance.


msdb88 on "Press This for custom post types"

$
0
0

Hi,
I've looked hi and low for a "press this" plugin or code that can add information like links and text to a custom post type. The two most promising results have been:
1) http://wordpress.mfields.org/2010/bookmark-this/
2) Press This Custom Post Types

1) the first code logs me off of my site, I'm guessing for some security reason...
2) the second written by the almighty scribu :) seems to be outdated. That code only works if i change:

$link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link);

to

$link = str_replace('press-this.php', "post-new.php?post_type=$post_type", $link);

which bypasses all of the press this functionality completely.

Is there anyone who has figured this out, or knows why this is such a limited feature?
...Thanks!

charlyanderson on "PHP calculation for plugin"

$
0
0

PHP calculation help
Good evening,

I am very new to PHP and wondered if someone could help me add something onto a PHP calculation?

If someone could help it would be a HUGE help :-)

Basically I am working on a due date calculator... Currently it tells you when you due date will be from last period date. I need it to also say how many weeks pregnant the person currently is.

So last period date -> current date (displayed in weeks).

This is the PHP

function ovpredct2_datechooser($name,$value="")
{
    $months=array('','January','February','March','April','May','June','July','August',
    'September','October','November','December'); 

    if(empty($value)) $value=date("Y-m-d"); 

    $parts=explode("-",$value); 

    $day=$parts[2]+0;
    $month=$parts[1]+0;
    $year=$parts[0]; 

    $chooser=""; 

    $chooser.="<select name=".$name."month>";
    for($i=1;$i<=12;$i++)
    {
        if($i==$month) $selected='selected';
        else $selected='';
        $chooser.="<option $selected value=$i>$months[$i]</option>";
    }
    $chooser.="</select> / "; 

    $chooser.="<select name=".$name."day>";
    for($i=1;$i<=31;$i++)
    {
        if($i==$day) $selected='selected';
        else $selected='';
        $chooser.="<option $selected>$i</option>";
    }
    $chooser.="</select> / "; 

    $chooser.="<select name=".$name."year>";
    for($i=(date("Y")-1);$i<=2050;$i++)
    {
        if($i==$year) $selected='selected';
        else $selected='';
        $chooser.="<option $selected>$i</option>";
    }
    $chooser.="</select> ";     

    return $chooser;
} 

function ovpredct2_generate_html()
{
    //construct the calculator page
    $ovcalc="<style type=\"text/css\">
    .ovpredct2_table
    {
        ".get_option('ovpredct2_table')."
    }
    </style>\n\n"; 

    if(!empty($_POST['calculator_ok']))
    {
        //last cycle date
        $date="$_POST[dateyear]-$_POST[datemonth]-$_POST[dateday]"; 

        //convert to time
        $lasttime=mktime(0,0,0,$_POST[datemonth],$_POST[dateday],$_POST[dateyear]); 

        //first fertile day
        $firstdaytime=$lasttime + $_POST[days]*24*3600 - 16*24*3600;
        $firstday=date("F d, Y",$firstdaytime); 

        //last fertile day
        $lastdaytime=$lasttime + $_POST[days]*24*3600 - 12*24*3600;
        $lastday=date("F d, Y",$lastdaytime); 

        //have to adjust due date?
        $diff=$_POST[days] - 28; 

        //due date $date + 280 days
        $duedatetime=$lasttime + 280*24*3600 + $diff*24*3600;
        $duedate=date("F d, Y",$duedatetime); 

        //the result is here
        $ovcalc.='<div class="ovpredct2_table">
        Your estimated due date is <strong>'.$duedate.'</strong>
        <p align="center"><input type="button" value="Calculate again!" onclick="javascript:history.back();"></p>
        </div>'; 

    }
    else
    {
        $ovcalc.='<div class="ovpredct2_table">
        <form method="post">
        When was the first day of your last period?<br /><br />
        '.ovpredct2_datechooser("date",date("Y-m-d")).'<br><br>
        Usual number of days in your cycle: <select name="days">'; 

        for($i=20;$i<=45;$i++)
        {
            if($i==28) $selected='selected';
            else $selected='';
            $ovcalc.="<option $selected value='$i'>$i</option>";
        } 

        $ovcalc.='</select>
        <p align="center"><input type="submit" name="calculator_ok" value="Calculate"></p>
        </form>
        </div>';
    } 

    return $ovcalc;
}

A_NZ on "Add "Reply to Comment" to "This comment is already approved. Edit comment""

$
0
0

Can we add a "Reply to Comment" link to the message "This comment is already approved. Edit comment" that appears when approving an already approved comment? I sometimes approve a comment, but then come back to it (via the link sent to me via email) and try to approve it again in order to then add a reply. Currently, it is very hard to find the already-approved comment to reply to it.

yeahman45 on "When to escape and when not?"

$
0
0

I have started coding in wordpress and noticed a weird behaviour; my $_POST were being escaped...although magic quote is turned off. so after some research I found out that WP escapes superglobals even if magic quotes is off (a lot of wp programmers don't seem to be aware of that ... I guess some plugins are probably even vulnerable to sql injection)... Fine but.....

I found out that some core functions expects escaped values and some don't.....

e.g.

wp_insert_post expects all data to be escaped.
wpdb->update/insert/delete expects all data to not to be escaped...

How do I know when to escape and not?? I will not talk about implementations of actions (I guess i would need to dig through each actions and see what core functions it is calling and if i need to escape or not??)

Is there a list/guideline for this? All is so confusing....

I think I miss something (a config?); developing in wp shouldn't be that insecured right?

juzkyte on "Get query post form tag id in post"

$
0
0

I want to get other post from tag in post

In a post can have one, two,.. or more tags...

I want to get query post from tag, example: tag_id=1,2,3...

:( Help me...

morningmist on "Warning: call_user_func_array() errors"

$
0
0

The website I am working on got completely deleted and then we uploaded a back up then we have had these function errors. Suggestion how to fix?

Here are the errors:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'do_css' not found or invalid function name in /home/fresheye/public_html/rentlucky.com/wp-includes/plugin.php on line 470

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'do_jslibs' not found or invalid function name in /home/fresheye/public_html/rentlucky.com/wp-includes/plugin.php on line 470

Here is the line it refers to:

* @return null Will return null if $tag does not exist in $wp_filter array

Here is the whole section:

/**
 * Execute functions hooked on a specific action hook, specifying arguments in an array.
 *
 * @see do_action() This function is identical, but the arguments passed to the
 * functions hooked to <tt>$tag</tt> are supplied using an array.
 *
 * @package WordPress
 * @subpackage Plugin
 * @since 2.1
 * @global array $wp_filter Stores all of the filters
 * @global array $wp_actions Increments the amount of times action was triggered.
 *
 * @param string $tag The name of the action to be executed.
 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
 * @return null Will return null if $tag does not exist in $wp_filter array
 */
function do_action_ref_array($tag, $args) {
	global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;

	if ( ! isset($wp_actions[$tag]) )
		$wp_actions[$tag] = 1;
	else
		++$wp_actions[$tag];

	// Do 'all' actions first
	if ( isset($wp_filter['all']) ) {
		$wp_current_filter[] = $tag;
		$all_args = func_get_args();
		_wp_call_all_hook($all_args);
	}

	if ( !isset($wp_filter[$tag]) ) {
		if ( isset($wp_filter['all']) )
			array_pop($wp_current_filter);
		return;
	}

	if ( !isset($wp_filter['all']) )
		$wp_current_filter[] = $tag;

	// Sort
	if ( !isset( $merged_filters[ $tag ] ) ) {
		ksort($wp_filter[$tag]);
		$merged_filters[ $tag ] = true;
	}

	reset( $wp_filter[ $tag ] );

	do {
		foreach( (array) current($wp_filter[$tag]) as $the_ )
			if ( !is_null($the_['function']) )
				call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

	} while ( next($wp_filter[$tag]) !== false );

	array_pop($wp_current_filter);
}

TBean on "Twenty Twelve comment badges for Admins and Editors"

$
0
0

Hi all,

I copied twentytwelve_comment() from the functions.php to my child theme to include a "Moderator" badge beside the name if the person commenting is a site admin or editor.

I have this but it only adds badges to the post authors.

printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
	get_comment_author_link(),
	// If current post author is also comment author, make it known visually.
	( $comment->user_id === $post->post_author ) ? '<span> ' . __( 'Moderator', 'twentytwelve' ) . '</span>' : '');

I found this snippet but I don't know how to integrate it into the code above.

<?php
   $commentator_id = get_comment(get_comment_ID())->user_id;
   $commentator_info = get_userdata($commentator_id);
   $capabilities = $user_info->wp_capabilities;
   if (array_key_exists('editor', $capabilities)) {
      // echo markup here
   }
?>

Source

I'm hoping someone can show me how to get the first code to work for admins and editors too. Any help is appreciated! Thanks!


joker1234 on "show_admin_bar(false); doesn't work"

$
0
0

I tried to put show_admin_bar(false); anywhere but it doesn't work. Is there something I must do before?

Jiri Hon on "How to change template for the new gallery preview in editor?"

$
0
0

Dear WordPress community,
I am wondering what is the suggested way to customize the template of the new gallery preview in editor?

I found out, that the current template is located in /wp-includes/media-template.php in #tmpl-editor-gallery block. So I can use the print_media_templates action hook to output my own editor gallery template, but how to switch from the default to that new template?

By digging a little bit into the associated JavaScript code I found out that executing the following JavaScript code in the right time (after wordpress code is loaded) works:

wp.mce.gallery.View = wp.mce.gallery.View.extend({ template: wp.media.template("my-editor-gallery") });

Please tell me, is that the best solution? Or is there something more elegant and more stable with respect to the future development?

Thank you a lot,
Jiri Hon

T.oby on "use jquery post onsubmit function"

$
0
0

Hi, I would like to post data to PHP via a jquery post after clicking a button using the onsubmit function:

<script>
function Do () {
  alert("Before");
  jQuery(document).ready(function($) {
    $.post("/code.php", {"arg1": "1", "arg2": "2"}, function(response) {
      alert('Got this from the server: ' + response);
    });
  });
  alert("After");
}
</script>
<form name="Form1" action="" onsubmit="Do()">
<input type="submit" value="Send">
</form>

Clicking the button the before and after text is shown but not the server response. I tested the code without the button and loading it directly, i.e.:

<script>
jQuery(document).ready(function($) {
  $.post("/code.php", {"arg1": "1", "arg2": "2"}, function(response) {
    alert('Got this from the server: ' + response);
  });
});
</script>

which worked.

Any help is highly appreciated - Thanks,

Toby

Jiri Hon on "Why can't hook into wp_ajax_image-editor action?"

$
0
0

Dear WordPress community,
please, does anybody know why the following code does not work? It should output Hello world when loading image editor with AJAX, but does nothing.

function say_hello()
{
	var_dump("Hello world");
}
add_action( 'wp_ajax_image-editor', 'say_hello' );

Is there something I'm missing?

Thank you a lot,
Jiri Hon

Richzendy on "switch between two wordpress versions in to same instalation"

$
0
0

Hi, all

I have a wordpress site with only two categories: A1 and B2, i need switch between them with a button or link, if someone do click in the link A1 all my website will show only content/post to the category A1 (the same to the B2 category but with other button or link).

My wordpress website must remember the user preference and show only posts or content from the selected category to all session.

How i can do this? qtranslate does something similar, but i don't want two versions to same post.

I can filter the content using my templates by one category or other, but i don't know how detect if a user do select A1 site version or B2.

I'm open to others choices to do this, but i don't want have two wordpress instalations, multisite instalations or two themes.

Any help can be appreciated.

cpcosentino on "uncategorized and blogroll hacked"

Umbercode on "conditionals (e.g. is_page()) do not work in head?"

$
0
0

I noticed that checking for type of page with is_singular() etc. does not (or no longer?) work in the head of the page? Neither doing it directly nor using the wp_head action.
Oddly enough, Wordpress uses this construct itself for several things amongst which is the inclusion of meta-canonical which now shows up on every page not just singular ones (look at line 2405 in link-template.php).
Is this a bug, intended or am I doing something wrong?


the_jwj on "Custom Searching..."

$
0
0

I got my issue solved with a custom SQL Query but was just wondering if anyone out there knows of more of a 'built-in' way to customize the search feature for Wordpress sites. I had a client that insisted on filling in Descriptions of a custom taxonomy and then was not happy when said taxonomy did not show up in a search. I had to add results to the existing search results by running my query specifically checking the taxonomy description field for the search keyword.

Thoughts for the future?

Thanks in advance!

sinious on "Best practice means of "waiting" until specific JavaScript is loaded in Plugin"

$
0
0

Hey all,

Brand new to WP. I've been toying with creating a plugin and I'd like to use jQuery UI. I'm finding that a <script/> I add directly into some content loaded by an admin menu is firing off too fast. jQuery is loaded but not jQuery UI.

Since jQuery UI is only needed in the plugin administration pages, I'm trying to keep from unnecessarily loading it otherwise. I put it in my /myplugin/lib/jquery.ui.min.js folder and upon launching the menu item which triggers the page content to load, I run wp_enqueue_script() in that function right before loading content.

e.g.:

# ...
# add the submenu link to the function
add_submenu_page( 'parent-menu-id', 'The Page', 'The Page', 'manage_options', 'my-page-unique-id', 'my_plugin_some_panel'); 

# ... 

function my_plugin_some_panel() {
	wp_enqueue_style("jquismoothness", plugins_url("css/smoothness/jquery-ui-1.10.4.custom.min.css", __FILE__), FALSE);
	wp_enqueue_script("jquery_ui_ldr", plugins_url("js/jquery-ui-1.10.4.custom.min.js", __FILE__), FALSE);
	include(plugin_dir_path(__FILE__) . '/views/thismenuspage.php');
}

The menu/submenu shows up fine, the page shows up fine but inspecting the JavaScript console (or just <script>console.log(jQuery.ui);</script>) shows up as undefined. So the queued script to load isn't quite ready yet.

I feel I'm way off course on how I should be doing this. My only course of action here is to literally setTimeout() and run a loop continuously sniffing for jQuery.ui to be defined before proceeding with the page. It works but it definitely feels dirty.

What is the best way to assure this library loads before I start to make use of it in the plugin admin panels?

Should I be putting my JS in the /js/ folder with yet another wp_enqueue_script() call to it with jquery UI as a dependency?

Thanks for tips!

brendan on "Reusing a submenu on a dropdown?"

$
0
0

Does anyone know if any plugin or script exists to take a parent menu's dropdown, and use that as an element elsewhere on the page?

for example, you have a menu that display this when you hover over one of the items:
http://i.imgur.com/978fuWi.png

And on the actual page you re-use that dropdown menu on the top as another way for the user to explore your page's parent/children, it'd be something like this:
http://i.imgur.com/s3rHLtD.png

Right now I'm using a script that displays the page's parent and all it's children, as opposed to grabbing a sub-menu - the only problem with this method is that it doesn't list them in the same order as in the menu, it alphabetizes the items automatically.

The best way my friend came up with so far is making a new template and menu for every single page. Seems like an extraordinary amount of work for something potentially so simple!

I hope this makes sense, I can clarify more if needed!

tdustrude on "Move "Recent Activity" widget from Dashboard to "Add New Post" screen"

$
0
0

I would like to see the "recent activity" widget on my "add new post" screen, so that I can easily see the time stamps on already scheduled posts and make sure I'm posting things for the next morning in a good sequence.

Right now, I'm always jumping back and forth between the Dashboard or the "All Posts" screens and the "Add New Post" screen when composing new posts.

Already searched Google and these forums with no luck.

Thanks!
Tim

tdustrude on "Move "Recent Activity" widget from Dashboard to "Add New Post" screen"

$
0
0

I would like to see the "recent activity" widget on my "add new post" screen, so that I can easily see the time stamps on already scheduled posts and make sure I'm posting things for the next morning in a good sequence.

Right now, I'm always jumping back and forth between the Dashboard or the "All Posts" screens and the "Add New Post" screen when composing new posts.

Already searched Google and these forums with no luck.

Thanks!
Tim

Viewing all 8245 articles
Browse latest View live




Latest Images