how to Include json manifest file in wordpress theme - wordpress

I want to build a pwa from my wordpress site and I don't want to use any plugin to do so how do I add a manifest.json file to my wordpress site please?

Open your function file from your theme directory and add the following code
//manifest file
add_action( 'wp_head', 'inc_manifest_link' );
// Creates the link tag
function inc_manifest_link() {
echo '<link rel="manifest" href="'.get_template_directory_uri().'/manifest.json">';
}

Related

HTTPS Issue With Mixed Content - ARForms Plugin

I have a site wordpress in HTTPS, but also i have an Mixed Content because of ARForms Plugin. PHP 5.6
fonts.googleapis.com and some images in this plugin unsecure, and that files i cant find in database anf template files, please help me by PHP.
Thank you.
This is what i found in configuration and this functional not work:
$arfsiteurl = home_url();
if (is_ssl() and ( !preg_match('/^https:\/\/.*\..*$/', $arfsiteurl) or ! preg_match('/^https:\/\/.*\..*$/', WP_PLUGIN_URL))) {
$arfsiteurl = str_replace('http://', 'https://', $arfsiteurl);
define('ARFURL', str_replace('http://', 'https://', WP_PLUGIN_URL . '/arforms'));
} else {
define('ARFURL', WP_PLUGIN_URL . '/arforms');
}
You should try to download these scripts locally and enqueue them with your HTTPS secure server.
As for the plugin scripts, you could also try to install this plugin and click the flush rewrite rules for it to automatically add code into your .htaccess file.

Using WordPress outside of WordPress (wp-load.php): "Cannot modify header information - headers already sent"

I'm trying to use PHP Unit to test an API class that I've written to work with an addon for the WordPress plugin Gravity Forms. The class is dependent on several functions from WordPress such as wp_remote_request().
In order to have access to these WordPress dependencies, I'm trying to require wp-load.php in my PHP Unit test class using:
define( 'WP_USE_THEMES', false );
require '../../../wp-load.php';
However, when I try this, I get the following output in my terminal upon running phpunit:
Cannot modify header information - headers already sent by (output started at phar:///usr/local/Cellar/phpunit/6.4.2/libexec/phpunit-6.4.2.phar/phpunit/Util/Printer.php:112)
../wp-includes/functions.php:3760
../wp-includes/load.php:422
../wp-settings.php:110
../wp-config.php:228
../wp-load.php:37
../wp-content/plugins/gravity-dpo/tests/TestCaseAddon.php:37
Looking at the wp-includes/functions.php file, I can see the following class at line 3760 within the function dead_db(), which is what causes the error:
header( 'Content-Type: text/html; charset=utf-8' );
Surely it should be trivial to require wp-load.php so I can test a class with some WordPress dependencies using PHP Unit? I would appreciate any pointers as to what I'm doing wrong here. I'm trying to avoid having to create a fully fledged WordPress unit testing set up because I just want to test one or two functions from my API class.
On occasion you may want to test some functionality without actually creating a plugin/add on to do so. Create a test.php file with the following code snippet and place it in your WordPress root directory:
<?php
// Load the WordPress Environment
// define( 'WP_DEBUG', true ); /* uncomment for debug mode */
require(./wp-load.php);
// require_once (./wp-admin/admin.php); /* uncomment for is_admin() */
?>
<pre>
<?php
/* test stuff here */
var_dump( is_admin() );
?>
</pre>
This is a quick way to load all of the required WordPress functions to test plugin functionality without actually creating a plugin. As you can see wp-load.php is included at the beginning of the file. You can also include wp-admin/admin.php if you want to test admin side functionality.
Once you have included the required WordPress core files, you want test any code that would otherwise exist reside in your plugin. Don’t forget to remove your test.php file when you are done testing.

Unable to access analytics.txt once uploaded, returns 404

I've been asked to add an analytics.txt file to a wordpress website so I've created the file and uploaded it to the server document root but when I go to it via the url www.examples.com/analytics.txt all I get is a 404 error.
I've checked the file permissions and I've cleared the wordpress cache but neither have helped.
Any ideas?
The folder structure is as follows:
wp-admin
wp-content
wp-includes
analytics.txt <-- added this file, but cannot seem to access it via a web browser
index.php
etc...
This is NOT the solution but it is a work-around while I carry on trying to figure out why wordpress won't allow me to access my file.
So if you're desperate and HAVE to get it sorted right now, here is what you could do, but I warn you, it's ugly! Open your index.php file and you should see something like this:
<?php
define('WP_USE_THEMES', true);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
?>
Make a backup copy first and then add the wrapping if statement:
<?php
if ($_SERVER[REQUEST_URI] == '/analytics.txt') {
die('Put the text that you were instructed to put into your analytics.txt file in here');
} else {
define('WP_USE_THEMES', true);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
}
?>
Like I said, this is a dirty solution but when needs must and the client is getting impatient, this could help in the mean time.
Hoping that someone will have a better solution though!
I was able to get this to work with the following for the Sage theme:
Upload the analytics.txt through the theme administration panel
Copy the url of the upload and remove the hostname. For me it looked like this: app/uploads/2018/09/analytics.txt
Open the functions.php file and add the following:
function analytics_txt_rewrite(){
add_rewrite_rule('^analytics\.txt$','<route to your analytics.txt file>','top');
}
add_action('init','analytics_txt_rewrite');
Flush and regenerate the rewrite rules database: From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.

How to require a file in Wordpress plugin folder?

I have Stripe plugin installed at wp-content/plugins/stripe/. I have a page named "Payment.php" in theme/fifthteen/Payment.php. Now I want to include the file wp-content/plugins/stripe/Stripe.php in my Payment.php. How can I do that?
Use
plugins_url( $path, $plugin );
$path will hold path of the file in your plugin
$path = 'stripe.php';
$plugin holds the name of your plugin
$plugin='stripe' ;
include plugins_url($path,$plugin) ;

Including header and footer to a custom location

Is it possible to include a wordpress header into a php file which is located in folder e.g.: wp-content/uploads/custom.php ?
You can make use of this documentation: Integrating WordPress with your website
In your case, you can create the file content.php and add this code, I just tried this on my website and it worked:
<?php
$path = $_SERVER['DOCUMENT_ROOT']; // Gets the root directory URL
$path .= '/domain_dir'; // Appends your WordPress installation URL
require( dirname($path) . '/wp-blog-header.php'); // Require this to execute get_header();
get_header(); // Executes header.php
?>

Resources