This may be a dumb question. I am getting an unexpected T_ERROR for the following code in my WordPress Functions.php file. This happens often and I review the code several times seeing no problems... So I've decided to ask someone why.
Thank you.
<?php
/*
**Remove WordPress 'w'
*/
function annointed_admin_bar_remove() {
global $wp_admin_bar;
/* Remove their stuff */
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove', 0);
/*
** Remove WordPress Dashboard Widgets
*/
function remove_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}
add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
?>
Related
I have been developing a website in wordpress and when i am fetching the functgions...the dbppwl_script() it response wbut when im trying to ru the after theme functgion it shows an syntax error related to the fucntion after_theme
<?php
// theme function code
function dbpplwp_theme_setup(){
add_theme_support('custom-logo');
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_image_size('home-featured', 680, 400, array('center','center'));
add_theme_size('single-img', 600, 550, array('center','center'));
add_thehe_support('automatic-feed-links');
register_nav_menus( array(
'primary' => _('Primary Menu','dbpplwp')
));
}
add_action('after_setup_theme', 'dbpplwp_theme_setup' )
function dbpplwp_scripts(){
wp_enqueue_style('style',get_stylesheet_uri() );
};
add_action('wp_enqueue_scripts','dbpplwp_scripts');
?>
Can anybody tell what kind of error is recurring here
You missed ; Each statement must ends up with a semicolon in PHP.
missed here : add_action('after_setup_theme', 'dbpplwp_theme_setup' )
to
add_action('after_setup_theme', 'dbpplwp_theme_setup' );
am getting the following syntax error, unexpected 'public' (T_PUBLIC), expecting end of file when running this code from Microsoft PHP Graph Tutorial.
(https://learn.microsoft.com/en-us/graph/tutorials/php?tutorial-step=1)
public function loadViewData(){
$viewData = [];
// Check for flash errors
if (session('error')) {
$viewData['error'] = session('error');
$viewData['errorDetail'] = session('errorDetail');
}
// Check for logged on user
if (session('userName')) {
$viewData['userName'] = session('userName');
$viewData['userEmail'] = session('userEmail');
$viewData['userTimeZone'] = session('userTimeZone');
}
return $viewData;
}
( I am relatively inexperienced php person, trying to learn laravel and link to Microsoft Graph. There are many tutorials for linking to Microsoft but none of them work as far as I can see, most are out of date. This was my best hope.
Code not working: note line below is one causing problem. If remove 'public;' then no errors are reported in VSCode
i.e. Note in VSCode it reports no errors in the file if public is removed. As soon as you add it back in you get '
As per the the code is correct but you need to check the class of curly brackets properly close or not .
1 ) when you are using the class and no closing curly brackets properly that time it's given error like unexpected 'public' (T_PUBLIC), expecting end of file .
class yourController extends Controller {
public function loadViewData(){
$viewData = [];
// Check for flash errors
if (session('error')) {
$viewData['error'] = session('error');
$viewData['errorDetail'] = session('errorDetail');
}
// Check for logged on user
if (session('userName')) {
$viewData['userName'] = session('userName');
$viewData['userEmail'] = session('userEmail');
$viewData['userTimeZone'] = session('userTimeZone');
}
return $viewData;
}
}
This question already has answers here:
The plugin generated X characters of unexpected output during activation (WordPress)
(25 answers)
Closed 4 years ago.
I am trying to develop a plugin. When I activate the plugin it's showing me following error message:
The plugin generated 2651 characters of unexpected output during
activation. If you notice “headers already sent” messages, problems
with syndication feeds or other issues, try deactivating or removing
this plugin.
I can not understand why it's showing this error. I can see there is no white space to show this error!
Here is my code:
<?php
/*
Plugin Name: Forum Roles
Plugin URI: http://www.creativeartbd.com
Description: Generate a google map
Version: 1.0
Author: Shibbir
Author URI: http://creativeartbd.com/bio/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: gmape
Domain Path: /languages/
*/
// custom forum roles and capabilites class
class BOJ_Forum_Roles {
function __construct() {
// register plugin activation hook
register_activation_hook( __FILE__, 'activation' );
// register plgin deactivation hook
register_deactivation_hook( __FILE__, 'deactivation' );
}
// plugin activation method
function activation () {
// get the default administrator tole
$role =& get_role('administrator');
// add forum capabilities to the administrator role
if( !empty($role) ) {
$role->add_cap('publish_forum_topics');
$role->add_cap('edit_others_forum_topics');
$role->add_cap('delete_forum_topics');
$role->add_cap('read_forum_topics');
}
// create the forum administator tole
add_role( 'forum_administrator', 'Forum Administrator', array(
'publish_forum_topics', 'edit_others_forum_topics', 'delete_forum_topics', 'read_forum_topics'
) );
// create the moderator role
add_role('forum_moderator', 'Forum Moderator', array(
'publish_forum_topics', 'edit_others_forum_topics','read_forum_topics'
));
// create the forum member role
add_role('forum_member', 'Forum Member', array(
'publish_forum_topics', 'read_forum_topics'
));
// create the forum suspended role
add_role( 'forum_suspended', 'Forum Suspeded', array(
'read_forum_topics'
) );
}
// plugin deactivation method
function deactivation () {
// get the default administrator role
$role =& get_role('administrator');
//remove forum capabilites to the administrator role
if(!empty($role)) {
$role->remove_cap('publish_forum_topics');
$role->remove_cap('edit_others_forum_topics');
$role->remove_cap('delete_forum_topics');
$role->remove_cap('read_forum_topics');
}
// set up an array of roles to delete
$roles_to_delete = array(
'forum_administrator',
'forum_moderator',
'forum_member',
'forum_suspended'
);
// loop through each role, deleting the role if necessary
foreach ($roles_to_delete as $role) {
// get the users of the role
$users = get_users(array(
'role' => $role
));
// check if there are no users for the role
if( count($users) <= 0 ) {
//remove the role from the site
remove_role( $role );
}
}
}
}
$forum_roles = new BOJ_Forum_Roles();
Can you tell me how can I solve it?
For this error
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'activation' not found or invalid function name ..
You'll wan't to call the method of your object (class). To do that you can pass an array to the callback, the first element is the class name (in static calls) or an instance of the object, the second element is the method name such as:
class BOJ_Forum_Roles {
public function __construct() {
register_activation_hook( __FILE__, [$this,'activation'] );
register_deactivation_hook( __FILE__, [$this,'deactivation'] );
}
public function activation(){...}
public function deactivation(){...}
}
In core PHP call_user_func_array() is called like this
call_user_func_array([$this,'activation'], $args);
http://php.net/manual/en/function.call-user-func-array.php
It's possible output from this error is giving you the original error you were seeing.
Static Calls
Just for completeness if you had
public static function activation(){...}
You would call it this way (static)
class BOJ_Forum_Roles {
public function __construct() {
register_activation_hook( __FILE__, [__CLASS__,'activation'] );
register_deactivation_hook( __FILE__, [__CLASS__,'deactivation'] );
}
public static function activation(){...}
public static function deactivation(){...}
}
Using the __CLASS__ constant is preferable to putting in the class name, in PHP5.5+ you can also do it this way self::class, although I believe the constant is a bit faster. I think the same holds true for static::class which would be late static binding. And of course you can always do this (in 5.5+) BOJ_Forum_Roles::class which in this example makes little sense, but it can be useful with namespaces.
UPDATE
showing...Notice: Only variables should be assigned by reference in
$role =& get_role('administrator');
Remove the Amp, as you are assigning the results of a function by reference. I am not certain, but if it's an object it's passed by reference anyway. It dosn't matter because you probably shouldn't be modifying it in your function and in fact this just caught my attention (in deactivation):
$role =& get_role('administrator');
...
foreach ($roles_to_delete as $role) {
...
}
You are re-assigning the $role variable in the loop. This may or may not cause issues (I can't tell for sure without testing it), but overwriting it is probably a simple over site on your part. It's generally bad practice to overwrite a variable this way (as the assignment of a loop) if it's been previously declared as often this would not be an intentional thing.
Cheers!
I'm new to this forum so not so sure if I'm posting in the right place or about the full rules and regulations of the forum system, so if I've got something wrong please redirect me and let me know.
Basically, I'm receiving a parse error when trying to go onto our website - I had tried restoring my website from an old backup and now it's giving me this error:
Parse error: syntax error, unexpected 'exit' (T_EXIT) in /home/cdchk/domains/dev.cdchk.org/public_html/wp-content/plugins/woocommerce-catalog/include/php/settings.php on line 1
I tried looking into this file (settings.php under the WooCommerce Catalog Plugin files), but am lost as to what the error is. I will post the first section of the code below. Let me know if there's an issue. Thanks.
<?php
if (!defined('ABSPATH')) exit;
class Woo_Catalog_Settings
{
private $dir;
private $file;
private $assets_dir;
private $assets_url;
private $settings_base;
private $settings;
public
function __construct($file)
{
$this->file = $file;
$this->dir = dirname($this->file);
$this->assets_dir = trailingslashit($this->dir) . 'include';
$this->assets_url = esc_url(trailingslashit(plugins_url('/include/', $this->file)));
$this->settings_base = 'woo_Catalog_';
// Initialise settings
add_action('admin_init', array(
$this,
'init'
));
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' );
}
?>