__( '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" />

post_type ); /* Check if the current user has permission to edit the post. */ if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; /* Get the posted data and sanitize it for use as an HTML class. */ $new_meta_value = ( isset( $_POST['algorithmia-post-options'] ) ); echo print_r($new_meta_value, true); /* Get the meta key. */ $meta_key = 'algorithmia_exclude_post'; /* Get the meta value of the custom field key. */ $meta_value = get_post_meta( $post_id, $meta_key, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, $meta_key, $new_meta_value, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $new_meta_value && $new_meta_value != $meta_value ) update_post_meta( $post_id, $meta_key, $new_meta_value ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, $meta_key, $meta_value ); }