get( self::PAGE, 0 ) ); $page = $id ? get_post( $id ) : null; if ( ! $page instanceof \WP_Post || 'page' !== $page->post_type || 'trash' === $page->post_status ) { return null; } return $page; } /** * The status of the chosen page: 'none' when there is none, else its post * status (publish, draft, pending, private, future). * * @param Settings $settings Plugin settings. * @return string */ public static function status( Settings $settings ) { $page = self::page( $settings ); return $page ? (string) $page->post_status : 'none'; } /** * The link of the chosen page while it is published: its address, title and id. * * @param Settings $settings Plugin settings. * @return array{url:string,title:string,id:int}|null */ public static function link( Settings $settings ) { $page = self::page( $settings ); if ( ! $page || 'publish' !== $page->post_status ) { return null; } $title = trim( wp_strip_all_tags( get_the_title( $page ) ) ); return array( 'url' => (string) get_permalink( $page ), 'title' => '' !== $title ? $title : (string) get_permalink( $page ), 'id' => (int) $page->ID, ); } /** * True while the form asks for the consent: switched on, with a published page. * * @param Settings $settings Plugin settings. * @return bool */ public static function consent_on( Settings $settings ) { return ! empty( $settings->get( self::CONSENT, 0 ) ) && null !== self::link( $settings ); } /** * True when a request on this route needs the consent: the shop asks for it * and the route is one it goes with (Routes `policy_consent`). * * @param string $route Route key. * @param Settings $settings Plugin settings. * @return bool */ public static function asks( $route, Settings $settings ) { return self::consent_on( $settings ) && (bool) Routes::property( (string) $route, 'policy_consent' ); } /** * What a request records of the consent: the page, its title and the moment * it last changed (UTC), so the version agreed to can be told later. * * @param Settings $settings Plugin settings. * @return array{page:int,title:string,changed:string}|null */ public static function record( Settings $settings ) { $link = self::link( $settings ); if ( null === $link ) { return null; } $page = get_post( $link['id'] ); return array( 'page' => $link['id'], 'title' => $link['title'], 'changed' => $page instanceof \WP_Post ? (string) $page->post_modified_gmt : '', ); } /** * The page a new install starts with: WooCommerce's "Refund and Returns * Policy" page, when it is published. WooCommerce makes it as a draft with a * template text, which no form should link before the shop has written it. * * @return int Page id, or 0. */ public static function new_install_page() { $id = absint( get_option( 'woocommerce_refund_returns_page_id', 0 ) ); $page = $id ? get_post( $id ) : null; return $page instanceof \WP_Post && 'page' === $page->post_type && 'publish' === $page->post_status ? (int) $page->ID : 0; } }