'mastodon_widget', 'description' => __( 'Display a profile timeline', 'fediembedi' ), 'customize_selective_refresh' => true, ); parent::__construct( 'mastodon', _x( 'Mastodon', 'fediembedi' ), $widget_ops ); } /** * Outputs the content for the current Mastodon widget instance. * * @since 2.8.0 * * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance Settings for the current Mastodon widget instance. */ public function widget( $args, $instance ) { $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; //fedi instance $fedi_instance = get_option('fediembedi-mastodon-instance'); $access_token = get_option('fediembedi-mastodon-token'); $client = new \FediClient($fedi_instance, $access_token); $cred = $client->verify_credentials($access_token); //widget options $show_header = (!empty($instance['show_header'])) ? $instance['show_header'] : ''; $only_media = (!empty($instance['only_media'])) ? $instance['only_media'] : ''; $pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : ''; $exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : ''; $exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : ''; $limit = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : '100%'; echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; }; //getStatus from remote instance $status = $client->getStatus($only_media, $pinned, $exclude_replies, null, null, null, $limit, $exclude_reblogs); //if(WP_DEBUG_DISPLAY === true): echo '
Mastodon
'; var_dump($status); echo '
'; endif; $account = $status[0]->account; include(plugin_dir_path(__FILE__) . 'templates/mastodon.tpl.php' ); echo $args['after_widget']; } /** * Outputs the settings form for the Mastodon widget. * * @since 2.8.0 * * @param array $instance Current settings. */ public function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => '') ); //Radio inputs : https://wordpress.stackexchange.com/a/276659/87622 $show_header = (!empty( $instance['show_header'])) ? $instance['show_header'] : NULL; $only_media = (!empty( $instance['only_media'])) ? $instance['only_media'] : NULL; $pinned = (!empty($instance['pinned'])) ? $instance['pinned'] : NULL; $exclude_replies = (!empty($instance['exclude_replies'])) ? $instance['exclude_replies'] : NULL; $exclude_reblogs = (!empty($instance['exclude_reblogs'])) ? $instance['exclude_reblogs'] : NULL; $limit = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5; $height = isset( $instance['height'] ) ? esc_attr( $instance['height'] ) : ''; ?>

'' ) ); $instance['title'] = sanitize_text_field( $new_instance['title'] ); $instance['show_header'] = $new_instance['show_header']; $instance['only_media'] = $new_instance['only_media']; $instance['pinned'] = $new_instance['pinned']; $instance['exclude_replies'] = $new_instance['exclude_replies']; $instance['exclude_reblogs'] = $new_instance['exclude_reblogs']; $instance['number'] = (int) $new_instance['number']; $instance['height'] = sanitize_text_field( $new_instance['height'] ); return $instance; } }