コード例 #1
0
ファイル: hooks.php プロジェクト: cumi/pressbooks
// Shortcodes
// -------------------------------------------------------------------------------------------------------------------
remove_filter('the_content', 'wpautop');
add_filter('the_content', 'wpautop', 12);
// execute wpautop after shortcode processing
$_ = \PressBooks\Shortcodes\Footnotes\Footnotes::getInstance();
$_ = \PressBooks\Shortcodes\Generics\Generics::getInstance();
$_ = \PressBooks\Shortcodes\WikiPublisher\Glyphs::getInstance();
// -------------------------------------------------------------------------------------------------------------------
// Upgrade Book Metadata
// -------------------------------------------------------------------------------------------------------------------
if (\PressBooks\Book::isBook()) {
    add_action('init', function () {
        $meta_version = get_option('pressbooks_metadata_version', 0);
        if ($meta_version < \PressBooks\Metadata::$currentVersion) {
            $metadata = new \PressBooks\Metadata();
            $metadata->upgrade($meta_version);
            update_option('pressbooks_metadata_version', \PressBooks\Metadata::$currentVersion);
        }
    }, 1000);
}
// -------------------------------------------------------------------------------------------------------------------
// Upgrade Catalog
// -------------------------------------------------------------------------------------------------------------------
add_action('init', function () {
    $catalog_version = get_site_option('pressbooks_catalog_version', 0);
    if ($catalog_version < \PressBooks\Catalog::$currentVersion) {
        $metadata = new \PressBooks\Catalog();
        $metadata->upgrade($catalog_version);
        update_site_option('pressbooks_catalog_version', \PressBooks\Catalog::$currentVersion);
    }
コード例 #2
0
ファイル: candela-utility.php プロジェクト: BCcampus/candela
function adjust_admin_menu()
{
    global $blog_id;
    $current_user = wp_get_current_user();
    if ($blog_id != 1) {
        remove_menu_page("edit.php?post_type=lti_consumer");
    }
    add_submenu_page('pb_export', 'Export to Thin-CC', 'Thin-CC Export', 'export', 'tools.php?page=candela-thin-export.php');
    // Remove items that non-admins should not see
    if (!(in_array('administrator', $current_user->roles) || is_super_admin())) {
        remove_menu_page('themes.php');
        remove_menu_page('pb_export');
        remove_menu_page('pb_import');
        remove_menu_page('pb_sell');
        remove_submenu_page('options-general.php', 'pb_import');
        remove_menu_page('lti-maps');
        remove_menu_page('edit-comments.php');
    }
    // Remove items for non-admins and non-editors
    if (!(in_array('administrator', $current_user->roles) || in_array('editor', $current_user->roles) || is_super_admin())) {
        $metadata = new \PressBooks\Metadata();
        $meta = $metadata->getMetaPost();
        if (!empty($meta)) {
            $book_info_url = 'post.php?post=' . absint($meta->ID) . '&action=edit';
        } else {
            $book_info_url = 'post-new.php?post_type=metadata';
        }
        remove_menu_page($book_info_url);
        remove_submenu_page('pb_export', 'tools.php?page=candela-thin-export.php');
    }
}
コード例 #3
0
ファイル: pb-admin-laf.php プロジェクト: samsruti/pressbooks
/**
 * Removes some default WordPress Admin Sidebar items and adds our own
 */
function replace_book_admin_menu()
{
    global $menu, $submenu;
    // Modify $menu and $submenu global arrays to do some tasks, such as adding a new separator, moving items from one menu into another, and reordering sub-menu items.
    $menu[13] = $menu[60];
    // Relocate Appearance
    unset($menu[60]);
    $menu[68] = $menu[10];
    // Relocate Media
    unset($menu[10]);
    $menu[69] = $menu[25];
    // Relocate Comments
    unset($menu[25]);
    // Remove items we don't want the user to see.
    remove_submenu_page('index.php', 'my-sites.php');
    remove_submenu_page('options-general.php', 'options-general.php');
    remove_submenu_page('options-general.php', 'options-writing.php');
    remove_submenu_page('options-general.php', 'options-reading.php');
    remove_submenu_page('options-general.php', 'options-discussion.php');
    remove_submenu_page('options-general.php', 'options-media.php');
    remove_submenu_page('options-general.php', 'options-permalink.php');
    remove_menu_page("edit.php?post_type=part");
    remove_menu_page("edit.php");
    remove_menu_page("edit.php?post_type=front-matter");
    remove_menu_page("edit.php?post_type=back-matter");
    remove_menu_page("edit.php?post_type=metadata");
    remove_menu_page("link-manager.php");
    remove_menu_page("edit.php?post_type=page");
    add_theme_page(__('Theme Options', 'pressbooks'), __('Theme Options', 'pressbooks'), 'edit_theme_options', 'pressbooks_theme_options', 'pressbooks_theme_options_display');
    remove_submenu_page("tools.php", "tools.php");
    remove_submenu_page("tools.php", "import.php");
    remove_submenu_page("tools.php", "export.php");
    remove_submenu_page("tools.php", "ms-delete-site.php");
    remove_menu_page("plugins.php");
    remove_submenu_page("edit.php?post_type=chapter", "edit.php?post_type=chapter");
    // Organize
    $page = add_submenu_page('edit.php?post_type=chapter', __('Organize', 'pressbooks'), __('Organize', 'pressbooks'), 'edit_posts', 'pressbooks', __NAMESPACE__ . '\\display_organize');
    add_action('admin_enqueue_scripts', function ($hook) use($page) {
        if ($hook == $page) {
            wp_enqueue_style('pb-organize');
            wp_enqueue_script('jquery-blockui');
            wp_enqueue_script('pb-organize');
            wp_localize_script('pb-organize', 'PB_OrganizeToken', array('orderNonce' => wp_create_nonce('pb-update-book-order'), 'exportNonce' => wp_create_nonce('pb-update-book-export'), 'showTitleNonce' => wp_create_nonce('pb-update-book-show-title'), 'privacyNonce' => wp_create_nonce('pb-update-book-privacy'), 'private' => __('Private', 'pressbooks'), 'published' => __('Published', 'pressbooks'), 'public' => __('Public', 'pressbooks')));
        }
    });
    if (current_user_can('publish_posts')) {
        $add_chapter = $submenu['edit.php?post_type=chapter'][10];
        unset($submenu['edit.php?post_type=chapter'][10]);
        $add_part = $submenu['edit.php?post_type=part'][10];
        $add_front_matter = $submenu['edit.php?post_type=front-matter'][10];
        $add_back_matter = $submenu['edit.php?post_type=back-matter'][10];
        array_push($submenu['edit.php?post_type=chapter'], $add_part, $add_chapter, $add_front_matter, $add_back_matter);
    }
    if (is_super_admin()) {
        // If network administrator, give the option to see chapter, front matter and back matter types.
        $front_matter_types = $submenu['edit.php?post_type=front-matter'][15];
        $back_matter_types = $submenu['edit.php?post_type=back-matter'][15];
        if (isset($submenu['edit.php?post_type=chapter'][15])) {
            $chapter_types = $submenu['edit.php?post_type=chapter'][15];
            unset($submenu['edit.php?post_type=chapter'][15]);
            array_push($submenu['edit.php?post_type=chapter'], $chapter_types, $front_matter_types, $back_matter_types);
        } else {
            array_push($submenu['edit.php?post_type=chapter'], $front_matter_types, $back_matter_types);
        }
    }
    // Book Information
    $metadata = new \PressBooks\Metadata();
    $meta = $metadata->getMetaPost();
    if (!empty($meta)) {
        $book_info_url = 'post.php?post=' . absint($meta->ID) . '&action=edit';
    } else {
        $book_info_url = 'post-new.php?post_type=metadata';
    }
    $page = add_menu_page(__('Book Info', 'pressbooks'), __('Book Info', 'pressbooks'), 'edit_posts', $book_info_url, '', 'dashicons-info', 12);
    add_action('admin_enqueue_scripts', function ($hook) use($page) {
        if ($hook == 'post-new.php' || $hook == 'post.php') {
            if ('metadata' == get_post_type()) {
                wp_enqueue_script('pb-metadata');
                wp_localize_script('pb-metadata', 'PB_BookInfoToken', array('bookInfoMenuId' => preg_replace('|[^a-zA-Z0-9_:.]|', '-', $page)));
            }
        }
    });
    // Export
    $page = add_menu_page(__('Export', 'pressbooks'), __('Export', 'pressbooks'), 'edit_posts', 'pb_export', __NAMESPACE__ . '\\display_export', 'dashicons-migrate', 14);
    add_action('admin_enqueue_scripts', function ($hook) use($page) {
        if ($hook == $page) {
            wp_enqueue_style('pb-export');
            wp_enqueue_script('pb-export');
            wp_localize_script('pb-export', 'PB_ExportToken', array('mobiConfirm' => __('EPUB is required for MOBI export. Would you like to reenable it?', 'pressbooks')));
        }
    });
    // Sell
    add_menu_page(__('Publish', 'pressbooks'), __('Publish', 'pressbooks'), 'edit_posts', 'pb_publish', __NAMESPACE__ . '\\display_publish', 'dashicons-products', 16);
    // Privacy
    add_options_page(__('Privacy Settings', 'pressbooks'), __('Privacy', 'pressbooks'), 'manage_options', 'pb_privacy_settings', __NAMESPACE__ . '\\display_privacy_settings');
    // Export
    add_options_page(__('Export Settings', 'pressbooks'), __('Export', 'pressbooks'), 'manage_options', 'pb_export_settings', __NAMESPACE__ . '\\display_export_settings');
    // Import
    $page = add_management_page(__('Import', 'pressbooks'), __('Import', 'pressbooks'), 'edit_posts', 'pb_import', __NAMESPACE__ . '\\display_import');
    add_action('admin_enqueue_scripts', function ($hook) use($page) {
        if ($hook == $page) {
            wp_enqueue_script('pb-import');
        }
    });
    // Catalog
    add_submenu_page('index.php', __('My Catalog', 'pressbooks'), __('My Catalog', 'pressbooks'), 'read', 'pb_catalog', '\\PressBooks\\Catalog::addMenu');
}