Wordpress - Upload media to different server - wordpress

I've split the resources on a WP site into two servers: Server A with administration files, Server B with public files. They are connected by the data base.
Are there any way that will cause media that I upload from the WP admin installation on Server A to be stored over on Server B? Whit this, that media will be served from Server B ("public site").
If possible, other than through an FTP connection, my client doesn't want a FTP in the public site :-(
Thanks in advance!

First, create a remote storage service where you can post the file and return a URL addressing the file on server B. Then you can use wp filters to attain the url from server A.
You can hook into this filter: "wp_handle_upload"
apply_filters{
'wp_handle_upload'
array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload'
)
just replace the URL to the new one

Related

How to Configure Your Domain linked to Firebase Hosting, and maintain mail access (DNS records)

There are already many posts on the web to help you connect your custom domain to Firebase.
In fact, if you have enough experience, you wouldn't even need a guide...it's that simple.
What is NOT commonly known is that, with your default hosting configuration (for example a cPanel hosted service)... Once you've reconfigured the domain's A-record to the Firebase IP, everything pointing to that domain is redirected to the new IP.
For example:
A => yourfunkydomain.com => yourFirebaseIP
A => ftp.yourfunkydomain.com => yourHostingServiceIP
All good...
But what about your MX record?
MX => yourfunkydomain.com
CNAME => mail.yourfunkydomain.com => yourfunkydomain.com
You won't be getting mails any time soon...
The Fix:
MX => mail.yourfunkydomain.com
CNAME becomes A => mail.yourfunkydomain.com => yourHostingServiceIP
So keep in mind, any other records needs to be updated to their own respective IP's.
Hope this helps someone.

Receiving Stripe Webhooks on a wordpress website

I have a wordpress website hosted on GoDaddy.
I am an advanced stripe user and have integrated stripe with many Ruby on Rails apps , along with stripe-webhook integration with the Rails. Also i am well versed in how web-hooks work.
But recently i was made owner of a wordpress website hosted on GoDaddy and on that website i am supposed to receive stripe payment failed webhook and then trigger an email based on that webhook event.
I am not able to make much connect with wordpress and stripe from online resources and need help on how to receive stripe-webhooks in wordpress website i.e where to put code to make that happen etc.
I recently had the same problem and pippins stripe integration plugin seemed to answer it but it had a lot of extra code I did not need so I removed it and made a concise version just for the webhook integration: WPStripeWebhook. README is self explanatory. Basically make changes to includes/stripe_listener.php for your events. Also attaching readme here as per stackoverflow guidelines:
Usage:
Copy the complete folder WPStripeWebhook in wp-content/plugins. Go
to website admin page.
Activate the WP Stripe webhook plugin for
plugins section.
After this Settings will start showing Stripe
webhook settings section. Click on it. In the page fill the stripe
keys and check test mode option if you want to test the plugin.
In WPStripeWebhook/includes/stripe_listener.php, make changes for your
event type and email or whatever you want to do in response to
an event. It currently sends out an email.
Important notes and suggestions
For live mode, add stripe webhook endpoint (stripe account -> settings -> account settings -> webhook) like this
https://yourdomain.com?webhook-listener=stripe
For testing locally on your machine, you can use Ultrahook. Its awesome! Set up your keys and username and start ultrahook on your machine using:
ultrahook -k your_ultrahook_key stripe 8888
Add a webhook endpoint url in your stripe account similar to this:
http://stripe.your_ultrahook_username.ultrahook.com/your_wp_website_folder_name/stripe-listener.php?webhook-listener=stripe
And it should start working for you. Also, you might see 404 in ultrahook console. Just ignore it. I would suggest setting up debugging too. It really helps. For debugging, add these to your wp_config.php
define('WP_DEBUG', true);
define( 'WP_DEBUG_LOG', true );
define('WP_DEBUG_DISPLAY', false );
#ini_set( 'display_errors', 0 );
define('SCRIPT_DEBUG', true );
After this, you should see a debug.log file in your wp-content folder and it will display errors and warnings and whatever you print using error_log()
Here is my two cents. For posterity and because the accepted answer didn't do it for me.
We can use the WordPress REST api.
By Extending the REST API and Adding Custom Endpoints through the register_rest_route function.
<?php
add_action( 'rest_api_init', 'wpso40015091' );
function wpso40015091() {
$routes = array(
array(
'namespace' => 'wpso40015091/listener/v1',
'route' => 'endpoint',
//www.example.com/index.php/wp-json/wpso40015091/listener/v1/endpoint
//This is the endpoint to add in your Stripe dashboard webhook section.
//From time to time, depending on your host, the "index.php" might be omitted.
//You can use "get_rest_url()" to Retrieves the URL to a REST endpoint on a site.
//https://developer.wordpress.org/reference/functions/get_rest_url/
'args' => array(
'methods' => 'POST',
'callback' => function () {
//...
},
'permission_callback' => '__return_true',
),
'override' => true,
),
);
foreach ( $routes as $route ) {
register_rest_route( $route['namespace'], $route['route'], $route['args'], $route['override'] );
};
};
The callback function is the event listener. Stripe has a built in generator, refer https://stripe.com/docs/webhooks/quickstart.

How to proxy per-request WordPress user authentication data to another server in the same domain?

