Esempio n. 1
0
 public function create_from_media()
 {
     $response = array();
     $response['success'] = false;
     $response['data'] = array();
     if (!wp_verify_nonce($_POST['_nonce'], 'seoslides-media')) {
         wp_send_json($response);
     }
     // First, get our slideset
     $slideset_id = (int) $_POST['slideset'];
     $slideset = new SEOSlides_Slideset($slideset_id);
     $defaults = $slideset->default_slide();
     // Now get our attachments
     $attachment_ids = $_POST['slides'];
     $attachment_ids = array_map('intval', $attachment_ids);
     // Initial position of new slide
     $position = count($slideset->slides);
     // Iteratively insert new slides
     foreach ($attachment_ids as $attachment_id) {
         $image = wp_get_attachment_image_src($attachment_id, 'full');
         // Create our slide content
         $content = array('title' => $slideset->title . ' - ' . ($position + 1), 'content' => '', 'image' => '', 'bg-image' => $image[0]);
         // Create the slide
         $slide = wp_insert_post(array('post_parent' => $slideset_id, 'post_type' => 'seoslides-slide', 'menu_order' => $position, 'post_status' => 'publish', 'post_content' => serialize($content)));
         if (0 !== $slide && !is_wp_error($slide)) {
             update_post_meta($slide, 'seoslides_fillcolor', '');
             update_post_meta($slide, 'seoslides_oembed', $defaults->oembed);
             // Update SEO
             $seo = array('title' => $defaults->title, 'description' => $defaults->seo_description, 'keywords' => $defaults->seo_keywords);
             update_post_meta($slide, 'seoslides_seo_settings', $seo);
             /** @var SEOSlides_CanvasObject $object */
             foreach ($defaults->objects as $object) {
                 add_post_meta($slide, 'seoslides_canvas_object', $object);
             }
             // Add our slide to the response array
             $response['data'][] = array('id' => $slide);
             // Increment the position for next time
             $position += 1;
         }
     }
     $response['success'] = true;
     wp_send_json($response);
 }
Esempio n. 2
0
 /**
  * Enqueue scripts and styles used on the admin side of the plugin.
  */
 public function admin_enqueue_scripts()
 {
     $current_screen = get_current_screen();
     if ('seoslides-slideset' === $current_screen->post_type) {
         wp_register_style('seoslides-iconography', SEOSLIDES_URL . 'css/seoslides-iconography.css', array(), SEOSLIDES_VERSION);
         wp_enqueue_style('seoslides-iconography');
         if ('post' === $current_screen->base) {
             $admin_deps = array('utils', 'jquery', 'wp-mediaelement', 'wpdialogs');
             wp_enqueue_script('wp-color-picker');
             wp_enqueue_style('wp-color-picker');
             wp_enqueue_style('wp-jquery-ui-dialog');
             wp_enqueue_media();
             // Thickbox for selecting background images
             wp_enqueue_script('media-upload');
             wp_enqueue_style('thickbox');
             $this->enqueue_mediaelement();
             $this->enqueue_script('poly_fill', null);
             $this->enqueue_script('seoslides_admin', $admin_deps, true);
             $slideset = new SEOSlides_Slideset(get_the_ID());
             $js_variables = array('ajaxurl' => admin_url('admin-ajax.php'), 'slideset' => get_the_ID(), 'slideset_data' => $slideset, 'slide_default' => $slideset->default_slide(), 'create_nonce' => wp_create_nonce('seoslides_create'), 'update_nonce' => wp_create_nonce('seoslides_update'), 'delete_nonce' => wp_create_nonce('seoslides_delete'), 'trash_nonce' => wp_create_nonce('seoslides_trash'), 'restore_nonce' => wp_create_nonce('seoslides_restore'), 'media_nonce' => wp_create_nonce('seoslides-media'), 'menu_order_nonce' => wp_create_nonce('seoslides_order'), 'thickbox_noimage' => esc_url(admin_url('images/no.png')), 'thickbox_spinner' => esc_url(admin_url('images/wpspin_light.gif')), 'thickbox_yes' => esc_url(admin_url('images/yes.png')), 'themes' => $this->presentation_theme(get_the_ID()));
             wp_localize_script('seoslides_admin', 'seoslides', $js_variables);
             wp_localize_script('seoslides_admin', 'CKEDITOR_BASEPATH', SEOSLIDES_URL . 'vendor/ckeditor/');
             $this->script_translations('seoslides_admin');
             wp_enqueue_script('ckeditor', SEOSLIDES_URL . 'vendor/ckeditor/ckeditor.js', null, SEOSLIDES_VERSION, true);
         } else {
             $js_variables = array('ajaxurl' => admin_url('admin-ajax.php'));
             $this->enqueue_script('seoslides_list', array('jquery'), true);
             wp_localize_script('seoslides_list', 'seoslides', $js_variables);
             $this->script_translations('seoslides_list');
         }
         wp_enqueue_style('seoslides-admin-slides', SEOSLIDES_URL . '/css/admin-styles-slides.css', array(), SEOSLIDES_VERSION, 'all');
     }
     if ('post' === $current_screen->post_type) {
         wp_enqueue_script('wpdialogs');
         wp_enqueue_style('wp-jquery-ui-dialog');
     }
     wp_enqueue_style('seoslides-bucket', SEOSLIDES_URL . '/js/lib/canvas/css/bucket.css', array(), SEOSLIDES_VERSION, 'all');
     wp_enqueue_style('seoslides-admin', SEOSLIDES_URL . '/css/admin-styles.css', array(), SEOSLIDES_VERSION, 'all');
 }