Created
March 10, 2021 10:54
-
-
Save mexiter/2eed116fd4e7653e8e082a478e1f69a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* The admin-specific functionality of the plugin. | |
* | |
* @link http://casino.tables.plugin | |
* @since 1.0.0 | |
* | |
* @package Casino_Tables_Plugin | |
* @subpackage Casino_Tables_Plugin/admin | |
*/ | |
/** | |
* The admin-specific functionality of the plugin. | |
* | |
* Defines the plugin name, version, and two examples hooks for how to | |
* enqueue the admin-specific stylesheet and JavaScript. | |
* | |
* @package Casino_Tables_Plugin | |
* @subpackage Casino_Tables_Plugin/admin | |
* @author Casino Man <[email protected]> | |
*/ | |
class Casino_Tables_Plugin_Admin { | |
/** | |
* The ID of this plugin. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @var string $plugin_name The ID of this plugin. | |
*/ | |
private $plugin_name; | |
/** | |
* The version of this plugin. | |
* | |
* @since 1.0.0 | |
* @access private | |
* @var string $version The current version of this plugin. | |
*/ | |
private $version; | |
/** | |
* Initialize the class and set its properties. | |
* | |
* @since 1.0.0 | |
* @param string $plugin_name The name of this plugin. | |
* @param string $version The version of this plugin. | |
*/ | |
public function __construct( $plugin_name, $version ) { | |
$this->plugin_name = $plugin_name; | |
$this->version = $version; | |
} | |
/** | |
* Register the stylesheets for the admin area. | |
* | |
* @since 1.0.0 | |
*/ | |
public function enqueueAdminStyles() { | |
/** | |
* This function is provided for demonstration purposes only. | |
* | |
* An instance of this class should be passed to the run() function | |
* defined in Casino_Tables_Plugin_Loader as all of the hooks are defined | |
* in that particular class. | |
* | |
* The Casino_Tables_Plugin_Loader will then create the relationship | |
* between the defined hooks and the functions defined in this | |
* class. | |
*/ | |
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/casino-tables-plugin-admin.css', array(), $this->version, 'all' ); | |
} | |
/** | |
* Register the JavaScript for the admin area. | |
* | |
* @since 1.0.0 | |
*/ | |
public function enqueueAdminScripts() { | |
/** | |
* This function is provided for demonstration purposes only. | |
* | |
* An instance of this class should be passed to the run() function | |
* defined in Casino_Tables_Plugin_Loader as all of the hooks are defined | |
* in that particular class. | |
* | |
* The Casino_Tables_Plugin_Loader will then create the relationship | |
* between the defined hooks and the functions defined in this | |
* class. | |
*/ | |
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/casino-tables-plugin-admin.js', array( 'jquery' ), $this->version, false ); | |
} | |
/* /** | |
* Registers Custom Post Type for Casino Data | |
* | |
* @param none | |
* @return object | |
* @author | |
* @copyright | |
*/ | |
// Register Custom Post Type | |
public function registerCasinoPostTypes() { | |
$labels = array( | |
'name' => _x( 'Casinos', 'Post Type General Name', 'casino-tables-plugin' ), | |
'singular_name' => _x( 'Casino', 'Post Type Singular Name', 'casino-tables-plugin' ), | |
'menu_name' => __( 'Casinos', 'casino-tables-plugin' ), | |
'name_admin_bar' => __( 'Casinos', 'casino-tables-plugin' ), | |
'archives' => __( 'Casinos Archives', 'casino-tables-plugin' ), | |
'attributes' => __( 'Casinos Attributes', 'casino-tables-plugin' ), | |
'parent_item_colon' => __( 'Parent Casinos:', 'casino-tables-plugin' ), | |
'all_items' => __( 'All Casinos', 'casino-tables-plugin' ), | |
'add_new_item' => __( 'Add New Casino:', 'casino-tables-plugin' ), | |
'add_new' => __( 'Add New', 'casino-tables-plugin' ), | |
'new_item' => __( 'New Casino', 'casino-tables-plugin' ), | |
'edit_item' => __( 'Edit Casino', 'casino-tables-plugin' ), | |
'update_item' => __( 'Update Casino', 'casino-tables-plugin' ), | |
'view_item' => __( 'View Casino', 'casino-tables-plugin' ), | |
'view_items' => __( 'View Casinos', 'casino-tables-plugin' ), | |
'search_items' => __( 'Search Casino', 'casino-tables-plugin' ), | |
'not_found' => __( 'Not Casino found', 'casino-tables-plugin' ), | |
'not_found_in_trash' => __( 'Not Casino found in Trash', 'casino-tables-plugin' ), | |
'featured_image' => __( 'Featured Casino Image', 'casino-tables-plugin' ), | |
'set_featured_image' => __( 'Set featured Casino image', 'casino-tables-plugin' ), | |
'remove_featured_image' => __( 'Remove featured Casino image', 'casino-tables-plugin' ), | |
'use_featured_image' => __( 'Use as featured Casino image', 'casino-tables-plugin' ), | |
'insert_into_item' => __( 'Insert into Casino', 'casino-tables-plugin' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this Casino', 'casino-tables-plugin' ), | |
'items_list' => __( 'Casinos list', 'casino-tables-plugin' ), | |
'items_list_navigation' => __( 'Casinos list navigation', 'casino-tables-plugin' ), | |
'filter_items_list' => __( 'Filter Casinos list', 'casino-tables-plugin' ), | |
); | |
$args = array( | |
'label' => __( 'Casino', 'casino-tables-plugin' ), | |
'description' => __( 'Casino Data for Top Tables Plugin', 'casino-tables-plugin' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'revisions', 'custom-fields', 'post-formats' ), | |
'taxonomies' => array( 'category', 'post_tag' ), | |
'hierarchical' => false, | |
'public' => false, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-smiley', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => true, | |
'publicly_queryable' => false, | |
'capability_type' => 'page', | |
'show_in_rest' => true, | |
"rewrite" => array( | |
"slug" => "casino", | |
"with_front" => true, | |
), | |
"query_var" => true, | |
); | |
register_post_type( 'casinos', $args ); | |
} | |
/* /** | |
* Register Top TAbles | |
* | |
* @param | |
* @return void | |
* @author | |
* @copyright | |
*/ | |
// Register Custom Post Type | |
public function registerCasinoTablesPostTypes() { | |
$labels = array( | |
'name' => _x( 'Casino Tables', 'Post Type General Name', 'casino-tables-plugin' ), | |
'singular_name' => _x( 'Casino Table', 'Post Type Singular Name', 'casino-tables-plugin' ), | |
'menu_name' => __( 'Casino Tables', 'casino-tables-plugin' ), | |
'name_admin_bar' => __( 'Casino Tables', 'casino-tables-plugin' ), | |
'archives' => __( 'Tables Archives', 'casino-tables-plugin' ), | |
'attributes' => __( 'Tables Attributes', 'casino-tables-plugin' ), | |
'parent_item_colon' => __( 'Parent Table:', 'casino-tables-plugin' ), | |
'all_items' => __( 'All Tables', 'casino-tables-plugin' ), | |
'add_new_item' => __( 'Add New Table:', 'casino-tables-plugin' ), | |
'add_new' => __( 'Add New', 'casino-tables-plugin' ), | |
'new_item' => __( 'New Table', 'casino-tables-plugin' ), | |
'edit_item' => __( 'Edit Table', 'casino-tables-plugin' ), | |
'update_item' => __( 'Update Table', 'casino-tables-plugin' ), | |
'view_item' => __( 'View Table', 'casino-tables-plugin' ), | |
'view_items' => __( 'View Table', 'casino-tables-plugin' ), | |
'search_items' => __( 'Search Table', 'casino-tables-plugin' ), | |
'not_found' => __( 'Not Table found', 'casino-tables-plugin' ), | |
'not_found_in_trash' => __( 'Not Table found in Trash', 'casino-tables-plugin' ), | |
'featured_image' => __( 'Featured Table Image', 'casino-tables-plugin' ), | |
'set_featured_image' => __( 'Set featured Table image', 'casino-tables-plugin' ), | |
'remove_featured_image' => __( 'Remove featured Table image', 'casino-tables-plugin' ), | |
'use_featured_image' => __( 'Use as featured Table image', 'casino-tables-plugin' ), | |
'insert_into_item' => __( 'Insert into Table', 'casino-tables-plugin' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this Table', 'casino-tables-plugin' ), | |
'items_list' => __( 'Table list', 'casino-tables-plugin' ), | |
'items_list_navigation' => __( 'Table list navigation', 'casino-tables-plugin' ), | |
'filter_items_list' => __( 'Filter Table list', 'casino-tables-plugin' ), | |
); | |
$rewrite = array( | |
'slug' => 'casino-tables', | |
'with_front' => true, | |
'pages' => true, | |
'feeds' => true, | |
); | |
$args = array( | |
'label' => __( 'Casino Table', 'casino-tables-plugin' ), | |
'description' => __( 'Top Tables for Casinos', 'casino-tables-plugin' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'revisions', 'custom-fields', 'post-formats' ), | |
'taxonomies' => array( 'category', 'post_tag' ), | |
'hierarchical' => false, | |
'public' => false, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-editor-table', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => true, | |
'publicly_queryable' => false, | |
'rewrite' => $rewrite, | |
'capability_type' => 'page', | |
'show_in_rest' => true, | |
); | |
register_post_type( 'casino-tables', $args ); | |
} | |
/** /** | |
* Casino Table Taxonomies Categories | |
* | |
* @param | |
* @return void | |
* @author | |
* @copyright | |
*/ | |
// Register Custom Taxonomy | |
public function registerCasinoTablesTaxonomies() { | |
$labels = array( | |
'name' => _x( 'Table Categories', 'Taxonomy General Name', 'casino-tables-plugin' ), | |
'singular_name' => _x( 'Table Category', 'Taxonomy Singular Name', 'casino-tables-plugin' ), | |
'menu_name' => __( 'Table Category', 'casino-tables-plugin' ), | |
'all_items' => __( 'All Categories', 'casino-tables-plugin' ), | |
'parent_item' => __( 'Parent Category', 'casino-tables-plugin' ), | |
'parent_item_colon' => __( 'Parent Category:', 'casino-tables-plugin' ), | |
'new_item_name' => __( 'New Category Name', 'casino-tables-plugin' ), | |
'add_new_item' => __( 'Add New Category', 'casino-tables-plugin' ), | |
'edit_item' => __( 'Edit Category', 'casino-tables-plugin' ), | |
'update_item' => __( 'Update Category', 'casino-tables-plugin' ), | |
'view_item' => __( 'View Category', 'casino-tables-plugin' ), | |
'separate_items_with_commas' => __( 'Separate categories with commas', 'casino-tables-plugin' ), | |
'add_or_remove_items' => __( 'Add or remove Categories', 'casino-tables-plugin' ), | |
'choose_from_most_used' => __( 'Choose from the most used Categories', 'casino-tables-plugin' ), | |
'popular_items' => __( 'Popular Categories', 'casino-tables-plugin' ), | |
'search_items' => __( 'Search Categories', 'casino-tables-plugin' ), | |
'not_found' => __( 'Not Category Found', 'casino-tables-plugin' ), | |
'no_terms' => __( 'No Categories', 'casino-tables-plugin' ), | |
'items_list' => __( 'Categories list', 'casino-tables-plugin' ), | |
'items_list_navigation' => __( 'Categories list navigation', 'casino-tables-plugin' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'show_in_rest' => true, | |
); | |
register_taxonomy( 'table-categories', array( 'casino-tables' ), $args ); | |
} | |
/** | |
* Register custom fields | |
* @postType - Table | |
* | |
* @field - Header Title @slug - header_title | |
* @field - Header Background color @slug - bg_title_color | |
* @field - Casinos @slug - casinos | |
*/ | |
public function acfRegisterRelationshipFields() { | |
if(function_exists("acf_add_local_field_group")) { | |
acf_add_local_field_group(array( | |
'id' => 'table_casinos', | |
'title' => 'Table Details', | |
'fields' => array( | |
array( | |
'key' => 'field_59ef14678f49712ax34', | |
'label' => 'Casino Table Title', | |
'name' => 'header_title', | |
'type' => 'text', | |
'default_value' => '', | |
'instructions' => 'Please insert the header title', | |
'placeholder' => 'Best Casino Reviews Table', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
array( | |
'key' => 'field_5aad2a1a65303123', | |
'label' => 'Add Casinos', | |
'name' => 'casinos', | |
'type' => 'relationship', | |
'instructions' => 'Add casinos from the left to the right table by clicking on the post. </br> You can also order the casinos via drag and drop', | |
'return_format' => 'object', | |
'post_type' => array ( | |
'0' => 'casinos', | |
), | |
'taxonomy' => array ( | |
0 => 'all', | |
), | |
'filters' => array ( | |
0 => 'search', | |
), | |
'result_elements' => array ( | |
0 => 'post_type', | |
1 => 'post_title', | |
), | |
'max' => '', | |
), | |
), | |
'location' => array ( | |
array ( | |
array ( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'casino-tables', | |
'order_no' => 0, | |
'group_no' => 0, | |
), | |
), | |
), | |
'options' => array ( | |
'position' => 'normal', | |
'layout' => 'box', | |
'hide_on_screen' => array ( | |
), | |
), | |
'menu_order' => 0, | |
)); | |
} | |
} | |
/** | |
* | |
* Register custom fields | |
* @postType - Casino | |
* | |
* @field - Casinos Logo @slug - logo | |
* @field - Bonus text @slug - bonus_text | |
* @field - Rating @slug - rating | |
* @field - Term and Conditions link @slug - terms_and_conditions_link | |
* @field - Affiliate tracker link @slug - affiliate_tracker_link | |
* @field - Affiliate tracker button color @slug - bg_affiliate_tracker_color | |
* @field - Review Link @slug - review_link | |
*/ | |
public function acfRegisterCasinoFields() { | |
if (function_exists("acf_add_local_field_group")) { | |
acf_add_local_field_group( array( | |
'id' => 'acf_casino_details', | |
'title' => 'Casino Details', | |
'fields' => array( | |
array( | |
'key' => 'field_5eebcb27347b3', | |
'label' => 'Casino Name', | |
'name' => 'casino_name', | |
'type' => 'text', | |
'instructions' => 'Add the original Casino Name here: ex. 888', | |
'required' => 1, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '40', | |
'class' => 'cm-casino-name-admin', | |
'id' => '', | |
), | |
'default_value' => '888 Casino', | |
'placeholder' => 'Enter Casino Name Here', | |
'prepend' => '', | |
'append' => '', | |
'maxlength' => '', | |
), | |
array ( | |
'key' => 'field_5a0079f1c7ec412ab', | |
'label' => 'Casino\'s Logo', | |
'name' => 'logo', | |
'type' => 'image', | |
'instructions' => 'Please upload the casino\'s logo', | |
'wrapper' => array( | |
'width' => '40', | |
'class' => 'cm-casino-logo-admin', | |
'id' => '', | |
), | |
'default_value' => '', | |
'save_format' => 'object', | |
'preview_size' => 'medium', | |
'library' => 'all', | |
'required' => 0, | |
), | |
array( | |
'key' => 'field_5eee952154dd6', | |
'label' => 'Star Rating', | |
'name' => 'star_rating', | |
'type' => 'number', | |
'instructions' => 'Add the star rating for the casino in the form of a decimal number. ex. 4.8 out of 5', | |
'required' => 0, | |
'conditional_logic' => 0, | |
'wrapper' => array( | |
'width' => '20', | |
'class' => 'cm-casino-rating-admin', | |
'id' => '', | |
), | |
'default_value' => 5, | |
'placeholder' => 'Please choose casino rating between 1 and 5', | |
'prepend' => '', | |
'append' => 'stars', | |
'min' => 0, | |
'max' => 5, | |
'step' => '0.1', | |
), | |
array( | |
'key' => 'field_59ef14678f497', | |
'label' => 'Bonus Text', | |
'name' => 'bonus_text', | |
'type' => 'text', | |
'default_value' => '', | |
'instructions' => 'Please insert the bonus text', | |
'placeholder' => 'ex. €30 in free bets ', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
'required' => 1, | |
), | |
array ( | |
'key' => 'field_5dc17875f5da4', | |
'label' => 'Bonus list(USP List)', | |
'name' => 'bonus_list', | |
'type' => 'textarea', | |
'instructions' => 'To add a lis item in your list please use the pipe " | " . That will generate a list. ', | |
'default_value' => '', | |
'placeholder' => 'Example: USP 1| USP2| USP3 will create a list with those 3 items', | |
'prepend' => '', | |
'append' => '', | |
'formatting' => 'html', | |
'maxlength' => '', | |
), | |
array( | |
'key' => 'field_59ef14678f498ab', | |
'label' => 'Terms and Conditions link', | |
'name' => 'terms_and_conditions_link', | |
'type' => 'text', | |
'default_value' => '', | |
'instructions' => 'Please insert the Terms and Conditions link', | |
'placeholder' => 'http://google.com', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
array( | |
'key' => 'field_59ef14678f49bc', | |
'label' => 'Affiliate tracker link', | |
'name' => 'affiliate_tracker_link', | |
'type' => 'url', | |
'default_value' => '', | |
'instructions' => 'Please insert the Affiliate tracker link', | |
'placeholder' => 'http://google.com', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
'required' => 1, | |
), | |
array( | |
'key' => 'field_59ef14678f50bc', | |
'label' => 'Review link', | |
'name' => 'review_link', | |
'type' => 'text', | |
'default_value' => '', | |
'instructions' => 'Please insert the Review link', | |
'placeholder' => 'http://google.com', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
array( | |
'key' => 'field_59ef14678fe3bc', | |
'label' => 'Casino Tag', | |
'name' => 'casino_tag', | |
'type' => 'text', | |
'default_value' => '', | |
'instructions' => 'Please insert the casino tag', | |
'placeholder' => 'New Casino', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
array( | |
'key' => 'field_59ef14321fe3bc', | |
'label' => 'Casino Caption', | |
'name' => 'casino_caption', | |
'type' => 'textarea', | |
'default_value' => '', | |
'instructions' => 'Please insert the casino Caption', | |
'placeholder' => 'Large hotels can be cool, trendy and chic, but they can’t be boutique. Just as the word is used to describe small, design-led specialist shops, so it applies to hotels.', | |
'prepend' => '', | |
'append' => '', | |
'min' => '', | |
'max' => '', | |
'step' => '', | |
), | |
), | |
'location' => array( | |
array( | |
array( | |
'param' => 'post_type', | |
'operator' => '==', | |
'value' => 'casinos', | |
'order_no' => 0, | |
'group_no' => 0, | |
), | |
), | |
), | |
'options' => array( | |
'position' => 'normal', | |
'layout' => 'box', | |
'hide_on_screen' => array(), | |
), | |
'menu_order' => 0, | |
) ); | |
} | |
} | |
/** | |
* Generate Metabox Placeholder for the shortocode | |
* @postType - Table | |
*/ | |
public function renderMetaBoxOption() { | |
add_meta_box('customer-meta', 'Table Shortcode', array($this, 'displayMetaBoxOptions'), 'casino-tables', 'side', 'high'); | |
} | |
/** | |
* Display the Metabox for the shortocode | |
* @postType - Table | |
*/ | |
public function displayMetaBoxOptions() { | |
global $post; | |
$terms = get_the_terms($post->ID, 'table-categories'); | |
// $related = get_field( 'casinos', get_the_ID() ); | |
// echo '<pre>'; | |
// var_dump($related); | |
// echo '<pre>'; | |
$ids = get_field('casinos', false, false); | |
$countIds= count($ids); | |
// echo '<pre>'; | |
// var_dump($ids); | |
// echo '<pre>'; | |
if (!empty($terms)) { | |
foreach($terms as $term) { | |
if(!empty($term->slug)) { | |
$termsSlugs[] = $term->slug; | |
} | |
} | |
} | |
//return or echo | |
echo '[casino-table table_id="' .$post->ID. '" limit="" title="' . get_field('header_title') .'"' . (!empty($termsSlugs) ? 'category="' .implode(',', $termsSlugs) . '"' : '') . ']'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment