<commit_before><?php
/*
Plugin Name: StartUp CPT Testimonials
Description: Le plugin pour activer le Custom Post Testimonials
Author: <NAME>
Version: 1.0.0
Text Domain: startup-cpt-testimonials
Domain Path: /languages
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

//Include this to check if a plugin is activated with is_plugin_active
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

//GitHub Plugin Updater
function startup_cpt_testimonials_updater() {
	include_once 'lib/updater.php';
	//define( 'WP_GITHUB_FORCE_UPDATE', true );
	if ( is_admin() ) {
		$config = array(
			'slug' => plugin_basename( __FILE__ ),
			'proper_folder_name' => 'startup-cpt-testimonials',
			'api_url' => 'https://api.github.com/repos/yozzi/startup-cpt-testimonials',
			'raw_url' => 'https://raw.github.com/yozzi/startup-cpt-testimonials/master',
			'github_url' => 'https://github.com/yozzi/startup-cpt-testimonials',
			'zip_url' => 'https://github.com/yozzi/startup-cpt-testimonials/archive/master.zip',
			'sslverify' => true,
			'requires' => '3.0',
			'tested' => '3.3',
			'readme' => 'README.md',
			'access_token' => '',
		);
		new WP_GitHub_Updater( $config );
	}
}

//add_action( 'init', 'startup_cpt_testimonials_updater' );

//CPT
function startup_cpt_testimonials() {
	$labels = array(
		'name'                => _x( 'Testimonials', 'Post Type General Name', 'startup-cpt-testimonials' ),
		'singular_name'       => _x( 'Testimonial', 'Post Type Singular Name', 'startup-cpt-testimonials' ),
		'menu_name'           => __( 'Testimonials', 'startup-cpt-testimonials' ),
		'name_admin_bar'      => __( 'Testimonials', 'startup-cpt-testimonials' ),
		'parent_item_colon'   => __( 'Parent Item:', 'startup-cpt-testimonials' ),
		'all_items'           => __( 'All Items', 'startup-cpt-testimonials' ),
		'add_new_item'        => __( 'Add New Item', 'startup-cpt-testimonials' ),
		'add_new'             => __( 'Add New', 'startup-cpt-testimonials' ),
		'new_item'            => __( 'New Item', 'startup-cpt-testimonials' ),
		'edit_item'           => __( 'Edit Item', 'startup-cpt-testimonials' ),
		'update_item'         => __( 'Update Item', 'startup-cpt-testimonials' ),
		'view_item'           => __( 'View Item', 'startup-cpt-testimonials' ),
		'search_items'        => __( 'Search Item', 'startup-cpt-testimonials' ),
		'not_found'           => __( 'Not found', 'startup-cpt-testimonials' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'startup-cpt-testimonials' )
	);
	$args = array(
		'label'               => __( 'testimonials', 'startup-cpt-testimonials' ),
		'labels'              => $labels,
		'supports'            => array( 'title', 'editor', 'revisions' ),
		'hierarchical'        => true,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'menu_position'       => 5,
		'menu_icon'           => 'dashicons-format-chat',
		'show_in_admin_bar'   => false,
		'show_in_nav_menus'   => false,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => true,
		'publicly_queryable'  => true,
        'capability_type'     => array('testimonial','testimonials'),
        'map_meta_cap'        => true
	);
	register_post_type( 'testimonials', $args );
}

add_action( 'init', 'startup_cpt_testimonials', 0 );

//Flusher les permalink à l'activation du plugin pour qu'ils fonctionnent sans mise à jour manuelle
function startup_cpt_testimonials_rewrite_flush() {
    startup_cpt_testimonials();
    flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'startup_cpt_testimonials_rewrite_flush' );

// Capabilities
function startup_cpt_testimonials_caps() {	
	$role_admin = get_role( 'administrator' );
	$role_admin->add_cap( 'edit_testimonial' );
	$role_admin->add_cap( 'read_testimonial' );
	$role_admin->add_cap( 'delete_testimonial' );
	$role_admin->add_cap( 'edit_others_testimonials' );
	$role_admin->add_cap( 'publish_testimonials' );
	$role_admin->add_cap( 'edit_testimonials' );
	$role_admin->add_cap( 'read_private_testimonials' );
	$role_admin->add_cap( 'delete_testimonials' );
	$role_admin->add_cap( 'delete_private_testimonials' );
	$role_admin->add_cap( 'delete_published_testimonials' );
	$role_admin->add_cap( 'delete_others_testimonials' );
	$role_admin->add_cap( 'edit_private_testimonials' );
	$role_admin->add_cap( 'edit_published_testimonials' );
}

register_activation_hook( __FILE__, 'startup_cpt_testimonials_caps' );

// Shortcode
function startup_cpt_testimonials_shortcode( $atts ) {

	// Attributes
    $atts = shortcode_atts(array(
            'bg' => '#fff'
        ), $atts);
    
	// Code
        ob_start();
        require get_template_directory() . '/template-parts/content-testimonials.php';
        return ob_get_clean();    
}

add_shortcode( 'testimonials', 'startup_cpt_testimonials_shortcode' );

// Shortcode UI
/**
 * Detection de Shortcake. Identique dans tous les plugins.
 */
