get_option( '3dhubs_url' ),
), $atts ) );
return '
3D Print';
}
// Function for the shortcode
add_shortcode( '3DHubs', 'insert_3DHubs' );
} // END public function __construct
public static function activate() {}
public static function deactivate() {}
}
}
// ------------------------
// Plugin class ending here
// ------------------------
// --------------------------
// Widget class starting here
// --------------------------
class ThreeDHubsWidget extends WP_Widget {
// This array contains all the form fields
public $widget_form_fields = array(
array( 'title' => 'Title', 'type' => 'text' ),
array( 'title' => 'URL', 'type' => 'text' ),
array( 'title' => 'Free text', 'type' => 'text' )
);
function ThreeDHubsWidget() {
$widget_ops = array( 'classname' => 'ThreeDHubsWidget', 'description' => 'Displays link to 3DHubs.' );
$this->WP_Widget( 'ThreeDHubsWidget', '3DHubs.com Widget', $widget_ops );
}
function form( $instance ) {
foreach( $this->widget_form_fields as $field ) {
echo '
'; echo $field[ 'title' ].': '; echo '
'; } } function update( $new_instance, $old_instance ) { $instance = $old_instance; foreach( $this->widget_form_fields as $field ) { $instance[ $field[ 'title' ] ] = $new_instance[ $field[ 'title' ] ]; } return $instance; } function widget( $args, $instance ) { extract( $args, EXTR_SKIP ); echo $before_widget; $title = apply_filters( 'widget_title', $instance[ 'Title' ] ); if ( !empty( $title )) { echo $before_title . $title . $after_title;; echo '
3D Print';
echo ''.$instance[ "Free text" ].'
'; echo $after_widget; } } } // ------------------------ // Widget class ending here // ------------------------ if( class_exists( 'ThreeDHubsPlugin' )) { // Installation and uninstallation hooks register_activation_hook( __FILE__, array( 'ThreeDHubsPlugin', 'activate' )); register_deactivation_hook( __FILE__, array( 'ThreeDHubsPlugin', 'deactivate' )); // Instantiate the plugin class $ThreeDHubsPlugin = new ThreeDHubsPlugin(); // Add a link to the settings page onto the plugin page if( isset( $ThreeDHubsPlugin )) { // Add the widget and the script for the live update add_action( 'widgets_init', create_function( '', 'return register_widget( "ThreeDHubsWidget" );' ) ); function ThreeDHubsCSS() { wp_enqueue_style('3d-hubs-button', plugins_url( '3dhubs.css' , __FILE__ )); } add_action( 'wp_enqueue_scripts', 'ThreeDHubsCSS' ); // Add the settings link to the plugins page function ThreeDHubsWidget_settings_link( $links ) { $threeDHubs_settings_link = 'Settings'; array_unshift( $links, $ThreeDHubs_settings_link ); return $links; } $plugin = plugin_basename( __FILE__ ); add_filter( "plugin_action_links_$plugin", 'ThreeDHubsWidget_settings_link' ); } }