PluginProbe
AffiliateX – Amazon Affiliate Plugin, Product Boxes, Comparison Tables & Affiliate Link Tracking / trunk
AffiliateX – Amazon Affiliate Plugin, Product Boxes, Comparison Tables & Affiliate Link Tracking vtrunk
2.3.9 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.0 2.2.1 2.1.0 2.0.8 2.0.7 2.0.6 2.0.5 2.0.4 2.0.3 2.0.2 2.0.1 2.0 1.2.9 1.2.9.1 1.2.9.2 All 87 releases
affiliatex / includes / modules / WelcomeAPI.php

WelcomeAPI.php in AffiliateX – Amazon Affiliate Plugin, Product Boxes, Comparison Tables & Affiliate Link Tracking trunk, at includes/modules/WelcomeAPI.php

67 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AffiliateX\Modules;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Welcome / Getting Started REST API
9 *
10 * @package AffiliateX
11 */
12 class WelcomeAPI {
13 use \AffiliateX\Helpers\ResponseHelper;
14
15 public function register_routes(): void {
16 register_rest_route(
17 'affiliatex/v1/welcome',
18 '/create-starter-page',
19 array(
20 'methods' => 'POST',
21 'callback' => array( $this, 'create_starter_page' ),
22 'permission_callback' => function () {
23 return current_user_can( 'publish_posts' );
24 },
25 )
26 );
27 }
28
29 public function create_starter_page(): void {
30 $post_id = wp_insert_post(
31 array(
32 'post_title' => esc_html__( 'My first AffiliateX page', 'affiliatex' ),
33 'post_status' => 'draft',
34 'post_type' => 'post',
35 'post_content' => wp_slash( $this->get_starter_content() ),
36 ),
37 true
38 );
39
40 if ( is_wp_error( $post_id ) ) {
41 $this->send_json_plain_error( array( 'message' => $post_id->get_error_message() ) );
42 return;
43 }
44
45 $this->send_json_plain_success(
46 array(
47 'post_id' => (int) $post_id,
48 'edit_url' => admin_url( 'post.php?post=' . (int) $post_id . '&action=edit' ),
49 )
50 );
51 }
52
53 private function get_starter_content(): string {
54 $template = <<<'HTML'
55 <!-- wp:affiliatex/single-product {"block_id":"__SP_ID__","productTitle":"CuttyClassic 198X","productTitleTypography":{"family":"Default","variation":"n4","size":{"desktop":"24px","mobile":"24px","tablet":"24px"},"line-height":{"desktop":"1.333","mobile":"1.333","tablet":"1.333"},"letter-spacing":{"desktop":"0em","mobile":"0em","tablet":"0em"},"text-transform":"none","text-decoration":"none"},"productTitleColor":"#ed833c","productImageType":"external","productImageExternal":"https://affiliatexblocks.com/wp-content/uploads/2024/12/retro-computer-desk-arrangement.jpg","productSubTitle":"\u003cstrong\u003eReady to jump back to the future?\u003c/strong\u003e","productIconList":{"name":"chevron-right","value":"fas fa-chevron-right"},"productContent":"Step back in time with this charming, pastel-pink Single Product template that features a delightful retro computer animation. Rounded corners and playful accent details evoke a cute 80s tech vibe, while bold headings and an eye-catching CTA ensure your product stands out.","productContentColor":"rgba(41, 41, 41, 0.84)","contentMargin":{"desktop":{"top":"0px","left":"0px","right":"0px","bottom":"39px"},"mobile":{"top":"0px","left":"0px","right":"0px","bottom":"30px"},"tablet":{"top":"0px","left":"0px","right":"0px","bottom":"30px"},"__changed":[]},"contentSpacing":{"desktop":{"top":"30px","left":"25px","right":"25px","bottom":"10px"},"mobile":{"top":"30px","left":"25px","right":"25px","bottom":"30px"},"tablet":{"top":"30px","left":"25px","right":"25px","bottom":"30px"},"__changed":[]},"productBorderWidth":{"desktop":{"top":"1px","left":"1px","right":"1px","bottom":"1px","linked":true},"mobile":{"top":"1px","left":"1px","right":"1px","bottom":"1px"},"tablet":{"top":"1px","left":"1px","right":"1px","bottom":"1px"},"__changed":[]},"productBorderRadius":{"desktop":{"top":"30px","left":"30px","right":"30px","bottom":"30px","linked":true},"mobile":{"top":"0","left":"0","right":"0","bottom":"0"},"tablet":{"top":"0","left":"0","right":"0","bottom":"0"},"__changed":[]},"productShadow":{"enable":true,"h_offset":0,"v_offset":5,"blur":"49","spread":0,"inset":false,"color":{"color":"rgba(144, 145, 148, 0.2)"},"inherit":false},"productDivider":{"style":"dashed","width":"1","color":{"color":"#E6ECF7"}},"ratings":4,"ratingStarSize":24,"edSubtitle":true,"productBgColorType":"gradient","productBgGradient":{"gradient":"linear-gradient(130deg,rgba(255,106,0,0.01) 0%,rgba(255,106,0,0.13) 100%)"},"ribbonText":"50% Discount","ribbonBGColor":"rgba(254, 5, 206, 0.32)","edRibbon":true} -->
56 <!-- wp:affiliatex/buttons {"block_id":"__BTN_ID__","buttonLabel":"Buy Now","buttonBGColor":"#ff8989","buttonBGHoverColor":"#fa5b5b","buttonMargin":{"desktop":{"top":"30px","left":"0px","right":"0px","bottom":"0px"},"mobile":{"top":"16px","left":"0px","right":"0px","bottom":"0px"},"tablet":{"top":"16px","left":"0px","right":"0px","bottom":"0px"},"__changed":[]},"buttonPadding":{"desktop":{"top":"px","left":"","right":"","bottom":""},"mobile":{"top":"","left":"","right":"","bottom":""},"tablet":{"top":"","left":"","right":"","bottom":""},"__changed":[]},"buttonURL":"https://affiliatexblocks.com/demo/?utm_source=playground\u0026utm_medium=editor\u0026utm_campaign=single_product","openInNewTab":true,"buttonRadius":{"desktop":{"top":"8px","left":"8px","right":"8px","bottom":"8px","linked":true},"mobile":{"top":"0","left":"0","right":"0","bottom":"0"},"tablet":{"top":"0","left":"0","right":"0","bottom":"0"},"__changed":[]},"layoutStyle":"layout-type-2","priceTextColor":"#ff8989"} /-->
57 <!-- /wp:affiliatex/single-product -->
58 HTML;
59
60 return str_replace(
61 array( '__SP_ID__', '__BTN_ID__' ),
62 array( 'block-' . wp_generate_uuid4(), 'block-' . wp_generate_uuid4() ),
63 $template
64 );
65 }
66 }
67