| @@ -1,0 +1,83 @@ | ||
| 1 | +<?php | |
| 2 | +/* | |
| 3 | + * License: GPLv3 | |
| 4 | + * License URI: https://www.gnu.org/licenses/gpl.txt | |
| 5 | + * Copyright 2024-2026 Jean-Sebastien Morisset (https://wpsso.com/) | |
| 6 | + */ | |
| 7 | + | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + | |
| 10 | + die( 'These aren\'t the droids you\'re looking for.' ); | |
| 11 | +} | |
| 12 | + | |
| 13 | +if ( ! defined( 'WPSSO_PLUGINDIR' ) ) { | |
| 14 | + | |
| 15 | + die( 'Do. Or do not. There is no try.' ); | |
| 16 | +} | |
| 17 | + | |
| 18 | +if ( ! class_exists( 'WpssoAdminHeadSuggestAttributes' ) ) { | |
| 19 | + | |
| 20 | + class WpssoAdminHeadSuggestAttributes { | |
| 21 | + | |
| 22 | + private $p; // Wpsso class object. | |
| 23 | + | |
| 24 | + /* | |
| 25 | + * Instantiated by WpssoAdminHeadSuggest->__construct(). | |
| 26 | + */ | |
| 27 | + public function __construct( &$plugin ) { | |
| 28 | + | |
| 29 | + $this->p =& $plugin; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public function suggest( $suggest_max = 2 ) { | |
| 33 | + | |
| 34 | + if ( $this->p->debug->enabled ) { | |
| 35 | + | |
| 36 | + $this->p->debug->log_args( array( | |
| 37 | + 'suggest_max' => $suggest_max, | |
| 38 | + ) ); | |
| 39 | + } | |
| 40 | + | |
| 41 | + $suggested = 0; | |
| 42 | + | |
| 43 | + /* | |
| 44 | + * Suggest woocommerce attributes, in that order. | |
| 45 | + */ | |
| 46 | + foreach ( array( 'woocommerce' ) as $suffix ) { | |
| 47 | + | |
| 48 | + $methodname = 'suggest_attributes_' . $suffix; | |
| 49 | + $suggested = $suggested + $this->$methodname( $suggest_max - $suggested ); | |
| 50 | + | |
| 51 | + if ( $this->p->debug->enabled ) { | |
| 52 | + | |
| 53 | + $this->p->debug->log( $methodname . ' suggested = ' . $suggested ); | |
| 54 | + } | |
| 55 | + | |
| 56 | + if ( $suggested >= $suggest_max ) break; | |
| 57 | + } | |
| 58 | + | |
| 59 | + if ( $this->p->debug->enabled ) { | |
| 60 | + | |
| 61 | + $this->p->debug->log( 'return suggested = ' . $suggested ); | |
| 62 | + } | |
| 63 | + | |
| 64 | + return $suggested; | |
| 65 | + } | |
| 66 | + | |
| 67 | + private function suggest_attributes_woocommerce( $suggest_max ) { | |
| 68 | + | |
| 69 | + $suggested = 0; | |
| 70 | + $notice_key = 'notice-wc-attributes-available'; | |
| 71 | + | |
| 72 | + if ( empty( $this->p->avail[ 'ecom' ][ 'woocommerce' ] ) ) return $suggested; // WooCommerce plugin is not active. | |
| 73 | + | |
| 74 | + if ( ! $this->p->notice->is_admin_pre_notices( $notice_key ) ) return $suggested; | |
| 75 | + | |
| 76 | + $notice_msg = $this->p->msgs->get( $notice_key ); | |
| 77 | + | |
| 78 | + $this->p->notice->inf( $notice_msg, null, $notice_key, $dismiss_time = true ); | |
| 79 | + | |
| 80 | + return ++$suggested; | |
| 81 | + } | |
| 82 | + } | |
| 83 | +} | |