getting error in activation of theme in wordpress - php

I have install a new theme in wordpress after uploading but at the time of activation of the theme , getting the error like this:
Parse error: parse error in C:\wamp\www\wordpress\wp-content\themes\realhomes\framework\meta-box\inspiry-meta-box.php on line 11
Please help me through this:
add_action('admin_init',function(){ : is line 11 in my code.
add_action( 'admin_init', function() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
// Meta Box Plugin
if ( is_plugin_active( 'meta-box/meta-box.php' ) ) {
deactivate_plugins( 'meta-box/meta-box.php' );
add_action( 'admin_notices', function () {
?>
<div class="update-nag notice is-dismissible">
<p><strong><?php _e( 'Meta Box plugin has been deactivated!', 'framework' ); ?></strong></p>
<p><?php _e( 'As now its functionality is embedded with in Real Homes theme.', 'framework' ); ?></p>
<p><em><?php _e( 'So, You should completely remove it from your plugins.', 'framework' ); ?></em></p>
</div>
<?php
} );
}

please check your brackets not over in your last line of code..
please add this in last line });

Related

How do I WooCommerce empty cart message

I've tried editing the empty cart message, but the changes made do not seem to show on the front end.
From the usual text "No products in the cart." to "Oops! Looks like your cart is empty." I've also tried the code provided by numerous other similar questions asked, but none seem to work either.
I tried using the following code in the mini-cart.php file;
<p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'Oops! Looks like your cart is empty.', 'woocommerce' ); ?></p>
and also tried using the following code in the functions.php file;
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
if ( isset( $_GET['empty-cart'] ) ) {
$woocommerce->cart->empty_cart();
}
}
add_action( 'woocommerce_widget_shopping_cart_buttons', 'add_clear_cart_button', 10, 2 );
function add_clear_cart_button() {
?>
<a class="button" href="<?php echo $woocommerce->cart->get_cart_url(); ?>?empty-cart"><?php _e( 'Empty Cart', 'woocommerce' ); ?></a>
<?php
}
add_filter('gettext_woocommerce', 'translate_woocommerce_strings');
function translate_woocommerce_strings($string) {
if ('No products in the cart.' === $string) {
$string = esc_html__('Oops! Looks like your cart is empty.', 'woocommerce');
}
return $string;
}

Custom Wordpress Plugin Not Saving Settings

I'm working on my first custom WP plugin and I'm trying to register a setting using the Settings API. I've followed a number of guides, and I've successfully created an admin menu page with the section and field defined in the plugin, but the single setting (in the code its fbm_lockout_updates) will not save, and no table in the database has been created for it.
EDIT: It is in fact in the options table. I was mistaken about that much. However, my options page still cant seem to update it, so I suppose my callback function is bad?
After trying a dozen things, I'm not sure where I'm going wrong. Here is the relevant code edited for brevity:
/* Create Menu */
add_action( 'admin_menu', 'fbm_config_menu' );
function fbm_config_menu() {
$page_title = 'Sample Plugin';
$menu_title = 'Sample Plugin Config';
$capability = 'manage_options';
$menu_slug = 'fbm_config';
$function = 'fbm_config_page';
add_menu_page(
$page_title,
$menu_title,
$capability,
$menu_slug,
$function
);
}
/* Register Settings and Fields */
function fbm_register_settings() {
register_setting( 'fbm_config', 'fbm_lockout_updates');
add_settings_section(
'fbm_restriction_section',
'Development Restrictions',
'fbm_restriction_callback',
'fbm_config'
);
add_settings_field(
'fbm_lockout_updates_field',
'Lockout Updates',
'fbm_lockout_field_callback',
'fbm_config',
'fbm_restriction_section'
);
}
add_action( 'admin_init', 'fbm_register_settings' );
/* Settings Callbacks */
function fbm_restriction_callback() {
?>
<p><?php esc_html_e( 'Description of Setting Section', 'fbm_config' ); ?></p>
<?php
}
function fbm_lockout_field_callback() {
$setting = get_option('fbm_lockout_updates');
?>
<input type="checkbox" name="fbm_lockout_updates" value="0" <?php checked('1', $setting); ?> >
<?php
}
/* Load Admin Page */
function fbm_config_page(){
if ( isset( $_GET['settings-updated'] ) ) {
add_settings_error( 'fbm_con_messages', 'fbm_con_message', __( 'Settings Saved', 'fbm_config' ), 'updated' );
}
settings_errors( 'fbm_con_messages' );
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form method="post" action="options.php">
<?php
settings_fields( 'fbm_config' );
do_settings_sections( 'fbm_config' );
submit_button( 'Save Settings' );
?>
</form>
<div>
<?php }
?>
In this case register_setting will save your data in wp-options table, take a look into it.
Recommended if you want your setting to be shown in the wordpress api use both admin and api hook
add_action( 'rest_api_init', 'bm_register_settings' );
add_action( 'admin_init', 'fbm_register_settings' );

PHP Class of composer package not found

