Can't get plugin to pull data from file
-
I am working on a plugin that consists of 3 files; the main plugin file, compression_results.php and form.php.
The main file will grab data (using cURL) from one of the other two files, depending on whether there is data in a particular variable or not. The problem is that it currently won’t load the data. I’ve also tried using get_file_contents but it gave me an error saying the file didn’t exist.
I navigated to the url where the file is, and it displayed, so I know it’s there and accessible. I know I can hard-code the contents of the two files into the plugin and be done with it, but I was hoping to make it easier to modify by using three files vs. one.
Any ideas what’s wrong?
<?php /* Plugin Name: CSS Compressor Plugin URI: https://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: The Plugin's Version Number, e.g.: 1.0 Author: Wildfire Marketing Group Author URI: https://URI_Of_The_Plugin_Author License: A "Slug" license name e.g. GPL2 */ function css_compressor() { if (isset($_POST["css"])) { $old_css_size = strlen($_POST["css"]); $css = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $_POST["css"]); $un_comp = array("" , " ", " ", "\r\n", "\n", "\r", "\t", "\\", ";}", "000000", "FFFFFF", "ffffff", "CCCCCC", "cccccc", "999999", "666666", "333333", "0px"); $comp = array("", "", "", "", "", "", "", "", "}", "000", "FFF", "fff", "CCC", "ccc", "999", "666", "333", "0"); $css = strip_tags(str_replace($un_comp, $comp, $css)); $new_css_size = strlen($css); $savings = number_format($old_css_size - $new_css_size); $percent = round((($old_css_size - $new_css_size) / $old_css_size) * 100); $repvar = array('{old_css_size}', '{new_css_size}', '{savings}', '{percent}', '{css}'); $repval = array($old_css_size, $new_css_size, $savings, $percent, $css); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, 'compression-results.php'); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout); $compression_results = curl_exec($ch); curl_close($ch); $compression_results = str_replace($repvar,$repval,$compression_results); echo $compression_results; } else $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, 'form.php'); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout); $form = curl_exec($ch); curl_close($ch); echo $form; } add_shortcode('csscompressor', 'css_compressor'); ?>
- The topic ‘Can't get plugin to pull data from file’ is closed to new replies.