uploading photos to news feed - facebook-php-sdk

I'm using php api to upload photos and post checkins.
Several weeks ago my photos displayed in News Feed automatically, but not now.
My code:
$photo_details = array('message'=> 'TEST');
$file='../uploads/'.$_GET['filename'];
$photo_details['image'] = '#' . realpath($file);
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
By the way my chekins are displayed in News Feed

Related

how to bulk remove all woocommerce products images gallery from host and site

I’ve just inherited a site that’s being migrated to a new host, and I’m attempting to tidy up the database during the process.
The WooCommerce site had roughly 100,000 products resulting in somewhere around 3,000,000 product images gallery.
how to erase all product images gallery attached to _product type posts, as well as wiping their records from the database.
End goal is to permanently delete all product images gallery from the media library as well as the database.
Any help would be much appreciated.
This is not tested and its recommended to create backup before this. Test it step by step with debug to know what is happening. Uncomment //if($attachment_ids): if you are happy with the results and run again to delete the images. Also before that i will recommend to remove any unneeded image sizes to optimize your image situation and then continue with this function.
function clear_product_gallery_images() {
//For speed we need only product ids
$args = array('return' => 'ids');
//Get all ids
$product_ids = wc_get_products($args);
error_log(print_r($product_ids,true));
//Collect all attachment ids
$attachment_ids = array();
foreach($product_ids as $pid) {
//Get product object
$product = new WC_product($pid);
$image_ids = $product->get_gallery_image_ids();
//Check image ids that we collect for each product
error_log(print_r($image_ids,true));
foreach($image_ids as $image_id):
if(!in_array($image_id, $attachment_ids)):
$attachment_ids[] = $image_id;
endif;
endforeach;
}
//Check what kind of ids we have collected
error_log(print_r($attachment_ids,true));
//if($attachment_ids):
//foreach($attachment_ids as $att_id):
//Set to false if you want to move in trash
//Set to true if you want to delete
//wp_delete_attachment($att_id,false);
//endforeach;
//endif;
}
add_action( 'init', 'clear_product_gallery_images');

wordpress add payment system. Where to handle form

I wanna to add payment to wordpress . Payment system called PayBox. https://paybox.money/docs/ru/pay-in/3.3#tag/Inicializaciya-cherez-brauzer-polzovatelya/paths/~1payment.php/get . I trying to create form and send data with post method to php file and send request to payment with code below.
<?php
$request = [
'pg_merchant_id'=> 111,
'pg_amount' => 25,
'pg_salt' => 'some_random_string',
'pg_order_id'=>'123',
'pg_description' => 'Описание заказа',
'pg_result_url' => 'https://example.com'
];
// $request['pg_testing_mode'] = 1; //add this parameter to request for testing payments
//if you pass any of your parameters, which you want to get back after the payment, then add them. For example:
// $request['client_name'] = 'My Name';
// $request['client_address'] = 'Earth Planet';
//generate a signature and add it to the array
ksort($request); //sort alphabetically
array_unshift($request, 'payment.php');
array_push($request, 'secret_key'); //add your secret key (you can take it in your personal cabinet on paybox system)
$request['pg_sig'] = md5(implode(';', $request));
unset($request[0], $request[1]);
$query = http_build_query($request);
//redirect a customer to payment page
header('Location:http://core.local/payment.php?'.$query);
But problem is . Where can I handle this code? I dont know how to do this in wp. Form created with page builder .
You need to find out with your page builder that creates the form if they are able to handle hooks. See if there's a function you can hook into when the form is processed.
Generally this would go in your functions.php file of your theme (or a child theme if you're using a ready-made theme).

Create post with custom fields through WP Rest API

I am doing an IONIC app and the project requires to create a post through the Wordpress API with custom fields (I am using ACF Pro and Aires ACF to REST API), I can create a normal post with the REST API, even tho, the ACF fields are not created or asiggned, they are created for the post only if I create the post in Wordpress admin interface.
I was reading the documentation for the ACF to REST API , but I see only edit and show capabilities. Does that mean the post meta have to exist? So how to "create" them for the post
Thanks in advance for the help
Best regards
phpadmin post creating:
absence of post meta:
$json = file_get_contents('PATH/TO/FILE.json');
function the_json_contents($json_to_get){
$json_in_array = json_decode($json_to_get, true); //json string to array
return $json_in_array;
}
function do_stuff_do_json() {
$json_array = the_json_contents($json);
foreach($json_array['id'] as $js) { //assuming we have an 'id' key
$somevariable = $js['someKey'];
$somevariable2 = $js['someOtherKey'];
}
}
Refer this solution

Get current Highest hit post ID from google analytic or Parsely

Is there any way that I can get today's top post's IDs from google analytic or from Parsely API.
I want to show it under "Todays Most Viewed" section of my news website. It shows top 5, posts which where viewed most.
Thank you in advance.
I found a way using parsely:
/*
Function to return latest post, which are retrived from Parse.ly's API
*/
public static function get_most_viewed_homepage_articles ($limit=6) {
$attr= array('apikey' => "YOUR_API_KEY",
"secret" => "YOUR_API_SECRET",
"page" => "1",
"limit" => "$limit",
"time" =>"5m");
$url="https://api.parsely.com/v2/realtime/posts";
$url.="?";
reset($attr);
while(list($attr_key, $attr_val) = each($attr)){$url.=$attr_key."=".$attr_val."&";}
$result = #file_get_contents($url);
$result_json = json_decode($result, true);
return $result_json;
}
This worked for me. I used it on function.php

Save data to custom field from youtube api

I've made a wordpress video section for one of my clients. In the backend it's a custom post type where the users can place the ID (http://www.youtube.com/watch?v=kFHshctPO9E) of a video.
With this ID i embed the video and get the duration and rating of each video from the youtube api.
Now each time a video is loaded (in the overview template all the video's are loaded) it has to reach out to YouTube to get the duration (which i then parse to hours and minutes instead of seconds) and rating of all video's.
I would somehow like to cache or save these values to a custom field or somewhat.
Anyone got any idea?
Thank in advance!
Rick
You can use post_meta to save this information the first time the post is saved and then load the information from the database instead of using youtube api again.
I put you an example in pseudocode:
add_action('save_post', 'my_function_to_save_posts_action');
function my_function_to_save_posts_action($post_id) {
$the_post = get_post($post_id);
if ($the_post->type == 'my_custom_post_type') {
$youtube_data = my_function_to_retrieve_youtube_data();
if (my_function_exists_post_meta($post_id)) {
update_post_meta($post_id, 'my_video_duration', $youtube_data['duration']);
update_post_meta($post_id, 'my_video_rating', $youtube_data['rating']);
}
else {
add_post_meta($post_id, 'my_video_duration', $youtube_data['duration'], true);
add_post_meta($post_id, 'my_video_rating', $youtube_data['rating'], true);
}
}
}
And of course, when you are queryng for your custom post type you must retrive the post_meta information and show this information properly.

Resources