__( 'Add content recomendations to your site.', 'algorithmia_widget_domain' ), ) ); } // Creating widget front-end. public function widget( $args, $instance ) { // We only display on single post pages, not on the homepage, user pages, etc. if ( is_single() == false ) { return false; } $title = apply_filters( 'widget_title', $instance['title'] ); // Before and after widget arguments are defined by themes. echo $args['before_widget']; if ( ! empty( $title ) ) { echo $args['before_title'] . $title . $args['after_title']; } // This is the Algorithmia API key. $api_key = $instance['api_key']; // This is the number of related pages we will request from the API. $post_count = $instance['post_count']; // We need the site name to prevent the display of the site name in the links that the Algorithmia API returns. // Algorithmia API expects this as the content value in the meta tag. We pass this below. $site_name = get_bloginfo('name', 'raw'); $name_no_spaces = str_replace(' ', '', $site_name); if ( ! empty( $api_key ) ) { echo '
'; echo $args['after_widget']; } } // Widget form. public function form( $instance ) { $api_key = ''; if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'widget_title', 'algorithmia_widget_domain' ); } if ( isset($instance['api_key']) ) { $api_key = $instance['api_key']; } if ( !isset($instance['api_key']) ) { $api_key = 'simrVXm+4zoYFbPtJwW783K8V6n1'; } if ( isset($instance['post_count']) ) { $post_count = $instance['post_count']; } if ( !isset($instance['post_count']) ) { $post_count = 10; } // Widget admin form ?>
"; echo $output; } } add_action( 'load-post.php', 'algorithmia_post_meta_boxes_setup' ); add_action( 'load-post-new.php', 'algorithmia_post_meta_boxes_setup' ); /* Create one or more meta boxes to be displayed on the post editor screen. */ function algorithmia_add_post_meta_boxes() { $screens = array( 'post', 'page' ); foreach( $screens as $screen ) { add_meta_box( 'algorithmia-post-options', // Unique ID esc_html__( 'Recommender Options', 'example' ), // Title 'algorithmia_post_options_meta_box', // Callback function $screen, // Admin page (or post type) 'side', // Context 'default' // Priority ); } } /* Display the post meta box. */ function algorithmia_post_options_meta_box( $object, $box ) { ?>
size="30" />