abstracts
9 months ago
admin
10 months ago
ads
9 months ago
compatibility
9 months ago
crons
1 year ago
frontend
11 months ago
groups
1 year ago
importers
1 year ago
installation
1 year ago
interfaces
1 year ago
placements
1 year ago
rest
1 year ago
traits
1 year ago
utilities
11 months ago
array_ad_conditions.php
1 year ago
cap_map.php
3 years ago
class-assets-registry.php
1 year ago
class-autoloader.php
1 year ago
class-constants.php
1 year ago
class-entities.php
1 year ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
1 year ago
class-post-data.php
10 months ago
class-shortcodes.php
1 year ago
class-upgrades.php
1 year ago
class-widget.php
11 months ago
default-hooks.php
1 year ago
functions-ad.php
1 year ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 year ago
functions-placement.php
1 year ago
functions.php
1 year ago
index.php
2 years ago
load_modules.php
2 years ago
class-entities.php
248 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The class handles the registration of custom post types and taxonomies in the plugin. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds; |
| 11 | |
| 12 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 13 | |
| 14 | defined( 'ABSPATH' ) || exit; |
| 15 | |
| 16 | /** |
| 17 | * Entities. |
| 18 | */ |
| 19 | class Entities implements Integration_Interface { |
| 20 | |
| 21 | /** |
| 22 | * Hook into WordPress. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function hooks(): void { |
| 27 | $this->register_ad_post_type(); |
| 28 | $this->register_placement_post_type(); |
| 29 | $this->register_group_taxonomy(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Register ad post type. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | private function register_ad_post_type(): void { |
| 38 | // Early bail!! |
| 39 | if ( post_type_exists( Constants::POST_TYPE_AD ) ) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | $labels = [ |
| 44 | 'name' => __( 'Ads', 'advanced-ads' ), |
| 45 | 'singular_name' => __( 'Ad', 'advanced-ads' ), |
| 46 | 'add_new' => __( 'New Ad', 'advanced-ads' ), |
| 47 | 'add_new_item' => __( 'Add New Ad', 'advanced-ads' ), |
| 48 | 'edit' => __( 'Edit', 'advanced-ads' ), |
| 49 | 'edit_item' => __( 'Edit Ad', 'advanced-ads' ), |
| 50 | 'new_item' => __( 'New Ad', 'advanced-ads' ), |
| 51 | 'view' => __( 'View', 'advanced-ads' ), |
| 52 | 'view_item' => __( 'View the Ad', 'advanced-ads' ), |
| 53 | 'search_items' => __( 'Search Ads', 'advanced-ads' ), |
| 54 | 'not_found' => __( 'No Ads found', 'advanced-ads' ), |
| 55 | 'not_found_in_trash' => __( 'No Ads found in Trash', 'advanced-ads' ), |
| 56 | 'parent' => __( 'Parent Ad', 'advanced-ads' ), |
| 57 | ]; |
| 58 | |
| 59 | $supports = [ 'title', 'author' ]; |
| 60 | if ( defined( 'ADVANCED_ADS_ENABLE_REVISIONS' ) ) { |
| 61 | $supports[] = 'revisions'; |
| 62 | } |
| 63 | |
| 64 | $args = [ |
| 65 | 'labels' => $labels, |
| 66 | 'public' => false, |
| 67 | 'show_ui' => true, |
| 68 | 'show_in_menu' => false, |
| 69 | 'hierarchical' => false, |
| 70 | 'capabilities' => [ |
| 71 | // Meta capabilities. |
| 72 | 'edit_post' => 'advanced_ads_edit_ads', |
| 73 | 'read_post' => 'advanced_ads_edit_ads', |
| 74 | 'delete_post' => 'advanced_ads_edit_ads', |
| 75 | 'edit_page' => 'advanced_ads_edit_ads', |
| 76 | 'read_page' => 'advanced_ads_edit_ads', |
| 77 | 'delete_page' => 'advanced_ads_edit_ads', |
| 78 | // Primitive capabilities used outside of map_meta_cap(). |
| 79 | 'edit_posts' => 'advanced_ads_edit_ads', |
| 80 | 'publish_posts' => 'advanced_ads_edit_ads', |
| 81 | 'read_private_posts' => 'advanced_ads_edit_ads', |
| 82 | // Primitive capabilities used within map_meta_cap(). |
| 83 | 'read' => 'advanced_ads_edit_ads', |
| 84 | 'delete_posts' => 'advanced_ads_edit_ads', |
| 85 | 'delete_private_posts' => 'advanced_ads_edit_ads', |
| 86 | 'delete_published_posts' => 'advanced_ads_edit_ads', |
| 87 | 'edit_private_posts' => 'advanced_ads_edit_ads', |
| 88 | 'edit_published_posts' => 'advanced_ads_edit_ads', |
| 89 | 'create_posts' => 'advanced_ads_edit_ads', |
| 90 | ], |
| 91 | 'has_archive' => false, |
| 92 | 'query_var' => false, |
| 93 | 'rewrite' => false, |
| 94 | 'supports' => $supports, |
| 95 | 'taxonomies' => [ Constants::TAXONOMY_GROUP ], |
| 96 | ]; |
| 97 | |
| 98 | register_post_type( |
| 99 | Constants::POST_TYPE_AD, |
| 100 | apply_filters( 'advanced-ads-post-type-ad', $args ) |
| 101 | ); |
| 102 | |
| 103 | register_post_status( |
| 104 | Constants::AD_STATUS_EXPIRED, |
| 105 | [ |
| 106 | 'label' => __( 'Expired', 'advanced-ads' ), |
| 107 | 'private' => true, |
| 108 | ] |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Register placement post type. |
| 114 | * |
| 115 | * @return void |
| 116 | */ |
| 117 | private function register_placement_post_type(): void { |
| 118 | // Early bail!! |
| 119 | if ( post_type_exists( Constants::POST_TYPE_PLACEMENT ) ) { |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | $labels = [ |
| 124 | 'name' => __( 'Ad Placements', 'advanced-ads' ), |
| 125 | 'singular_name' => __( 'Ad Placement', 'advanced-ads' ), |
| 126 | 'add_new' => __( 'New Placement', 'advanced-ads' ), |
| 127 | 'add_new_item' => __( 'Add New Placement', 'advanced-ads' ), |
| 128 | 'edit' => __( 'Edit', 'advanced-ads' ), |
| 129 | 'edit_item' => __( 'Edit Placement', 'advanced-ads' ), |
| 130 | 'new_item' => __( 'New Placement', 'advanced-ads' ), |
| 131 | 'view' => __( 'View', 'advanced-ads' ), |
| 132 | 'view_item' => __( 'View the Ad Placement', 'advanced-ads' ), |
| 133 | 'search_items' => __( 'Search Ad Placements', 'advanced-ads' ), |
| 134 | 'not_found' => __( 'No Ad Placements found', 'advanced-ads' ), |
| 135 | 'not_found_in_trash' => __( 'No Ad Placements found in Trash', 'advanced-ads' ), |
| 136 | ]; |
| 137 | |
| 138 | $args = [ |
| 139 | 'labels' => $labels, |
| 140 | 'description' => __( 'Placements are physically places in your theme and posts. You can use them if you plan to change ads and ad groups on the same place without the need to change your templates.', 'advanced-ads' ), |
| 141 | 'public' => false, |
| 142 | 'show_ui' => true, |
| 143 | 'show_in_menu' => false, |
| 144 | 'hierarchical' => false, |
| 145 | 'capabilities' => [ |
| 146 | // Meta capabilities. |
| 147 | 'edit_post' => 'advanced_ads_manage_placements', |
| 148 | 'read_post' => 'advanced_ads_manage_placements', |
| 149 | 'delete_post' => 'advanced_ads_manage_placements', |
| 150 | 'edit_page' => 'advanced_ads_manage_placements', |
| 151 | 'read_page' => 'advanced_ads_manage_placements', |
| 152 | 'delete_page' => 'advanced_ads_manage_placements', |
| 153 | // Primitive capabilities used outside of map_meta_cap(). |
| 154 | 'edit_posts' => 'advanced_ads_manage_placements', |
| 155 | 'publish_posts' => 'advanced_ads_manage_placements', |
| 156 | 'read_private_posts' => 'advanced_ads_manage_placements', |
| 157 | // Primitive capabilities used within map_meta_cap(). |
| 158 | 'read' => 'advanced_ads_manage_placements', |
| 159 | 'delete_posts' => 'advanced_ads_manage_placements', |
| 160 | 'delete_private_posts' => 'advanced_ads_manage_placements', |
| 161 | 'delete_published_posts' => 'advanced_ads_manage_placements', |
| 162 | 'edit_private_posts' => 'advanced_ads_manage_placements', |
| 163 | 'edit_published_posts' => 'advanced_ads_manage_placements', |
| 164 | 'create_posts' => 'advanced_ads_manage_placements', |
| 165 | ], |
| 166 | 'has_archive' => false, |
| 167 | 'query_var' => false, |
| 168 | 'rewrite' => false, |
| 169 | 'supports' => [ 'title' ], |
| 170 | ]; |
| 171 | |
| 172 | register_post_type( |
| 173 | Constants::POST_TYPE_PLACEMENT, |
| 174 | apply_filters( 'advanced-ads-post-type-placement', $args ) |
| 175 | ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Register group taxonomy. |
| 180 | * |
| 181 | * @return void |
| 182 | */ |
| 183 | private function register_group_taxonomy(): void { |
| 184 | // Early bail!! |
| 185 | if ( taxonomy_exists( Constants::TAXONOMY_GROUP ) ) { |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | $labels = [ |
| 190 | 'name' => _x( 'Ad Groups & Rotations', 'ad group general name', 'advanced-ads' ), |
| 191 | 'singular_name' => _x( 'Ad Group', 'ad group singular name', 'advanced-ads' ), |
| 192 | 'search_items' => __( 'Search Ad Groups', 'advanced-ads' ), |
| 193 | 'all_items' => __( 'All Ad Groups', 'advanced-ads' ), |
| 194 | 'parent_item' => __( 'Parent Ad Groups', 'advanced-ads' ), |
| 195 | 'parent_item_colon' => __( 'Parent Ad Groups:', 'advanced-ads' ), |
| 196 | 'edit_item' => __( 'Edit Ad Group', 'advanced-ads' ), |
| 197 | 'update_item' => __( 'Update Ad Group', 'advanced-ads' ), |
| 198 | 'add_new_item' => __( 'New Ad Group', 'advanced-ads' ), |
| 199 | 'new_item_name' => __( 'New Ad Groups Name', 'advanced-ads' ), |
| 200 | 'menu_name' => __( 'Groups', 'advanced-ads' ), |
| 201 | 'not_found' => __( 'No Ad Group found', 'advanced-ads' ), |
| 202 | ]; |
| 203 | |
| 204 | $args = [ |
| 205 | 'public' => false, |
| 206 | 'hierarchical' => true, |
| 207 | 'labels' => $labels, |
| 208 | 'show_ui' => true, |
| 209 | 'show_in_nav_menus' => false, |
| 210 | 'show_in_menu' => false, |
| 211 | 'show_tagcloud' => false, |
| 212 | 'show_admin_column' => true, |
| 213 | 'query_var' => false, |
| 214 | 'rewrite' => false, |
| 215 | 'capabilities' => [ |
| 216 | 'manage_terms' => 'advanced_ads_edit_ads', |
| 217 | 'edit_terms' => 'advanced_ads_edit_ads', |
| 218 | 'delete_terms' => 'advanced_ads_edit_ads', |
| 219 | 'assign_terms' => 'advanced_ads_edit_ads', |
| 220 | ], |
| 221 | ]; |
| 222 | |
| 223 | register_taxonomy( |
| 224 | Constants::TAXONOMY_GROUP, |
| 225 | Constants::POST_TYPE_AD, |
| 226 | apply_filters( 'advanced-ads-group-taxonomy-params', $args ) |
| 227 | ); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Placement description |
| 232 | * |
| 233 | * @return string |
| 234 | */ |
| 235 | public static function get_placement_description(): string { |
| 236 | return __( 'Placements are customizable ad spots on your site. Use them to see and change all the assigned ads and groups on this page. Furthermore, you can set up exclusive features like Cache Busting, Lazy Loading, AdBlocker fallbacks, or Parallax effects.', 'advanced-ads' ); |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Group description |
| 241 | * |
| 242 | * @return string |
| 243 | */ |
| 244 | public static function get_group_description(): string { |
| 245 | return __( 'Ad Groups are a flexible method to bundle ads. Use them to create ad rotations, run split tests, and organize your ads in the backend. An ad can belong to multiple ad groups.', 'advanced-ads' ); |
| 246 | } |
| 247 | } |
| 248 |