"5Km","10k"=>"10Km","15k"=>"15km","semimarathon"=>"Semi-Marathon","marathon"=>"Marathon","100k"=>"100Km","24h"=>"24h","cross"=>"Cross","trailurbain"=>"Trail Urbain", "trail"=>"Trail Nature","autre"=>"Autre"); class AgendaRunning { public function __construct(){ //add_action( 'plugins_loaded', array( $this, 'load_textdomain') ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_script_style' ) ); add_action( 'init', array( $this, 'event_post_type'), 0 ); add_action('add_meta_boxes', array( $this, 'event_info_metabox') ); add_action( 'save_post', array( $this, 'save_event_info' ) ); add_filter( 'manage_edit-agenda-running_columns', array( $this, 'custom_columns_head'), 10 ); add_action( 'manage_agenda-running_posts_custom_column', array( $this, 'custom_columns_content'), 10, 2 ); add_filter( 'the_content', array( $this, 'AgendaRunning_single_content') ); add_filter("manage_edit-agenda-running_sortable_columns", array( $this, "agenda_running_sortable_columns"), 10 ); add_filter("request", array( $this, "event_column_orderby"), 10 ); // Include required files $this->includes(); } // Including the widget public function includes(){ include_once ( 'widget-agenda-running.php' ); } public function load_textdomain(){ //load_plugin_textdomain( 'agenda-running', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Enqueueing scripts and styles in the admin * @param int $hook Current page hook */ public function admin_script_style( $hook ) { global $post_type; if ( ( 'post.php' == $hook || 'post-new.php' == $hook ) && ( 'agenda-running' == $post_type ) ) { wp_enqueue_script( 'agenda-running', plugins_url('/js/upcoming-script.js', __FILE__ ), array( 'jquery', 'jquery-ui-datepicker' ), false, true ); wp_enqueue_style('jquery-ui-calendar', plugins_url('css/jquery-ui-1.10.4.custom.min.css', __FILE__)); } } // Register Custom Post Type public function event_post_type() { $labels = array( 'name' => _x( 'AgendaRunning', 'Post Type General Name', 'agenda-running' ), 'singular_name' => _x( 'AgendaRunning', 'Post Type Singular Name', 'agenda-running' ), 'menu_name' => __( 'AgendaRunning', 'agenda-running' ), 'all_items' => __( 'Toutes les dates', 'agenda-running' ), 'view_item' => __( 'Voir la date', 'agenda-running' ), 'add_new_item' => __( 'Ajouter une nouvelle date', 'agenda-running' ), 'add_new' => __( 'Ajouter une date', 'agenda-running' ), 'edit_item' => __( 'Modifier une date', 'agenda-running' ), 'update_item' => __( 'Mettre à jour une date', 'agenda-running' ), 'search_items' => __( 'Rechercher', 'agenda-running' ), 'not_found' => __( 'Aucun élément trouvé', 'agenda-running' ), 'not_found_in_trash' => __( 'Non trouvée dans la corbeille', 'agenda-running' ), ); $args = array( 'label' => __( 'AgendaRunning', 'agenda-running' ), 'description' => __( 'Liste des prochaines dates', 'agenda-running' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-calendar-alt', 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', ); register_post_type( 'agenda-running', $args ); } //Adding metabox for event information public function event_info_metabox() { add_meta_box( 'event-info-metabox', __( 'Informations sur la date', 'agenda-running' ), array( $this, 'render_event_info_metabox'), 'agenda-running','side', 'core' ); } /** * Rendering the metabox for event information * @param object $post The post object */ public function render_event_info_metabox( $post ) { //generate a nonce field global $list_type; wp_nonce_field( basename( __FILE__ ), 'event-info-nonce' ); //get previously saved meta values (if any) $event_date = get_post_meta( $post->ID, 'event-date', true ); $event_lieu = get_post_meta( $post->ID, 'event-lieu', true ); $event_url = get_post_meta( $post->ID, 'event-url', true ); $event_chrono = get_post_meta( $post->ID, 'event-chrono', true ); $event_distance = get_post_meta( $post->ID, 'event-distance', true ); $event_type = get_post_meta( $post->ID, 'event-type', true ); $event_place = get_post_meta( $post->ID, 'event-place', true ); ?>
'event-date', 'orderby' => 'meta_value_num', 'order' => $vars['order'] ) ); } } return $vars; } /** * Custom columns content * @param string $column_name The name of the current column * @param int $post_id The id of the current post */ function custom_columns_content( $column_name, $post_id ) { global $list_type; if ( 'event_date' == $column_name ) { $start_date = get_post_meta( $post_id, 'event-date', true ); if($start_date) echo date( 'd-m-Y', $start_date ); } if ( 'event_lieu' == $column_name ) { $venue = get_post_meta( $post_id, 'event-lieu', true ); echo $venue; } if ( 'event_url' == $column_name ) { $url = get_post_meta( $post_id, 'event-url', true ); echo $url; } if ( 'event_distance' == $column_name ) { $distance = get_post_meta( $post_id, 'event-distance', true ); echo $distance; } if ( 'event_chrono' == $column_name ) { $chrono = get_post_meta( $post_id, 'event-chrono', true ); echo $chrono; } if ( 'event_type' == $column_name ) { $type = get_post_meta( $post_id, 'event-type', true ); echo $list_type[$type]; } if ( 'event_place' == $column_name ) { $place = get_post_meta( $post_id, 'event-place', true ); echo $place; } } function AgendaRunning_single_content( $content ){ if ( is_singular('agenda-running') || is_post_type_archive('agenda-running') ) { global $list_type; $event_lieu = get_post_meta( get_the_ID(), 'event-lieu', true ); $event_distance = get_post_meta( get_the_ID(), 'event-distance', true ); $event_chrono = get_post_meta( get_the_ID(), 'event-chrono', true ); $event_type = get_post_meta( get_the_ID(), 'event-type', true ); if($event_lieu) $event = $event_lieu." "; if($event_type) $event .= $list_type[$event_type]." "; if($event_distance) $event .= "(".$event_distance."km)"; $content .= $event; } return $content; } } $AgendaRunning_lists = new AgendaRunning(); /** * Flushing rewrite rules on plugin activation/deactivation * for better working of permalink structure */ function AgendaRunning_lists_activation_deactivation() { $events = new AgendaRunning(); $events->event_post_type(); flush_rewrite_rules(); } register_activation_hook( __FILE__, 'AgendaRunning_lists_activation_deactivation' ); function get_infos_html($affichage, $data){ global $list_type; $affichage = str_replace("{TITRE}",$data['title'], $affichage); $affichage = str_replace("{DATE}",date("d/m/Y",$data['date']), $affichage); $affichage = str_replace("{JOUR}",date("d",$data['date']), $affichage); $affichage = str_replace("{MOIS}",date("m",$data['date']), $affichage); $affichage = str_replace("{MOISALPHA}",date("M",$data['date']), $affichage); $affichage = str_replace("{ANNEE}",date("Y",$data['date']), $affichage); $affichage = str_replace("{LIEU}",$data['lieu'], $affichage); $affichage = str_replace("{TYPE}",$list_type[$data['type']], $affichage); $affichage = str_replace("{DISTANCE}",$data['distance']."km", $affichage); $affichage = str_replace("{CLASSEMENT}",$data['place'], $affichage); if($data['type'] == "trail" || $data['type'] == "trailurbain" || $data['type'] == "cross") $affichage = str_replace("{TYPEDISTANCE}",$list_type[$data['type']]." ".($data['distance']."km"), $affichage); elseif($data['type'] == "autre") $affichage = str_replace("{TYPEDISTANCE}",($data['distance']."km"), $affichage); else $affichage = str_replace("{TYPEDISTANCE}",($list_type[$data['type']]), $affichage); $affichage = str_replace("{CHRONO}",$data['chrono'], $affichage); $affichage = str_replace("{IMAGE}","