I am writing a Wordpress plugin to create custom Gutenberg blocks. I am using a composer package called Carbon Fields. But when I try to use the package I am getting an Error:
Fatal error: Uncaught Error: Class 'Carbon_Fields\Block' not found in /my-path/my-plugin/my-plugin.php on line 10.
The strange thing is that I can use the Container and Field classes without problems.
Note
I have just included the basic file structure and code so that you can focus on the important things.
File structure
my-plugin
vendor
htmlburger
core
Block.php
Carbon_Fields.php
Container.php
Field.php
my-plugin.php
Code
my-plugin.php
add_action( 'after_setup_theme', 'carbon_fields_init' );
function carbon_fields_init() {
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
\Carbon_Fields\Carbon_Fields::boot();
}
use \Carbon_Fields\Block;
use \Carbon_Fields\Filed;
Block::make( __( 'Hero Image' ) )
->add_fields( array(
Field::make( 'text', 'heading', __( 'Block Heading' ) ),
) )
->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
?>
<div class="block">
<div class="block__heading">
<h1><?php echo esc_html( $fields['heading'] ); ?></h1>
</div><!-- /.block__heading -->
<?php
} );
Block.php
namespace Carbon_Fields;
class Block extends Container {
public static function make() {
return call_user_func_array( array( 'parent', 'make' ), array_merge( array( 'block' ), func_get_args() ) );
}
}
Finally I got the answer from a portuguese tutorial (https://www.youtube.com/watch?v=bKY-7_wR2n0). I had to wrap the block creation in a function and set that function as a callback for the carbon_fields_register_fields action hook.
use Carbon_Fields\Field;
use Carbon_Fields\Block;
add_action( 'after_setup_theme', 'crb_load' );
function crb_load() {
require_once( 'vendor/autoload.php' );
\Carbon_Fields\Carbon_Fields::boot();
}
add_action( 'carbon_fields_register_fields', 'crb_add_test_block' );
function crb_add_test_block() {
Block::make( __( 'My Shiny Gutenberg Block' ) )
->add_fields( array(
Field::make( 'text', 'heading', __( 'Block Heading' ) ),
Field::make( 'rich_text', 'content', __( 'Block Content' ) ),
) )
->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
?>
<div class="block">
<div class="block__heading">
<h1><?php echo esc_html( $fields['heading'] ); ?></h1>
</div><!-- /.block__heading -->
<div class="block__content">
<?php echo apply_filters( 'the_content', $fields['content'] ); ?>
Reload
</div><!-- /.block__content -->
</div><!-- /.block -->
<?php
} );
}

removing action in wordpress where action has an array with $this

I'm trying to simply replace a message that is added by a plugin called 'sensei' from woothemes.
For that my plan was to remove the action that places the message, and then add an action where i copied the normal function and edited to what i wanted it to be.
However the message was never removed and instead my new message is placed on the page next to the default message.
i used this code in functions.php:
add_action( 'sensei_loop_course_inside_before', 'remove_old_course_message', 15 );
add_action( 'sensei_loop_course_inside_before', 'active_no_course_message_output2', 11 );
function remove_old_course_message(){
global $Sensei_Shortcode_User_Courses;
remove_action( 'sensei_loop_course_inside_before', array( 'Sensei_Shortcode_User_Courses', 'sensei_loop_course_inside_before' ), 10);
remove_action( 'sensei_loop_course_inside_before', array( $Sensei_Shortcode_User_Courses, 'sensei_loop_course_inside_before' ), 10);
}
function active_no_course_message_output2(){
?>
<li class="user-active">
<div class="sensei-message info">
This is the message to be shown:
<?php _e( 'You have no active courses.', 'woothemes-sensei' ); ?>
<a href="www.google.com">
<?php _e( 'Start a Course!', 'woothemes-sensei' ); ?>
</a>
</div>
</li>
<?php
}
(all that changed is that i changed the button in the message to link to google instead of another page, this is so the code is a bit more understandable.)
In the plugin file there is a class named 'sensei shortcode-user-courses' and it contains the code:
if( empty( $active_ids ) ){
add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) );
}

Page not showing after add a function on child theme

I am using Genesis framework and modern-studio-pro as a child theme. I have just copy this code
function genesis_standard_loop() {
//* Use old loop hook structure if not supporting HTML5
if ( ! genesis_html5() ) {
genesis_legacy_loop();
return;
}
if ( have_posts() ) :
do_action( 'genesis_before_while' );
while ( have_posts() ) : the_post();
do_action( 'genesis_before_entry' );
printf( '<article %s>', genesis_attr( 'entry' ) );
do_action( 'genesis_entry_header' );
do_action( 'genesis_before_entry_content' );
printf( '<div %s>', genesis_attr( 'entry-content' ) );
do_action( 'genesis_entry_content' );
echo '</div>';
do_action( 'genesis_after_entry_content' );
do_action( 'genesis_entry_footer' );
echo '</article>';
do_action( 'genesis_after_entry' );
endwhile; //* end of one post
do_action( 'genesis_after_endwhile' );
else : //* if no posts exist
do_action( 'genesis_loop_else' );
endif; //* end loop
}
from Genesis to child theme functions.php. After that my site is showing
Fatal error: Cannot redeclare genesis_standard_loop() (previously declared in /home/u282646374/public_html/wp-content/themes/modern-studio-pro/functions.php:198) in /home/u282646374/public_html/wp-content/themes/genesis/lib/structure/loops.php on line 115
I have delete that code from child theme but site not showing. Please tell me how can i regain my site? This is the link of my page http://andrewspalding.co.uk/
Your problem is that you are redeclaring the function genesis_standard_loop() inside functions.php of your child theme while on the main genesis theme this function is inside lib/structure/loops.php child themes will overwrite the parent theme functions if they are inside the same file that they are in the parent theme, if you want to modify a function from the parent theme you might contemplate the idea of looking for filters or actions.
If you MUST redeclare the function try recreating the same file structure, but remember to add all of the other functions inside that particular file.

Categories