A
A
Artem Kirsov2020-04-21 14:39:02
WordPress
Artem Kirsov, 2020-04-21 14:39:02

Error connecting your widget?

When creating your own plugin and connecting it directly to the functions.php file, there is no error and the plugin works correctly.
And when you try to put it in a separate file, it gives the following errors:
5e9edb104b015579052728.png
Plugin file code (/inc/widgets/contacts-widget.php)

class contacts_widget extends WP_Widget {
function __construct() {
  parent::__construct(
  // widget ID
  'contacts_widget',
  // widget name
  __('Вывод контактов', ' custom_widget_domain'),
  // widget description
  array( 'description' => __( 'Вывод номера телефонов и электронной почты', 'custom_widget_domain' ), )
  );
}
public function widget( $args, $instance ) {
  $title = apply_filters( 'widget_title', $instance['title'] );
  echo $args['before_widget'];
  //if title is present
  if ( ! empty( $title ) )
  echo $args['before_title'] . $title . $args['after_title'];
  //output
  $tel1 = fw_option('tel1');
  $tel2 = fw_option('tel2');
  $email = fw_option('email1');

  echo ('<ul><li><a href="tel:'.$tel1.'">'.$tel1.'</a></li>');
  echo ('<li><a href="tel:'.$tel2.'">'.$tel2.'</a></li>');
  echo ('<li><a href="mailto:'.$email.'">'.$email.'</a></li></ul>');
  echo $args['after_widget'];
}
public function form( $instance ) {
  if ( isset( $instance[ 'title' ] ) )
  $title = $instance[ 'title' ];
  else
  $title = __( 'Контакты', 'custom_widget_domain' );
  ?>
  <p>
    <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  </p>
  <?php
}
public function update( $new_instance, $old_instance ) {
  $instance = array();
  $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  return $instance;
}
}
function custom_register_widget() {
  register_widget( 'contacts_widget' );
}
add_action( 'widgets_init', 'custom_register_widget' );

Connection in the functions.php file
require get_stylesheet_directory_uri() . '/inc/widgets/contacts-widget.php';

I'm doing it on a child theme.

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question