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

weslebsack on "Looping through post meta data and outputting to PHP variable"

$
0
0

Hi Everyone,
I'm currently using the do_shortcode function to place a map from the Comprehensive Google Map Plugin in my page template, with PHP variables echoing out the address, zip code and name from custom meta in the post, which works great, but only outputs one pin:

<?php echo do_shortcode('[google-map-v3 width="868" height="490" zoom="12" maptype="roadmap" mapalign="center" directionhint="false" language="default" poweredby="false" maptypecontrol="true" pancontrol="true" zoomcontrol="true" scalecontrol="true" streetviewcontrol="true" scrollwheelcontrol="false" draggable="true" tiltfourtyfive="false" addmarkermashupbubble="false" addmarkermashupbubble="false" addmarkerlist="'.$the_address.' '.$the_city.', '.$the_state.' '.$the_zip.'#http://www.apple.com#{}4-default.png{}'.$place_title.'" bubbleautopan="true" showbike="false" showtraffic="false" showpanoramio="false"]'); ?>

I'd like to be able to loop through all my posts and output their location meta data into a single variable that I can echo out in the above shortcode.

Can anyone please help?

Thanks!


b.bishop on "plugins"

$
0
0

Basically, what I need to do, is create a plugin that will “build” a URL on http://www.canpar.com/XML/BaserateXML.jsp, so that it passes the pieces, weight, destination, etc, into the URL. These values can be extracted via the $woocommerce global variable.

everyeurocounts on "jQuery .post save to database"

$
0
0

Hi,

I have the following code to pass a post_date to a php file to save it after a user selects a date. The problem is the event is not firing...i hard coded the values into the phpfile to check..Anyone any ideas?

jQuery

