Wordpress plugin, do not prepend host in wp_register_script - wordpress

I am pretty new to WP and have a little question about the wp_register_script function,.
I have a dev environment where the url is test.example.com .. right know when i make a plugin and use wordpress wp_register_script to insert the .js and .css files wordpress prepend the host in front of the url ..
Is there a good way to handle this?? without creating a test DB and change the "siteurl" ?

I found a workaround for my issue ..
I could set WP_SITEURL in the we-config.php file (not the best solution)
if(isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == "test.example.com") {
define('WP_SITEURL','http://test.example.com'); // use this if we are testing on test.skala.fm (not localhost)
define('ENVIRONMENT', 'local'); // using localdb
//define('ENVIRONMENT', 'production'); // use this if we are testing on test.example.com (not localhost)
} else {
define('ENVIRONMENT', 'production');
}

Related

How can I integrate wordpress into magento 2 project in valet plus?

I am using Valet+ for my Magento projects.
Currently I’m trying to add WP integration for M2 project. I put wordpress copy into pub/wp/ directory and want to go through the installation process, but I’m receiving 404 error when I’m trying to access url like https://magento2.test/wp/
Could anyone advice for it?
Thank you!
You can use custom valet driver for it.
Copy Magento2ValetDriver.php into magento root directory and rename it to LocalValetDriver.php
Also, change the class name to LocalValetDriver in it.
In the function frontControllerPath, add the following code at the top.
if ($uri === '/wp') {
$_SERVER['DOCUMENT_ROOT'] = $sitePath . '/pub/wp';
return $sitePath . '/pub/wp/index.php';
}

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.

How to run codeigniter(HMVC) inside wordpress folder

Anybody have install codeigniter(HMVC) within wordpress.
I am trying to install codeigniter(HMVC) inside wordpress folder.
my codeigniter is work on Virtual host can it possible to run codeigniter within wordpress setup with codeigniter is work on virtual host.
Any suggestion.
It is very easy. Here is step by step process.
First see the structure.
You can see it is inside wordpress directory. Next Add this in index.php of codeigniter
require_once('../wp-load.php');
And finally to avoid conflict between Wordpress and Codeigntier's site_url function add this file in codeigniter/application/core as MY_url_helper.php
if (!defined('BASEPATH')) exit('No direct script access allowed');
if (!function_exists('ci_site_url')) {
function ci_site_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
if (!function_exists('ci_base_url')) {
function ci_base_url($uri = '')
{
$CI =& get_instance();
return $CI->config->base_url($uri);
}
}
Now when you use site_url() it will refer to wordpress site_url() and
ci_site_url() it will refer to codeigniter's site_url.
And now when you need to access codeigniter try this.
`http://localhost/wordpress/codeigniter/index.php/mycontroller/mymethod`
Hope it is easy to set up and helps.
Codeignetor can run OK in every directory if server allows to install on that directory.
If its not working please confirm the security settings from server.

Wordpress - Get root directory?

How can I get the root directory of my site? I want to use it as the src for <img>.
For example If I install the wordpress on www.mysite.com/blog/, the root is /blog.
But If I install it to www.mysite.com/test/blog, the root is /test/blog.
I tried to use the snippet from this question, but it returns the whole path as seen in FTP. So instead of returning just /blog, it returns /home/public_html/blog which won't work if used as src in image tag.
Any solution? Thanks.
You may use site_url() (eventually with echo) to get absolute path with server name and directory. Also, have a look at wordpress documentation about similar functions & what they provide.
You may have better luck over at the Wordpress Stack Exchange site :)
And this suggestion to use ABSPATH didn't help on that thread? https://stackoverflow.com/a/2356467/413254
site_url() return the path with http, in some cases, it is not allowed if the server turns off url inclusion. You can use the function below to get the root path of wordpress installation folder:
function get_wp_installation()
{
$full_path = getcwd();
$ar = explode("wp-", $full_path);
return $ar[0];
}

Force https on Wordpress multisite

I've got a Wordpress multisite and I'm trying to force https programmatically (better than via .htaccess as htaccess has many rules, set from cache plugin and the multisite itself).
The code I'm using is this one:
if ( FORCE_HTTPS && (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ))
{
//echo("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
header("Location: " . "https://" . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
exit();
}
It's working properly in main site but not in subdmoains, but curiously is I type https://subsite.domain.com it works properly, but if I go with this redirection I see a blank page.
The certificate is working properly and as I sayed, if I type the full adress I see everything ok
What's going wrong or how can I force https?
Thank you
validate your server ssl for errors:
http://www.digicert.com/help/
use this wp plugin:
http://wordpress.org/plugins/force-ssl-everywhere/
ssl on logged in

Resources