function __construct($api_token = null, $api_url = null) { $this->api_token = $api_token; $this->api_url = $api_url; $this->options = grape_get_options(); /* user agent */ $this->client = 'Wordpress/' . get_bloginfo('version') . ' Grape/' . GRAPE_VERSION; }
private function import_tags($wp_post_id) { $tags = array(); $options = grape_get_options(); $tag = $this->options['tag']; if (1 == $tag || 3 == $tag) { $post_categories = wp_get_post_categories($wp_post_id); foreach ($post_categories as $c) { $cat = get_category($c); $tags[] = $cat->name; } } if (2 == $tag || 3 == $tag) { $post_tags = wp_get_post_categories($wp_post_id); foreach ($post_tags as $t) { $tag = get_category($t); $tags[] = $tags->name; } } return $tags; }
function grape_display_options() { ?> <?php include_once 'options-head.php'; ?> <div class="wrap grape"> <?php settings_fields('grape'); // settings_errors('grape'); $options = grape_get_options(); ?> <h1><?php _e('Grape Settings', 'grape'); ?> </h1> <form method="post" id="grape" action="options.php"> <h2 class="title"><?php _e('Index Options', 'grape'); ?> </h2> <input type="button" id="button-add" class="button" value="<?php _e('Add', 'grape'); ?> " /> <div id="placeholder-add-post-type"></div> <div id="placeholder-syncables"></div> </form> <script id="template1" type="text/x-handlebars-template"> <ul class="syncable-post-types"> {{#each post_type}} {{#each this}} <li> <span class="post-type">{{this.type_label}}</span><br> <span class="api-url">{{this.api_url}}</span><br> {{#if this.custom_title_field}} <span class="custom-title-field">Custom title field: {{this.custom_title_field}}</span><br> {{/if}} <a href="#" class="delete-syncable" data-syncable-type="post_type" data-type="{{this.type}}" data-id="{{this.index}}">Delete</a> </li> {{/each}} {{/each}} </ul> <ul class="syncable-taxonomies"> {{#each taxonomy}} {{#each this}} <li> <span class="taxonomy">{{this.type}}</span><br> <span class="api-url">{{this.api_url}}</span><br> <span class="custom-url">{{this.custom_url}}</span><br> <a href="#" class="delete-syncable" data-syncable-type="taxonomy" data-type="{{this.type}}" data-id="{{this.index}}">Delete</a> </li> {{/each}} {{/each}} </ul> </script> <script type="text/javascript"> <?php $args = array('public' => true); $post_types = get_post_types($args, 'objects'); $syncable_post_types = $options['syncables']['post_type']; foreach ($syncable_post_types as $type => $connections) { foreach ($connections as $index => $connection) { $syncable_post_types[$type][$index]['index'] = $index; $syncable_post_types[$type][$index]['type_label'] = $post_types[$type]->label; } } $syncable_taxonomies = $options['syncables']['taxonomy']; foreach ($syncable_taxonomies as $type => $connections) { foreach ($connections as $index => $connection) { $syncable_taxonomies[$type][$index]['index'] = $index; } } ?> var syncables = { 'post_type': <?php echo json_encode($syncable_post_types); ?> , 'taxonomy': <?php echo json_encode($syncable_taxonomies); ?> }; </script> <?php do_action('grape_index_options'); ?> <hr> <h2>Tools</h2> <input type="button" name="grape[full_sync]" id="grape-full-sync" value="<?php esc_attr_e('Sync all posts with Grape'); ?> " class="button button-secondary" /> <div class='grape-progress-container hidden'> <span class="grape-loading"><img src="<?php echo grape_plugin_dir_url(); ?> img/loading.gif"></span> <div class='grape-progress-wrap grape-progress' data-progress-percent='0' data-speed='500' style=''> <div class='grape-progress-bar grape-progress'></div> <div class='grape-progress-text'></div> </div> </div> <div class='grape-progress-error hidden'><div> <span class='grape-progress-done hidden'> <?php _e('done'); ?> <span class="dashicons dashicons-yes"></span> </span> <?php do_action('grape_tools'); ?> <?php if (GRAPE_DEBUG) { ?> <hr> <h2>Options (raw)</h2> <pre> <?php print_r($options); ?> </pre> <?php } ?> </div> <div style="display:none" id="div-add-post-type" class="div-add-post-type"> <h2><?php _e('Add', 'grape'); ?> </h2> <form class="syncable_type"> <label for="syncable_type"> <?php _e('Type (required)', 'grape'); ?> </label> <select name="syncable_type"> <option value="post_type"> <?php _e('Post type', 'grape'); ?> </option> <option value="taxonomy"> <?php _e('Taxonomy', 'grape'); ?> </option> </select> </form> <form class="post_type"> <input name="syncable_type" type="hidden" value="post_type"> <?php $args = array('public' => true); $post_types = get_post_types($args, 'objects'); ?> <label for="type"> <?php _e('Post type (required)', 'grape'); ?> </label> <select name="type"> <?php foreach ($post_types as $post_type) { ?> <option value="<?php echo $post_type->name; ?> "> <?php echo $post_type->labels->name; ?> <?php if (!post_type_supports($post_type->name, 'title')) { ?> <span class="grape-warning"><?php _e('Warning: These posts have no title'); ?> </span> <?php } ?> </option> <?php } ?> </select> <input name="action" type="hidden" value="grape_add_syncable"> <label for="api_url"><?php _e('API URL (required)', 'grape'); ?> </label> <input name="api_url" type="text" class="regular-text" required="required"> <label for="api_token"><?php _e('API Token (required)', 'grape'); ?> </label> <input name="api_token" type="text" class="regular-text" required="required"> <label for="custom_title_field">Custom title field name (leave empty for default)</label> <input name="custom_title_field" type="text"> <br> <input type="submit" name="add" value="<?php _e('Add', 'grape'); ?> " class="button button-primary button-add" /> </form> <form class="taxonomy"> <input name="syncable_type" type="hidden" value="taxonomy"> <?php $args = array(); $taxonomies = get_taxonomies($args, 'objects'); ?> <label for="type"> <?php _e('Taxonomy type (required)', 'grape'); ?> </label> <select name="type"> <?php foreach ($taxonomies as $taxonomy) { ?> <option value="<?php echo $taxonomy->name; ?> "> <?php echo $taxonomy->labels->name; ?> </option> <?php } ?> </select> <input name="action" type="hidden" value="grape_add_syncable"> <label for="api_url"><?php _e('API URL (required)', 'grape'); ?> </label> <input name="api_url" type="text" class="regular-text" required="required"> <label for="api_token"><?php _e('API Token (required)', 'grape'); ?> </label> <input name="api_token" type="text" class="regular-text" required="required"> <label for="custom_url"><?php _e('Custom URL (required)', 'grape'); ?> </label> <span class="descripton">Example: <tt><?php echo get_site_url(); ?> /my/taxonomy/$title</tt>. <tt>$title</tt> will be replaced by the taxonomy title</span> <input name="custom_url" type="text" required="required"> <br> <input type="submit" name="add" value="<?php _e('Add', 'grape'); ?> " class="button button-primary button-add" /> </form> </div> <?php }