<script type="text/javascript">
			var array = ["<?php
echo $comma_seperated;
?>"];

				jQuery(document).ready(function() {
				jQuery('#MyDate').datepicker({
				beforeShowDay: function(date){
				var string = jQuery.datepicker.formatDate('yy/mm/dd', date);
				return [ array.indexOf(string) == -1 ]
				},
				})

				var bf = jQuery('#stotal').val();
				var vf = parseInt(bf)*.21;

				jQuery('#vat').val(vf);

				vtf = (parseFloat(vf)+parseFloat(bf)).toFixed(2);

				jQuery('#Total').val(vtf);
			});

				jQuery('#MyDate').change(function() {
					$.post(
					"http://xxxxxxx.com/www/wp-content/themes/gbs-prime-child-theme-merchant-dashboard/datesave.php",
					{
						MyDate: jQuery('#MyDate').val()

					}
					)});

			</script>

datesave.php

<?php
$posted_id = "408";
//(isset($_POST['$posted_id'])) ? htmlspecialchars($_POST['posted_id') : 0;
$temp_submitted_post_time = "12/13/2013"; 

//(isset($_POST['MyDate'])) ? strtotime($_POST['MyDate']) : 0;

$args = array(
    'ID' => $posted_id,
    'post_status' => 'temp',
    "edit_date" => true,
    'post_date' => date('Y-m-d H:i:s', $temp_submitted_post_time),
    'post_date_gmt' => gmdate('Y-m-d H:i:s', $temp_submitted_post_time)
);
wp_update_post($args);

?>

allm on "shortcodes running twice"

$
0
0

Today I ran into a situation where a shortcode was processed twice in a page, although it was only once in the content of the page.

After a lot of trial and error / looking at what others have done in the past the problem went away when I stopped adding the registry of the shortcode through the init hook. The add_shortcode call is now all by itself in the functions.php file.

I noticed the problem because I needed to register the firing of the shortcode, after which some info was written to SESSION variables. This was done twice per page, so I was really surprised.

This process left me with 3 questions:

1. Will the fact that I stopped registry of the shortcode through the init hook assure me of the fact that the shortcode is only run once on a page? (assuming the shortcode is only once in the content of the page)

2. If it is still unknown how often the shortcode function fires: why is that? It seems to be bad for response times to execute a function twice, where once is sufficient.

3. Is there some way to guarantee that a shortcode is run exactly the number of times it is in the content of a page? Which is what you would expect intuitively. Isn't that so?

JeremyPark123999 on "Allow only specific usernames"

$
0
0

Hi, I am trying to set up a website for my minecraft server. I want to set up the buddypress registration to only allow users to register if their username reads as a premium account on the minecraft.net server. I found a plugin that was meant to do that, but it hasn't been updated for a long time, and it no longer works. I have been trying to alter the plugin, but so far, it hasn't shown any results. As far as I can tell, the plugin is not blocking users, and that is all. Could someone tell me if I have done something wrong?
I have changed the code a lot from the original, but I don't think that I have damaged anything, let me know if you need the original, and I will post it.

EDIT: It turns out that I did damage some of the code, I was getting a very small error on the wordpress plugin page, I fixed that, and upaded the code below.

Here is the plugin's code:

<?php
/*
   Plugin Name: Minecraft Validator
   Description: Simple plugin to verify new WordPress accounts against the Minecraft user database. If the username doesn't show up as a valid Minecraft player, it won't let them register.
   Version: 1.4
   Author: Ghost1227
   Author URI: http://www.ghost1227.com
*/

/* Run activation hook when plugin is activated */
register_activation_hook(__FILE__, 'get_wp_version');

/* Rewrite registration form */
function mcv_registration_form() {
	wp_enqueue_script( 'login_form', plugins_url() . '/minecraft-validator/usernamerewrite.js', array('jquery'), false, false );
}
add_action('login_head', 'mcv_registration_form');

/* Get WordPress version */
function get_wp_version() {
    global $wp_version;
    if ( version_compare ( $wp_version, '3.1', '<')) {
        exit ( "<div style='font-size: 13px; font-family: 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', sans-serif;'><strong>Attention:</strong> This plugin will not work with your version of WordPress.</div>" );
    }
}

/* Register actions */
add_action('register_post', 'verify_mc_account', 10, 3);
add_action('admin_menu', 'add_mcval_options');

/* Check account on minecraft.net */
function verify_mc_account($login, $email, $errors) {
	$user_info = get_userdata(1);
	$options = array(
        'timeout' => 5,
    );
    $mcacct = wp_remote_get('http://www.minecraft.net/haspaid.jsp?user='.$user_info->user_login);

    if ( $mcacct == 'false' ) {
        if ( $mcacct == 'false' ) {
            $errors->add('mc_error',__('<strong>ERROR:</strong> Minecraft account is invalid.'));
            return $errors;
        } else {
            $errors->add('mc_error',__('<strong>ERROR:</strong> Unable to contact minecraft.net.'));
            return $errors;
        }
        add_filter('registration_errors', 'verify_mc_account', 10, 3);
    }
}
/* Activation/Deactivation */
function set_mcval_options() {
    add_option('hide_me', 'false');
}

function unset_mcval_options() {
    delete_option('hide_me');
}

register_activation_hook(__FILE__, 'set_mcval_options');
register_deactivation_hook(__FILE__, 'unset_mcval_options');

/* Add admin menu */
function add_mcval_options() {
    if ( get_option('hide_me') != "true" ) {
        add_options_page('Minecraft Validator Options', 'Minecraft Validator', 8, 'mcval-options', 'mcval_options');
    }
}

/* Display options page */
function mcval_options() {

    ?>

    <div class="wrap">
        <h2>Minecraft Validator</h2>

    <?php
        if ( $_REQUEST['submit'] ) {
            update_mcval_options();
            ?>
                <script type="text/javascript">
                <!--
                    window.location = <?php echo "'options-general.php'"; ?>
                //-->
                </script>
            <?php
        }
        print_mcval_form();
    ?>

    </div>

<?php }

function update_mcval_options() {
    update_option( 'hide_me', 'true' );
}

function print_mcval_form() {
    ?>

<?php }

Jenny_EoF on "help with php?"

$
0
0

Does someone know php and can help me with a, probably simple, task? It would really be helpful to me!

I'm trying to modify the plugin Media Library Gallery, but the gallery is so ugly.
The gallery creates this:

*) A link (titled the image name, which I really don't want visible since it's all numbers etc) which links to display the image in version "A".
*) Underneath is the image (thumbnail), which links to displaying the image in version "B".
*) Then a link (another title) which links to displaying the image in version "C".

