Skip to content

Instantly share code, notes, and snippets.

View olenkadark's full-sized avatar
🎯
Focusing

Olena ZHyvohliad olenkadark

🎯
Focusing
View GitHub Profile
@rxnlabs
rxnlabs / wp-upload-file-post-wp-http.php
Last active July 18, 2023 20:13
WordPress - Upload files to remote API using WP_Http / wp_remote_post + cURL + fsockopen + CurlFile
<?php
$url = 'https://insert-domain-here.com/api-endpoint';
// The file is stored on your system/host
$path_to_uploaded_file = '/full-path-to-file/picture.jpg';
$form_fields = [ 'first_name' => 'Foo', 'last_name' => 'Bar' ];
if ( file_exists( $path_to_uploaded_file ) ) {
$form_fields['profile_picture'] = new CurlFile( $path_to_uploaded_file );
}
/*
@sirbrillig
sirbrillig / functions.php
Last active November 20, 2024 09:52 — forked from UmeshSingla/functions.php
Post file using wp_remote_post in WordPress
<?php
$local_file = 'file_path'; //path to a local file on your server
$post_fields = array(
'name' => 'value',
);
$boundary = wp_generate_password( 24 );
$headers = array(
'content-type' => 'multipart/form-data; boundary=' . $boundary,
);
@iandunn
iandunn / programmatic_login.php
Last active March 7, 2023 18:18
Programmatically log in a WordPress user
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {
wp_logout();