plugin_type = AFFCF_Plugin_Checker::get_active_plugin(); if ( 'acf' === $this->plugin_type ) { $this->compat = AFFCF_ACF_Compat::get_instance(); } elseif ( 'scf' === $this->plugin_type ) { $this->compat = AFFCF_SCF_Compat::get_instance(); } } /** * Check if available */ public function is_available() { return null !== $this->plugin_type; } /** * Get plugin type */ public function get_plugin_type() { return $this->plugin_type; } /** * Get field groups * * @param string $post_type Post type. * @return array Field groups. */ public function get_field_groups( $post_type ) { if ( ! $this->compat ) { return array(); } return $this->compat->get_field_groups_for_cpt( $post_type ); } /** * Get fields * * @param string $group_id Group ID. * @return array Fields. */ public function get_fields( $group_id ) { if ( ! $this->compat ) { return array(); } return $this->compat->get_fields_for_group( $group_id ); } /** * Get field * * @param string $field_key Field key. * @return array|null Field data. */ public function get_field( $field_key ) { if ( ! $this->compat ) { return null; } return $this->compat->get_field( $field_key ); } /** * Get field value * * @param string $field_key Field key. * @param int $post_id Post ID. * @return mixed Field value. */ public function get_field_value( $field_key, $post_id ) { if ( ! $this->compat ) { return null; } return $this->compat->get_field_value( $field_key, $post_id ); } /** * Update field * * @param string $field_key Field key. * @param mixed $value Field value. * @param int $post_id Post ID. * @return bool Success. */ public function update_field( $field_key, $value, $post_id ) { if ( ! $this->compat ) { return false; } return $this->compat->update_field( $field_key, $value, $post_id ); } /** * Get available post types */ public function get_available_post_types() { $post_types = get_post_types( array( 'public' => true, 'show_ui' => true, ), 'objects' ); $available = array(); foreach ( $post_types as $post_type ) { $available[] = array( 'value' => $post_type->name, 'label' => $post_type->labels->singular_name, 'icon' => $post_type->menu_icon ?? 'dashicons-admin-post', ); } return $available; } /** * Get taxonomies * * @param string $post_type Post type. * @return array Taxonomies. */ public function get_taxonomies( $post_type ) { $taxonomies = get_object_taxonomies( $post_type, 'objects' ); $available = array(); foreach ( $taxonomies as $taxonomy ) { if ( ! $taxonomy->public || ! $taxonomy->show_ui ) { continue; } $available[] = array( 'name' => $taxonomy->name, 'label' => $taxonomy->labels->singular_name, 'label_plural' => $taxonomy->labels->name, 'hierarchical' => $taxonomy->hierarchical, ); } return $available; } /** * Get version */ public function get_version() { if ( ! $this->compat ) { return null; } return $this->compat->get_version(); } }