if ( !function_exists( 'shortcode_ui_detection' ) ) {
    function shortcode_ui_detection() {
        if ( !function_exists( 'shortcode_ui_register_for_shortcode' ) ) {
            add_action( 'admin_notices', 'shortcode_ui_notice' );
        }
    }

    function shortcode_ui_notice() {
        if ( current_user_can( 'activate_plugins' ) ) {
            echo '<div class="error message"><p>' . __( 'Shortcake plugin must be active to use fast shortcodes.', 'startup-cpt-testimonials' ) . '</p></div>';
        }
    }

    add_action( 'init', 'shortcode_ui_detection' );
}

function startup_cpt_testimonials_shortcode_ui() {

    shortcode_ui_register_for_shortcode(
        'testimonials',
        array(
            'label' => esc_html__( 'Testimonials', 'startup-cpt-testimonials' ),<commit_msg>Message id template file not found<commit_after><?php
/*
Plugin Name: StartUp CPT Testimonials
Description: Le plugin pour activer le Custom Post Testimonials
Author: <NAME>
Version: 1.0.0
Text Domain: startup-cpt-testimonials
Domain Path: /languages
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

//Include this to check if a plugin is activated with is_plugin_active
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

//GitHub Plugin Updater
function startup_cpt_testimonials_updater() {
	include_once 'lib/updater.php';
	//define( 'WP_GITHUB_FORCE_UPDATE', true );
	if ( is_admin() ) {
		$config = array(
			'slug' => plugin_basename( __FILE__ ),
			'proper_folder_name' => 'startup-cpt-testimonials',
			'api_url' => 'https://api.github.com/repos/yozzi/startup-cpt-testimonials',
			'raw_url' => 'https://raw.github.com/yozzi/startup-cpt-testimonials/master',
			'github_url' => 'https://github.com/yozzi/startup-cpt-testimonials',
			'zip_url' => 'https://github.com/yozzi/startup-cpt-testimonials/archive/master.zip',
			'sslverify' => true,
			'requires' => '3.0',
			'tested' => '3.3',
			'readme' => 'README.md',
			'access_token' => '',
		);
		new WP_GitHub_Updater( $config );
	}
}

//add_action( 'init', 'startup_cpt_testimonials_updater' );

//CPT
function startup_cpt_testimonials() {
	$labels = array(
		'name'                => _x( 'Testimonials', 'Post Type General Name', 'startup-cpt-testimonials' ),
		'singular_name'       => _x( 'Testimonial', 'Post Type Singular Name', 'startup-cpt-testimonials' ),
		'menu_name'           => __( 'Testimonials', 'startup-cpt-testimonials' ),
		'name_admin_bar'      => __( 'Testimonials', 'startup-cpt-testimonials' ),
		'parent_item_colon'   => __( 'Parent Item:', 'startup-cpt-testimonials' ),
		'all_items'           => __( 'All Items', 'startup-cpt-testimonials' ),
		'add_new_item'        => __( 'Add New Item', 'startup-cpt-testimonials' ),
		'add_new'             => __( 'Add New', 'startup-cpt-testimonials' ),
		'new_item'            => __( 'New Item', 'startup-cpt-testimonials' ),
		'edit_item'           => __( 'Edit Item', 'startup-cpt-testimonials' ),
		'update_item'         => __( 'Update Item', 'startup-cpt-testimonials' ),
		'view_item'           => __( 'View Item', 'startup-cpt-testimonials' ),
		'search_items'        => __( 'Search Item', 'startup-cpt-testimonials' ),
		'not_found'           => __( 'Not found', 'startup-cpt-testimonials' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'startup-cpt-testimonials' )
	);
	$args = array(
		'label'               => __( 'testimonials', 'startup-cpt-testimonials' ),
		'labels'              => $labels,
		'supports'            => array( 'title', 'editor', 'revisions' ),
		'hierarchical'        => true,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'menu_position'       => 5,
		'menu_icon'           => 'dashicons-format-chat',
		'show_in_admin_bar'   => false,
		'show_in_nav_menus'   => false,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => true,
		'publicly_queryable'  => true,
        'capability_type'     => array('testimonial','testimonials'),
        'map_meta_cap'        => true
	);
	register_post_type( 'testimonials', $args );
}

add_action( 'init', 'startup_cpt_testimonials', 0 );

//Flusher les permalink à l'activation du plugin pour qu'ils fonctionnent sans mise à jour manuelle
function startup_cpt_testimonials_rewrite_flush() {
    startup_cpt_testimonials();
    flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'startup_cpt_testimonials_rewrite_flush' );

// Capabilities
function startup_cpt_testimonials_caps() {	
	$role_admin = get_role( 'administrator' );
	$role_admin->add_cap( 'edit_testimonial' );
	$role_admin->add_cap( 'read_testimonial' );
	$role_admin->add_cap( 'delete_testimonial' );
	$role_admin->add_cap( 'edit_others_testimonials' );
	$role_admin->add_cap( 'publish_testimonials' );
	$role_admin->add_cap( 'edit_testimonials' );
	$role_admin->add_cap( 'read_private_testimonials' );
	$role_admin->add_cap( 'delete_testimonials' );
	$role_admin->add_cap( 'delete_private_testimonials' );
	$role_admin->add_cap( 'delete_published_testimonials' );
	$role_admin->add_cap( 'delete_others_testimonials' );
	$role_admin->add_cap( 'edit_private_testimonials' );
	$role_admin->add_cap( 'edit_published_testimonials' );
}

register_activation_hook( __FILE__, 'startup_cpt_testimonials_caps' );

// Shortcode
function startup_cpt_testimonials_shortcode( $atts ) {

	// Attributes
    $atts = shortcode_atts(array(
            'bg' => '#fff'
        ), $atts);
    
	// Code
    ob_start();
    if ( function_exists( 'startup_reloaded_setup' ) ) {
        require get_template_directory() . '/template-parts/content-testimonials.php';
    } else {
        echo 'Should <a href="https://github.com/yozzi/startup-reloaded" target="_blank">install StartUp Reloaded Theme</a> to make things happen...';
    }
    return ob_get_clean();    
}

add_shortcode( 'testimonials', 'startup_cpt_testimonials_shortcode' );

// Shortcode UI
/**
 * Detection de Shortcake. Identique dans tous les plugins.
 */
if ( !function_exists( 'shortcode_ui_detection' ) ) {
    function shortcode_ui_detection() {
        if ( !function_exists( 'shortcode_ui_register_for_shortcode' ) ) {
            add_action( 'admin_notices', 'shortcode_ui_notice' );
        }
    }

    function shortcode_ui_notice() {
        if ( current_user_can( 'activate_plugins' ) ) {
            echo '<div class="error message"><p>' . __( 'Shortcake plugin must be active to use fast shortcodes.', 'startup-cpt-testimonials' ) . '</p></div>';
        }
    }

    add_action( 'init', 'shortcode_ui_detection' );
}

function startup_cpt_testimonials_shortcode_ui() {

    shortcode_ui_register_for_shortcode(
        'testimonials',
        array(
            'label' => esc_html__( 'Testimonials', 'startup-cpt-testimonials' ),
{'fraction_non_alphanumeric': 0.15246179966044143, 'fraction_numerical': 0.0015280135823429542, 'mean_word_length': 3.6436736302719748, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 131, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '942896', 'n_tokens_mistral': 4451, 'n_tokens_neox': 4211, 'n_words': 707}