liquet/liquet/functions.php

100 lines
3.0 KiB
PHP
Raw Normal View History

2019-05-03 08:45:48 +02:00
<?php
2019-05-06 21:36:49 +02:00
include_once( 'logos.php' );
2019-05-03 08:45:48 +02:00
add_theme_support( 'align-wide' );
2019-05-03 11:01:35 +02:00
add_theme_support( 'title-tag' );
2019-07-03 10:32:05 +02:00
add_theme_support( 'post-thumbnails' );
2019-05-03 08:45:48 +02:00
2019-08-19 13:16:55 +02:00
add_filter( 'wp_headers', function ( $headers ) {
2019-08-27 17:33:24 +02:00
$headers['Content-Security-Policy'] = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://s.w.org; report-uri csp@nicco.io";
2019-08-19 13:16:55 +02:00
$headers['X-Content-Type-Options'] = 'nosniff';
$headers['X-Frame-Options'] = "deny";
$headers['Strict-Transport-Security'] = "max-age=31536000";
$headers['Referrer-Policy'] = "origin";
return $headers;
} );
2019-05-03 08:45:48 +02:00
add_action( 'wp_enqueue_scripts', function () {
2019-09-27 16:04:02 +02:00
wp_enqueue_style( 'liquet', get_template_directory_uri() . '/dist/styles/index.css' );
wp_enqueue_script( 'liquet', get_template_directory_uri() . '/dist/js/index.js' );
2019-05-06 21:36:49 +02:00
} );
2019-09-06 22:46:32 +02:00
function lazy_load_ajax_handler() {
$args = json_decode( stripslashes( $_POST['query'] ), true );
2019-09-27 16:04:02 +02:00
$args['paged'] = $_POST['page'] + 1;
2019-09-06 22:46:32 +02:00
$args['post_status'] = 'publish';
query_posts( $args );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'post-preview', get_post_format() );
}
}
die;
}
add_action( 'wp_ajax_lazy_load', 'lazy_load_ajax_handler' );
add_action( 'wp_ajax_nopriv_lazy_load', 'lazy_load_ajax_handler' );
2019-06-02 12:05:20 +02:00
add_action( 'widgets_init', function () {
register_sidebar( array(
'name' => 'Below posts',
'id' => 'below_posts',
'before_widget' => '<div class="widget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="alt-font">',
'after_title' => '</h3>',
) );
} );
2019-05-06 21:36:49 +02:00
add_action( 'admin_init', function () {
2019-06-01 00:17:57 +02:00
add_settings_section( 'section-link', 'Links', null, 'theme-options' );
2019-05-06 21:36:49 +02:00
global $links;
foreach ( $links as $link ) {
$id = $link . '_url';
add_settings_field( $id, ucfirst( $link ) . ' Url', function () use ( $id ) { ?>
<input type="text" name="<?= $id ?>" id="<?= $id ?>" value="<?= get_option( $id ); ?>"/>
2019-06-01 00:17:57 +02:00
<?php }, 'theme-options', 'section-link' );
2019-05-06 21:36:49 +02:00
2019-06-01 00:17:57 +02:00
register_setting( 'section-link', $id );
2019-05-06 21:36:49 +02:00
}
2019-06-01 00:17:57 +02:00
add_settings_section( 'section-views', 'View counter', null, 'theme-options' );
add_settings_field( 'view_min', 'Show view counter if views are above:', function () { ?>
<input type="text" name="view_min" id="view_min" value="<?= (int) get_option( 'view_min' ) ?>"/>
<?php }, 'theme-options', 'section-views' );
register_setting( 'section-views', 'view_min' );
2019-05-06 21:36:49 +02:00
} );
function theme_settings_page() { ?>
<div class='wrap'>
<h1>Theme Panel</h1>
<form method="post" action="options.php">
<?php
2019-06-01 00:17:57 +02:00
settings_fields( 'section-link' );
settings_fields( 'section-views' );
2019-05-06 21:36:49 +02:00
do_settings_sections( 'theme-options' );
submit_button();
?>
</form>
</div>
<?php }
function add_theme_menu_item() {
add_menu_page( 'Theme Panel', 'Theme Panel', 'manage_options', 'theme-panel', 'theme_settings_page', null, 99 );
}
add_action( 'admin_menu', 'add_theme_menu_item' );