PluginProbe ʕ •ᴥ•ʔ
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback / 5.0
Atarim – AI Agency for WordPress: Edit Pages, Fix Code, Update Plugins, SEO & Client Feedback v5.0
5.1.3 5.1.2 5.1.1 5.1 5.0 trunk 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 3.2.0 3.2.1 3.22 3.22.1 3.22.2 3.22.3 3.22.4 3.22.5 3.22.6 3.3.0 3.3.1 3.3.2 3.3.2.1 3.3.2.2 3.3.3 3.30 3.31 3.32 3.4 3.4.1 3.4.3 3.4.4 3.5 3.5.1 3.6 3.6.1 3.7 3.8 3.9 3.9.1 3.9.2 3.9.3 3.9.4 3.9.6 3.9.6.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.2 4.2.1 4.2.2 4.3 4.3.1 4.3.2 4.3.3 4.3.4 4.3.5 4.4
atarim-visual-collaboration / third-party / content-model / ase / class-avcf-ase-helpers.php
atarim-visual-collaboration / third-party / content-model / ase Last commit date
class-avcf-abilities-ase.php 1 month ago class-avcf-ase-detector.php 1 month ago class-avcf-ase-helpers.php 1 month ago
class-avcf-ase-helpers.php
88 lines
1 <?php
2 /**
3 * Shared helpers for the ASE ability cluster.
4 *
5 * ASE stores its definitions as ordinary WordPress post types with config in
6 * post meta:
7 * - field groups -> asenha_cfgroup (cfgroup_fields / cfgroup_rules / cfgroup_extras)
8 * - post types -> asenha_cpt (slug + cpt_label_* + settings)
9 * - taxonomies -> asenha_ctax (slug + ctax_label_* + settings)
10 * Because storage is plain wp_insert_post + post meta, reads and the
11 * field-group writes are reliable; the full label-key schema for CPT/taxonomy
12 * (ASE auto-generates ~31 cpt_label_* keys) is version-specific, so CPT/tax
13 * authoring is best-effort. Not tested against a live ASE here.
14 *
15 * @package atarim-visual-collaboration
16 */
17
18 if ( ! defined('ABSPATH') ) {
19 exit;
20 }
21
22 class AVCF_ASE_Helpers {
23
24 public static function list_cpt( $cpt ) {
25 return get_posts( [ 'post_type' => $cpt, 'post_status' => 'any', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ] );
26 }
27
28 public static function find_cpt( $cpt, $key ) {
29 if ( is_numeric( $key ) ) {
30 $p = get_post( (int) $key );
31 return ( $p && $p->post_type === $cpt ) ? $p : null;
32 }
33 // Match by stored slug meta first, then by post_name.
34 $posts = self::list_cpt( $cpt );
35 foreach ( $posts as $p ) {
36 $slug = get_post_meta( $p->ID, 'cpt_slug', true );
37 if ( $slug === '' ) { $slug = get_post_meta( $p->ID, 'ctax_slug', true ); }
38 if ( $slug === '' ) { $slug = get_post_meta( $p->ID, 'cfgroup_slug', true ); }
39 if ( (string) $slug === (string) $key || $p->post_name === sanitize_title( (string) $key ) ) {
40 return $p;
41 }
42 }
43 return null;
44 }
45
46 public static function post_meta_flat( $post_id ) {
47 $raw = get_post_meta( $post_id );
48 $out = [];
49 if ( is_array( $raw ) ) {
50 foreach ( $raw as $k => $vals ) {
51 if ( strpos( $k, '_' ) === 0 ) { continue; }
52 $v = is_array( $vals ) && count( $vals ) === 1 ? $vals[0] : $vals;
53 $out[ $k ] = is_string( $v ) ? maybe_unserialize( $v ) : $v;
54 }
55 }
56 return $out;
57 }
58
59 public static function shape_post( $post, $with_meta = false ) {
60 $out = [ 'id' => (int) $post->ID, 'title' => $post->post_title, 'slug' => $post->post_name, 'status' => $post->post_status ];
61 if ( $with_meta ) { $out['settings'] = self::post_meta_flat( $post->ID ); }
62 return $out;
63 }
64
65 /**
66 * Insert/update an asenha_* post and write the supplied meta map.
67 *
68 * @return int|WP_Error
69 */
70 public static function upsert( $cpt, $title, $meta, $post_id = null ) {
71 $postarr = [ 'post_type' => $cpt, 'post_title' => $title, 'post_status' => 'publish' ];
72 if ( $post_id ) {
73 $postarr['ID'] = (int) $post_id;
74 $id = wp_update_post( $postarr, true );
75 } else {
76 $id = wp_insert_post( $postarr, true );
77 }
78 if ( is_wp_error( $id ) ) { return $id; }
79 if ( is_array( $meta ) ) {
80 foreach ( $meta as $k => $v ) {
81 if ( strpos( (string) $k, '_' ) === 0 ) { continue; }
82 update_post_meta( $id, $k, $v );
83 }
84 }
85 return (int) $id;
86 }
87 }
88