| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- <?php
- /**
- * Theme Functions - functions.php
- *
- * 1. Scripts needed to run the vue theme
- */
-
- // Load WP stuff as needed
- // https://www.smashingmagazine.com/2018/10/headless-wordpress-decoupled/#improving-performance-decoupled-json-approach
- define( 'SHORTINIT', true );
- // $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
- // require_once( $parse_uri[0] . 'wp-load.php' );
-
- $path = $_SERVER['DOCUMENT_ROOT'];
-
- require_once $path . '/wp-load.php';
- require_once $path . '/wp-config.php';
- require_once $path . '/wp-includes/wp-db.php';
- require_once $path . '/wp-includes/pluggable.php';
-
- // https://github.com/EvanAgee/vuejs-wordpress-theme-starter/blob/master/functions.php
- remove_action( 'template_redirect', 'redirect_canonical' );
- function remove_redirects() {
- add_rewrite_rule( '^/(.+)/?', 'index.php', 'top' );
- }
- add_action( 'init', 'remove_redirects' );
-
-
- function vue_theme_routes() {
- $routes = array();
-
- $query = new WP_Query( array(
- 'post_type' => 'any',
- 'post_status' => 'publish',
- 'posts_per_page' => -1
- ) );
- if( $query->have_posts() ) {
- while( $query->have_posts() ) {
- $query->the_post();
- $routes[] = array(
- 'id' => get_the_ID(),
- 'type' => get_post_type(),
- 'slug' => basename( get_permalink() ),
- );
- }
- }
- wp_reset_postdata();
-
- return $routes;
- }
-
- /* 1 */
- function vue_theme_scripts() {
-
- wp_enqueue_style( 'style', get_stylesheet_uri() );
-
- if ( defined( 'IS_DEV' ) && IS_DEV === 'true') {
- wp_register_script(
- 'vue-theme',
- 'http://localhost:8081/build/main.js',
- array( 'jquery' ),
- false,
- true
- );
- } else {
- wp_register_script(
- 'vue-theme',
- get_template_directory_uri() . '/build/main.js',
- array( 'jquery' ),
- false,
- true
- );
- }
-
- wp_localize_script( 'vue-theme', 'wp', array(
- 'template' => get_stylesheet_directory_uri(),
- 'rest' => esc_url_raw( rest_url() ),
- 'site_name' => get_bloginfo( 'name' ),
- // 'nonce' => wp_create_nonce( 'wp_rest' ),
- 'routes' => vue_theme_routes(),
- ) );
-
- wp_enqueue_script( 'vue-theme' );
- }
- add_action( 'wp_enqueue_scripts', 'vue_theme_scripts' );
-
- /**
- * disable endpoints in rest api
- **/
- add_filter( 'rest_endpoints', function ( $endpoints ) {
- $remove = [
- 'users',
- 'users/(?P<id>[\d]+)',
- 'comments',
- 'comments/(?P<id>[\d]+)',
- 'settings',
- ];
- foreach( $remove as $endpoint )
- if ( isset( $endpoints['/wp/v2/' . $endpoint] ) )
- unset( $endpoints['/wp/v2/' . $endpoint] );
- return $endpoints;
- } );
-
- // Remove wordpress version number from files
- remove_action( 'wp_head', 'wp_generator' );
-
- // Disable XML-RPC
- add_filter('xmlrpc_enabled', '__return_false');
-
- // Disable WLManifest
- remove_action( 'wp_head', 'wlwmanifest_link' ) ;
-
- // Disable self ping
- function disable_pingback( &$links ) {
- foreach ( $links as $l => $link )
- if ( 0 === strpos( $link, get_option( 'home' ) ) )
- unset($links[$l]);
- }
- add_action( 'pre_ping', 'disable_pingback' );
-
- // Disable RSD (used with self ping and XML-RPC)
- remove_action( 'wp_head', 'rsd_link' ) ;
-
- // Disable post embed
- function disable_embed() { wp_dequeue_script( 'wp-embed' ); }
- add_action( 'wp_footer', 'disable_embed' );
-
- // Disable Shortlinking
- remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
-
- // Remove versions from static assets (prevents cache-ing)
- function remove_cssjs_ver( $src ) {
- if( strpos( $src, '?ver=' ) )
- $src = remove_query_arg( 'ver', $src );
- return $src;
- }
- // !:Possible Bug HERE
- add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
- add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );
-
- // Do NOT include jquery
- function no_default_jquery( ) {
- if (!is_admin()) {
- wp_deregister_script('jquery');
- wp_register_script('jquery', false);
- }
- }
- add_action( 'init', 'no_default_jquery' );
- // REMOVE emoji support
- remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
- remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
- remove_action( 'wp_print_styles', 'print_emoji_styles' );
- remove_action( 'admin_print_styles', 'print_emoji_styles' );
-
- // REMOVE block CSS
- function webapptiv_remove_block_library_css() {
- wp_dequeue_style( 'wp-block-library' );
- }
- // add_action( 'wp_enqueue_scripts', 'webapptiv_remove_block_library_css' );
-
- // header( 'Access-Control-Allow-Origin: http://localhost:8080' );
- header( 'Content-Type: application/json' );
-
- // Add featured image support
- function craft_post_thumbnails() { add_theme_support( 'post-thumbnails' ); }
- add_action( 'after_setup_theme', 'craft_post_thumbnails' );
-
- // Gutenberg custom stylesheet for editor
- add_theme_support('editor-styles');
- add_editor_style( 'editor-style.css' );
-
- // Custom Dashboard Menu Order
- function custom_menu_order($menu_ord) {
- if (!$menu_ord) return true;
- return array(
- 'index.php', // this represents the dashboard link
- 'upload.php', // this is the MEDIA library
- 'edit.php', // default POST
- 'edit.php?post_type=artist',
- 'edit.php?post_type=exhibition',
- 'edit.php?post_type=event',
- 'edit.php?post_type=episode',
- 'edit.php?post_type=short',
- 'edit.php?post_type=technique',
- 'edit.php?post_type=guide',
- 'edit.php?post_type=object',
- 'edit.php?post_type=publication',
- 'edit.php?post_type=page', // PAGES
- );
- }
- add_filter('custom_menu_order', 'custom_menu_order');
- add_filter('menu_order', 'custom_menu_order');
-
- /*
- * Remove COMMENTS in its entirety
- */
- // Removes COMMENTS from admin menu
- add_action( 'admin_menu', 'remove_admin_menus' );
- function remove_admin_menus() {
- remove_menu_page( 'edit-comments.php' );
- }
- // Removes COMMENTS from post and pages
- add_action('init', 'remove_comment_support', 100);
- function remove_comment_support() {
- remove_post_type_support( 'post', 'comments' );
- remove_post_type_support( 'page', 'comments' );
- }
- // Removes COMMENTS from admin bar
- add_action( 'wp_before_admin_bar_render', 'remove_comments_admin_bar' );
- function remove_comments_admin_bar() {
- global $wp_admin_bar;
- $wp_admin_bar->remove_menu('comments');
- }
-
- /*
- * ADMIN CUSTOM COLUMNS
- */
- // Add the custom columns for ARTIST:
- add_filter( 'manage_artist_posts_columns', 'set_custom_edit_artist_columns' );
- function set_custom_edit_artist_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['artist_type'] = __('Artist Type' );
- $columns['material'] = __('Material' );
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for ARTIST:
- add_action( 'manage_artist_posts_custom_column' , 'custom_artist_column', 10, 2 );
- function custom_artist_column( $column, $post_id ) {
- switch ( $column ) {
- // display a list of artist_type terms assigned to the post
- case 'artist_type' :
- $terms = get_the_term_list( $post_id , 'artist_type' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- // display a list of material terms assigned to the post
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for EVENT:
- add_filter( 'manage_event_posts_columns', 'set_custom_edit_event_columns' );
- function set_custom_edit_event_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['event_type'] = __('Event Type' );
- $columns['material'] = __('Material' );
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for EVENT:
- add_action( 'manage_event_posts_custom_column' , 'custom_event_column', 10, 2 );
- function custom_event_column( $column, $post_id ) {
- switch ( $column ) {
- case 'event_type' :
- $terms = get_the_term_list( $post_id , 'event_type' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- // display a list of material terms assigned to the post
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for EXHIBITION:
- add_filter( 'manage_exhibition_posts_columns', 'set_custom_edit_exhibition_columns' );
- function set_custom_edit_exhibition_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for EXHIBITION:
- add_action( 'manage_exhibition_posts_custom_column' , 'custom_exhibition_column', 10, 2 );
- function custom_exhibition_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for SHORT:
- add_filter( 'manage_short_posts_columns', 'set_custom_edit_short_columns' );
- function set_custom_edit_short_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for SHORT:
- add_action( 'manage_short_posts_custom_column' , 'custom_short_column', 10, 2 );
- function custom_short_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for TECHNIQUE:
- add_filter( 'manage_technique_posts_columns', 'set_custom_edit_technique_columns' );
- function set_custom_edit_technique_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for TECHNIQUE:
- add_action( 'manage_technique_posts_custom_column' , 'custom_technique_column', 10, 2 );
- function custom_technique_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for GUIDE:
- add_filter( 'manage_guide_posts_columns', 'set_custom_edit_guide_columns' );
- function set_custom_edit_guide_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for GUIDE:
- add_action( 'manage_guide_posts_custom_column' , 'custom_guide_column', 10, 2 );
- function custom_guide_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for OBJECT:
- add_filter( 'manage_object_posts_columns', 'set_custom_edit_object_columns' );
- function set_custom_edit_object_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for OBJECT:
- add_action( 'manage_object_posts_custom_column' , 'custom_object_column', 10, 2 );
- function custom_object_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
-
- // Add the custom columns for PUBLICATION:
- add_filter( 'manage_publication_posts_columns', 'set_custom_edit_publication_columns' );
- function set_custom_edit_publication_columns($columns) {
- $date = $columns['date'];
- unset( $columns['date'] );
- $columns['material'] = __('Material');
- $columns['date'] = $date;
- return $columns;
- }
- // Add the data to the custom columns for PUBLICATION:
- add_action( 'manage_publication_posts_custom_column' , 'custom_publication_column', 10, 2 );
- function custom_publication_column( $column, $post_id ) {
- switch ( $column ) {
- case 'material' :
- $terms = get_the_term_list( $post_id , 'material' , '' , ', ' , '' );
- echo is_string( $terms ) ? $terms : '—';
- break;
- }
- }
- // Add Author to Custom Post Type
- function add_author_support_to_posts() {
- $args = array(
- 'public' => true,
- '_builtin' => false
- );
-
- $output = 'names';
-
- $post_types = get_post_types( $args, $output );
-
- foreach ( $post_types as $post_type ) {
- add_post_type_support( $post_type, 'author' );
- }
-
- }
- add_action( 'init', 'add_author_support_to_posts' );
|