hello..
i'm jay, i currently learn how to develop website using wordpress.
i really love wordpress with tons of plugin and theme available out there, i just learn how to write my own custom widget.
my widget is work fine when i include it on my theme function. its show on backend and also on frontend just like another widget.
the only problem i got, when i add/create another widgets, the widgets(all widgets) start act wierd. when i add the widget(s) to widget area it show the options(form) but then option suddently dissapear. when i try to refresh the page (widget.php) on admin area the options on that widget appear normal and i can modify the value on that widget and save it just like normal widget.
this behavior affect the other functionality in my admin area such ass add image thumbnail is wierd(i can add thumbnail image, but image not shows on the thumbnail section on editor page.
and also with the other functionality, for example when i add new post it show on blank page when i hit save, also the same condition for adding category, page, menu, or anything that say add new. even on saving my theme options it direct me to blank page after i hit save.
this is the widget code.
<?php
class chalax_try_widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'chalax_try_widget', // Base ID
__('Chalax try List', 'text_domain'), // Name
array( 'description' => __( 'Widget untuk menampilkan daftar artikel/berita tertentu', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo $args['before_title'].$instance['title1'].$args['after_title'];
echo "string";
echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if (isset($instance['title1'])) {
# code...
$title1=$instance['title1'];
}else{
$title1="jajal";
}
?>
<input id="<?php echo $this->get_field_id( 'title1' ); ?>" name="<?php echo $this->get_field_name( 'title1' ); ?>" value="<?php echo $title1 ;?>">
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title1'] = ( ! empty( $new_instance['title1'] ) ) ? strip_tags( $new_instance['title1'] ) : '';
return $instance;
}
} // class Foo_Widget
?>
and the other widget.
<?php
class chalax_try2_widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
function __construct() {
parent::__construct(
'chalax_try2_widget', // Base ID
__('Chalax try2 List', 'text_domain'), // Name
array( 'description' => __( 'Widget untuk menampilkan daftar artikel/berita tertentu', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
echo $args['before_widget'];
echo $args['before_title'].$instance['title'].$args['after_title'];
echo "string";
echo $args['after_widget'];
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form( $instance ) {
if (isset($instance['title'])) {
# code...
$title=$instance['title'];
}else{
$title="jajal";
}
?>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $title ;?>">
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // class Foo_Widget
?>