Plugin Directory

Changeset 2383745


Ignore:
Timestamp:
09/17/2020 02:01:24 PM (6 years ago)
Author:
kodeks
Message:

Fix styling if kodeks.php exists

Location:
kodeks-dashboard/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kodeks-dashboard/trunk/functions.php

    r2383736 r2383745  
    11<?php
     2
     3/* Enable / disable branding */
     4if (!isset($kodeks_options['setting_branding']) || $kodeks_options['setting_branding'] == 1) {
     5    /* Admin page style */
     6    function kodeks_admin_theme_style() {
     7        wp_enqueue_style('my-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin.css');
     8    }
     9    add_action('admin_enqueue_scripts', 'kodeks_admin_theme_style');
     10
     11    /* Edit footer-text */
     12    function wpse_edit_footer() {
     13        add_filter( 'admin_footer_text', 'wpse_edit_text', 11 );
     14    }
     15
     16    function wpse_edit_text($content) {
     17        return "WordPress levert av <a href='https://kodeks.no' target='_blank'>Kodeks AS</a>";
     18    }
     19    add_action( 'admin_init', 'wpse_edit_footer' );
     20
     21    /* Custom logo */
     22    function my_login_logo() { ?>
     23<style>
     24    #login h1 a, .login h1 a {
     25        background-image: url(https://kodeks.no/media/dist/images/K.png);
     26        height:140px;
     27        width:140px;
     28        background-size: 140px 140px;
     29        background-repeat: no-repeat;
     30        padding-bottom: 30px;
     31    }
     32    #wpadminbar {
     33        background:#186962;
     34    }
     35</style>
     36<?php }
     37    add_action( 'login_enqueue_scripts', 'my_login_logo' );
     38
     39    // Endre link
     40    function my_login_logo_url() {
     41        return home_url();
     42    }
     43    add_filter( 'login_headerurl', 'my_login_logo_url' );
     44
     45    function my_login_logo_url_title() {
     46        return 'Kodeks';
     47    }
     48    add_filter( 'login_headertext', 'my_login_logo_url_title' );
     49
     50    // Legge til CSS
     51    function my_login_stylesheet() {
     52        wp_enqueue_style('custom-login', content_url() . '/plugins/kodeks-dashboard/css/admin.css');
     53    }
     54    add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
     55
     56    // Legge til hjelpetekst login page
     57    function smallenvelop_login_message( $message ) {
     58        if ( empty($message) ){
     59            return "<p class='kodeksInfo'><strong>Kodeks kundesenter: 21 00 01 01 — <a href='mailto:hjelp@kodeks.no'>hjelp@kodeks.no</a></strong></p>";
     60        } else {
     61            return $message;
     62        }
     63    }
     64    add_filter( 'login_message', 'smallenvelop_login_message' );
     65}
     66
     67
     68// Functions
     69
    270
    371$inc_kodeks = get_template_directory() . '/inc/kodeks.php';
    472if (!file_exists($inc_kodeks)) {
    5    
    6 /* Enable / disable Dashboard */
    7 if (!isset($kodeks_options['setting_dashboard']) || $kodeks_options['setting_dashboard'] == 1) {
    8     // add new dashboard widgets
    9     function kodeks_add_dashboard_widgets() {
    10         wp_add_dashboard_widget( 'dashboard_welcome', 'Velkommen', 'kodeks_add_welcome_widget' );
    11     }
    12 
    13     add_action( 'wp_dashboard_setup', 'kodeks_add_dashboard_widgets' );
    14 
    15     function kodeks_add_welcome_widget(){ ?>
     73
     74    /* Enable / disable Dashboard */
     75    if (!isset($kodeks_options['setting_dashboard']) || $kodeks_options['setting_dashboard'] == 1) {
     76        // add new dashboard widgets
     77        function kodeks_add_dashboard_widgets() {
     78            wp_add_dashboard_widget( 'dashboard_welcome', 'Velkommen', 'kodeks_add_welcome_widget' );
     79        }
     80
     81        add_action( 'wp_dashboard_setup', 'kodeks_add_dashboard_widgets' );
     82
     83        function kodeks_add_welcome_widget(){ ?>
    1684<h1>Hei<?php $current_user = wp_get_current_user();
    17                                          if ($current_user->user_firstname != '') {
    18                                              echo ' ';
    19                                              echo $current_user->user_firstname; echo ','; } else {echo '!';}?></h1>
     85                                             if ($current_user->user_firstname != '') {
     86                                                 echo ' ';
     87                                                 echo $current_user->user_firstname; echo ','; } else {echo '!';}?></h1>
    2088<p>Vi jobber kontinuerlig for at du skal kunne redigere dine nettsider så enkelt som mulig. Ved hjelp av Wordpress har dere total kontroll over alle deler av deres websider. Du kan selv oppdatere tekst, bilder og dokumenter på alle sider.</p>
    2189<p>Har du spørsmål til løsningen eller ønsker oppdateringer på siden er du velkommen til å ta kontakt med oss.</p>
     
    2492
    2593<?php
    26                                          global $kodeks_options;
    27                                          if (!isset($kodeks_options['setting_news']) || $kodeks_options['setting_news'] == 1) {?>
     94                                             global $kodeks_options;
     95                                             if (!isset($kodeks_options['setting_news']) || $kodeks_options['setting_news'] == 1) {?>
    2896<hr/>
    2997<h2>Nytt fra Kodeks</h2>
    3098<?php // Get RSS Feed(s)
    31                                              include_once( ABSPATH . WPINC . '/feed.php' );
    32 
    33                                              // Get a SimplePie feed object from the specified feed source.
    34                                              $rss = fetch_feed( 'https://kodeks.dev.kodeks.no/feed/' );
    35 
    36                                              $maxitems = 0;
    37 
    38                                              if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
    39 
    40                                              // Figure out how many total items there are, but limit it to 5.
    41                                              $maxitems = $rss->get_item_quantity( 3 );
    42 
    43                                              // Build an array of all the items, starting with element 0 (first element).
    44                                              $rss_items = $rss->get_items( 0, $maxitems );
    45 
    46                                              endif;
     99                                                 include_once( ABSPATH . WPINC . '/feed.php' );
     100
     101                                                 // Get a SimplePie feed object from the specified feed source.
     102                                                 $rss = fetch_feed( 'https://kodeks.dev.kodeks.no/feed/' );
     103
     104                                                 $maxitems = 0;
     105
     106                                                 if ( ! is_wp_error( $rss ) ) : // Checks that the object is created correctly
     107
     108                                                 // Figure out how many total items there are, but limit it to 5.
     109                                                 $maxitems = $rss->get_item_quantity( 3 );
     110
     111                                                 // Build an array of all the items, starting with element 0 (first element).
     112                                                 $rss_items = $rss->get_items( 0, $maxitems );
     113
     114                                                 endif;
    47115?>
    48116
     
    62130</ul>
    63131<?php
    64                                          }
    65                                         }
    66 }
    67 
    68 /* Enable / disable front page widgets */
    69 if (!isset($kodeks_options['setting_fp_widget_disable']) || $kodeks_options['setting_fp_widget_disable'] == 1) {
    70     function kodeks_remove_dashboard_meta() {
    71         remove_action('welcome_panel', 'wp_welcome_panel');
    72         remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
    73         remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
    74         remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
    75         remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
    76         remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
    77         remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
    78         remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
    79         remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
    80         remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8
    81         remove_meta_box( 'jetpack_summary_widget', 'dashboard', 'normal' );
    82         remove_meta_box( 'tribe_dashboard_widget', 'dashboard', 'normal' );
    83         remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'side' );
    84 
    85     }
    86     add_action( 'admin_init', 'kodeks_remove_dashboard_meta' );
    87 }
    88 
    89 /* Enable / disable branding */
    90 if (!isset($kodeks_options['setting_branding']) || $kodeks_options['setting_branding'] == 1) {
    91     /* Admin page style */
    92     function kodeks_admin_theme_style() {
    93         wp_enqueue_style('my-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin.css');
    94     }
    95     add_action('admin_enqueue_scripts', 'kodeks_admin_theme_style');
    96 
    97     /* Edit footer-text */
    98     function wpse_edit_footer() {
    99         add_filter( 'admin_footer_text', 'wpse_edit_text', 11 );
    100     }
    101 
    102     function wpse_edit_text($content) {
    103         return "WordPress levert av <a href='https://kodeks.no' target='_blank'>Kodeks AS</a>";
    104     }
    105     add_action( 'admin_init', 'wpse_edit_footer' );
    106 
    107     /* Custom logo */
    108     function my_login_logo() { ?>
    109 <style>
    110     #login h1 a, .login h1 a {
    111         background-image: url(https://kodeks.no/media/dist/images/K.png);
    112         height:140px;
    113         width:140px;
    114         background-size: 140px 140px;
    115         background-repeat: no-repeat;
    116         padding-bottom: 30px;
    117     }
    118     #wpadminbar {
    119         background:#186962;
    120     }
    121 </style>
    122 <?php }
    123     add_action( 'login_enqueue_scripts', 'my_login_logo' );
    124 
    125     // Endre link
    126     function my_login_logo_url() {
    127         return home_url();
    128     }
    129     add_filter( 'login_headerurl', 'my_login_logo_url' );
    130 
    131     function my_login_logo_url_title() {
    132         return 'Kodeks';
    133     }
    134     add_filter( 'login_headertext', 'my_login_logo_url_title' );
    135 
    136     // Legge til CSS
    137     function my_login_stylesheet() {
    138         wp_enqueue_style('custom-login', content_url() . '/plugins/kodeks-dashboard/css/admin.css');
    139     }
    140     add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
    141 
    142     // Legge til hjelpetekst login page
    143     function smallenvelop_login_message( $message ) {
    144         if ( empty($message) ){
    145             return "<p class='kodeksInfo'><strong>Kodeks kundesenter: 21 00 01 01 — <a href='mailto:hjelp@kodeks.no'>hjelp@kodeks.no</a></strong></p>";
    146         } else {
    147             return $message;
    148         }
    149     }
    150     add_filter( 'login_message', 'smallenvelop_login_message' );
    151 }
    152 
    153 /* Enable / disable acl */
    154 if (!isset($kodeks_options['setting_acl']) || $kodeks_options['setting_acl'] == 1) {
    155     /*
     132                                             }
     133                                            }
     134    }
     135
     136    /* Enable / disable front page widgets */
     137    if (!isset($kodeks_options['setting_fp_widget_disable']) || $kodeks_options['setting_fp_widget_disable'] == 1) {
     138        function kodeks_remove_dashboard_meta() {
     139            remove_action('welcome_panel', 'wp_welcome_panel');
     140            remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'normal' );
     141            remove_meta_box( 'dashboard_plugins', 'dashboard', 'normal' );
     142            remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
     143            remove_meta_box( 'dashboard_secondary', 'dashboard', 'normal' );
     144            remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
     145            remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' );
     146            remove_meta_box( 'dashboard_recent_comments', 'dashboard', 'normal' );
     147            remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' );
     148            remove_meta_box( 'dashboard_activity', 'dashboard', 'normal');//since 3.8
     149            remove_meta_box( 'jetpack_summary_widget', 'dashboard', 'normal' );
     150            remove_meta_box( 'tribe_dashboard_widget', 'dashboard', 'normal' );
     151            remove_meta_box( 'wpseo-dashboard-overview', 'dashboard', 'side' );
     152
     153        }
     154        add_action( 'admin_init', 'kodeks_remove_dashboard_meta' );
     155    }
     156
     157    /* Enable / disable acl */
     158    if (!isset($kodeks_options['setting_acl']) || $kodeks_options['setting_acl'] == 1) {
     159        /*
    156160     * Let Editors manage users, and run this only once.
    157161     */
    158     function isa_editor_manage_users() {
    159 
    160         if ( get_option( 'isa_add_cap_editor_once' ) != 'done' ) {
    161 
    162             // let editor manage users
    163 
    164             $edit_editor = get_role('editor'); // Get the user role
    165             $edit_editor->add_cap('edit_users');
    166             $edit_editor->add_cap('list_users');
    167             $edit_editor->add_cap('promote_users');
    168             $edit_editor->add_cap('create_users');
    169             $edit_editor->add_cap('add_users');
    170             $edit_editor->add_cap('delete_users');
    171 
    172             update_option( 'isa_add_cap_editor_once', 'done' );
    173         }
    174 
    175     }
    176     add_action( 'init', 'isa_editor_manage_users' );
    177 
    178     //prevent editor from deleting, editing, or creating an administrator
    179     // only needed if the editor was given right to edit users
    180 
    181     class ISA_User_Caps {
    182 
    183         // Add our filters
    184         function __construct() {
    185             add_filter( 'editable_roles', array(&$this, 'editable_roles'));
    186             add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
    187         }
    188         // Remove 'Administrator' from the list of roles if the current user is not an admin
    189         function editable_roles( $roles ){
    190             if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
    191                 unset( $roles['administrator']);
    192             }
    193             return $roles;
    194         }
    195         // If someone is trying to edit or delete an
    196         // admin and that user isn't an admin, don't allow it
    197         function map_meta_cap( $caps, $cap, $user_id, $args ){
    198             switch( $cap ){
    199                 case 'edit_user':
    200                 case 'remove_user':
    201                 case 'promote_user':
    202                     if( isset($args[0]) && $args[0] == $user_id )
     162        function isa_editor_manage_users() {
     163
     164            if ( get_option( 'isa_add_cap_editor_once' ) != 'done' ) {
     165
     166                // let editor manage users
     167
     168                $edit_editor = get_role('editor'); // Get the user role
     169                $edit_editor->add_cap('edit_users');
     170                $edit_editor->add_cap('list_users');
     171                $edit_editor->add_cap('promote_users');
     172                $edit_editor->add_cap('create_users');
     173                $edit_editor->add_cap('add_users');
     174                $edit_editor->add_cap('delete_users');
     175
     176                update_option( 'isa_add_cap_editor_once', 'done' );
     177            }
     178
     179        }
     180        add_action( 'init', 'isa_editor_manage_users' );
     181
     182        //prevent editor from deleting, editing, or creating an administrator
     183        // only needed if the editor was given right to edit users
     184
     185        class ISA_User_Caps {
     186
     187            // Add our filters
     188            function __construct() {
     189                add_filter( 'editable_roles', array(&$this, 'editable_roles'));
     190                add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
     191            }
     192            // Remove 'Administrator' from the list of roles if the current user is not an admin
     193            function editable_roles( $roles ){
     194                if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
     195                    unset( $roles['administrator']);
     196                }
     197                return $roles;
     198            }
     199            // If someone is trying to edit or delete an
     200            // admin and that user isn't an admin, don't allow it
     201            function map_meta_cap( $caps, $cap, $user_id, $args ){
     202                switch( $cap ){
     203                    case 'edit_user':
     204                    case 'remove_user':
     205                    case 'promote_user':
     206                        if( isset($args[0]) && $args[0] == $user_id )
     207                            break;
     208                        elseif( !isset($args[0]) )
     209                            $caps[] = 'do_not_allow';
     210                        $other = new WP_User( absint($args[0]) );
     211                        if( $other->has_cap( 'administrator' ) ){
     212                            if(!current_user_can('administrator')){
     213                                $caps[] = 'do_not_allow';
     214                            }
     215                        }
    203216                        break;
    204                     elseif( !isset($args[0]) )
    205                         $caps[] = 'do_not_allow';
    206                     $other = new WP_User( absint($args[0]) );
    207                     if( $other->has_cap( 'administrator' ) ){
    208                         if(!current_user_can('administrator')){
    209                             $caps[] = 'do_not_allow';
     217                    case 'delete_user':
     218                    case 'delete_users':
     219                        if( !isset($args[0]) )
     220                            break;
     221                        $other = new WP_User( absint($args[0]) );
     222                        if( $other->has_cap( 'administrator' ) ){
     223                            if(!current_user_can('administrator')){
     224                                $caps[] = 'do_not_allow';
     225                            }
    210226                        }
    211                     }
    212                     break;
    213                 case 'delete_user':
    214                 case 'delete_users':
    215                     if( !isset($args[0]) )
    216227                        break;
    217                     $other = new WP_User( absint($args[0]) );
    218                     if( $other->has_cap( 'administrator' ) ){
    219                         if(!current_user_can('administrator')){
    220                             $caps[] = 'do_not_allow';
    221                         }
    222                     }
    223                     break;
    224                 default:
    225                     break;
    226             }
    227             return $caps;
    228         }
    229 
    230     }
    231 
    232     $isa_user_caps = new ISA_User_Caps();
    233     // Hide all administrators from user list.
    234     add_action('pre_user_query','isa_pre_user_query');
    235     function isa_pre_user_query($user_search) {
    236 
    237         $user = wp_get_current_user();
    238 
    239         if ( ! current_user_can( 'manage_options' ) ) {
    240 
    241             global $wpdb;
    242 
    243             $user_search->query_where =
    244                 str_replace('WHERE 1=1',
    245                             "WHERE 1=1 AND {$wpdb->users}.ID IN (
     228                    default:
     229                        break;
     230                }
     231                return $caps;
     232            }
     233
     234        }
     235
     236        $isa_user_caps = new ISA_User_Caps();
     237        // Hide all administrators from user list.
     238        add_action('pre_user_query','isa_pre_user_query');
     239        function isa_pre_user_query($user_search) {
     240
     241            $user = wp_get_current_user();
     242
     243            if ( ! current_user_can( 'manage_options' ) ) {
     244
     245                global $wpdb;
     246
     247                $user_search->query_where =
     248                    str_replace('WHERE 1=1',
     249                                "WHERE 1=1 AND {$wpdb->users}.ID IN (
    246250            SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
    247251            WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
    248252            AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')",
    249                             $user_search->query_where
    250                            );
    251         }
    252     }
    253 }
    254 
    255 /* Enable / disable emoji */
    256 if (!isset($kodeks_options['setting_emoji']) || $kodeks_options['setting_emoji'] == 1) {
    257     add_filter( 'emoji_svg_url', '__return_false' );
    258     add_action( 'init', 'disable_wp_emojicons' );
    259 
    260     function disable_wp_emojicons() {
    261         // all actions related to emojis
    262         remove_action( 'admin_print_styles', 'print_emoji_styles' );
    263         remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    264         remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
    265         remove_action( 'wp_print_styles', 'print_emoji_styles' );
    266         remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
    267         remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
    268         remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
    269         // filter to remove TinyMCE emojis
    270         add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
    271     }
    272 
    273     function disable_emojicons_tinymce( $plugins ) {
    274         if ( is_array( $plugins ) ) {
    275             return array_diff( $plugins, array( 'wpemoji' ) );
    276         } else {
    277             return array();
    278         }
    279     }
    280 }
    281 
    282 /* Enable / disable rest API */
    283 if (!isset($kodeks_options['setting_api']) || $kodeks_options['setting_api'] == 1) {
    284 
    285     remove_action ('wp_head', 'rsd_link');
    286     remove_action( 'wp_head', 'wlwmanifest_link');
    287     remove_action('template_redirect', 'rest_output_link_header', 11, 0);
    288     remove_action('wp_head', 'rest_output_link_wp_head', 10);
    289 
    290     // Sikkerhet - slå av xml-rpc
    291     // Disable use XML-RPC
    292     add_filter('xmlrpc_enabled', '__return_false');
    293 
    294     // Disable X-Pingback to header
    295     add_filter( 'wp_headers', 'disable_x_pingback' );
    296     function disable_x_pingback( $headers ) {
    297         unset( $headers['X-Pingback'] );
    298         return $headers;
    299     }
    300 
    301     // Turn off oEmbed auto discovery.
    302     add_filter( 'embed_oembed_discover', '__return_false' );
    303 
    304     // Don't filter oEmbed results.
    305     remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
    306 
    307     // Remove oEmbed discovery links.
    308     remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
    309 
    310     // Remove oEmbed-specific JavaScript from the front-end and back-end.
    311     remove_action( 'wp_head', 'wp_oembed_add_host_js' );
    312 
    313     /**
     253                                $user_search->query_where
     254                               );
     255            }
     256        }
     257    }
     258
     259    /* Enable / disable emoji */
     260    if (!isset($kodeks_options['setting_emoji']) || $kodeks_options['setting_emoji'] == 1) {
     261        add_filter( 'emoji_svg_url', '__return_false' );
     262        add_action( 'init', 'disable_wp_emojicons' );
     263
     264        function disable_wp_emojicons() {
     265            // all actions related to emojis
     266            remove_action( 'admin_print_styles', 'print_emoji_styles' );
     267            remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
     268            remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
     269            remove_action( 'wp_print_styles', 'print_emoji_styles' );
     270            remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
     271            remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
     272            remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
     273            // filter to remove TinyMCE emojis
     274            add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
     275        }
     276
     277        function disable_emojicons_tinymce( $plugins ) {
     278            if ( is_array( $plugins ) ) {
     279                return array_diff( $plugins, array( 'wpemoji' ) );
     280            } else {
     281                return array();
     282            }
     283        }
     284    }
     285
     286    /* Enable / disable rest API */
     287    if (!isset($kodeks_options['setting_api']) || $kodeks_options['setting_api'] == 1) {
     288
     289        remove_action ('wp_head', 'rsd_link');
     290        remove_action( 'wp_head', 'wlwmanifest_link');
     291        remove_action('template_redirect', 'rest_output_link_header', 11, 0);
     292        remove_action('wp_head', 'rest_output_link_wp_head', 10);
     293
     294        // Sikkerhet - slå av xml-rpc
     295        // Disable use XML-RPC
     296        add_filter('xmlrpc_enabled', '__return_false');
     297
     298        // Disable X-Pingback to header
     299        add_filter( 'wp_headers', 'disable_x_pingback' );
     300        function disable_x_pingback( $headers ) {
     301            unset( $headers['X-Pingback'] );
     302            return $headers;
     303        }
     304
     305        // Turn off oEmbed auto discovery.
     306        add_filter( 'embed_oembed_discover', '__return_false' );
     307
     308        // Don't filter oEmbed results.
     309        remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
     310
     311        // Remove oEmbed discovery links.
     312        remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
     313
     314        // Remove oEmbed-specific JavaScript from the front-end and back-end.
     315        remove_action( 'wp_head', 'wp_oembed_add_host_js' );
     316
     317        /**
    314318    *    Disables WordPress Rest API for external requests
    315319    */
    316     // function restrict_rest_api_to_localhost() {
    317     //     $whitelist = array('127.0.0.1', "::1");
    318     //
    319     //     if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
    320     //         die('REST API is disabled.');
    321     //     }
    322     // }
    323     // add_action( 'rest_api_init', 'restrict_rest_api_to_localhost', 1 );
    324 }
    325 
    326 /* Enable / disable admin-bar */
    327 if (!isset($kodeks_options['setting_adminbar']) || $kodeks_options['setting_adminbar'] == 1) {
    328     add_filter('show_admin_bar', 'remove_admin_bar');
    329     function remove_admin_bar() {
    330         return false;
    331     }
    332 }
    333 
    334 /* Enable / disable widgets */
    335 if (!isset($kodeks_options['setting_widget']) || $kodeks_options['setting_widget'] == 0) {
    336     /**
     320        // function restrict_rest_api_to_localhost() {
     321        //     $whitelist = array('127.0.0.1', "::1");
     322        //
     323        //     if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
     324        //         die('REST API is disabled.');
     325        //     }
     326        // }
     327        // add_action( 'rest_api_init', 'restrict_rest_api_to_localhost', 1 );
     328    }
     329
     330    /* Enable / disable admin-bar */
     331    if (!isset($kodeks_options['setting_adminbar']) || $kodeks_options['setting_adminbar'] == 1) {
     332        add_filter('show_admin_bar', 'remove_admin_bar');
     333        function remove_admin_bar() {
     334            return false;
     335        }
     336    }
     337
     338    /* Enable / disable widgets */
     339    if (!isset($kodeks_options['setting_widget']) || $kodeks_options['setting_widget'] == 0) {
     340        /**
    337341     * Register widget area.
    338342     *
    339343     * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
    340344     */
    341     function kodeks_widgets_init() {
    342         register_sidebar( array(
    343             'name'          => esc_html__( 'Widgets', 'kodeks' ),
    344             'id'            => 'widgets',
    345             'description'   => esc_html__( 'Add widgets here.', 'kodeks' ),
    346             'before_widget' => '<section id="%1$s" class="widget %2$s">',
    347             'after_widget'  => '</section>',
    348             'before_title'  => '<h2 class="widget-title">',
    349             'after_title'   => '</h2>',
    350         ) );
    351     }
    352     add_action( 'widgets_init', 'kodeks_widgets_init' );
    353 }
    354 
    355 /* Gutenberg */
    356 
    357 if (!isset($kodeks_options['setting_gutenberg']) || $kodeks_options['setting_gutenberg'] == 1) {
    358     add_action( 'enqueue_block_editor_assets', function() {
    359         // Main block styles.
    360         wp_enqueue_style( 'uuups-blocks', asset( 'styles/editor.css' ), null, null );
    361 
    362         // Overwrite Core block styles with empty styles.
    363         wp_deregister_style( 'wp-block-library' );
    364         wp_register_style( 'wp-block-library', '' );
    365 
    366         // Overwrite Core theme styles with empty styles.
    367         wp_deregister_style( 'wp-block-library-theme' );
    368         wp_register_style( 'wp-block-library-theme', '' );
    369     }, 10 );
    370 
    371     function custom_theme_assets() {
    372         wp_dequeue_style( 'wp-block-library' );
    373     }
    374 
    375     add_action( 'wp_enqueue_scripts', 'custom_theme_assets', 100 );
    376 }
    377 
    378 
    379 /* Enable / disable css */
    380 if (!isset($kodeks_options['setting_css']) || $kodeks_options['setting_css'] == 1) {
    381 
    382     /**
     345        function kodeks_widgets_init() {
     346            register_sidebar( array(
     347                'name'          => esc_html__( 'Widgets', 'kodeks' ),
     348                'id'            => 'widgets',
     349                'description'   => esc_html__( 'Add widgets here.', 'kodeks' ),
     350                'before_widget' => '<section id="%1$s" class="widget %2$s">',
     351                'after_widget'  => '</section>',
     352                'before_title'  => '<h2 class="widget-title">',
     353                'after_title'   => '</h2>',
     354            ) );
     355        }
     356        add_action( 'widgets_init', 'kodeks_widgets_init' );
     357    }
     358
     359    /* Gutenberg */
     360
     361    if (!isset($kodeks_options['setting_gutenberg']) || $kodeks_options['setting_gutenberg'] == 1) {
     362        add_action( 'enqueue_block_editor_assets', function() {
     363            // Main block styles.
     364            wp_enqueue_style( 'uuups-blocks', asset( 'styles/editor.css' ), null, null );
     365
     366            // Overwrite Core block styles with empty styles.
     367            wp_deregister_style( 'wp-block-library' );
     368            wp_register_style( 'wp-block-library', '' );
     369
     370            // Overwrite Core theme styles with empty styles.
     371            wp_deregister_style( 'wp-block-library-theme' );
     372            wp_register_style( 'wp-block-library-theme', '' );
     373        }, 10 );
     374
     375        function custom_theme_assets() {
     376            wp_dequeue_style( 'wp-block-library' );
     377        }
     378
     379        add_action( 'wp_enqueue_scripts', 'custom_theme_assets', 100 );
     380    }
     381
     382
     383    /* Enable / disable css */
     384    if (!isset($kodeks_options['setting_css']) || $kodeks_options['setting_css'] == 1) {
     385
     386        /**
    383387 * Remove the additional CSS section, introduced in 4.7, from the Customizer.
    384388 * @param $wp_customize WP_Customize_Manager
    385389 */
    386     add_action( 'customize_register', 'prefix_remove_css_section', 15 );
    387     function prefix_remove_css_section( $wp_customize ) {
    388         $wp_customize->remove_section( 'custom_css' );
    389     }
    390 }
    391 
    392 /* Default */
    393 
    394 // Fjerne static_front_page
    395 
    396 add_action( 'customize_register', 'prefix_remove_front', 15 );
    397 function prefix_remove_front( $wp_customize ) {
    398     $wp_customize->remove_section( 'static_front_page' );
    399 }
    400 
    401 
    402 // Fjerne theme-picker
    403 remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
    404 
    405 // Custom logo
    406 add_theme_support('custom-logo');
    407 
    408 // Slå av editering via admin
    409 define('DISALLOW_FILE_EDIT', true);
    410 
    411 
    412 // remove version from head
    413 remove_action('wp_head', 'wp_generator');
    414 
    415 // remove version from rss
    416 add_filter('the_generator', '__return_empty_string');
    417 
    418 // remove version from scripts and styles
    419 function shapeSpace_remove_version_scripts_styles($src) {
    420     if (strpos($src, 'ver=')) {
    421         $src = remove_query_arg('ver', $src);
    422     }
    423     return $src;
    424 }
    425 add_filter('style_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
    426 add_filter('script_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
    427 
    428 
    429 // Media uploader - enable SVG
    430 function cc_mime_types($mimes) {
    431     $mimes['svg'] = 'image/svg+xml';
    432     return $mimes;
    433 }
    434 add_filter('upload_mimes', 'cc_mime_types');
    435 
    436 // Move Yoast to bottom
    437 function yoasttobottom() {
    438     return 'low';
    439 }
    440 add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
    441 
    442 // Remove All Yoast HTML Comments
    443 // https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
    444 add_action('wp_head',function() { ob_start(function($o) {
    445     return preg_replace('/^\n?<!--.*?[Y]oast.*?-->\n?$/mi','',$o);
    446 }); },~PHP_INT_MAX);
    447 
    448 
    449 // STOP TINYMCE CLASSES
    450 add_filter('tiny_mce_before_init', 'customize_tinymce');
    451 
    452 function customize_tinymce($in) {
    453     $in['paste_preprocess'] = "function(pl,o){ o.content = o.content.replace(/p class=\"p[0-9]+\"/g,'p'); o.content = o.content.replace(/span class=\"s[0-9]+\"/g,'span'); }";
    454     return $in;
    455 }
    456 
    457 /* Remove edit-button */
    458 add_filter( 'edit_post_link', '__return_false' );
    459 
    460 // block WP enum scans
    461 // https://m0n.co/enum
    462 if (!is_admin()) {
    463     // default URL format
    464     if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])) die();
    465     add_filter('redirect_canonical', 'shapeSpace_check_enum', 10, 2);
    466 }
    467 function shapeSpace_check_enum($redirect, $request) {
    468     // permalink URL format
    469     if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) die();
    470     else return $redirect;
    471 }
    472 
    473 add_action('init','do_stuff');
    474 function do_stuff(){
    475     $current_user = wp_get_current_user();
    476     // Disable W3TC footer comment for everyone but Admins (single site & network mode)
    477     if ( !current_user_can( 'activate_plugins' ) ) {
    478         add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
    479     }
    480 
    481 }
    482 
    483 // Remove type="javascript/css"
    484 
    485 add_action( 'template_redirect', function(){
    486     ob_start( function( $buffer ){
    487         $buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );
    488 
    489         // Also works with other attributes...
    490         $buffer = str_replace( array( 'type="text/css"', "type='text/css'" ), '', $buffer );
    491         $buffer = str_replace( array( 'frameborder="0"', "frameborder='0'" ), '', $buffer );
    492         $buffer = str_replace( array( 'scrolling="no"', "scrolling='no'" ), '', $buffer );
    493 
    494         return $buffer;
     390        add_action( 'customize_register', 'prefix_remove_css_section', 15 );
     391        function prefix_remove_css_section( $wp_customize ) {
     392            $wp_customize->remove_section( 'custom_css' );
     393        }
     394    }
     395
     396    /* Default */
     397
     398    // Fjerne static_front_page
     399
     400    add_action( 'customize_register', 'prefix_remove_front', 15 );
     401    function prefix_remove_front( $wp_customize ) {
     402        $wp_customize->remove_section( 'static_front_page' );
     403    }
     404
     405
     406    // Fjerne theme-picker
     407    remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
     408
     409    // Custom logo
     410    add_theme_support('custom-logo');
     411
     412    // Slå av editering via admin
     413    define('DISALLOW_FILE_EDIT', true);
     414
     415
     416    // remove version from head
     417    remove_action('wp_head', 'wp_generator');
     418
     419    // remove version from rss
     420    add_filter('the_generator', '__return_empty_string');
     421
     422    // remove version from scripts and styles
     423    function shapeSpace_remove_version_scripts_styles($src) {
     424        if (strpos($src, 'ver=')) {
     425            $src = remove_query_arg('ver', $src);
     426        }
     427        return $src;
     428    }
     429    add_filter('style_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
     430    add_filter('script_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
     431
     432
     433    // Media uploader - enable SVG
     434    function cc_mime_types($mimes) {
     435        $mimes['svg'] = 'image/svg+xml';
     436        return $mimes;
     437    }
     438    add_filter('upload_mimes', 'cc_mime_types');
     439
     440    // Move Yoast to bottom
     441    function yoasttobottom() {
     442        return 'low';
     443    }
     444    add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
     445
     446    // Remove All Yoast HTML Comments
     447    // https://gist.github.com/paulcollett/4c81c4f6eb85334ba076
     448    add_action('wp_head',function() { ob_start(function($o) {
     449        return preg_replace('/^\n?<!--.*?[Y]oast.*?-->\n?$/mi','',$o);
     450    }); },~PHP_INT_MAX);
     451
     452
     453    // STOP TINYMCE CLASSES
     454    add_filter('tiny_mce_before_init', 'customize_tinymce');
     455
     456    function customize_tinymce($in) {
     457        $in['paste_preprocess'] = "function(pl,o){ o.content = o.content.replace(/p class=\"p[0-9]+\"/g,'p'); o.content = o.content.replace(/span class=\"s[0-9]+\"/g,'span'); }";
     458        return $in;
     459    }
     460
     461    /* Remove edit-button */
     462    add_filter( 'edit_post_link', '__return_false' );
     463
     464    // block WP enum scans
     465    // https://m0n.co/enum
     466    if (!is_admin()) {
     467        // default URL format
     468        if (preg_match('/author=([0-9]*)/i', $_SERVER['QUERY_STRING'])) die();
     469        add_filter('redirect_canonical', 'shapeSpace_check_enum', 10, 2);
     470    }
     471    function shapeSpace_check_enum($redirect, $request) {
     472        // permalink URL format
     473        if (preg_match('/\?author=([0-9]*)(\/*)/i', $request)) die();
     474        else return $redirect;
     475    }
     476
     477    add_action('init','do_stuff');
     478    function do_stuff(){
     479        $current_user = wp_get_current_user();
     480        // Disable W3TC footer comment for everyone but Admins (single site & network mode)
     481        if ( !current_user_can( 'activate_plugins' ) ) {
     482            add_filter( 'w3tc_can_print_comment', '__return_false', 10, 1 );
     483        }
     484
     485    }
     486
     487    // Remove type="javascript/css"
     488
     489    add_action( 'template_redirect', function(){
     490        ob_start( function( $buffer ){
     491            $buffer = str_replace( array( 'type="text/javascript"', "type='text/javascript'" ), '', $buffer );
     492
     493            // Also works with other attributes...
     494            $buffer = str_replace( array( 'type="text/css"', "type='text/css'" ), '', $buffer );
     495            $buffer = str_replace( array( 'frameborder="0"', "frameborder='0'" ), '', $buffer );
     496            $buffer = str_replace( array( 'scrolling="no"', "scrolling='no'" ), '', $buffer );
     497
     498            return $buffer;
     499        });
    495500    });
    496 });
    497 
    498 // remove links/menus from the admin bar
    499 function mytheme_admin_bar_render() {
    500     global $wp_admin_bar;
    501     $wp_admin_bar->remove_menu('comments');
    502     $wp_admin_bar->remove_menu('updates');
    503 }
    504 add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
    505 
    506 
    507 function jp_wpseo_fat_slicer() {
    508 
    509     // Only do this for users who don't have Editor capabilities
    510     if ( ! current_user_can( 'edit_others_posts' ) ) {
    511         add_action( 'add_meta_boxes', 'jp_remove_yoast_metabox', 99 );
    512         add_filter( 'manage_edit-post_columns', 'jp_remove_columns' );
    513         add_filter( 'manage_edit-page_columns', 'jp_remove_columns' );
    514         // add_filter( 'manage_edit-CPTNAME_columns', 'jp_remove_columns' ); // Replace CPTNAME with your custom post type name, for example "restaurants".
    515     }
    516 }
    517 add_action( 'init', 'jp_wpseo_fat_slicer' );
    518 
    519 
    520 
    521 /**
     501
     502    // remove links/menus from the admin bar
     503    function mytheme_admin_bar_render() {
     504        global $wp_admin_bar;
     505        $wp_admin_bar->remove_menu('comments');
     506        $wp_admin_bar->remove_menu('updates');
     507    }
     508    add_action( 'wp_before_admin_bar_render', 'mytheme_admin_bar_render' );
     509
     510
     511    function jp_wpseo_fat_slicer() {
     512
     513        // Only do this for users who don't have Editor capabilities
     514        if ( ! current_user_can( 'edit_others_posts' ) ) {
     515            add_action( 'add_meta_boxes', 'jp_remove_yoast_metabox', 99 );
     516            add_filter( 'manage_edit-post_columns', 'jp_remove_columns' );
     517            add_filter( 'manage_edit-page_columns', 'jp_remove_columns' );
     518            // add_filter( 'manage_edit-CPTNAME_columns', 'jp_remove_columns' ); // Replace CPTNAME with your custom post type name, for example "restaurants".
     519        }
     520    }
     521    add_action( 'init', 'jp_wpseo_fat_slicer' );
     522
     523
     524
     525    /**
    522526 * Removes the WordPress SEO meta box from posts and pages
    523527 *
     
    525529 * @uses remove_meta_box()
    526530 */
    527 function jp_remove_yoast_metabox() {
    528 
    529     $post_types = array( 'page', 'post' ); // add any custom post types here
    530 
    531     foreach( $post_types as $post_type ) {
    532         remove_meta_box( 'wpseo_meta', $post_type, 'normal' );
    533     }
    534 }
    535 
    536 
    537 
    538 /**
     531    function jp_remove_yoast_metabox() {
     532
     533        $post_types = array( 'page', 'post' ); // add any custom post types here
     534
     535        foreach( $post_types as $post_type ) {
     536            remove_meta_box( 'wpseo_meta', $post_type, 'normal' );
     537        }
     538    }
     539
     540
     541
     542    /**
    539543 * Removes the SEO item from the admin bar
    540544 *
     
    542546 * @uses remove_menu
    543547 */
    544 function jp_admin_bar_seo_cleanup() {
    545 
    546     global $wp_admin_bar;
    547     $wp_admin_bar->remove_menu( 'wpseo-menu' );
    548 }
    549 
    550 
    551 
    552 /**
     548    function jp_admin_bar_seo_cleanup() {
     549
     550        global $wp_admin_bar;
     551        $wp_admin_bar->remove_menu( 'wpseo-menu' );
     552    }
     553
     554
     555
     556    /**
    553557 * Removes the extra columns on the post/page listing screens.
    554558 *
    555559 * @since 1.0.0
    556560 */
    557 function jp_remove_columns( $columns ) {
    558 
    559     unset( $columns['wpseo-score'] );
    560     unset( $columns['wpseo-title'] );
    561     unset( $columns['wpseo-metadesc'] );
    562     unset( $columns['wpseo-focuskw'] );
    563 
    564     return $columns;
    565 }
    566 
    567 /** Hide update nag
    568  */
    569 
    570 function hide_update_notice_to_all_but_admin_users()
    571 {
    572     if (!current_user_can('update_core')) {
    573         remove_action( 'admin_notices', 'update_nag',      3  );
    574         remove_action( 'admin_notices', 'maintenance_nag', 10 );
    575     }
    576 }
    577 add_action( 'admin_head', 'hide_update_notice_to_all_but_admin_users', 1 );
    578 
    579 
    580 /* Show current teplate --- echo get_current_template( true ); */
    581 
    582 add_filter( 'template_include', 'var_template_include', 1000 );
    583 function var_template_include( $t ){
    584     $GLOBALS['current_theme_template'] = basename($t);
    585     return $t;
    586 }
    587 
    588 function get_current_template( $echo = false ) {
    589     if( !isset( $GLOBALS['current_theme_template'] ) )
     561    function jp_remove_columns( $columns ) {
     562
     563        unset( $columns['wpseo-score'] );
     564        unset( $columns['wpseo-title'] );
     565        unset( $columns['wpseo-metadesc'] );
     566        unset( $columns['wpseo-focuskw'] );
     567
     568        return $columns;
     569    }
     570
     571    /** Hide update nag
     572 */
     573
     574    function hide_update_notice_to_all_but_admin_users()
     575    {
     576        if (!current_user_can('update_core')) {
     577            remove_action( 'admin_notices', 'update_nag',      3  );
     578            remove_action( 'admin_notices', 'maintenance_nag', 10 );
     579        }
     580    }
     581    add_action( 'admin_head', 'hide_update_notice_to_all_but_admin_users', 1 );
     582
     583
     584    /* Show current teplate --- echo get_current_template( true ); */
     585
     586    add_filter( 'template_include', 'var_template_include', 1000 );
     587    function var_template_include( $t ){
     588        $GLOBALS['current_theme_template'] = basename($t);
     589        return $t;
     590    }
     591
     592    function get_current_template( $echo = false ) {
     593        if( !isset( $GLOBALS['current_theme_template'] ) )
     594            return false;
     595        if( $echo )
     596            echo $GLOBALS['current_theme_template'];
     597        else
     598            return $GLOBALS['current_theme_template'];
     599    }
     600
     601    function is_post_type($type){
     602        global $wp_query;
     603        if($type == get_post_type($wp_query->post->ID)) return true;
    590604        return false;
    591     if( $echo )
    592         echo $GLOBALS['current_theme_template'];
    593     else
    594         return $GLOBALS['current_theme_template'];
    595 }
    596 
    597 function is_post_type($type){
    598     global $wp_query;
    599     if($type == get_post_type($wp_query->post->ID)) return true;
    600     return false;
    601 }
    602 
    603 // Add options page
    604 
    605 if( function_exists('acf_add_options_page') ) {
    606 
    607     acf_add_options_page();
    608 
    609 }
    610 
    611 if ( ! function_exists( 'kodeks_setup' ) ) :
    612 /**
     605    }
     606
     607    // Add options page
     608
     609    if( function_exists('acf_add_options_page') ) {
     610
     611        acf_add_options_page();
     612
     613    }
     614
     615    if ( ! function_exists( 'kodeks_setup' ) ) :
     616    /**
    613617 * Sets up theme defaults and registers support for various WordPress features.
    614618 *
     
    617621 * as indicating support for post thumbnails.
    618622 */
    619 function kodeks_setup() {
    620     /*
     623    function kodeks_setup() {
     624        /*
    621625     * Make theme available for translation.
    622626     * Translations can be filed in the /languages/ directory.
     
    624628     * to change 'kodeks' to the name of your theme in all the template files.
    625629     */
    626     load_theme_textdomain( 'kodeks', get_template_directory() . '/languages' );
    627 
    628     // Add default posts and comments RSS feed links to head.
    629     add_theme_support( 'automatic-feed-links' );
    630 
    631     /*
     630        load_theme_textdomain( 'kodeks', get_template_directory() . '/languages' );
     631
     632        // Add default posts and comments RSS feed links to head.
     633        add_theme_support( 'automatic-feed-links' );
     634
     635        /*
    632636     * Let WordPress manage the document title.
    633637     * By adding theme support, we declare that this theme does not use a
     
    635639     * provide it for us.
    636640     */
    637     add_theme_support( 'title-tag' );
    638     /*
     641        add_theme_support( 'title-tag' );
     642        /*
    639643     * Enable support for Post Thumbnails on posts and pages.
    640644     *
    641645     * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
    642646     */
    643     add_theme_support( 'post-thumbnails' );
    644 
    645     /*
     647        add_theme_support( 'post-thumbnails' );
     648
     649        /*
    646650     * Switch default core markup for search form, comment form, and comments
    647651     * to output valid HTML5.
    648652     */
    649     add_theme_support( 'html5', array(
    650         'search-form',
    651         'comment-form',
    652         'comment-list',
    653         'gallery',
    654         'caption',
    655     ) );
    656 }
    657 endif;
    658 add_action( 'after_setup_theme', 'kodeks_setup' );
    659 
    660 
    661 /**
     653        add_theme_support( 'html5', array(
     654            'search-form',
     655            'comment-form',
     656            'comment-list',
     657            'gallery',
     658            'caption',
     659        ) );
     660    }
     661    endif;
     662    add_action( 'after_setup_theme', 'kodeks_setup' );
     663
     664
     665    /**
    662666 * Set the content width in pixels, based on the theme's design and stylesheet.
    663667 *
     
    666670 * @global int $content_width
    667671 */
    668 function kodeks_content_width() {
    669     $GLOBALS['content_width'] = apply_filters( 'kodeks_content_width', 640 );
    670 }
    671 add_action( 'after_setup_theme', 'kodeks_content_width', 0 );
    672 
    673 /**
     672    function kodeks_content_width() {
     673        $GLOBALS['content_width'] = apply_filters( 'kodeks_content_width', 640 );
     674    }
     675    add_action( 'after_setup_theme', 'kodeks_content_width', 0 );
     676
     677    /**
    674678 * Enqueue scripts and styles.
    675679 */
    676 function kodeks_scripts() {
    677     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    678         wp_enqueue_script( 'comment-reply' );
    679     }
    680 }
    681 add_action( 'wp_enqueue_scripts', 'kodeks_scripts' );
    682 
    683 // post thumbnails support
    684 add_theme_support( 'post-thumbnails' );
    685 
    686 // Make editors able to edit privacy page
    687 
    688 add_action('map_meta_cap', 'custom_manage_privacy_options', 1, 4);
    689 function custom_manage_privacy_options($caps, $cap, $user_id, $args)
    690 {
    691     if ('manage_privacy_options' === $cap) {
    692         $manage_name = is_multisite() ? 'manage_network' : 'manage_options';
    693         $caps = array_diff($caps, [ $manage_name ]);
    694     }
    695     return $caps;
    696 }
    697 
    698 add_filter( 'yoast-acf-analysis/refresh_rate', function () {
    699     // Refresh rates in milliseconds
    700     return 20000;
    701 });
    702 
    703 
    704 /**
     680    function kodeks_scripts() {
     681        if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
     682            wp_enqueue_script( 'comment-reply' );
     683        }
     684    }
     685    add_action( 'wp_enqueue_scripts', 'kodeks_scripts' );
     686
     687    // post thumbnails support
     688    add_theme_support( 'post-thumbnails' );
     689
     690    // Make editors able to edit privacy page
     691
     692    add_action('map_meta_cap', 'custom_manage_privacy_options', 1, 4);
     693    function custom_manage_privacy_options($caps, $cap, $user_id, $args)
     694    {
     695        if ('manage_privacy_options' === $cap) {
     696            $manage_name = is_multisite() ? 'manage_network' : 'manage_options';
     697            $caps = array_diff($caps, [ $manage_name ]);
     698        }
     699        return $caps;
     700    }
     701
     702    add_filter( 'yoast-acf-analysis/refresh_rate', function () {
     703        // Refresh rates in milliseconds
     704        return 20000;
     705    });
     706
     707
     708    /**
    705709 * Extend WordPress search to include custom fields
    706710 *
     
    708712 */
    709713
    710 /**
     714    /**
    711715 * Join posts and postmeta tables
    712716 *
     
    714718 */
    715719
    716 $search_plugin = false;
    717 if(in_array('acf-better-search/acf-better-search.php', apply_filters('active_plugins', get_option('active_plugins')))){
    718     $search_plugin = true;
    719 };
    720 
    721 if ( ! function_exists( 'kodeks_search_join' ) && $search_plugin == false ) {
    722 
    723     function kodeks_search_join( $join ) {
    724         global $wpdb;
    725 
    726         if ( is_search() ) {   
    727             $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
    728         }
    729 
    730         return $join;
    731     }
    732     add_filter('posts_join', 'kodeks_search_join' );
    733 
    734 }
    735 
    736 /**
     720    $search_plugin = false;
     721    if(in_array('acf-better-search/acf-better-search.php', apply_filters('active_plugins', get_option('active_plugins')))){
     722        $search_plugin = true;
     723    };
     724
     725    if ( ! function_exists( 'kodeks_search_join' ) && $search_plugin == false ) {
     726
     727        function kodeks_search_join( $join ) {
     728            global $wpdb;
     729
     730            if ( is_search() ) {   
     731                $join .=' LEFT JOIN '.$wpdb->postmeta. ' ON '. $wpdb->posts . '.ID = ' . $wpdb->postmeta . '.post_id ';
     732            }
     733
     734            return $join;
     735        }
     736        add_filter('posts_join', 'kodeks_search_join' );
     737
     738    }
     739
     740    /**
    737741 * Modify the search query with posts_where
    738742 *
     
    740744 */
    741745
    742 if ( ! function_exists( 'kodeks_search_where' ) && $search_plugin == false ) {
    743     function kodeks_search_where( $where ) {
    744         global $pagenow, $wpdb;
    745 
    746         if ( is_search() ) {
    747             $where = preg_replace(
    748                 "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
    749                 "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
    750         }
    751 
    752         return $where;
    753     }
    754     add_filter( 'posts_where', 'kodeks_search_where' );
    755 }
     746    if ( ! function_exists( 'kodeks_search_where' ) && $search_plugin == false ) {
     747        function kodeks_search_where( $where ) {
     748            global $pagenow, $wpdb;
     749
     750            if ( is_search() ) {
     751                $where = preg_replace(
     752                    "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
     753                    "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
     754            }
     755
     756            return $where;
     757        }
     758        add_filter( 'posts_where', 'kodeks_search_where' );
     759    }
    756760
    757761    /**
  • kodeks-dashboard/trunk/kodeks-dashboard.php

    r2383732 r2383745  
    33Plugin Name: Kodeks Dashboard
    44Description: This plugin customizes WordPress for Kodeks customers.
    5 Version: 3
     5Version: 3.0.5
    66Author: Thomas Johannessen & Marius Kaase
    77Author URI: http://kodeks.no
  • kodeks-dashboard/trunk/readme.txt

    r2383732 r2383745  
    11=== Kodeks Dashboard ===
    2 Version: 3
     2Version: 3.0.5
    33Contributors: Kodeks AS
    44Tested up to: 5.5.1
Note: See TracChangeset for help on using the changeset viewer.