I’m using WordPress as my frontend for user administration, handling registration, logins, authentication and logouts. Users register and login using WordPress.
The site has URLs served by a backend mod_perl server in the same domain.
When a user clicks a link that proxies to the backend server, I would like for the frontend server, the proxy, to pass the authenticated user’s name or login credentials to the backend server. The backend server will use those credentials to do authorization.
I can imagine several ways to do this.
Maybe the backend server reads the username from the WordPress
cookie. The Cookie HTTP Header is visible in the backend server
logs (I configured intentionally this as a debugging aid.) Is it
possible to do this, one server read a cookie written by another
server (in the same domain)?
The frontend WordPress server might write the authenticated username
into an environment variable which mod_rewrite would tack on to the
URL proxiing to the backend server. Maybe using a WordPress plugin,
but I’ve not found such.
WordPress SSO/OAuth might be possible, but my OS X El Capitan
development environment presents another layer of challenges for
that.
The frontend is Apache2.4, PHP 5.5.34, WordPress 4.5.3. Apache modules can be added and removed as DSOs. The backend is Apache 2.4, mod_perl 2.0.10, MySQL 5.7.
Both servers run in the same AWS instance running AWS Linux. (I’m beginning to think AWS Linux was the wrong choice for me, but that’s a whole nother thread.)
I have Apache, MySQL and Perl skills. PHP and Javascript I never learnt.
The simplest way (perhaps it's also the only practicable one) would be to use PHP because wordpress is a PHP application, which indeed is a problem for you. Nevertheless, I have a simple example for you:
PHP page on your wordpress site:
<?php
require('path/to/wp-blog-header.php');
if (is_user_logged_in()) {
$user = wp_get_current_user();
header("Location:backend.php?user=".$user);
exit();
} else {
echo "User is not logged in!";
};
?>
PHP page on your backend server:
<?php
if (isset($_GET['user'])) {
$user = $_GET['user'];
// do something with $user.
} else {
echo "No user passed!";
}
?>
This simply uses two of Wordpress' built-in functions. First the is_user_logged_in() function is used to determine whether a user is logged in. If the function returns true, the wp_get_current_user() function is called to pass the username to the backend server's php page using the GET method. Then the backend server validates the passed variable.
Please note that this simple procedure is illustrative only and is extremely unsafe!

Alfresco with Drupal CMIS

I am attempting to configure Drupal CMIS to connect to the Alfresco public test repository.
I am using this CMIS module
https://www.drupal.org/project/cmis
I am using Alfresco 4.x CMIS Content Repository as found here
https://www.alfresco.com/cmis
The problem is that when i try to browse the repository in drupal I get the following message
There has been an problem contacting the CMIS server, please see the logs.
The error log always reads
HTTP call to [repository link here, shown in code sample bellow] returned [307]. Response: Authentication Required Authentication Required
my Drupal settings file contains the following
$conf['cmis_repositories'] = array(
'default' => array(
'user' => 'admin',
'password' => 'admin',
'url' => 'http://docs.oasis-open.org/ns/cmis/ws/200908/'
)
);
The config is copy/pasted from the modules documentation and includes the URL which appears in the error message. Also I have viewed the $conf global using print('' .print_r($conf,true) . '') so I definitely have settings.php correct.
is my admin, pass, url combination still valid (ie is the site up to date)
what else could be causing this?
Your url seems to be wrong.
Please try with http://cmis.alfresco.com/cmisatom (Atompub ) , http://cmis.alfresco.com/cmisbrowser (json)
Links are there in the alfresco web link mentioned by you
cheers,
Saurav

Can not Connect Drupal to DB only on AWS

uploaded an existing drupal codebase to a virtual host set up on AWS. it is showing "can not connect to database"
I created database "dbname" and can connect fine through ssh. But can not get settings.php to connect. As far as I can tell the mysql user has all needed permissions to access the db remotely.
what I have
$db_url = 'mysql://username:password#us-west-rds.amazonaws.com/dbname';
Here is example of settings.php with a drupal 7 site of ours that connects fine
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'dbname',
'username' => 'dbuser',
'password' => 'password',
'host' => 'us-west-rds.amazonaws.com',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
),
),
);
There are several things to check:
do you have the security group open to allow access from your server (as said by Bob Kinney in the other answer)?
do you have a firewall set up on your server that prevents connecting to your RDS instance?
does your user have sufficient rights to connect to your database?
The easiest way to debug this is to use the console mysql command and try to connect to your instance from there:
mysql dbname -u username -p password -h db01b2.ck1dmcn6kfws.us-west-1.rds.amazonaws.com
If this does not work, check the points given above. If this works and does not work in Drupal only, check your PHP code and/or Drupal config.
Sounds like you may not have set up your security groups to allow access from your EC2 instances. You'll want to make sure your DB security group has an ingress rule to allow traffic from your EC2 instance/security group.
How do I control network access to my DB Instance(s)?
You're pointing at the wrong hostname.
'host' => 'us-west-rds.amazonaws.com'
Each individual database instance will have it's own hostname. You can look it up in the AWS Console. The one you're currently pointing to looks like you intended to point to the RDS web service API endpoint.
You might also want to check...
setsebool httpd_can_network_connect_db on

Resources