. ****/ define( 'ARCWV', '1.0.6' ); // current version of the plugin define( 'ARCW_DEBUG', false ); // enable or disable debug (for dev instead of echo or print_r use debug() function) $themes = array( 'calendrier' => 'Calendrier', 'pastel' => 'Pastel', 'classiclight' => 'Classic', 'classicdark' => 'Classic Dark', 'twentytwelve' => 'Twenty Twelve', 'twentythirteen' => 'Twenty Thirteen', 'twentyfourteen' => 'Twenty Fourteen', 'twentyfourteenlight' => 'Twenty Fourteen Light', ); // ACTIVATION require( 'arw-install.php' ); require( 'arw-settings.php' ); require( 'arw-widget.php' ); register_activation_hook( __FILE__, 'archivesCalendar_activation' ); register_uninstall_hook( __FILE__, 'archivesCalendar_uninstall' ); add_action( 'wpmu_new_blog', 'archivesCalendar_new_blog', 10, 6 ); // in case of creation of a new site in WPMU // LOCALISATION add_action( 'init', 'archivesCalendar_init' ); // ADD setting action link add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'arcw_plugin_action_links' ); // Register and enqueue Archives Calendar Widjet jQuery plugin add_action( 'wp_enqueue_scripts', 'archivesCalendar_jquery_plugin' ); // Scripts to be included on Widget configuration page add_action( 'admin_print_scripts-widgets.php', 'arcw_admin_widgets_scripts' ); add_action( 'admin_print_scripts-customize.php', 'arcw_admin_widgets_scripts' ); if ( $archivesCalendar_options['css'] == 1 ) // Archives Calendar Widget Themes CSS { add_action( 'wp_enqueue_scripts', 'archives_calendar_styles' ); } // WIDGET INITIALISATION add_action( 'widgets_init', create_function( '', 'register_widget( "Archives_Calendar" );' ) ); /**** INIT/ENQUEUE FUNCTIONS ****/ function archivesCalendar_init() { load_plugin_textdomain( 'arwloc', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } function arcw_plugin_action_links( $links ) { $links[] = '' . __( 'Settings' ) . ''; return $links; } function archivesCalendar_jquery_plugin() { global $archivesCalendar_options; $jQarcw = $archivesCalendar_options['plugin-init'] == 1 ? '/admin/js/jquery.arcw-init.js' : '/admin/js/jquery.arcw.js'; wp_register_script( 'jquery-arcw', plugins_url( $jQarcw, __FILE__ ), array( "jquery" ), ARCWV ); wp_enqueue_script( 'jquery-arcw' ); } function archives_calendar_styles() { $archivesCalendar_options = get_option( 'archivesCalendar' ); wp_register_style( 'archives-cal-' . $archivesCalendar_options['theme'], plugins_url( 'themes/' . $archivesCalendar_options['theme'] . '.css', __FILE__ ), array(), ARCWV ); wp_enqueue_style( 'archives-cal-' . $archivesCalendar_options['theme'] ); } function arcw_admin_widgets_scripts() { wp_register_style( 'arcw-widget-settings', plugins_url( '/admin/css/widget-settings.css', __FILE__ ), array(), ARCWV ); wp_register_script( 'arcwpWidgetsPage', plugins_url( '/admin/js/widgets-page.js', __FILE__ ), array(), ARCWV ); wp_enqueue_script( 'arcwpWidgetsPage' ); wp_enqueue_style( 'arcw-widget-settings' ); } /***** CHECK MULTISITE NETWORK *****/ if ( ! function_exists( 'isMU' ) ) { function isMU() { if ( function_exists( 'is_multisite' ) && is_multisite() ) { return true; } return false; } } function make_arcw_link( $type = null, $cats = null ) { global $archivesCalendar_options; if ( $archivesCalendar_options['filter'] == 0 ) { return ''; } $attrs = ''; if ( ! empty( $type ) && count( $type ) ) { if ( $type == 'post' ) { $attrs = ''; } else { $attrs .= '?arcw/type/' . $type; } } if ( ! empty( $cats ) ) { if ( $attrs == '' ) { $attrs .= '?arcw/cat/' . $cats; } else { $attrs .= '/cat/' . $cats; } $attrs = str_replace( ' ', '', $attrs ); } return $attrs; } // Activate filter in archives page if ( isset( $archivesCalendar_options['filter'] ) && $archivesCalendar_options['filter'] == 1 ) { add_action( 'pre_get_posts', 'arcw_filter' ); } function arcw_filter( $query ) { if ( ! is_archive() || is_admin() ) { return; } $url = $_SERVER['REQUEST_URI']; $params = explode( '?arcw/', $url ); if ( isset( $params[1] ) ) { $re = "/cat\\/([^\\/]+)/"; preg_match( $re, $params[1], $cats ); if ( $cats[1] ) { $cats = $cats[1]; echo $cats; $query->set( 'cat', $cats ); } $re = "/type\\/([^\\/]+)/"; preg_match( $re, $params[1], $types ); if ( $types[1] ) { $post_types = explode( ',', $types[1] ); print_r( $post_types ); $query->set( 'post_type', $post_types ); if ( isset( $cats ) ) { $query->set( 'tax_query', array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'term_id', 'terms' => explode( ',', $cats ), 'operator' => 'IN', ), ) ); } } } } /** DEBUG FUNCTION **/ if ( ! function_exists( 'debug' ) ) { function debug( $context = "" ) { if ( ARCW_DEBUG === true ) { print_r( $context ); } } }