Getting an error on wordpress theme - php

I'm making a website using wordpress and a custom theme. I tested the website on my computer using XAMP and it worked perfectly. But when I uploaded my code to the web hosting, it gave this error:
ERROR : Parse error: syntax error, unexpected '{' in /home/a5709387/public_html/wp-content/themes/gameaddict/themeOptions/functions.php on line 1
Can anyone help? Here's my code:
<?php
if ( !function_exists( 'optionsframework_init' ) )
{
/*-----------------------------------------------------------------------------------*/
/* Options Framework Theme
/*-----------------------------------------------------------------------------------*/
/* Set the file path based on whether the Options Framework Theme is a parent theme or child theme */
define('OPTIONS_FRAMEWORK_URL', get_template_directory() . '/themeOptions/admin/');
define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/themeOptions/admin/');
require_once (OPTIONS_FRAMEWORK_URL . 'options-framework.php');
}
/*
* This is an example of how to add custom scripts to the options panel.
* This one shows/hides the an option when a checkbox is clicked.
*/
add_action('optionsframework_custom_scripts', 'optionsframework_custom_scripts');
function optionsframework_custom_scripts() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#example_showhidden').click(function() {
jQuery('#section-example_text_hidden').fadeToggle(400);
});
if (jQuery('#example_showhidden:checked').val() !== undefined) {
jQuery('#section-example_text_hidden').show();
}
});
</script>
<?php
}
/*
* Turns off the default options panel from Twenty Eleven
*/
add_action('after_setup_theme','remove_twentyeleven_options', 100);
function remove_twentyeleven_options() {
remove_action( 'admin_menu', 'twentyeleven_theme_options_add_page' );
}
?>

Related

Error in WordPress with plugin reactpress

