Complex classes like View often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class View implements \ArrayAccess { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \WP_Post The backing post instance. |
||
| 21 | */ |
||
| 22 | private $post; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var \GV\View_Settings The settings. |
||
| 26 | * |
||
| 27 | * @api |
||
| 28 | * @since 2.0 |
||
| 29 | */ |
||
| 30 | public $settings; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \GV\Widget_Collection The widets attached here. |
||
| 34 | * |
||
| 35 | * @api |
||
| 36 | * @since 2.0 |
||
| 37 | */ |
||
| 38 | public $widgets; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \GV\GF_Form|\GV\Form The backing form for this view. |
||
| 42 | * |
||
| 43 | * Contains the form that is sourced for entries in this view. |
||
| 44 | * |
||
| 45 | * @api |
||
| 46 | * @since 2.0 |
||
| 47 | */ |
||
| 48 | public $form; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var \GV\Field_Collection The fields for this view. |
||
| 52 | * |
||
| 53 | * Contains all the fields that are attached to this view. |
||
| 54 | * |
||
| 55 | * @api |
||
| 56 | * @since 2.0 |
||
| 57 | */ |
||
| 58 | public $fields; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var array |
||
| 62 | * |
||
| 63 | * Internal static cache for gets, and whatnot. |
||
| 64 | * This is not persistent, resets across requests. |
||
| 65 | |||
| 66 | * @internal |
||
| 67 | */ |
||
| 68 | private static $cache = array(); |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var \GV\Join[] The joins for all sources in this view. |
||
| 72 | * |
||
| 73 | * @api |
||
| 74 | * @since 2.0.1 |
||
| 75 | */ |
||
| 76 | public $joins = array(); |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var \GV\Field[][] The unions for all sources in this view. |
||
| 80 | * An array of fields grouped by form_id keyed by |
||
| 81 | * main field_id: |
||
| 82 | * |
||
| 83 | * array( |
||
| 84 | * $form_id => array( |
||
| 85 | * $field_id => $field, |
||
| 86 | * $field_id => $field, |
||
| 87 | * ) |
||
| 88 | * ) |
||
| 89 | * |
||
| 90 | * @api |
||
| 91 | * @since 2.2.2 |
||
| 92 | */ |
||
| 93 | public $unions = array(); |
||
| 94 | |||
| 95 | /** |
||
| 96 | * The constructor. |
||
| 97 | */ |
||
| 98 | 153 | public function __construct() { |
|
| 103 | |||
| 104 | /** |
||
| 105 | * Register the gravityview WordPress Custom Post Type. |
||
| 106 | * |
||
| 107 | * @internal |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | public static function register_post_type() { |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Add extra rewrite endpoints. |
||
| 217 | * |
||
| 218 | * @return void |
||
| 219 | */ |
||
| 220 | 1 | public static function add_rewrite_endpoint() { |
|
| 221 | /** |
||
| 222 | * CSV. |
||
| 223 | */ |
||
| 224 | global $wp_rewrite; |
||
| 225 | |||
| 226 | $slug = apply_filters( 'gravityview_slug', 'view' ); |
||
| 227 | $rule = array( sprintf( '%s/([^/]+)/csv/?', $slug ), 'index.php?gravityview=$matches[1]&csv=1', 'top' ); |
||
| 228 | |||
| 229 | 1 | add_filter( 'query_vars', function( $query_vars ) { |
|
| 230 | 1 | $query_vars[] = 'csv'; |
|
| 231 | 1 | return $query_vars; |
|
| 232 | } ); |
||
| 233 | |||
| 234 | if ( ! isset( $wp_rewrite->extra_rules_top[ $rule[0] ] ) ) { |
||
| 235 | call_user_func_array( 'add_rewrite_rule', $rule ); |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | /** |
||
| 240 | * A renderer filter for the View post type content. |
||
| 241 | * |
||
| 242 | * @param string $content Should be empty, as we don't store anything there. |
||
| 243 | * |
||
| 244 | * @return string $content The view content as output by the renderers. |
||
| 245 | */ |
||
| 246 | 11 | public static function content( $content ) { |
|
| 247 | 11 | $request = gravityview()->request; |
|
| 248 | |||
| 249 | // Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality. |
||
| 250 | 11 | if ( ! defined( 'DOING_GRAVITYVIEW_TESTS' ) ) { |
|
| 251 | if ( ! did_action( 'loop_start' ) ) { |
||
| 252 | gravityview()->log->debug( 'Not processing yet: loop_start hasn\'t run yet. Current action: {action}', array( 'action' => current_filter() ) ); |
||
| 253 | return $content; |
||
| 254 | } |
||
| 255 | |||
| 256 | // We don't want this filter to run infinite loop on any post content fields |
||
| 257 | remove_filter( 'the_content', array( __CLASS__, __METHOD__ ) ); |
||
| 258 | } |
||
| 259 | |||
| 260 | /** |
||
| 261 | * This is not a View. Bail. |
||
| 262 | * |
||
| 263 | * Shortcodes and oEmbeds and whatnot will be handled |
||
| 264 | * elsewhere. |
||
| 265 | */ |
||
| 266 | 11 | if ( ! $view = $request->is_view() ) { |
|
| 267 | 5 | return $content; |
|
| 268 | } |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Check permissions. |
||
| 272 | */ |
||
| 273 | 6 | while ( $error = $view->can_render( null, $request ) ) { |
|
| 274 | 6 | if ( ! is_wp_error( $error ) ) |
|
| 275 | 6 | break; |
|
| 276 | |||
| 277 | 1 | switch ( str_replace( 'gravityview/', '', $error->get_error_code() ) ) { |
|
| 278 | 1 | case 'post_password_required': |
|
| 279 | 1 | return get_the_password_form( $view->ID ); |
|
|
|
|||
| 280 | 1 | case 'no_form_attached': |
|
| 281 | |||
| 282 | gravityview()->log->error( 'View #{view_id} cannot render: {error_code} {error_message}', array( 'error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message() ) ); |
||
| 283 | |||
| 284 | /** |
||
| 285 | * This View has no data source. There's nothing to show really. |
||
| 286 | * ...apart from a nice message if the user can do anything about it. |
||
| 287 | */ |
||
| 288 | if ( \GVCommon::has_cap( array( 'edit_gravityviews', 'edit_gravityview' ), $view->ID ) ) { |
||
| 289 | return __( sprintf( 'This View is not configured properly. Start by <a href="%s">selecting a form</a>.', esc_url( get_edit_post_link( $view->ID, false ) ) ), 'gravityview' ); |
||
| 290 | } |
||
| 291 | break; |
||
| 292 | 1 | case 'no_direct_access': |
|
| 293 | 1 | case 'embed_only': |
|
| 294 | 1 | case 'not_public': |
|
| 295 | default: |
||
| 296 | 1 | gravityview()->log->notice( 'View #{view_id} cannot render: {error_code} {error_message}', array( 'error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message() ) ); |
|
| 297 | 1 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
| 298 | } |
||
| 299 | |||
| 300 | return $content; |
||
| 301 | } |
||
| 302 | |||
| 303 | 6 | $is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID ); |
|
| 304 | |||
| 305 | /** |
||
| 306 | * Editing a single entry. |
||
| 307 | */ |
||
| 308 | 6 | if ( $entry = $request->is_edit_entry( $view->form ? $view->form->ID : 0 ) ) { |
|
| 309 | if ( $entry['status'] != 'active' ) { |
||
| 310 | gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $entry->ID ) ); |
||
| 311 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
||
| 312 | } |
||
| 313 | |||
| 314 | if ( apply_filters( 'gravityview_custom_entry_slug', false ) && $entry->slug != get_query_var( \GV\Entry::get_endpoint_name() ) ) { |
||
| 315 | gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', array( 'entry_id' => $entry->ID ) ); |
||
| 316 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
||
| 317 | } |
||
| 318 | |||
| 319 | if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) { |
||
| 320 | if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
||
| 321 | gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $entry->ID ) ); |
||
| 322 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
||
| 323 | } |
||
| 324 | } |
||
| 325 | |||
| 326 | $renderer = new Edit_Entry_Renderer(); |
||
| 327 | return $renderer->render( $entry, $view, $request ); |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Viewing a single entry. |
||
| 331 | */ |
||
| 332 | 6 | } else if ( $entry = $request->is_entry( $view->form ? $view->form->ID : 0 ) ) { |
|
| 333 | |||
| 334 | 2 | $entryset = $entry->is_multi() ? $entry->entries : array( $entry ); |
|
| 335 | |||
| 336 | 2 | $custom_slug = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
| 337 | 2 | $ids = explode( ',', get_query_var( \GV\Entry::get_endpoint_name() ) ); |
|
| 338 | |||
| 339 | 2 | $show_only_approved = $view->settings->get( 'show_only_approved' ); |
|
| 340 | |||
| 341 | 2 | foreach ( $entryset as $e ) { |
|
| 342 | |||
| 343 | 2 | if ( 'active' !== $e['status'] ) { |
|
| 344 | 1 | gravityview()->log->notice( 'Entry ID #{entry_id} is not active', array( 'entry_id' => $e->ID ) ); |
|
| 345 | 1 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
| 346 | } |
||
| 347 | |||
| 348 | 2 | if ( $custom_slug && ! in_array( $e->slug, $ids ) ) { |
|
| 349 | 1 | gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', array( 'entry_id' => $e->ID ) ); |
|
| 350 | 1 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
| 351 | } |
||
| 352 | |||
| 353 | 2 | if ( $show_only_approved && ! $is_admin_and_can_view ) { |
|
| 354 | 1 | if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
| 355 | 1 | gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', array( 'entry_id' => $e->ID ) ); |
|
| 356 | 1 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
| 357 | } |
||
| 358 | } |
||
| 359 | |||
| 360 | 2 | $error = \GVCommon::check_entry_display( $e->as_entry(), $view ); |
|
| 361 | |||
| 362 | 2 | if ( is_wp_error( $error ) ) { |
|
| 363 | 1 | gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing: {message}', array( 'entry_id' => $e->ID, 'message' => $error->get_error_message() ) ); |
|
| 364 | 1 | return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 368 | 2 | $renderer = new Entry_Renderer(); |
|
| 369 | 2 | return $renderer->render( $entry, $view, $request ); |
|
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Plain old View. |
||
| 374 | */ |
||
| 375 | 5 | $renderer = new View_Renderer(); |
|
| 376 | 5 | return $renderer->render( $view, $request ); |
|
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Checks whether this view can be accessed or not. |
||
| 381 | * |
||
| 382 | * @param string[] $context The context we're asking for access from. |
||
| 383 | * Can any and as many of one of: |
||
| 384 | * edit An edit context. |
||
| 385 | * single A single context. |
||
| 386 | * cpt The custom post type single page acessed. |
||
| 387 | * shortcode Embedded as a shortcode. |
||
| 388 | * oembed Embedded as an oEmbed. |
||
| 389 | * rest A REST call. |
||
| 390 | * @param \GV\Request $request The request |
||
| 391 | * |
||
| 392 | * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
||
| 393 | */ |
||
| 394 | 26 | public function can_render( $context = null, $request = null ) { |
|
| 395 | 26 | if ( ! $request ) { |
|
| 396 | 5 | $request = gravityview()->request; |
|
| 397 | } |
||
| 398 | |||
| 399 | 26 | if ( ! is_array( $context ) ) { |
|
| 400 | 6 | $context = array(); |
|
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * @filter `gravityview/view/can_render` Whether the view can be rendered or not. |
||
| 405 | * @param bool|\WP_Error $result The result. Default: null. |
||
| 406 | * @param \GV\View $view The view. |
||
| 407 | * @param string[] $context See \GV\View::can_render |
||
| 408 | * @param \GV\Request $request The request. |
||
| 409 | */ |
||
| 410 | 26 | if ( ! is_null( $result = apply_filters( 'gravityview/view/can_render', null, $this, $context, $request ) ) ) { |
|
| 411 | return $result; |
||
| 412 | } |
||
| 413 | |||
| 414 | 26 | if ( in_array( 'rest', $context ) ) { |
|
| 415 | // REST |
||
| 416 | 8 | if ( gravityview()->plugin->settings->get( 'rest_api' ) === '1' && $this->settings->get( 'rest_disable' ) === '1' ) { |
|
| 417 | 1 | return new \WP_Error( 'gravityview/rest_disabled' ); |
|
| 418 | 8 | } elseif ( gravityview()->plugin->settings->get( 'rest_api' ) !== '1' && $this->settings->get( 'rest_enable' ) !== '1' ) { |
|
| 419 | 1 | return new \WP_Error( 'gravityview/rest_disabled' ); |
|
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | 26 | if ( in_array( 'csv', $context ) ) { |
|
| 424 | 5 | if ( $this->settings->get( 'csv_enable' ) !== '1' ) { |
|
| 425 | 1 | return new \WP_Error( 'gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View' ); |
|
| 426 | } |
||
| 427 | } |
||
| 428 | |||
| 429 | /** |
||
| 430 | * This View is password protected. Nothing to do here. |
||
| 431 | */ |
||
| 432 | 26 | if ( post_password_required( $this->ID ) ) { |
|
| 433 | 3 | gravityview()->log->notice( 'Post password is required for View #{view_id}', array( 'view_id' => $this->ID ) ); |
|
| 434 | 3 | return new \WP_Error( 'gravityview/post_password_required' ); |
|
| 435 | } |
||
| 436 | |||
| 437 | 26 | if ( ! $this->form ) { |
|
| 438 | gravityview()->log->notice( 'View #{id} has no form attached to it.', array( 'id' => $this->ID ) ); |
||
| 439 | return new \WP_Error( 'gravityview/no_form_attached' ); |
||
| 440 | } |
||
| 441 | |||
| 442 | 26 | if ( ! in_array( 'shortcode', $context ) ) { |
|
| 443 | /** |
||
| 444 | * Is this View directly accessible via a post URL? |
||
| 445 | * |
||
| 446 | * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
||
| 447 | */ |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
||
| 451 | * @deprecated |
||
| 452 | * @param[in,out] boolean `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true` |
||
| 453 | * @param int $view_id The ID of the View currently being requested. `0` for general setting |
||
| 454 | */ |
||
| 455 | 19 | $direct_access = apply_filters( 'gravityview_direct_access', true, $this->ID ); |
|
| 456 | |||
| 457 | /** |
||
| 458 | * @filter `gravityview/request/output/direct` Should this View be directly accessbile? |
||
| 459 | * @since 2.0 |
||
| 460 | * @param[in,out] boolean Accessible or not. Default: accessbile. |
||
| 461 | * @param \GV\View $view The View we're trying to directly render here. |
||
| 462 | * @param \GV\Request $request The current request. |
||
| 463 | */ |
||
| 464 | 19 | if ( ! apply_filters( 'gravityview/view/output/direct', $direct_access, $this, $request ) ) { |
|
| 465 | return new \WP_Error( 'gravityview/no_direct_access' ); |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Is this View an embed-only View? If so, don't allow rendering here, |
||
| 470 | * as this is a direct request. |
||
| 471 | */ |
||
| 472 | 19 | if ( $this->settings->get( 'embed_only' ) && ! \GVCommon::has_cap( 'read_private_gravityviews' ) ) { |
|
| 473 | 1 | return new \WP_Error( 'gravityview/embed_only' ); |
|
| 474 | } |
||
| 475 | } |
||
| 476 | |||
| 477 | /** Private, pending, draft, etc. */ |
||
| 478 | 26 | $public_states = get_post_stati( array( 'public' => true ) ); |
|
| 479 | 26 | if ( ! in_array( $this->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $this->ID ) ) { |
|
| 480 | 3 | gravityview()->log->notice( 'The current user cannot access this View #{view_id}', array( 'view_id' => $this->ID ) ); |
|
| 481 | 3 | return new \WP_Error( 'gravityview/not_public' ); |
|
| 482 | } |
||
| 483 | |||
| 484 | 26 | return true; |
|
| 485 | } |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Get joins associated with a view |
||
| 489 | * |
||
| 490 | * @param \WP_Post $post GravityView CPT to get joins for |
||
| 491 | * |
||
| 492 | * @api |
||
| 493 | * @since 2.0.11 |
||
| 494 | * |
||
| 495 | * @return \GV\Join[] Array of \GV\Join instances |
||
| 496 | */ |
||
| 497 | 153 | public static function get_joins( $post ) { |
|
| 534 | |||
| 535 | /** |
||
| 536 | * Get joined forms associated with a view |
||
| 537 | * In no particular order. |
||
| 538 | * |
||
| 539 | * @since 2.0.11 |
||
| 540 | * |
||
| 541 | * @api |
||
| 542 | * @since 2.0 |
||
| 543 | * @param int $post_id ID of the View |
||
| 544 | * |
||
| 545 | * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
||
| 546 | */ |
||
| 547 | 2 | public static function get_joined_forms( $post_id ) { |
|
| 548 | 2 | $forms = array(); |
|
| 549 | |||
| 550 | 2 | if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
| 551 | gravityview()->log->error( 'Cannot get joined forms; joins feature not supported.' ); |
||
| 552 | return $forms; |
||
| 553 | } |
||
| 554 | |||
| 555 | 2 | if ( ! $post_id || ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
| 556 | return $forms; |
||
| 557 | } |
||
| 558 | |||
| 559 | 2 | if ( empty( $post_id ) ) { |
|
| 560 | gravityview()->log->error( 'Cannot get joined forms; $post_id was empty' ); |
||
| 561 | return $forms; |
||
| 562 | } |
||
| 563 | |||
| 564 | 2 | $joins_meta = get_post_meta( $post_id, '_gravityview_form_joins', true ); |
|
| 565 | |||
| 566 | 2 | if ( empty( $joins_meta ) ) { |
|
| 567 | return $forms; |
||
| 568 | } |
||
| 569 | |||
| 570 | 2 | foreach ( $joins_meta as $meta ) { |
|
| 571 | 2 | if ( ! is_array( $meta ) || count( $meta ) != 4 ) { |
|
| 572 | continue; |
||
| 573 | } |
||
| 574 | |||
| 575 | 2 | list( $join, $join_column, $join_on, $join_on_column ) = $meta; |
|
| 576 | |||
| 577 | 2 | if ( $form = GF_Form::by_id( $join_on ) ) { |
|
| 578 | 2 | $forms[ $join_on ] = $form; |
|
| 579 | } |
||
| 580 | |||
| 581 | 2 | if ( $form = GF_Form::by_id( $join ) ) { |
|
| 582 | 2 | $forms[ $join ] = $form; |
|
| 583 | } |
||
| 584 | } |
||
| 585 | |||
| 586 | 2 | return $forms; |
|
| 587 | } |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Get unions associated with a view |
||
| 591 | * |
||
| 592 | * @param \WP_Post $post GravityView CPT to get unions for |
||
| 593 | * |
||
| 594 | * @api |
||
| 595 | * @since 2.2.2 |
||
| 596 | * |
||
| 597 | * @return \GV\Field[][] Array of unions (see self::$unions) |
||
| 598 | */ |
||
| 599 | 153 | public static function get_unions( $post ) { |
|
| 643 | |||
| 644 | /** |
||
| 645 | * Construct a \GV\View instance from a \WP_Post. |
||
| 646 | * |
||
| 647 | * @param \WP_Post $post The \WP_Post instance to wrap. |
||
| 648 | * |
||
| 649 | * @api |
||
| 650 | * @since 2.0 |
||
| 651 | * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
||
| 652 | */ |
||
| 653 | 154 | public static function from_post( $post ) { |
|
| 756 | |||
| 757 | /** |
||
| 758 | * Flush the view cache. |
||
| 759 | * |
||
| 760 | * @param int $view_id The View to reset cache for. Optional. Default: resets everything. |
||
| 761 | * |
||
| 762 | * @internal |
||
| 763 | */ |
||
| 764 | 167 | public static function _flush_cache( $view_id = null ) { |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Construct a \GV\View instance from a post ID. |
||
| 774 | * |
||
| 775 | * @param int|string $post_id The post ID. |
||
| 776 | * |
||
| 777 | * @api |
||
| 778 | * @since 2.0 |
||
| 779 | * @return \GV\View|null An instance around this \WP_Post or null if not found. |
||
| 780 | */ |
||
| 781 | 93 | public static function by_id( $post_id ) { |
|
| 787 | |||
| 788 | /** |
||
| 789 | * Determines if a view exists to begin with. |
||
| 790 | * |
||
| 791 | * @param int|\WP_Post|null $view The WordPress post ID, a \WP_Post object or null for global $post; |
||
| 792 | * |
||
| 793 | * @api |
||
| 794 | * @since 2.0 |
||
| 795 | * @return bool Whether the post exists or not. |
||
| 796 | */ |
||
| 797 | 17 | public static function exists( $view ) { |
|
| 800 | |||
| 801 | /** |
||
| 802 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 803 | * |
||
| 804 | * @internal |
||
| 805 | * @deprecated |
||
| 806 | * @since 2.0 |
||
| 807 | * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
||
| 808 | */ |
||
| 809 | 15 | public function offsetExists( $offset ) { |
|
| 813 | |||
| 814 | /** |
||
| 815 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 816 | * |
||
| 817 | * Maps the old keys to the new data; |
||
| 818 | * |
||
| 819 | * @internal |
||
| 820 | * @deprecated |
||
| 821 | * @since 2.0 |
||
| 822 | * |
||
| 823 | * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. If offset not found, return null. |
||
| 824 | */ |
||
| 825 | 15 | public function offsetGet( $offset ) { |
|
| 851 | |||
| 852 | /** |
||
| 853 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 854 | * |
||
| 855 | * @internal |
||
| 856 | * @deprecated |
||
| 857 | * @since 2.0 |
||
| 858 | * |
||
| 859 | * @return void |
||
| 860 | */ |
||
| 861 | 1 | public function offsetSet( $offset, $value ) { |
|
| 864 | |||
| 865 | /** |
||
| 866 | * ArrayAccess compatibility layer with GravityView_View_Data::$views |
||
| 867 | * |
||
| 868 | * @internal |
||
| 869 | * @deprecated |
||
| 870 | * @since 2.0 |
||
| 871 | * @return void |
||
| 872 | */ |
||
| 873 | 1 | public function offsetUnset( $offset ) { |
|
| 876 | |||
| 877 | /** |
||
| 878 | * Be compatible with the old data object. |
||
| 879 | * |
||
| 880 | * Some external code expects an array (doing things like foreach on this, or array_keys) |
||
| 881 | * so let's return an array in the old format for such cases. Do not use unless using |
||
| 882 | * for back-compatibility. |
||
| 883 | * |
||
| 884 | * @internal |
||
| 885 | * @deprecated |
||
| 886 | * @since 2.0 |
||
| 887 | * @return array |
||
| 888 | */ |
||
| 889 | 20 | public function as_data() { |
|
| 901 | |||
| 902 | /** |
||
| 903 | * Retrieve the entries for the current view and request. |
||
| 904 | * |
||
| 905 | * @param \GV\Request The request. Unused for now. |
||
| 906 | * |
||
| 907 | * @return \GV\Entry_Collection The entries. |
||
| 908 | */ |
||
| 909 | 54 | public function get_entries( $request = null ) { |
|
| 1285 | |||
| 1286 | /** |
||
| 1287 | * Last chance to configure the output. |
||
| 1288 | * |
||
| 1289 | * Used for CSV output, for example. |
||
| 1290 | * |
||
| 1291 | * @return void |
||
| 1292 | */ |
||
| 1293 | 5 | public static function template_redirect() { |
|
| 1397 | |||
| 1398 | /** |
||
| 1399 | 54 | * Return the query class for this View. |
|
| 1400 | * |
||
| 1401 | * @return string The class name. |
||
| 1402 | */ |
||
| 1403 | public function get_query_class() { |
||
| 1412 | 153 | ||
| 1413 | /** |
||
| 1414 | * Restrict View access to specific capabilities. |
||
| 1415 | * |
||
| 1416 | * Hooked into `map_meta_cap` WordPress filter. |
||
| 1417 | * |
||
| 1418 | * @since develop |
||
| 1419 | * |
||
| 1420 | * @param $caps array The output capabilities. |
||
| 1421 | * @param $cap string The cap that is being checked. |
||
| 1422 | * @param $user_id int The User ID. |
||
| 1423 | * @param $args array Additional arguments to the capability. |
||
| 1424 | * |
||
| 1425 | * @return array The resulting capabilities. |
||
| 1426 | */ |
||
| 1427 | public static function restrict( $caps, $cap, $user_id, $args ) { |
||
| 1457 | |||
| 1458 | public function __get( $key ) { |
||
| 1465 | } |
||
| 1466 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.