*/ final class AdminState { /** * Every section name, in the order the admin applies them. * * @since 4.4.0 * @var array */ const SECTIONS = array( 'onboarding', 'health', 'adstxt', 'cmp', 'presized_div', 'ad_format', 'optimization', 'custom_variables' ); /** * Website onboarding and contract state, written by the website push. * * The organization keys are left out on purpose. `organization_id` is * account data, kept out of every section (data minimisation); the * website push rewrites it only when the website moves to another * organization. `organization_country` only feeds the FastCMP head office * default, and the cmp section already carries `headOffice` computed from * it (Helpers::get_fastcmp_options()). * * @since 4.4.0 * @return array */ public function onboarding() { return array( 'onboarding_status' => Options::get( 'onboarding-status' ), 'contract_status' => Options::get( 'contract-status' ), 'contract_type' => Options::get( 'contract-type' ), 'contract_duration' => Options::get( 'contract-duration' ), 'trial_end_date' => Options::get( 'trial-end-date' ), 'ads_serving' => Options::get( 'ads-serving' ), 'website_exists' => Options::get( 'website-exists' ), 'activation_time' => Options::get( 'activation-time', 0 ), 'toggle_features' => array( 'website_settings' => Options::get( 'website-settings', array() ), ), ); } /** * Cached health check issues, or null when nothing is cached yet. * * Null is not "no issues" (that is an empty array): it means the cache * was never written, so the admin keeps the issues it already shows. The * page load computes the issues and writes the cache, which can call the * Actirise API; this section never does. So once the admin page has * loaded, the cache exists, and every action and push that changes what * the health check reads refreshes it. * * @since 4.4.0 * @return array */ public function health() { return array( 'health_check' => Options::get( 'health-check-cache', null ), ); } /** * Ads.txt mode, Actirise lines and custom lines. * * @since 4.4.0 * @return array */ public function adstxt() { return array( 'adstxt' => array( 'actirise' => AdsTxt::get_adstxt( false ), 'file' => Options::get( 'adstxt-file', false ), 'custom' => Options::get( 'adstxt-custom', array() ), 'enabled' => Options::get( 'adstxt-active', null ), 'update' => Options::get( 'adstxt-update', false ), 'hosted' => Options::get( 'hosted-adstxt-enabled', false ), 'redirect_error' => Options::get( 'hosted-adstxt-redirect-error', false ), ), ); } /** * FastCMP settings and vendors. * * @since 4.4.0 * @return array */ public function cmp() { return array( 'fastcmp' => Helpers::get_fastcmp_options( false ), ); } /** * Pre-sized div settings. * * @since 4.4.0 * @return array */ public function presized_div() { return array( 'presizedDiv' => array( 'actirise' => Options::get( 'presizeddiv-actirise', array() ), 'selected' => Options::get( 'presizeddiv-selected', array() ), 'enabled' => Options::get( 'presizeddiv-active', false ), 'notif' => Options::get( 'presizeddiv-notif', array() ), ), ); } /** * Ad format XPath checks and enabled slugs, from the option cache only. * * @since 4.4.0 * @return array */ public function ad_format() { return array( 'ad_format' => array( 'xpath_test' => Options::get( 'adformat-slots-xpath', array() ), 'enabled_slugs' => Options::get( 'ad-format-enabled-slugs', array() ), ), ); } /** * Manual optimization checklist, only for essential contracts. * * @since 4.4.0 * @return array */ public function optimization() { return array( 'optimization_checklist' => Options::get( 'contract-type' ) === 'essential' ? Options::get( 'optimization-checklist-manual', array( 'cache_exclusion' => false, 'editorial_best_practices' => false, ) ) : null, ); } /** * The custom variables mapping, written by the custom variables push. * * The whole `customVar` block of the page load: the selectable form, the * selected keys, the Platform's slot names and the sync version the next * save is based on. The form's postmeta query is local (and cached an * hour), so the section rule holds: no remote call, no write. * * @since 4.4.0 * @return array */ public function custom_variables() { $selected = array(); foreach ( CustomVariablesSync::SLOT_DEFAULTS as $slot => $default ) { $selected[ $slot ] = Options::get( $slot, $default ); } return array( 'customVar' => array( 'form' => $this->custom_v_form(), 'selected' => $selected, 'names' => CustomVariablesSync::names(), 'version' => CustomVariablesSync::version(), ), ); } /** * Get all custom v available * * Moved from Core so the page load and the tab refresh build the same * form from one place. * * @since 2.0.0 * @since 4.4.0 Moved from `Core::get_custom_v_form()`. * @return array All custom v available */ private function custom_v_form() { $base_array = array( array( 'name' => __( 'Not used', 'actirise' ), 'value' => '', ), array( 'name' => __( 'Author ID', 'actirise' ), 'value' => 'author_ID', ), array( 'name' => __( 'Author name', 'actirise' ), 'value' => 'author_display_name', ), array( 'name' => __( 'Post', 'actirise' ), 'value' => array( array( 'name' => __( 'ID', 'actirise' ), 'value' => 'post_ID', ), array( 'name' => __( 'Slug', 'actirise' ), 'value' => 'post_post_name', ), array( 'name' => __( 'Type', 'actirise' ), 'value' => 'post_post_type', ), ), ), array( 'name' => __( 'Category Level 1', 'actirise' ), 'value' => array( array( 'name' => __( 'ID', 'actirise' ), 'value' => 'category_0_cat_ID', ), array( 'name' => __( 'Slug', 'actirise' ), 'value' => 'category_0_slug', ), array( 'name' => __( 'Title', 'actirise' ), 'value' => 'category_0_name', ), array( 'name' => __( 'Parent', 'actirise' ), 'value' => 'category_0_category_parent', ), ), ), array( 'name' => __( 'Category Level 2', 'actirise' ), 'value' => array( array( 'name' => __( 'ID', 'actirise' ), 'value' => 'category_1_cat_ID', ), array( 'name' => __( 'Slug', 'actirise' ), 'value' => 'category_1_slug', ), array( 'name' => __( 'Title', 'actirise' ), 'value' => 'category_1_name', ), array( 'name' => __( 'Parent', 'actirise' ), 'value' => 'category_1_category_parent', ), ), ), array( 'name' => __( 'Tag Level 1', 'actirise' ), 'value' => array( array( 'name' => __( 'ID', 'actirise' ), 'value' => 'tag_0_term_id', ), array( 'name' => __( 'Slug', 'actirise' ), 'value' => 'tag_0_slug', ), array( 'name' => __( 'Title', 'actirise' ), 'value' => 'tag_0_name', ), array( 'name' => __( 'Parent', 'actirise' ), 'value' => 'tag_0_parent', ), ), ), array( 'name' => __( 'Tag Level 2', 'actirise' ), 'value' => array( array( 'name' => __( 'ID', 'actirise' ), 'value' => 'tag_1_term_id', ), array( 'name' => __( 'Slug', 'actirise' ), 'value' => 'tag_1_slug', ), array( 'name' => __( 'Title', 'actirise' ), 'value' => 'tag_1_name', ), array( 'name' => __( 'Parent', 'actirise' ), 'value' => 'tag_1_parent', ), ), ), ); $custom_fields = $this->custom_fields(); if ( $custom_fields !== null && count( $custom_fields ) > 0 ) { $custom_fields = array_map( function ( $field ) { return array( 'name' => ucfirst( $field['meta_key'] ), 'value' => 'customFields_' . $field['meta_key'], ); }, $custom_fields ); $base_array[] = array( 'name' => __( 'Custom Field', 'actirise' ), 'value' => $custom_fields, ); } return $base_array; } /** * Get all custom fields. * * @since 2.0.0 * @since 4.4.0 Moved from `Core::get_custom_fields()`. * @return array> */ private function custom_fields() { /** @var \wpdb $wpdb */ global $wpdb; $cache_key = 'actirise_cache_custom_fields'; $_posts = wp_cache_get( $cache_key ); if ( false === $_posts ) { $_posts = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery "SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE meta_key NOT LIKE '\_%'", ARRAY_A ); wp_cache_set( $cache_key, $_posts, '', 3600 ); } /** @var array> $_posts */ return $_posts; } }