I'm using WordPress version 5.7.2 and when I upgrade it to php version 7.4.19 I get these errors:
Failed opening 'default' for inclusion (include_path='.:/usr/lib/php7.4') wp-includes/template-loader.php on line 106
Warning: include(default): failed to open stream: No such file or directory in /homepages/1/d229455270/htdocs/clickandbuilds/WordPress/DaseCMS/wp-includes/template-loader.php on line 106
This happens when I activate the plugin reactpress. This is the piece of code where the error occurs:
/**
* Filters the path of the current template before including it.
*
* #since 3.0.0
*
* #param string $template The path of the template to include.
*/
$template = apply_filters( 'template_include', $template );
if ( $template ) {
include $template; //Error in this line
} elseif ( current_user_can( 'switch_themes' ) ) {
$theme = wp_get_theme();
if ( $theme->errors() ) {
wp_die( $theme->errors() );
}
Why is this happening? How can I fix it? I see that is compatible with my WordPress version...
And with my php version...
Thank you in advance
Why is this happening?
Because there's a mistake in the Reactpress_Public::repr_change_page_template() method (see line 99 in wp-content/plugins/reactpress/public/class-reactpress-public.php) which is hooked onto template_include.
The author should check if the value of the _wp_page_template metadata (which stores the path of a custom page template) is not default (which is the default value) and only if so, then should the $template value be set to the metadata value.
And if one doesn't do that check, then we'd end up with include 'default' which then emits the error/warning in question ("Failed opening 'default' for inclusion").
How can I fix it?
Please contact the plugin support and ask them to fix the issue ASAP, but for the time being, you may just change the conditional here to: (* change the entire "if")
if (!empty($meta['_wp_page_template'][0]) && $meta['_wp_page_template'][0] != $template && // wrapped
'default' !== $meta['_wp_page_template'][0] // check if the value is NOT "default"
) {
$template = $meta['_wp_page_template'][0];
}
Yes, you shouldn't modify core plugin files; but this is a special case, because the plugin needs a fix, which hopefully will come in the plugin's next release.
Alternate solution without modifying the plugin files
.. is by overriding the template using the same hook:
// Add to the theme functions.php file:
add_filter( 'template_include', 'my_fix_template_include', 100 );
function my_fix_template_include( $template ) {
if ( 'default' === $template && is_page() ) { // * the plugin uses is_page()
$template = get_page_template();
}
return $template;
}

Redirect doesn't work on a custom plugin wordpress

I'm trying to redirect when a file has been uploaded in media library to crop/resize it.
I'm adding a custom template and try to redirect after the admin add a media to library (admin panel).
But when I upload media I've got an error in wordpress : "An error occurred during upload. Please try again later."
And nothing comes.
My file is uploaded and saved but doesn't show in media library.
I've traveled through many topics but didn't find an answer. Maybe I can't redirect like that in a plugin.
I've got two php file in wp-contents/plugins/myplugin/plugin.php and custom-template.php
<?php
/*
Plugin name: Waouh_pictures
Description:
Version: 1.0
Author: Waouh
*/
require_once("lib/shortpixel-php-req.php");
if(!defined('ABSPATH'))
exit;
class plugin{
public function __construct(){
// Some code here
/* Add cropping template to wordpress */
function page_template( $page_template )
{
if ( is_page( 'cropping-waouh' ) ) {
$page_template = dirname( __FILE__ ) . '/crop_waouh.php';
}
return $page_template;
}
add_filter( 'page_template', 'page_template' );
/* Redirect to cropping-waouh when a file is uploaded */
function redirect_to_crop( $upload ) {
$url = get_site_url() . "/cropping-waouh";
wp_redirect( $url );
exit;
return $upload;
}
add_filter( 'wp_handle_upload', 'redirect_to_crop' );
}
}
new plugin();
?>
And my custom template :
<?php
/* Template Name: Cropping Waouh */
echo 'This is my cropping page :)';
?>
Network console log
Pretty sure I'm doing wrong but I'm new to wordpress and I'm open to any constructive comments.
If you need more informations just ask. Thank you in advance.
It seems like I can't do it that way so the thing I've done was to do it with jQuery.
I'm adding a button on my media library and hide the one who already exists.
jQuery(document).ready(function($){
$("#wp-media-grid > a").after("<form action=\"/wp-content/plugins/waouh_pictures/function.php\"><input type=\"file\" id=\"button_upload_waouh\" name=\"filename\" method=\"POST\"><input type=\"submit\" value=\"Ajouter\"></form>");
$("#wp-media-grid > a").hide();
});
And I can modify the file before uploading it into the server using croppie.
I hope I could help someone with that.

How to create a WordPress plugin that registers a custom sidebar widget

I have the following use case. I have created a custom "search" functionality, all it is an input box that is using some API fetch and jquery magic.
Essentially, I want to add this search function into its own custom sidebar navigation widget via a plugin installation.
I wish to create a plugin that registers a custom "menu" sidebar widget. The sidebar widget will drop this search functionality to were ever the widget is "dragged and dropped". The display is for only the front of the site. You know, how the default search widget works.
Some Facts:
I have created a boiler plated plugin in wp-contents, it had a blank
activate, deactivate and uninstall function within the mail plugin class and I have hooked the activate and deactivate button.
The source code for the "custom search functionality" is within the
same folder as the plugin.
Folder scheme looks like:
MBE PLUGIN
index.php
mbe-plugin.php
api-search.html
assets
css
scripts
ETC
In my plugin.php file, what must I include in the "activation" function to achieve this?
This is my boilerplate plugin code... pretty empty
.
<?php
/**
* #package MBEPlugin
*/
/*
Plugin Name: MBE Plugin
Plugin URI: http://localhost/mbeTest/plugin
Description: This plugin is for the search modal for MBE website. Project 'accordion'
Version: 1.0.0
Author: Erick Guerra
Author URI: http://bashs3c.com
License: GPLv2 or later
Text Domain: mbe-plugin
*/
// Secuirty measure, checks variable in env to ensure we are in WP
if ( ! defined( 'ABSPATH' ) ) {
echo 'These are not the drones you are looking for!';
exit;
}
class MbePlugin {
function activate() {
$searchHTML = file_get_contents(plugins_url('api-search.html', __FILE__));
echo $searchHTML;
// generate a CPT
// Flush the rewrite rules
}
function deactivate() {
// Flush rewrite rules
}
function uninstall() {
// delete CPT
// Delete all the plugin data from DB
}
function displaySearch() {
$searchHTML = file_get_contents(plugins_url('api-search.html', __FILE__));
echo $searchHTML;
}
}
if (class_exists('MbePlugin')) {
$mbePlugin = new MbePlugin();
}
//activation
register_activation_hook( __FILE__, array( $mbePlugin, 'activate' ) );
//deactivation
register_deactivation_hook( __FILE__, array( $mbePlugin, 'deactivate' ) );
//uninstall
//
//add_actions('wp_enqueue_scripts', 'search_init');

Stylesheet is getting removed/deregistered automatically - WordPress

I've put some custom code in my active child theme's functions.php. I'm trying to enqueue some style on a admin page. However, a style enqueued in admin_enqueue_scripts hook gets automatically removed and after debugging I found that its not present in the very next hook i.e. admin_print_styles.
Here's some code in active child theme's functions.php which I used for debugging purposes:
function debug_enqueue_admin_scripts() {
wp_enqueue_style( 'gforms_datepicker_css', GFCommon::get_base_url() . "/css/datepicker{$min}.css", null, GFCommon::$version );
if( wp_style_is( 'gforms_datepicker_css' ) {
// NOTE: This runs and I am able to view the following log
error_log( __FUNCTION__ . ': datepicker_css is enqueued.' );
}
}
add_action( 'admin_enqueue_scripts', 'debug_enqueue_admin_scripts', 11 );
function check_if_still_enqueued() {
if( wp_style_is( 'gforms_datepicker_css', 'registered' ) ) {
error_log( __FUNCTION__ . ' datepicker_css registered.');
} else {
// NOTE: It gets in this else block and following output is logged
error_log( __FUNCTION__ . ' datepicker_css **NOT** registered.');
}
}
add_action( 'admin_print_styles', 'check_if_still_enqueued' );
I'm not deregistering the gforms_datepicker_css anywhere, but its getting removed maybe due to some plugin.
While debugging, I've gone further and inspected if it was deregistered by putting extra line in WordPress core class method WP_Dependencies::remove() located here as following.
public function remove( $handles ) {
// NOTE: Check if deregistered
error_log( __METHOD__ . ' ' . var_export( $handles, true ) );
foreach ( (array) $handles as $handle )
unset($this->registered[$handle]);
}
But I'm unable to see log output with gforms_datepicker_css in it from this method.
I'm unsure why the style is getting removed from enqueue list. Can anybody please help me debugging this behaviour and find the solution?
The scripts and styles were not loading on admin pages because the No-Conflict Mode setting of Gravity Forms plugin was turned ON. As the setting is designed to do so:
As described in Gravity Forms documentation:
To temporarily resolve the issue, go to Forms > Settings and enable No
Conflict mode. This should stop third party scripts from writing to
Gravity Forms administration pages and allow you to do the things you
need.
The issue resolved after turning OFF the No-Conflict Mode.

Trouble with Wordpress and GSAP TweenLite

I'm in the process of creating my first WordPress theme and I'm trying to integrate the TweenLite library but it's not working. I'm not sure where the error lies.
First in my child theme's function.php file I have:
add_action('wp_enqueue_scripts', 'custom_theme_scripts');
function custom_theme_scripts() {
wp_register_script('GSAP', 'http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js', true);
wp_register_script('Animations', get_template_directory_uri() . '/animation.js', true);
}
The first script is the TweenLite and the second is my custom script I'm using test out of it worked or not.
This is my code for my test script:
var logo = document.getElementById("logo");
TweenLite.to(logo, 1.5, { width: 500 });
the wp_register_script is not enough.
You must enqueue it after registering with wp_enqueue_script();
add_action('wp_enqueue_scripts', 'custom_theme_scripts');
function custom_theme_scripts() {
wp_register_script('GSAP','http://cdnjs.cloudflare.com/ajax/libs/gsap/latest/TweenLite.min.js', true);
wp_register_script('Animations', get_template_directory_uri() . '/animation.js', true);
wp_enqueue_script('GSAP');
wp_enqueue_script('Animations');
}

Categories