I simply want everything to display the image in version "A", and if possible, delete the first link (the image name). So that it's just the thumbnail and the last link that is shown.

----------------
Here is the part of the code that I think needs to be edited:
-----------------

[please mark any posted code - http://codex.wordpress.org/Forum_Welcome#Posting_Code ]

if(($src = wp_get_attachment_thumb_url($post->ID))

&& $parent->post_status == "publish"

&& !preg_match("/\W(" . $parent->ID . ")\W/", " {$args["exclude"]} ")

&& $tag_ok

&& $category_ok)

{

$html_row .= "<div class='mlg-preview'>";

$html_row .= "<div class='mlg-title'>ID) . "' title='" . get_the_title($post->ID) . "'>" . get_the_title($post->ID) . " [+]</div>";

$html_row .= "<div class='mlg-img'>ID) . "' title='" . get_the_title($post->ID) . "'><img src='$src' alt='" . get_the_title($post->ID) . "' /></div>";

$html_row .= "<div class='mlg-actions'>";

$html_row .= "“post_parent) . "'>" . get_the_title($post->post_parent) . "”
";

$html_row .= "</div>";

$html_row .= "</div>";

$j++;

}

[please post only one topic per problem - continue with http://wordpress.org/support/topic/help-with-modifying-php-for-plugin?replies=2#post-4893789 ]

Peterzt on "REST API Post types question"

$
0
0

Greetings,

I have blog hosted at wordpress.com and desktop app which synchronizes blog content. The problem is that I'm not able to delete previously uploaded image. When I try to delete image with REST deletePost operation it returns "invalid_post_type" error. How it is possible to fix it? I'm able to delete image through XML-RPC operation, but I would like to use REST API only for everything.
According to REST API documentation -

Post types besides post and page need to be whitelisted using the rest_api_allowed_post_types filter

How it is possible to achieve it at wordpress.com hosted blog?

Thanks in advance,
Peter

Rakesh Raja on "TinyMice button for a shortcode"

$
0
0

Hi Friends

I have created a shortcode and now I want to add a button in TinyMice / Visual editor.

Can anyone guide me how to do that?

Regards


djeyewater on "Confused about WP_UNINSTALL_PLUGIN and uninstall hook"

$
0
0

Ref. http://codex.wordpress.org/Function_Reference/register_uninstall_hook
and http://wordpress.stackexchange.com/questions/25910/uninstall-a-plugin-method-typical-features-how-to/25979#25979/

In an uninstall hook callback you should check whether WP_UNINSTALL_PLUGIN is defined. However I am having trouble when the function called by the uninstall hook is not in the main plugin file.

If I pass the main plugin file as the $file parameter to register_uninstall_hook, then WP_UNINSTALL_PLUGIN is always undefined when the callback is called. (According to the docs it should be defined).

I've also tried passing the file containing the callback function as the $file parameter, but then the callback is not called at all.

I've uploaded my Test plugin here: http://www.iliveinabin.com/test.tar.gz
Or you can see the contents of the files here:
Main plugin file: http://pastebin.com/m4wMFXJM
Test.class.php: http://pastebin.com/ZYmtuDEZ

I'm activating / deactivating / deleting as an admin on a multisite installation if that makes any difference.

Thanks

Dave

UaMV on "2 Cents on Plugin 'Nagging'?"

$
0
0

In the Detailed Plugin Guidelines, it states:

11. Plugins should not hijack the blog admin. It is fine to include an Upgrade prompt on the plugin admin page, but not throughout the blog. It is acceptable to embed a widget on the dashboard but this should be the same size as others and be dismissable. It's fine to put an error message at the top of the admin for special cases, but it should be linked to a way to fix the error and it should be infrequent. Any form of "nagging" is absolutely prohibited.

How do we define nagging? I have seen many plugins, especially those that have created custom settings pages, use that space as a bulletin board for their external sites (whether it be plugin page, support page, community page). Is this considered 'nagging'?

Is it considered nagging to offer support help, request a plugin review, or offer an invitation to community involvement via a dismissible admin_notice? If so, is it acceptable if the plugin offers an option to disable all dismissible notices it might otherwise post? Is it acceptable if this is only done on select admin screens?

I am looking to soon update a few of my plugins and want to get an idea of what the community sees as acceptable behavior in this arena. In no way do I want to turn off or nag our users, but I do want to engage them and offer them necessary tools for their success.

I understand 'absolutely prohibited', but think more can be said to define 'nagging'.

Any thoughts you might have are welcome. Thanks!

andy_woz on "User Query help - Listing Authors"

$
0
0

I have a select menu for a search function populated by a custom query ordered by user last name that is working fine but I have a clunky exclude to stop the admin user being listed:

<select name="author" id="select-author">
<option value="">Select Author</option>

<?php
$excluded = "1"; //exclude users by ID
$authors = $wpdb->get_results("SELECT * FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id) WHERE $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.user_id NOT IN ($excluded) ORDER BY $wpdb->usermeta.meta_value ASC");
							      foreach($authors as $author):
$select .='<option value="'. $author -> user_nicename .'">' . $author -> display_name . '</option>';
endforeach;
print $select;
?>

</select>

At some point I'm sure we are going to have more users and I don't want to be excluding them based on their ID but I can make do by limiting the users to all those with the author role. I don't see user_role currently listed in the resulting array for $authors. What I'd like to do is to add to the query and instead of excluding user ID's have only users with the role of author in the results. What's the best way to do this? I've tried a few things but nothing works so far......

Thanks!

andy_woz on "Custom Query - List Users by last name"

$
0
0

I have a select menu for a search function populated by a custom query ordered by user last name that is working fine but I have a clunky exclude to stop the admin user being listed:

<select name="author" id="select-author">
<option value="">Select Author</option>

<?php
$excluded = "1"; //exclude users by ID
$authors = $wpdb->get_results("SELECT * FROM $wpdb->users INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id) WHERE $wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.user_id NOT IN ($excluded) ORDER BY $wpdb->usermeta.meta_value ASC");

foreach($authors as $author):
$select .='<option value="'. $author -> user_nicename .'">' . $author -> display_name . '</option>';
endforeach;
print $select;
?>

</select>

At some point I'm sure we are going to have more users and I don't want to be excluding them based on their ID but I can make do by limiting the users to all those with the author role. I don't see user_role currently listed in the resulting array for $authors. What I'd like to do is to add to the query and instead of excluding user ID's have only users with the role of author in the results. What's the best way to do this? I've tried a few things but nothing works so far......

Thanks!

Flasker on "Hello i need some help in Woocommerce"

$
0
0

Hello guys i´m from Azores and i need some help..

I programming in php but a have one problem to finish one job.
I want put this code in review-order.php

<select onChange="this.form.submit()" name="insurance_select">
  <option value="1" >YES</option>
  <option value="2" >Não</option>
</select>
</form>
<?php
if(!empty($_POST['insurance_select'])){
$_SESSION['seguro'] = $_POST['insurance_select'];
}
?>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

But the post don´t work. I don´t understand this.

jimmycrow on "Change the CSS in emails Word Press generates to subscribers"

robahas on "Make Calendar Widget Link to a Post, not an archive page"

$
0
0

Hi - I am working on a site that makes a new post each day. The customer would like a calendar in which, when you click on the day, it opens the post for that day. Unfortunately the WP calendar widget goes to the archive page first and then you have to click on the post.

Any ideas on how this might be accomplished? (One idea might be to use a calendar plugin and treat each post as an event, however, we have hundreds of existing post, so this is not ideal as it would involve retrofitting).

Thanks in advance


davisshaver on "Is post meta accessible during transition_post_status?"

$
0
0

Is post meta data accessible during transition_post_status?

I have hooked a function to 'transition_post_status' but am seeing null or empty returns for functions like get_post_meta and get_post_custom on valid keys.

Here is how I am hooking the function to 'transition_post_status'. Perhaps the problem is related to priority?

add_action('transition_post_status','dfm_publish_to_twitter', 10, 3);

AstroJones on "Rewrite Permalinks for Custom Post type and Custom Taxonomy combination"

$
0
0

I have a custom post type called Movies, which shows a listing of movies and info about each one. I also have a custom taxonomy called release_year which is just a 4 digit year. All movies post types have a release_year.

I have my rewrite rules working so that all movies follow: mysite.com/movies/movie-name.

Likewise, I have the rewrite rules for the taxonomy showing as:
mysite.com/movies/release_year/2013

But what I want to happen, is that all movies would always have the rewrite of: mysite.com/movies/year/2013/movie-name (where "year" is constant" and "2013" pulls the taxonomy year on the movies post).

Can anyone give me some ideas or tips on how I might write function or rewrite rule to accomplish this? The Rewrite API still confuses me, as I'm still learning Wordpress coding.

webheadllc on "Page ordering not working when using tax_query"

$
0
0

On the admin Pages screen (edit.php) I'm adding the following filter to only show a certain taxonomy for certain users.

The problem is this doesn't list out the pages in the same order as the default page ordering. For example this is how the pages show without my taxonomy filter:

  • Parent1 (menu_order: 4)
    • Child 1-1 (menu_order:0)
  • Parent2 (menu_order: 5)
    • Child 2-1 (menu_order:0)
    • Child 2-1 (menu_order:1)

And this is how the pages show with my taxonomy filter:

    • Child 1-1 (menu_order:0)
    • Child 2-1 (menu_order:0)
    • Child 2-1 (menu_order:1)
  • Parent1 (menu_order: 4)
  • Parent2 (menu_order: 5)

Understandably it is ordering by menu_order but it is ignoring the hierarchy. This different ordering only occurs when I set the tax_query. Is there any way to set the tax_query but still have it ordered as in the first example?

I have simplified my code to the following:

if ( $pagenow == 'edit.php' )
        add_filter( 'pre_get_posts', 'my_posts_query' );

    function my_posts_query( $query ){
        $taxquery = array(
            array(
                'taxonomy' => $taxonomy,
                'field' => 'id',
                'terms' => $ids
            )
        );
        $query->set( 'tax_query', $taxquery );
        $query->set( 'orderby', 'menu_order title' );
        $query->set( 'order', 'ASC' );</li>

        return $query;
    }

Storyman on "Make bloginfo('name') HTML friendly"

$
0
0

Objective: Wrap <span> tags around first word of blog title.

Status: Successfully hard coded header.php so that it wraps <span> tags around first word and assigning the string to $new_title.

Problem: How to replace bloginfo('name') with $new_title.

Is there a better way to approach this like creating a function that allows the blog title with HTML tags? Is there a trick in using HTML tags with the blog title?

Where to go from here?

Sebastian on "Allow bitcoin addresses as donate link in readme.txt"

$
0
0

It would be great if you could allow having a bitcoin address as donate link in the readme.txt file of a plugin. I set in the readme.txt file of my plugin (g-crossposting) the following code, which makes the donate link disappear on the plugin homepage:

Donate link: bitcoin:18dNV4mZyQMDdgd1ebe2Gm4f9MNZMLuNNb

And if you want to make it perfect, please show a 2D QR code of the given address when clicking on the donate link in case it is a bitcoin address :-)

The URI scheme for bitcoin addresses is defined here: https://en.bitcoin.it/wiki/URI_Scheme

Viewing all 8245 articles
Browse latest View live




Latest Images