I created a cron that will insert posts from the other site using the rest route and wp_insert_post. On the first cron run, the posts were inserted but when I added a new post from the source site and run the cron again, the new post is not added. I'm not sure what I'm doing wrong. If you could help me with this I would really appreciate it. Please see my code below.
add_action('create_posts_cron', function(){
$post_data = wp_remote_get( ' ' ); // inserted the rest route inside ''
$post_data_decode = json_decode( $post_data['body'] );
foreach ( $post_data_decode as $item ) {
$post_title = $item->title;
$customfield = $item->customfield;
$post_arr = array(
'post_title' => $post_title,
'post_status' => 'publish',
'post_type' => 'custompost',
);
if( !get_page_by_title( $post_title, OBJECT, 'custompost' ) ) {
$post_id = wp_insert_post( $post_arr );
update_field( 'customfield', $customfield, $post_id );
}
}
});
Related
Trying to load post ID (and then some ACF field) of the post, where the form is currently embedded. Using get_the_id() or global $post w/ $post->ID returns NULL.
Loading post ID works correctly when using the other Gravity Forms filters (e.g. gform_admin_pre_render), but I was told using the gform_form_post_get_meta is the better way to do ths. What is the right approach for this?
add_filter( 'gform_form_post_get_meta' , 'my_populate_cpt_as_choices' );
function my_populate_cpt_as_choices( $form ) {
$current_post_id = get_the_id();
$postargs = array(
'post_type' => 'suhlasy',
'post_status' => 'publish',
'posts_per_page' => '-1',
);
$posts = get_posts( $postargs );
$input_id = 1; // this makes sure the checkbox labels and inputs correspond
foreach ( $posts as $post ) {
//skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
if ( $input_id % 10 == 0 ) {
$input_id++;
}
$post_id = $post->ID;
$id_souhlasu = 1200 + $input_id;
$title = get_the_title($post_id);
$checkbox_text = get_field('checkbox_text', $post_id);
$text_suhlasu = get_field('text_suhlasu', $post_id);
$kategoria = get_field('kategoria_suhlas', $post_id);
// getting other fields for this post to display as values or checkbox labels
$nazev_souhlasu = GF_Fields::create( array(
'type' => 'consent',
'id' => $id_souhlasu, // The Field ID must be unique on the form
'formId' => $form['id'],
'isRequired' => true,
'label' => $title,
'parameterName' => 'my_custom_parameter',
'checkboxLabel' => $checkbox_text,
'description' => '<h2>' . $current_post_id . $post_id . $kategoria . '</h2><br>' . $text_suhlasu,
'pageNumber' => 1, // Ensure this is correct
) );
$form['fields'][] = $nazev_souhlasu;
$input_id++;
}
return $form;
}
Greeting everyone and especially to Senior of CodeIgniter Developer.
I have a problem with website that was built from CodeIgniter (I am not the developer inherited by previous epmployer). This website cannot working properly, especially when upload the image and shows warning about
Error Number: 1048 Column 'article_image' cannot be null
I did try with find the problem on the script and database, but nothing change and because no one change the codes & contents. Today, i try again with changing the "Null into yes" (previously is "No"), and tried to upload the article. It is miracle that it is working but the next problem is the image is gone (broken). I search at other and looking people with same problem with me says that i need to upgrade the CodeIgniter. Mine is 3.0.0 while the latest is 3.1.10. I copy paste the content inside /System and /views/error/cli not making better but make it worse, the image at the web page is gone(missing).
This is my Article_model
defined('BASEPATH') OR exit('No direct script access allowed');
class Article_model extends CI_Model {
public function get_all()
{
// $this->db->order_by('article_date', 'desc');
// $this->db->order_by('article_view', 'desc');
// $query = $this->db->get_where('article', array('flag !=' => 3));
// return $query->result_array();
$query = $this->db->query("SELECT A.*,B.*, A.id AS id_article FROM article AS A JOIN category B ON A.article_category = B.id WHERE A.flag != 3 ORDER BY article_date DESC, article_view DESC ");
return $query->result_array();
}
public function check($article_id)
{
$query = $this->db->get_where('article', array('flag !=' => 3, 'id' => $article_id));
return $query->row_array();
}
public function get_category()
{
$query = $this->db->order_by('category_name', 'ASC')->get_where('category', array('flag' => 1));
return $query->result_array();
}
public function get_tag()
{
$query = $this->db->order_by('tag_name', 'ASC')->get_where('tag', array('flag' => 1));
return $query->result_array();
}
public function get_selected_tag($article_id)
{
$query = $this->db
->select('tag.id, tag_name')
->join('article_tag', 'tag_id = tag.id')
->where(array('tag.flag' => 1, 'article_id' => $article_id))
->get('tag');
return $query->result_array();
}
public function insert()
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author' => $this->session->admin_id,
'article_title' => $this->input->post('article_title'),
'article_slug' => url_title($this->input->post('article_title'), '-', TRUE),
'article_category' => $this->input->post('article_category'),
'article_image' => $image['file_name'],
'article_content' => $this->input->post('article_content'),
'is_popup' => $this->input->post('is_poup'),
'article_date' => $this->input->post('article_date'),
);
$this->db->insert('article', $insert_data);
$article_id = $this->db->insert_id();
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
public function update($id)
{
$this->load->helper('upload');
$this->load->library('image_moo');
$image = file_upload('article_image', 'upload/article');
$this->image_moo->load($image['full_path']);
$this->image_moo->resize(924, 527)->save($image['path'] . '/' . $image['file_name'], TRUE);
$this->image_moo->resize_crop(100, 69)->save($image['path'] . '/thumb/' . $image['file_name']);
$this->image_moo->resize_crop(367, 232)->save($image['path'] . '/cover/' . $image['file_name']);
$insert_data = array(
'article_author' => $this->session->admin_id,
'article_title' => $this->input->post('article_title'),
'article_slug' => url_title($this->input->post('article_title'), '-', TRUE),
'article_category' => $this->input->post('article_category'),
'is_popup' => $this->input->post('is_popup'),
'article_content' => $this->input->post('article_content'),
'article_date' => $this->input->post('article_date'),
);
if ($image)
{
$insert_data['article_image'] = $image['file_name'];
}
$article_id = $id;
$this->db->where('id', $id);
$this->db->update('article', $insert_data);
$this->db->where('article_id', $id);
$this->db->delete('article_tag');
foreach ($this->input->post('article_tag') as $tag)
{
// Check apakah tag itu udah ada di database?
if (is_numeric($tag))
{
$tag_id = $tag;
}
else
{
$this->db->insert('tag', array('tag_name' => strtolower(trim($tag)), 'tag_slug' => url_title(trim($tag), '-', TRUE)));
$tag_id = $this->db->insert_id();
}
if ( ! $this->db->get_where('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id))->row_array())
{
$this->db->insert('article_tag', array('article_id' => $article_id, 'tag_id' => $tag_id));
}
}
}
}
What should i do guys? i did backup but it remain same like after upgraded. Thank you. Web Url (http://www.hidupseimbangku.com/)
First. If you want to upgrade CI Version you must follow Upgrading Guide one by one. There may be break changes and you need to correct them, you can find this guide here:
https://www.codeigniter.com/userguide3/installation/upgrading.html
I suggest you rollback upgrade changes and start again doing one by one. It is not hard, it is just time consuming.
The error you're getting is probably related to an error of uploading process. What is file_upload?
I also suggest you read this, for properly file upload.
The user flow I'm building for my application is that users can click on myAccounts and I'll display the getCustomerAccounts Results. That works perfectly. Then for each account I have a hyperlink called get transactions. That takes the user to a new page that should list out the transactions for that account. For some reason I'm always getting a 401 Code:ApplicationAuthenticationFailed when I call getAccountTransactions even though the previous call of getCustomerAccounts worked fine.
I'm confused as I imagine the authentication that is failing for the 401 is the exact same that works for the earlier call. Here is my code:
function get_transactions($accountID)
{
IntuitAggCatHelpers::GetOAuthTokens( $oauth_token, $oauth_token_secret);
$signatures = array( 'consumer_key' => OAUTH_CONSUMER_KEY,
'shared_secret' => OAUTH_SHARED_SECRET,
'oauth_token' => $oauth_token,
'oauth_secret' => $oauth_token_secret);
$txnStartDate = '2014-06-01'; // YYYY-MM-DD
$url = FINANCIAL_FEED_URL ."v1/accounts/$accountID/transactions?txnStartDate=$txnStartDate";
$action = 'GET';
$oauthObject = new OAuthSimple();
$oauthObject->setAction( $action );
$oauthObject->reset();
$result = $oauthObject->sign(
array
(
'path' => $url,
'parameters'=>
array
(
'oauth_signature_method' => 'HMAC-SHA1',
'Host' => FINANCIAL_FEED_HOST
),
'signatures'=> $signatures
)
);
$options = array();
$curlError = fopen('php://temp', 'rw+');
$options[CURLOPT_STDERR] = $curlError;
$options[CURLOPT_CUSTOMREQUEST] = $action;
$options[CURLOPT_URL] = $result['signed_url'];
$options[CURLOPT_HEADER] = 1;
$options[CURLOPT_VERBOSE] = 1;
$options[CURLOPT_RETURNTRANSFER] = 1;
$options[CURLOPT_SSL_VERIFYPEER] = true;
$options[CURLOPT_HTTPHEADER] = array
(
'Accept:application/json',
'Content-Type:application/json',
//'Content-Length:' . strlen( $postData ),
'Host:'. FINANCIAL_FEED_HOST,
//'Authorization:' . $result['header']
);
$curlError = fopen('php://temp', 'rw+');
$options[CURLOPT_STDERR] = $curlError;
$ch = curl_init();
curl_setopt_array( $ch, $options );
$responseText = urldecode( curl_exec( $ch ) );
echo $responseText;
//display curl http conversation
rewind( $curlError );
stream_get_contents( $curlError );
fclose( $curlError );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
return $responseText;
}
Using same certificate(.p12) please try the above getAccountTransaction call from APIExplorer tool.
https://developer.intuit.com/apiexplorer?apiname=CustomerAccountData
Usage Ref - https://developer.intuit.com/docs/0020_customeraccountdata/007_firstrequest
If that works well, then compare the request header and URL with the same from your above code. 401 suggests authentication error which comes when your OAuth header is not properly formed/incorrect. Above comparison should sort this out.
PN - While uploading .p12 file(SAML) in ApiExplorer, sometiems, I get the following error msg.
"Your certificate is invalid. Please use base64 encoded CER format and make sure that the file is not empty". If you get the same then this can't be tested in ApiExplorer.
Thanks
This worked for me:
$result = $oauthObject->sign(array(
'path' => FINANCIAL_FEED_URL . 'v1/accounts/400037865348',
'parameters'=> array('oauth_signature_method' => 'HMAC-SHA1',
'Host'=> FINANCIAL_FEED_HOST,
'txnStartDate' => '2014-01-01',
'txnEndDate' => '2014-08-29'),
'signatures'=> $signatures));
Found at https://intuitpartnerplatform.lc.intuit.com/questions/797819-how-to-get-txnstartdate-into-my-url-without-breaking-oauth-authentication.
I would like to retrieve all accounts datas and contact datas in Sugarcrm database using webservice .
I would like it to show it in a webpage .
How can i go about it?
Modify the below code to your requirements. It uses the SOAP API of SugarCRM.
$user_name = 'admin';
$user_password = 'admin';
$sugarcrm_url = 'http://example.com/'
$options = array(
"uri" => $sugarcrm_url,
"trace" => true
);
$offset = 0;
$limit = 100;
try {
$client = new SoapClient($sugarcrm_url.'service/v4_1/soap.php?wsdl', $options);
$response = $client->__soapCall('login',array(
'user_auth'=>array(
'user_name'=>$user_name,
'password'=>md5($user_password),
'version'=>'.01'
),
'application_name'=>'SoapTest'
));
$session_id = $response->id;
$response = $client->__soapCall('get_entry_list',array(
'session'=>$session_id,
'module_name'=>'Contacts',
'query'=>'',
'order_by'=>'contacts.last_name asc',
'offset'=>$offset,
'select_fields'=>array(),
'max_results'=>$limit)
);
print_r($response);
$response = $client->__soapCall('get_entry_list',array(
'session'=>$session_id,
'module_name'=>'Accounts',
'query'=>'',
'order_by'=>'accounts.name asc',
'offset'=>$offset,
'select_fields'=>array('id', 'name', 'email1'),
'max_results'=>$limit)
);
print_r($response);
$response = $client->__soapCall('logout',array('session'=>$session_id));
} catch (Exception $ex) {
echo $ex->getMessage();
}
I am trying to make an activity published by an admin to be visible to every member of the network, not just their friends.
As far as I could make until now, is that the table stream is preventing my message to became public, it only make a profile message. Visible only in its feed.
Does anyone have any idea how to enforce this?
[EDIT]
My code below is picking tweets in my account, I am using some settings i created (like the screen_name from twitter and the user who is publishing the tweet at the feed).
The code is doing as follows:
-> Checking if there is settings for twitter user to read its messages.
-> Save it in a table
-> Authorizing (in theory) to everyone to read this messages, ether is friend of the publisher or not.
-> Adding the activity, that I also created.
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
if ($TwitterUser != '') {
// Ultimo tweet postado
$TwitterUser = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.screen_name' );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$query = $table->select ()->order ( 'tweets_id desc')->limit(1);
$lastTweet = $table->fetchRow ( $query );
// Set the configuration parameters
$config = array ('adapter' => 'Zend_Http_Client_Adapter_Socket', 'ssltransport' => 'tls' );
// Instantiate a client object
if (is_null ( $lastTweet )) {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&count=4&include_rts=1", $config );
} else {
$client = new Zend_Http_Client ( "http://api.twitter.com/1/statuses/user_timeline.json?screen_name=$TwitterUser&include_rts=1&since_id=" . $lastTweet->real_id, $config );
}
// The following request will be sent over a TLS secure connection.
$response = $client->request ();
// Pegando a resposta
$body = json_decode ( $response->getBody () );
if (! empty ( $body )) {
$db = Engine_Api::_()->getDbtable('tweets', 'user')->getAdapter();
$db->beginTransaction();
try
{
$table = Engine_Api::_ ()->getDbtable ( 'users', 'user' );
$twitter_user = $table->fetchRow ( $table->select ()->where ( 'user_id = ?', Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'core.twitter.user_id' ) ) );
$table = Engine_Api::_ ()->getDbtable ( 'tweets', 'user' );
$activityApi = Engine_Api::_ ()->getDbtable ( 'actions', 'activity' );
foreach ( array_reverse($body) as $tweet ) {
$data = explode ( ' ', $tweet->created_at );
$meses = array ('Jan' => '01', 'Fev' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' );
$tweet_date = $data ['5'] . "-" . $meses [$data [1]] . '-' . $data [2] . " " . $data [3];
$tweet_date = (date ( 'Y-m-d H:i:s', strtotime ( $tweet_date ) ));
$last_tweet = $table->createRow();
$last_tweet->setFromArray(array(
'real_id' => $tweet->id_str,
'user_id' => $tweet->user->id_str,
'screen_name' => $tweet->user->screen_name,
'body' => $tweet->text,
'retweeted' => $tweet->retweeted,
'created_at' => $tweet_date,
'profile_image_url' => $tweet->user->profile_image_url,
'coordinates' => $tweet->coordinates
));
$last_tweet->save();
// Authorizations
$auth = Engine_Api::_()->authorization()->context;
$auth->setAllowed($last_tweet, 'everyone', 'view', true);
$auth->setAllowed($last_tweet, 'everyone', 'comment', true);
$auth->setAllowed($last_tweet, 'everyone', 'likes', true);
$action = $activityApi->addActivity ($twitter_user,$last_tweet, 'post_twitter', $tweet->text);
if( $action ) {
$activityApi->attachActivity($action, $last_tweet);
}
}
// Commit
$db->commit();
} catch ( Exception $e ) {
$db->rollBack ();
throw $e;
}
}
}
No problems happens, but the tweet that I am tracking only could be red by the user I used to publish it.
You should create entries in stream table for this action_id.