refactoeing
This commit is contained in:
parent
6dff179799
commit
021bbd6d8a
|
|
@ -4,18 +4,20 @@ define('WP_DEBUG', true);
|
||||||
define('WP_DEBUG_LOG', true);
|
define('WP_DEBUG_LOG', true);
|
||||||
define('WP_DEBUG_DISPLAY', false);
|
define('WP_DEBUG_DISPLAY', false);
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
// ##### Syntax
|
// ##### Syntax
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
<?php if ($var) : ?>
|
<?php if ($var) : ?>
|
||||||
<p><?php echo $var['title'] ?></p>
|
<p><?php echo $var['title'] ?></p>
|
||||||
|
<?php else : ?>
|
||||||
|
<p>Alternative content when $var is falsy or null</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
<?php if ($var) { ?>
|
<?php if ($var) { ?>
|
||||||
<p><?php echo $var['title'] ?></p>
|
<p><?php echo $var['title'] ?></p>
|
||||||
<?php }; ?>
|
<?php }; ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,9 +35,39 @@ get_template_part(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
/** ------------------------------
|
########################## WP LOOOP
|
||||||
|
?>
|
||||||
|
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
|
||||||
|
<?php the_content(); ?>
|
||||||
|
<?php endwhile; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------
|
||||||
QUERIES
|
QUERIES
|
||||||
------------------------------*/
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// ##### Query 🡒 Classic Query
|
||||||
|
|
||||||
|
$args = array('posts_per_page' => 6, 'post_type' => 'post');
|
||||||
|
$the_query = new WP_Query($args);
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
if ($the_query->have_posts()) {
|
||||||
|
echo '<ul>';
|
||||||
|
while ($the_query->have_posts()) {
|
||||||
|
$the_query->the_post();
|
||||||
|
echo '<li>' . get_the_title() . '</li>';
|
||||||
|
}
|
||||||
|
echo '</ul>';
|
||||||
|
} else {
|
||||||
|
// no posts found
|
||||||
|
}
|
||||||
|
/* Restore original Post Data */
|
||||||
|
wp_reset_postdata();
|
||||||
|
|
||||||
|
|
||||||
// ##### Query 🡒 Get posts
|
// ##### Query 🡒 Get posts
|
||||||
|
|
||||||
|
|
@ -76,34 +108,17 @@ $args = array(
|
||||||
|
|
||||||
$recent_activites = wp_get_recent_posts($args);
|
$recent_activites = wp_get_recent_posts($args);
|
||||||
|
|
||||||
// ##### Query 🡒 Wordpress Global Query Loop
|
|
||||||
|
|
||||||
$args = array('posts_per_page' => 6, 'post_type' => 'post');
|
/* -----------------------------------------------------------
|
||||||
$the_query = new WP_Query($args);
|
|
||||||
|
|
||||||
|
|
||||||
if ($the_query->have_posts()) {
|
|
||||||
echo '<ul>';
|
|
||||||
while ($the_query->have_posts()) {
|
|
||||||
$the_query->the_post();
|
|
||||||
echo '<li>' . get_the_title() . '</li>';
|
|
||||||
}
|
|
||||||
echo '</ul>';
|
|
||||||
} else {
|
|
||||||
// no posts found
|
|
||||||
}
|
|
||||||
/* Restore original Post Data */
|
|
||||||
wp_reset_postdata();
|
|
||||||
|
|
||||||
/** ------------------------------
|
|
||||||
POST DATES
|
POST DATES
|
||||||
------------------------------*/
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
$post_date = date_i18n('j F Y', strtotime($post['post_date']));
|
$post_date = date_i18n('j F Y', strtotime($post['post_date']));
|
||||||
|
|
||||||
|
|
||||||
/** ------------------------------
|
/* -----------------------------------------------------------
|
||||||
URL
|
URL
|
||||||
------------------------------*/
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
// ##### URL 🡒 Home Url
|
// ##### URL 🡒 Home Url
|
||||||
echo home_url('/admission/');
|
echo home_url('/admission/');
|
||||||
|
|
@ -112,66 +127,63 @@ echo home_url('/admission/');
|
||||||
echo site_url('/admission/', 'https');
|
echo site_url('/admission/', 'https');
|
||||||
|
|
||||||
|
|
||||||
/** ------------------------------
|
/* -----------------------------------------------------------
|
||||||
ENABLE SVG
|
ENABLE SVG
|
||||||
------------------------------*/
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* <?xml version="1.0" encoding="utf-8"?> */
|
/* <?xml version="1.0" encoding="utf-8"?> */
|
||||||
|
|
||||||
function cc_mime_types($mimes)
|
function cc_mime_types($mimes)
|
||||||
{
|
{
|
||||||
$mimes['svg'] = 'image/svg+xml';
|
$mimes['svg'] = 'image/svg+xml';
|
||||||
return $mimes;
|
return $mimes;
|
||||||
}
|
}
|
||||||
add_filter('upload_mimes', 'cc_mime_types');
|
add_filter('upload_mimes', 'cc_mime_types');
|
||||||
|
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------
|
||||||
/** ------------------------------
|
INIT WIDGET
|
||||||
INIT WIDGET
|
-----------------------------------------------------------*/
|
||||||
------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
function tailwind_widgets_init()
|
function tailwind_widgets_init()
|
||||||
{
|
{
|
||||||
register_sidebar(
|
register_sidebar(
|
||||||
array(
|
array(
|
||||||
'name' => esc_html__('Discover_next', 'tailwind'),
|
'name' => esc_html__('Discover_next', 'tailwind'),
|
||||||
'id' => 'discover_next',
|
'id' => 'discover_next',
|
||||||
'description' => esc_html__('Add widgets here.', 'tailwind'),
|
'description' => esc_html__('Add widgets here.', 'tailwind'),
|
||||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||||
'after_widget' => '</section>',
|
'after_widget' => '</section>',
|
||||||
'before_title' => '<h2 class="widget-title">',
|
'before_title' => '<h2 class="widget-title">',
|
||||||
'after_title' => '</h2>',
|
'after_title' => '</h2>',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** ------------------------------
|
/* -----------------------------------------------------------
|
||||||
POSTS
|
POSTS
|
||||||
------------------------------*/
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
// Change Defaults Posts to "News" in menu bar
|
// Change Defaults Posts to "News" in menu bar
|
||||||
function cp_change_post_object()
|
function cp_change_post_object()
|
||||||
{
|
{
|
||||||
$get_post_type = get_post_type_object('post');
|
$get_post_type = get_post_type_object('post');
|
||||||
|
|
||||||
$labels = $get_post_type->labels;
|
$labels = $get_post_type->labels;
|
||||||
$labels->name = 'News';
|
$labels->name = 'News';
|
||||||
$labels->singular_name = 'News';
|
$labels->singular_name = 'News';
|
||||||
$labels->add_new = 'Add News';
|
$labels->add_new = 'Add News';
|
||||||
$labels->add_new_item = 'Add News';
|
$labels->add_new_item = 'Add News';
|
||||||
$labels->edit_item = 'Edit News';
|
$labels->edit_item = 'Edit News';
|
||||||
$labels->new_item = 'News';
|
$labels->new_item = 'News';
|
||||||
$labels->view_item = 'View News';
|
$labels->view_item = 'View News';
|
||||||
$labels->search_items = 'Search News';
|
$labels->search_items = 'Search News';
|
||||||
$labels->not_found = 'No News found';
|
$labels->not_found = 'No News found';
|
||||||
$labels->not_found_in_trash = 'No News found in Trash';
|
$labels->not_found_in_trash = 'No News found in Trash';
|
||||||
$labels->all_items = 'All News';
|
$labels->all_items = 'All News';
|
||||||
$labels->menu_name = 'News';
|
$labels->menu_name = 'News';
|
||||||
$labels->name_admin_bar = 'News';
|
$labels->name_admin_bar = 'News';
|
||||||
}
|
}
|
||||||
add_action('init', 'cp_change_post_object');
|
add_action('init', 'cp_change_post_object');
|
||||||
|
|
||||||
|
|
@ -181,29 +193,87 @@ add_action('init', 'cp_change_post_object');
|
||||||
function change_menu_icon()
|
function change_menu_icon()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Access global variables.
|
// Access global variables.
|
||||||
global $menu;
|
global $menu;
|
||||||
|
|
||||||
foreach ($menu as $key => $val) {
|
foreach ($menu as $key => $val) {
|
||||||
|
|
||||||
if (__('News', 'plugin-name') == $val[0]) {
|
if (__('News', 'plugin-name') == $val[0]) {
|
||||||
$menu[$key][6] = 'dashicons-welcome-widgets-menus';
|
$menu[$key][6] = 'dashicons-welcome-widgets-menus';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action('admin_menu', 'change_menu_icon');
|
add_action('admin_menu', 'change_menu_icon');
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------
|
||||||
|
HIDE EDITOR ON SPECIFIC PAGE
|
||||||
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
/** ------------------------------
|
|
||||||
HIDE EDITOR ON SPECIFIC PAGE
|
|
||||||
------------------------------*/
|
|
||||||
function remove_editor_init()
|
function remove_editor_init()
|
||||||
{
|
{
|
||||||
if (isset($_GET['post'])) {
|
if (isset($_GET['post'])) {
|
||||||
$id = $_GET['post'];
|
$id = $_GET['post'];
|
||||||
if ($id == 7) {
|
if ($id == 7) {
|
||||||
remove_post_type_support('page', 'editor');
|
remove_post_type_support('page', 'editor');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action('init', 'remove_editor_init');
|
add_action('init', 'remove_editor_init');
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------
|
||||||
|
METABOX
|
||||||
|
-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
// ###### REGISTER METABOX — SPECTACLES DATE DE CREA ######
|
||||||
|
function add_spectacles_metabox()
|
||||||
|
{
|
||||||
|
$screens = ['spectacles'];
|
||||||
|
foreach ($screens as $screen) {
|
||||||
|
add_meta_box(
|
||||||
|
'add_spectacles_creationdate_metabox', // Unique ID
|
||||||
|
'Création', // Box title
|
||||||
|
'spectacles_custom_metabox_html', // Content callback, must be of type callable
|
||||||
|
$screen, // Post type
|
||||||
|
'side' // 'side' pour le coté, 'normal' ou rien pour en side
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('add_meta_boxes', 'add_spectacles_metabox');
|
||||||
|
|
||||||
|
|
||||||
|
// ###### METABOX CONTENT DESCRIPTION — SPECTACLES CREATION ######
|
||||||
|
function spectacles_custom_metabox_html($post)
|
||||||
|
{
|
||||||
|
$date_creation = get_post_meta($post->ID, '_date_crea_field', true);
|
||||||
|
$encreation = get_post_meta($post->ID, '_encreation_field', true);
|
||||||
|
?>
|
||||||
|
<label for="date_crea_field"><b>Date de création</b></label>
|
||||||
|
<input name="date_crea_field" type="number" id="date_crea_field" value="<?php echo $date_creation ?>">
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p><b>Le spectacle est en cours de création ?</b></p>
|
||||||
|
<input type="checkbox" id="encreation_field" name="encreation_field" <?php echo $encreation ? 'checked' : '' ?>>
|
||||||
|
<label for="encreation_field">Yes ! C'est en cours de création 🔥 </label>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
// ###### METABOX HANDLE SAVE — SPECTACLES DATE DE CREA ######
|
||||||
|
function date_crea_save_postdata($post_id)
|
||||||
|
{
|
||||||
|
if (array_key_exists('date_crea_field', $_POST)) {
|
||||||
|
update_post_meta(
|
||||||
|
$post_id,
|
||||||
|
'_date_crea_field',
|
||||||
|
$_POST['date_crea_field']
|
||||||
|
);
|
||||||
|
update_post_meta(
|
||||||
|
$post_id,
|
||||||
|
'_encreation_field',
|
||||||
|
$_POST['encreation_field']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('save_post', 'date_crea_save_postdata');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user