How can I update robots.txt on the pantheon environment Live site?
I have tried the following option
1) Via FTP
2) via word press SEO >> tool
Do I need to follow any steps, as it's a word press instance
Nothing special. Two options here,
Create a robots.txt file locally. Add desired statements. Upload to Pantheon via SFTP or Git.
Pull down the existing robots.txt file from Pantheon, modify as necessary, and push back up via SFTP or Git.
In both cases, you need to keep in mind that Pantheon forces a Workflow. You have the Dev, Testing, and Live Servers. When you push, whether by Git or SFTP, you are essentially pushing to the Dev environment. Note that if you choose to use SFTP, you must have the Pantheon site in SFTP mode (not Git), and you should log into the Dev environment SFTP. From there, you must deploy up to the Live environment. You do this via the Pantheon Dashboard.
EDIT:
Since you are going the SFTP route, you will need to login via SFTP to the dev environment. Once logged in via SFTP, you will want to upload to the /code directory. This is the root directory for the WordPress installation. So you will have uploaded /code/robots.txt. Once you upload, you will need to return to the Pantheon Dashboard and commit your changes through Dev, Testing, and Production.
Hope this helps.
If you do not have any experience with PHP and or don't feel comfortable modifying your themes code for whatever reason the solution above should work perfectly.
Alternative PHP approach
If this is a site you are developing / maintaining and feel comfortable modifying the theme there is another approach that will save you time in the long run.
Filters to the Rescue!
If you are unfamiliar with hooks and filters within WordPress I'll defer you to either this article from Treehouse blogs or a quick google search. The hooks and filter system plays a fundamental part in how plugins like Yoast SEO function, allowing them to modify the output of the robots.txt file for example.
We can use this same robots_txt filter to modify the output of our sites robots.txt file without any external plugin or theme dependency. If you use git or svn to manage your theme or /wp-content/ directories this approach allows you to keep any modifications under version control.
The code below should live in your themes functions.php file or another included PHP file of your chosing.
<?php
function so_robots_txt_50725645( $output ) {
// User-agent: *
$output .= 'User-agent: *' . PHP_EOL;
$output .= 'Disallow: /wp-includes/' . PHP_EOL;
$output .= 'Disallow: /wp-content/uploads/' . PHP_EOL;
return $output;
}
// Hook in our filter function.
add_filter( 'robots_txt', 'so_robots_txt_50725645', 10, 1 );
?>
What's listed above is just an example, you could populate the $output variable with whatever content you wanted to appear on the robots.txt page. In this example we are appending new Disallow lines to the existing output via the .= operator.
After all operations have been completed we return the modified $output and go on our way, never to worry about migrating pesky robots.txt files ever again.
Related
I know PHP but not much WordPress, and I need to upload a collection of files into my client's WP site. I'm wanting something a little different from what is being asked in this SO post.
I need to upload a collection of totally custom files, including PHP, html, js, and css files. Ideally I'd love to upload a zip with my collection of web files, with folder structure maintained. These files have nothing to do with the WP site, in that they don't need to hook in to the menuing/plugins/themes, etc. They are standalone files with custom functionality, I just need to launch my "main" page when a certain WP button is clicked.
Is there a way to upload a zip file through the WP admin interface and have it extract my files into a safe/isolated location?
How will I know the absolute or relative URL to my main page, after this upload occurs?
If 1 and 2 above are impossible, what's the best approach to get my files up there, in some kind of isolated folder? (I really don't want to create/modify themes or plugins if possible, I just literally want to dump some files onto the server and then know how to access them via URL.)
Note: If I had access to FTP on my client's server, that would be the easiest approach by far, but that is not an option, and my only doorway is the WP admin interface. This is a hosted wordpress site (version 4.7), hosted by Wordpress.com, and it's the Business Plan.
EDIT:
Here is Zero Gravity Payment Module.php:
<?php
/**
* #package ZeroGravityPaymentModule
* #version 1.0
*/
/*
Plugin Name: Zero Gravity Payment Module
Plugin URI: https://www.zerogravpro.com/CCPayment/
Description: Advanced Authorize.Net credit card payment form built by Zero Gravity Programming.
Author: Nate Jensen
Version: 1.0
Author URI: https://www.zerogravpro.com/
Text Domain: hello-dolly
*/
?>
And here is installer.php:
<?php
$destinationDir = $_SERVER['DOCUMENT_ROOT'] . '/' . 'ZeroGravityPaymentModule';
mkdir($destinationDir);
$zip = new ZipArchive;
$zip->open('ZeroGravityPaymentModule.zip');
$zip->extractTo($destinationDir);
$zip->close();
?>
I was able to upload my "plugin", but now cannot seem to find my php files via absolute url. I have tried the following locations:
https://[actualdomain]/wp-content/plugins/Zero%20Gravity%20Payment%20Module/installer.php
https://wordpress.com/view/[actualdomain]/wp-content/plugins/Zero%20Gravity%20Payment%20Module/installer.php
I have tested this answer end to end and it works. However, it now transpires that this question relates to Wordpress.com which provides modified/restricted versions of Wordpress - see edit at bottom of answer.
It can all be done with 2 miniscule scripts.
i: "mydummy.php" contains just a single comment on its own line (necessary to "fool" WP into uploading your actual script and archive file).
<?php
/* Plugin Name: mydummy */
?>
ii: "myinstaller.php" e.g.
<?php
$destinationDir = $_SERVER['DOCUMENT_ROOT'] . '/' . 'myparentdir';
mkdir( $destinationDir, 0775); // 0755 whatever
$zip = new ZipArchive;
$zip->open('myarchive.zip');
$zip->extractTo($destinationDir); // creates dirs and files below as per archive structure
$zip->close();
?>
Tested and works. Add your own error handling & info/progress msgs as required (you are familiar with php).
To upload and run:
Create a zip (e.g. myarchive.zip) of the directories and contained files you want to place on your server.
Place this zip and the 2 script files above in a folder called "mydummy".
Zip the "mydummy" folder" (the result should be "mydummy.zip" containing folder "mydummy" with your archive, myinstaller.php & dummy.php in it.
upload mydummy.zip via Wordpress admin: Plugins->Add New->Upload File. Dont bother activating. Your script and archive are now uploaded to (/maybe-path-to) /wp-content/plugins/mydummy.
run your script http://example.com/wp-content/plugins/mydummy/myinstaller.php JOB DONE
delete plugin, scripts and archive: via Wordpress admin: Plugins find "mydummy" and click its delete link
File perms shouldn't be a problem (I assume server will ensure files are 644 by default etc) the owner will obviously be the same as Wordpress - this should not be a problem for browser access.
Edit:
A common response to Wordpress.com questions is to advise contacting their support; and on a paid plan I would hope you get better answers from them than here. My knowledge of this host is near zero - I vaguely recollect its sites use a restricted variant of Wordpress and that on some(?) plans only specified plugins can be used.
You will need to build it as a WordPress plugin. Otherwise, it won't
work inside WordPress.com's structure.
If they mean the upload will only take place if there is a functioning plugin then try replacing the empty dummy plugin in my first answer with this:
<?php
/* Plugin Name: mydummy
Plugin URI: http://example.com
Description: do nothing plugin
Author: me
Version: 1.0.0
Author URI: http://example.com/
*/
$donothing = 0;
?>:
However; if they mean scripts will only execute if called by "Wordpress" you need to add extract code to plugin but ensure extract only occurs once not every time someone visits the site. In plugin, replace $donothing = 0 with:
function site_perm_function() {
// your code to create html string of dirs (e.g. root and current) + their permissions
// return permission string
}
add_shortcode( 'display_my_site_perms', 'site_perm_function' );
function install_function() {
// your code from myinstaller.php above with code to build message string from statement errors/results
// return message string
}
add_shortcode( 'myinstaller', 'install_function' );
Create a new zip and try installing and ACTIVATING plugin and. If OK:
Open the post editor to create a dummy post.
In the post editor insert the shortcode [display_my_site_perms] then preview the post - this should display permissions.
If permissions look OK for unarchiving then add shortcode [myinstaller] to the post and preview again - this should do the install.
Hopefully it will work, but not tested and I have zero knowledge of Wordpress.com.
In my projects, there are many links of forms, certificates. If suppose client want to migrate the project from one domain to another, automatically links should be updated. For that purpose, I have used Insert php plugin in wordpress. Also I have activated that plugin as per the given instructions. Unfortunately shortcode is also displaying in frontend. How should i get homeurl in frontend using this plugin.
Please don't use this plugin. I think enabling PHP in WordPress content is a high security risk. If the only thing you need is the home url, we you don't user relative paths? Then you are using always the right URL.
If that is not an option, consider creating a shortcode for replacing it with the home url.
//[home_url]
function home_url_shortcode( $atts ){
return home_url();
}
add_shortcode( 'home_url', 'home_url_shortcode' );
Place this in your themes functions.php and use it with [home_url]
Besides the solution of the above. If you migrate a WordPress project you should run a search/replace on the database for the old and the new domain. WordPress uses the full domain on multiple occasions. So this is not a solid solution.
https://wordpress.org/plugins/wp-migrate-db/
https://deliciousbrains.com/wp-migrate-db-pro/
I'm trying to get Wordpress running on AWS Elastic Beanstalk. I'm starting with:
Set of Wordpress 4.1 files (with some additional plugins, etc.)
An environment on AWS Elastic Beanstalk (let's call it app-dev)
A MySQL database running on AWS RDS
Local server running using MAMP
I can successfully get the app going locally. I start the server, point it to the WP directory, and can then access it. I go through the WP setup screens, plug in my database info, install WP, and everything works fine in conjunction with the database. This also generates my wp-config.php file.
Now, when I use the Elastic Beanstalk command line tools to attempt to deploy the app to the app-dev environment (by way of making a git repo, using eb init, and eb deploy), the result I get on app-dev.elasticbeanstalk.com is just a "This webpage is unavailable" problem. Interestingly, if I go to app-dev.elasticbeanstalk.com/wp-admin, it automatically redirects me to the localhost:8888/wp-admin page. This makes me think I'm doing something wrong when I set the wp-config - it's doing something to link it back to the localhost:8888 links.
I've tried to not go through WP setup locally, and just deployed to the server and set up there, but after I click through the setup, it oddly re-routes me to try setup again on localhost:8888. So I get the sense that's the wrong approach.
I've tried getting insights from the following tutorials, especially in regards to their local versus production setup (i.e. everything having to do with the local-config.php file), but every variation of things I've tried hasn't had better results.
https://www.otreva.com/blog/deploying-wordpress-amazon-web-services-aws-ec2-rds-via-elasticbeanstalk/
http://slicenpress.com/how-we-manage-sites-with-beanstalk/
I'm inclined to think I'm misunderstanding some basic concept about how WP setup works and what it does during setup. Could anyone point me in the right direction, or try to describe that for me?
Thanks!
Figured it out. Turns out I just wasn't accounting for a few variables that WP sets as you install WP - the URL's associated with the installation. So in this case, WP was pointing to my localhost links, even when I deployed to the server.
The straightforward fix is to go to WordPress, Settings > General, and change both the Wordpress Address and Site Address URLs to reflect the server URL rather than your local URL. You should do this right before you deploy, because after you change it you'll no longer be able to access it via localhost.
The more complete fix is to set up your wp-config.php file to account for this. Those two fields correspond to WP_HOME and WP_SITEURL variables. For my setup (in which I used git branching to differentiate between development and production code), I used this:
// Check for a local config file
if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
define( 'WP_LOCAL_DEV', true );
include( dirname( __FILE__ ) . '/local-config.php' );
} else {
define( 'WP_LOCAL_DEV', false );
define('WP_HOME','http://myserverurl.com');
define('WP_SITEURL','http://myserverurl.com');
}
In local-config.php, I just had:
<?php define('WP_HOME','http://localhost:8888');
define('WP_SITEURL','http://localhost:8888'); ?>
I listed local-config.php in .gitignore, which meant whenever I deployed, local-config.php was not included, and the right variables were used when trying to run on the server.
I'm using WordPress 3.5.1. On my web site, the image paths for my post thumbnails, instead of directly linking to the image (i.e. /wp-content/uploads/image.jpg) are linking to /wp-content/uploads/cache/image-slug/12314335235.jpg
Images 'inserted into posts' show up using their original URLs (i.e. /wp-content/uploads/image.jpg). The cache somehow only applies to post thumbnails.
I've searched for why this is happening, but haven't found any solutions. If it makes a difference, I used to have WP Super Cache installed, but it's been a few days since I've properly deactivated and deleted the plugin.
Why would this be happening, and how can I stop it (and pull the images directly)?
Thanks!
Enable/Disable Caching in wp-config.php.
Another caching mechanism you could take advantage of is the default WordPress object cache. You can enable or disable the native WordPress object cache using your wp-config.php file, like so.
define('WP_CACHE', true);
Simply add the above code directly above /* That's all, stop editing! Happy blogging. */ using any text editor (Notepad is fine) and save the file.
For me, it was malware that had installed itself onto my site, the docs and cache folder where simple a hideout to execute its malicious code (wordfence flagged all the files). I couldn't delete it through the wp-files plugin, so i did it through ssh using the command
cd /home/bitnami/apps/wordpress/htdocs
sudo rm -f -r docs
Hey guys I have a plugin and its displaying info on /courses.php (using theme)
How can I get it to display info on /courses/single_course.php
I figured I'd just have to make a /courses/ folder in theme and have single_course.php inside that. However this doesn't seem to work.
I've tried googling but I'm struggling to figure out the keywords to solve this problem! ^_^
OK edit cause nobody is understanding:
I have plugin working. This is a custom plugin
I want to know how to make the following work http://www.example.com/plugin/index.php http://www.example.com/plugin/index.php
Currently to make http://www.example.com/plugin work you just need to create plugin.php in the theme directory and give a callback to a function in the plugin.
Creating /wp-content/theme/themename/plugin/index.php did not work as anticipated.
WP uses specific directories for placing its themes and plugins tom maintain organization standards.
// Pointing to theme WP themes directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/themes/"
// Pointing to theme WP plugins directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/"
or you can use the built in functions in wordpress
// for themes in any php file after headers
get_template_directory_uri() . '/js/custom_script.js'
// for plugins in you main plugin class
plugins_url('/js/newscript.js', __FILE__);
I would recommend keeping plugins in plugins and themes in themes. What you may be looking for is creating some extra plugin features which will require you to include you extra php functions and classes when the plugin in question is loaded.
First create a folder in under your plugin directory and chmod it with proper web securities
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
mkdir php
chmod 755
Next either copy or create and edit the new single_courses.php file. I've listed a quick method below if you are creating the new file from scratch. Otherwise just cp it over. In both cases we need to insure proper web access right using chmod.
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
echo -n "/*Extra Plugin Functions*/" > single_courses.php
chmod 644 single_courses.php
Now we need to be sure to include the new file in our main plugin file
/* Main Plugin File :: ./wp-content/plugins/your-plugin/theplugin.php */
...
include_once $_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/you-plugin/php/single_courses.php"
...
Thats the basic way to go about it. Use the same process for hooking theme php files as well. Always make sure when creating directories and files on your server that proper security is put into effect or you open up your web directory and or server to get hacked.
Hope it helps...
You have to give us more information on what plugin you are using and what you are trying to achieve. The solution may be as simple as pasting a Plugin provided shortcode into the post area of the desired page. Alternatively you may have to edit the plugin itself.