예제 #1
0
 /**
  * Register theme directories, set a filter that hides themes under certain conditions
  */
 function registerThemeDirectories()
 {
     // No trailing slash, otherwise we get a double slash bug
     // @see \PressBooks\Metadata::fixDoubleSlashBug
     register_theme_directory(PB_PLUGIN_DIR . 'themes-root');
     register_theme_directory(PB_PLUGIN_DIR . 'themes-book');
     if (is_admin()) {
         if (Book::isBook()) {
             add_filter('allowed_themes', array($this, 'allowedBookThemes'));
         } else {
             add_filter('allowed_themes', array($this, 'allowedRootThemes'));
         }
     }
 }
예제 #2
0
 /**
  * Register theme directories, set a filter that hides themes under certain conditions
  */
 function registerThemeDirectories()
 {
     // No trailing slash, otherwise we get a double slash bug
     // @see \Pressbooks\Metadata::fixDoubleSlashBug
     register_theme_directory(PB_PLUGIN_DIR . 'themes-root');
     register_theme_directory(PB_PLUGIN_DIR . 'themes-book');
     do_action('pressbooks_register_theme_directory');
     // Check for local themes-root directory
     if (realpath(WP_CONTENT_DIR . '/themes-root')) {
         register_theme_directory(WP_CONTENT_DIR . '/themes-root');
     }
     if (is_admin()) {
         if (Book::isBook()) {
             add_filter('allowed_themes', array($this, 'allowedBookThemes'));
         } elseif (!is_network_admin()) {
             add_filter('allowed_themes', array($this, 'allowedRootThemes'));
         }
     }
 }
예제 #3
0
 /**
  * Put a Part/Chapter/Front Matter/Back Matter in the trash
  *
  * @param int $pid
  *
  * @return bool
  */
 static function deletePost($pid)
 {
     if (false == Book::isBook() || wp_is_post_revision($pid) || 'auto-draft' == get_post_status($pid)) {
         return false;
     }
     /** @var $wpdb \wpdb */
     global $wpdb;
     // remove chapter/part/front matter
     // decrement order of everything with a higher order, and if chapter, only within that part
     $post_to_delete = get_post($pid);
     $order = $post_to_delete->menu_order;
     $type = $post_to_delete->post_type;
     $parent = $post_to_delete->post_parent;
     $query = "UPDATE {$wpdb->posts} SET menu_order = menu_order - 1 WHERE menu_order > {$order} AND post_type = '{$type}' ";
     if ('chapter' == $type) {
         $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET menu_order = menu_order - 1 WHERE menu_order > %d AND post_type = %s AND post_parent = %d ", $order, $type, $parent));
     } else {
         $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET menu_order = menu_order - 1 WHERE menu_order > %d AND post_type = %s ", $order, $type));
     }
     clean_post_cache($post_to_delete);
     if ('part' == $type) {
         // We're setting two things here - the new post_parent (to the first part)
         // And the new menu order for the chapters that were in the part being deleted.
         $new_parent_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'part' AND post_status = 'publish' AND NOT ID = %d ORDER BY menu_order LIMIT 1 ", $pid));
         if ($new_parent_id) {
             $existing_numposts = $wpdb->get_var($wpdb->prepare("SELECT COUNT(1) AS numposts FROM {$wpdb->posts} WHERE post_type = 'chapter' AND post_parent = %d ", $new_parent_id));
             $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d, menu_order = menu_order + %d WHERE post_parent = %d AND post_type = 'chapter' ", $new_parent_id, $existing_numposts, $pid));
         } else {
             $success = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_status = 'trash' WHERE post_parent = %d AND post_type = 'chapter' ", $pid));
         }
         wp_cache_flush();
     }
     static::deleteBookObjectCache();
     return $success ? true : false;
 }