If you go to http://jbrazeal.com/galleries/bridals you can see my website with a PrettyPhoto gallery within a Wordpress theme. By default, when you click on a picture, the picture expands and gives you an option to "Tweet" or to "Like" the photos with buttons below the picture. I have installed a plugin called "prettyPhoto Media Pinterest" (https://github.com/Lawdawg/prettyphoto-media-pinterest) where it adds a "Pin It" button to each specific picture.
However, the plugin is only working for some pages and not others. It works on the page linked above, but it does not work on the other gallery pages. For instance, it does not work for any of the pictures on the page /galleries/weddings (I couldn't post the link because I am limited to two links.
Below is the PHP. I assume it is a PHP problem, but if you advise me otherwise, I can post up any other relevant information (the plugin has a javascript file as well). Additionally, you can see actual webpage as well as the plugin page as I linked above. Thanks!
<?php
add_action('init', 'ppm_pinterest_init');
function ppm_pinterest_init() {
define('PPM_PINTEREST_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
define('PPM_PINTEREST_VERSION', '0.1' );
if (!is_admin()) {
wp_enqueue_style('ppm_pinterest', PPM_PINTEREST_URI . 'css/ppm-pinterest.css', false, PPM_PINTEREST_VERSION, 'screen');
wp_enqueue_script('pinterest_plus', PPM_PINTEREST_URI . 'js/pinterest-plus.min.js', false, false, true);
add_action('wp_footer', 'ppm_pinterest_footer_script', 101);
}
}
function ppm_pinterest_footer_script() {
$out = '<script>' . "\n";
$out .= 'jQuery(function($) {' . "\n";
$out .= ' $(document).bind(\'DOMNodeInserted\', function(event) {' . "\n";
$out .= ' if (window.settings && !window.settings.changepicturecallbackupdated) {' . "\n";
$out .= ' window.settings.changepicturecallback = add_pinterest_pin_it_button' . "\n";
$out .= ' window.settings.changepicturecallbackupdated = true;' . "\n";
$out .= ' }' . "\n";
$out .= ' });' . "\n";
$out .= '});' . "\n";
$out .= "\n";
$out .= 'function add_pinterest_pin_it_button() {' . "\n";
$out .= ' var i = jQuery(\'.pp_gallery\').find(\'li\').index(jQuery(\'.selected\'));' . "\n";
$out .= ' var m = pp_images[i];' . "\n";
$out .= ' jQuery(\'.pp_social\').append(\'<div class="pinterest"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></div>\');' . "\n";
$out .= '}' . "\n";
$out .= '</script>' . "\n";
echo $out;
}
?>
I figured it out. You can view my plugin branch here, which works now!
https://github.com/Lawdawg/prettyphoto-media-pinterest
I changed the jQuery call to:
$out .= ' jQuery(\'.pp_social\').append(\'<div class="pinterest"><a target="_blank" href="http://pinterest.com/pin/create/button/?url=\' + encodeURI(location.href.replace(location.hash,"")) + \'&media=\' + encodeURI(m) + \'&description=\' + encodeURI(o) + \'" class="pin-it-button" count-layout="none"><img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" /></a></div>\');' . "\n";
$out .= '}' . "\n";
Related
I need to refactor this code, Im not a php developer so i dont understand the syntax thats apparent here, what i want is this button to activate the moment the page is loaded.
<?php
$h = '';
if ($newsermonstomove) {
foreach ($newsermonstomove as $vettel) {
$h .= "<div style=\"padding: 5px;\">";
$h .= "<button id=\"btn_" . $vettel->ID . "\" class=\"btn btn-primary btn-xs\" onclick=\"doMe(" . $vettel->ID . ");\" >s3</button><span style=\"padding-left:5px;\">Channel: " . $vettel->ChannelID . ", Sermon: " . $vettel->ID . " " . $vettel->SermonTitle . "</span> <div style=\"display:none;color:blue;\" id=\"msg_" . $vettel->ID . "\"></div><br/>";
$h .= "</div>";
}
} else {
$h = "<h3>No new sermons.</h3>";
}
echo $h;
?>
From what i understand, the onclick has an escape in it onclick=\"doMe(" . $vettel->ID . ");\" In HTML i know that with a button if you do onclick=doMe its a reference to a function, which i feel like is the same thing thats happening here with the escape keys in it. its making a reference to the function doMe, but i want the function to fire automatically when the page loads.
Ok, i was able to figure out the answer I needed using JQuery.
$("document").ready(function() {
setTimeout(function() {
$(".btn").trigger('click');
},10);
});
essentially what this function does is wait for the page to load then after 10 milliseconds it targets all buttons on the screen with the class name btn and triggers the click functionality of the button, thus firing off the button on the page load.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<?php
if (!empty($newsermonstomove)) {
$h = '';
foreach ($newsermonstomove as $vettel) {
$h .= '<div style="padding: 5px;">';
$h .= '<button data-id="' . $vettel->ID . '" class="btn-vettel btn btn-primary btn-xs">s3</button><span style="padding-left:5px;">Channel: ' . $vettel->ChannelID . ', Sermon: ' . $vettel->ID . ' ' . $vettel->SermonTitle . '</span> <div style="display:none;color:blue;" id="msg_'.$vettel->ID.'"></div><br/>';
$h .= '</div>';
}
} else {
$h = '<h3>No new sermons.</h3>';
}
echo $h;
?>
<script>
$(function() {
$('.bt-vettel').on('click', function(e) {
var id = $(this).data('id');
doMe(id);
});
});
<script>
Hi all i don't know if i'm doing this right or not but i can't understand how google checkout works.
I have the php code that sends the XML to the google checkout everything is ok i reach on the checkout process taxes prices shipping is ok.
$_currency = $params['currency'];
$base_domain = 'https://' . (($params['mode'] == 'transaction') ? 'checkout.google.com' : 'sandbox.google.com/checkout');
$base_url = $base_domain . '/cws/v2/Merchant/' . $params['merchantId'] . '/checkout';
// Form XML array with cart items
$_items = '';
$google_products = $this->CI->go_cart->contents();
foreach ($google_products as $k => $v) {
$item_options = '';
if (isset($v['options'])) {
foreach ($v['options'] as $name => $value) {
if (is_array($value)) {
foreach ($value as $item) {
$item_options .= $item;
}
} else {
$item_options .= $value;
}
}
}
$_items .= '<item>' . '<merchant-item-id>' . $v['id'] . '</merchant-item-id>' . '<item-name>' . strip_tags($v['name']) . ' ' . $item_options . '</item-name>' . '<item-description>' . substr(strip_tags($item_options), 0, 299) . '</item-description>' . "<unit-price currency='" . $_currency . "'>" . $v['price'] . '</unit-price>' . '<quantity>' . $v['quantity'] . '</quantity>' . '</item>';
}
$xml_cart = "<?xml version='1.0' encoding='UTF-8'?>
<checkout-shopping-cart xmlns='http://checkout.google.com/schema/2'>
<shopping-cart>
<merchant-private-data>
<additional_data>
<session_id>" . base64_encode($customer['bill_address']["email"] . date('h:i:s')) . "</session_id>
<currency_code>" . $_currency . "</currency_code>
<payment_id>" . base64_encode($customer['bill_address']["email"] . date('h:i:s')) . "</payment_id>
" . $private_ship_data . "
</additional_data>
</merchant-private-data>
<items>" . $_items . "</items>
</shopping-cart>
<checkout-flow-support>
<merchant-checkout-flow-support>
<platform-id>971865505315434</platform-id>
<request-buyer-phone-number>true</request-buyer-phone-number>
<edit-cart-url>" . $edit_cart_url . "</edit-cart-url>
<merchant-calculations>
<merchant-calculations-url>" . $calculation_url . "</merchant-calculations-url>
</merchant-calculations>
<continue-shopping-url>" . $return_url . "</continue-shopping-url>
" . $shippings . $taxes . "
</merchant-checkout-flow-support>
</checkout-flow-support>
</checkout-shopping-cart>";
$signature = $this->fn_calc_hmac_sha1($xml_cart, $params['merchantKey']);
$b64_cart = base64_encode($xml_cart);
$b64_signature = base64_encode($signature);
echo '<form method="post" action="' . $base_url . '" name="BB_BuyButtonForm">
<input type="hidden" name="cart" value="' . $b64_cart . '" />
<input type="hidden" name="signature" value="' . $b64_signature . '" />
<input alt="" src="' . $base_domain . '/buttons/checkout.gif?merchant_id=' . $params['merchantId'] . '&w=160&h=43&style=' . 'white' . '&variant=text&loc=en_US" type="image"/>
</form>';
exit;
}
After i click on submit payment i'm then redirected to a page with successfull message and with a link to return to my website.
I'm wondering how can i check if the payment was or not successfully.
Also there is a callback that i don't know exactly what is supposed to do.
Please help me understand better
I have attached the code below.
Disclaimer: Am not a PHP dev.
Your code above is known as Part 1. Checkout API documented here. It covers how you get your data/cart to Google for Checkout
Part II. Order Processing covers how to get data from Google (into your systems). A tutorial is provided here. This is where you provide a Callback API URL that listens to (waits for) HTTP POSTs from Google and proceed to process the data.
I'm using a custom theme option framework on my theme. I have been integrated everything, but in textarea when paste and try to save option it automatic remove HTML codes and <script> only text and <> are remain. Text showing in my website source page here http://www.wrock.org/ I don't know how to resolve this problem.
Also there is some google tracking code, and when I explored the source I found the following
/* ----------------------------------------------------------------------------------- */
/* Show analytics code in footer */
/* ----------------------------------------------------------------------------------- */
function wrockmetro_analytics() {
$shortname = wrockmetro_get_option('of_shortname');
$output = wrockmetro_get_option($shortname . 'wrock_analytics');
if ($output <> "")
echo "<script type='text/javascript'>" . stripslashes($output) . "</script>\n";
}
add_action('wp_footer', 'wrockmetro_analytics');
Textarea code from OptionInterface.php
// Textarea
case 'textarea':
$cols = '8';
$ta_value = '';
if (isset($value['options'])) {
$ta_options = $value['options'];
if (isset($ta_options['cols'])) {
$cols = $ta_options['cols'];
} else {
$cols = '8';
}
}
$val = stripslashes($val);
$output .= '<textarea id="' . esc_attr($value['id']) . '" class="of-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" cols="' . esc_attr($cols) . '" rows="8">' . esc_textarea($val) . '</textarea>';
break;
I have a link that is basically an 'about' page that has social icons pointing to my personal social media outlets. In PHP, the code is like this:
function wp_about_author_get_socials() {
$socials = array();
$socials['twitter'] = array('title'=>'Twitter', 'link'=>'http://www.twitter.com
/%%username%%', 'icon'=> WPAUTHORURL_URL .'/images/twitter.png');
$socials['facebook'] = array('title'=>'Facebook', 'link'=>'http://www.facebook.com
/%%username%%', 'icon'=> WPAUTHORURL_URL .'/images/facebook.png');
I've fiddled around with things, but just can't seem to implement things so the link opens up in a new tab/page. Currently, the links take the user off the website (not ideal). Any guidance in this regard would be greatly appreciated!
What I have tried was changing the links to this:
$socials['twitter'] = array('title'=>'Twitter', 'link'=>'http://www.twitter.com
/%%username%%', 'target'=>'_blank', 'icon'=> WPAUTHORURL_URL .'/images/twitter.png');
But that didn't work.
This may be the part that prints the links, from what I can tell:
// About Author Social
$wp_about_author_social .= wp_about_author_get_social_links($wp_about_author_settings);
if(isset($wp_about_author_settings['wp_author_social_images']) &&
$wp_about_author_settings['wp_author_social_images']){
$wp_about_author_content .= "<p>" .$wp_about_author_links . "</p>";
if($wp_about_author_social != ""){
$wp_about_author_content .= '<p class="wpa-nomargin">'.apply_filters(
'wp_about_author_follow_me', "Follow Me:").'<br />' . $wp_about_author_social.'</p>';
}
} else {
$wp_about_author_content .= "<p class='wpa-nomargin'>";
$wp_about_author_content .= $wp_about_author_links;
if($wp_about_author_social != ""){
$wp_about_author_content .= apply_filters( 'wp_about_author_separator', " - ") .
$wp_about_author_social;
}
$wp_about_author_content .= "</p>";
}
// Generate social icons
function wp_about_author_get_social_links($wp_about_author_settings){
$content="";
$socials = wp_about_author_get_socials();
foreach($socials as $social_key=>$social){
if (get_the_author_meta($social_key)){
if(isset($wp_about_author_settings['wp_author_social_images']) &&
$wp_about_author_settings['wp_author_social_images']){
$content .= "<a class='wpa-social-icons' href='".str_replace('%%username%%',
get_the_author_meta($social_key), $social['link'])."'><img src='". $social['icon']."'
alt='".$social['title']."'/></a>";
} else {
if($content != "")
$content .= apply_filters( 'wp_about_author_separator', " - ");
$content .= "<a href='".str_replace('%%username%%', get_the_author_meta($social_key),
$social['link'])."'>".$social['title']."</a>";
}
}
}
return $content;
}
Within the code you posted, you can add target="_blank" to the links on lines 28 and 34.
Line 28 becomes:
$content .= "<a class='wpa-social-icons' target='_blank' href='".str_replace('%%username%%',
Line 34 becomes:
$content .= "<a target='_blank' href='".str_replace('%%username%%', get_the_author_meta($social_key),
I know how to use add_image_size in PHP to register a new size which can be used in templates.
It makes images in this size, too when they're uploaded.
The sizes I added like that don't show in the admin, though.
So 2 questions...
How can I get the image sizes that I make show up in the 'upload image' thing when bloggers make a new post?
Is there a way to list it in the admin so the bloggers can add new ones without having to change PHP code?
Or am I doing something wrong, like not putting the add_image_size call in the right place/file? Are sizes like this supposed to show up in the upload menu section?
Cole
Wordpress doesn't show custom image size options in the media lightbox, but you can add them using an attachment_fields_to_edit filter. The below will add options for all the custom image sizes you have defined.
add_filter('attachment_fields_to_edit', 'my_attachment_fields_to_edit_filter', 100, 2);
function my_attachment_fields_to_edit_filter($form_fields, $post) {
if (!array_key_exists('image-size', $form_fields)) return $form_fields;
global $_wp_additional_image_sizes;
foreach($_wp_additional_image_sizes as $size => $properties) {
if ($size == 'post-thumbnail') continue;
$label = ucwords(str_replace('-', ' ', $size));
$cssID = "image-size-{$size}-{$post->ID}";
$downsize = image_downsize($post->ID, $size);
$enabled = $downsize[3];
$html = '<input type="radio" ' . disabled($enabled, false, false) . 'name="attachments[' . $post->ID. '][image-size]" id="' . $cssID . '" value="' . $size .'">';
$html .= '<label for="'. $cssID . '">' . $label . '</label>';
if ($enabled) $html .= ' <label for="' . $cssID . '" class="help">(' . $downsize[1] . ' × ' . $downsize[2] . ')</label>';
$form_fields['image-size']['html'] .= '<div class="image-size-item">' . $html . '</div>';
}
return $form_fields;
}