Dependencies.php
138 lines
| 1 | <?php namespace NestedPages\Activation; |
| 2 | |
| 3 | use NestedPages\Entities\PostType\PostTypeRepository; |
| 4 | /** |
| 5 | * Plugin JS & CSS Dependencies |
| 6 | */ |
| 7 | class Dependencies { |
| 8 | |
| 9 | /** |
| 10 | * Plugin Directory |
| 11 | */ |
| 12 | private $plugin_dir; |
| 13 | |
| 14 | /** |
| 15 | * Plugin Version |
| 16 | */ |
| 17 | private $plugin_version; |
| 18 | |
| 19 | /** |
| 20 | * Post Type Repository |
| 21 | */ |
| 22 | private $post_type_repo; |
| 23 | |
| 24 | |
| 25 | public function __construct() |
| 26 | { |
| 27 | $this->post_type_repo = new PostTypeRepository; |
| 28 | $this->setPluginVersion(); |
| 29 | add_action( 'admin_enqueue_scripts', array($this, 'styles') ); |
| 30 | add_action( 'admin_enqueue_scripts', array($this, 'scripts') ); |
| 31 | $this->plugin_dir = plugins_url() . '/wp-nested-pages'; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Set the Plugin Version |
| 37 | */ |
| 38 | private function setPluginVersion() |
| 39 | { |
| 40 | global $np_version; |
| 41 | $this->plugin_version = $np_version; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /** |
| 46 | * Admin Styles |
| 47 | */ |
| 48 | public function styles() |
| 49 | { |
| 50 | wp_enqueue_style( |
| 51 | 'nestedpages', |
| 52 | $this->plugin_dir . '/assets/css/nestedpages.css', |
| 53 | array(), |
| 54 | $this->plugin_version |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /** |
| 60 | * Admin Scripts required by plugin |
| 61 | * Only Loads on the Nested Pages screen |
| 62 | */ |
| 63 | public function scripts() |
| 64 | { |
| 65 | $screen = get_current_screen(); |
| 66 | global $np_env; |
| 67 | if ( strpos( $screen->id, 'nestedpages' ) ) : |
| 68 | wp_enqueue_script('suggest'); |
| 69 | wp_enqueue_script('jquery-ui-core'); |
| 70 | wp_enqueue_script('jquery-ui-sortable'); |
| 71 | wp_enqueue_script('jquery-ui-datepicker'); |
| 72 | wp_enqueue_script( |
| 73 | 'bootstrap-modal', |
| 74 | $this->plugin_dir . '/assets/js/lib/bs-modal.js', |
| 75 | array('jquery'), |
| 76 | '1.0' |
| 77 | ); |
| 78 | wp_enqueue_script( |
| 79 | 'ui-touch-punch', |
| 80 | $this->plugin_dir . '/assets/js/lib/jquery.ui.touch-punch.min.js', |
| 81 | array('jquery', 'jquery-ui-sortable'), |
| 82 | '1.0' |
| 83 | ); |
| 84 | wp_enqueue_script( |
| 85 | 'nested-sortable', |
| 86 | $this->plugin_dir . '/assets/js/lib/jquery.mjs.nestedSortable.js', |
| 87 | array('jquery', 'jquery-ui-sortable'), |
| 88 | '1.0' |
| 89 | ); |
| 90 | if ( $np_env == 'dev' ){ |
| 91 | wp_enqueue_script( |
| 92 | 'nestedpages', |
| 93 | $this->plugin_dir . '/assets/js/lib/nestedpages.js', |
| 94 | array('jquery'), |
| 95 | $this->plugin_version |
| 96 | ); |
| 97 | } else { |
| 98 | wp_enqueue_script( |
| 99 | 'nestedpages', |
| 100 | $this->plugin_dir . '/assets/js/nestedpages.min.js', |
| 101 | array('jquery'), |
| 102 | $this->plugin_version |
| 103 | ); |
| 104 | } |
| 105 | $localized_data = array( |
| 106 | 'np_nonce' => wp_create_nonce( 'nestedpages-nonce' ), |
| 107 | 'expand_text' => __('Expand All', 'nestedpages'), |
| 108 | 'collapse_text' => __('Collapse All', 'nestedpages'), |
| 109 | 'show_hidden' => __('Show Hidden', 'nestedpages'), |
| 110 | 'hide_hidden' => __('Hide Hidden', 'nestedpages'), |
| 111 | 'add_link' => __('Add Link', 'nestedpages'), |
| 112 | 'add_child_link' => __('Add Child Link', 'nestedpages'), |
| 113 | 'title' => __('Title', 'nestedpages'), |
| 114 | 'quick_edit' => __('Quick Edit', 'nestedpages'), |
| 115 | 'page_title' => __('Page Title', 'nestedpages'), |
| 116 | 'view' => __('View', 'nestedpages'), |
| 117 | 'add_child_short' => __('Add Child', 'nestedpages'), |
| 118 | 'add_child' => __('Add Child Page', 'nestedpages'), |
| 119 | 'add_child_pages' => __('Add Child Pages', 'nestedpages'), |
| 120 | 'add' => __('Add', 'nestedpages'), |
| 121 | 'add_page' => __('Add Page', 'nestedpages'), |
| 122 | 'add_pages' => __('Add Pages', 'nestedpages'), |
| 123 | 'add_multiple' => __('Add Multiple', 'nestedpages'), |
| 124 | 'trash_confirm' => __('Are you sure you would like to empty the trash? This action is not reversable.', 'nestedpages') |
| 125 | ); |
| 126 | $syncmenu = ( get_option('nestedpages_menusync') == 'sync' ) ? true : false; |
| 127 | $localized_data['syncmenu'] = $syncmenu; |
| 128 | $localized_data['post_types'] = $this->post_type_repo->getPostTypesObject(); |
| 129 | wp_localize_script( |
| 130 | 'nestedpages', |
| 131 | 'nestedpages', |
| 132 | $localized_data |
| 133 | ); |
| 134 | endif; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | } |