array( __( 'Create the WhatsApp Cloud API', 'afojet-new-post-alerts' ), $api_ok ), 'template' => array( __( 'Create the message template', 'afojet-new-post-alerts' ), $tpl_ok ), 'webhook' => array( __( 'Connect the webhook', 'afojet-new-post-alerts' ), $hook_ok ), 'live' => array( __( 'Go live & fix errors', 'afojet-new-post-alerts' ), false ), ); ?>
' . esc_html( $n ) . '

' . esc_html( $title ) . '

' . wp_kses_post( $html ) . '
'; } private static function link( $url, $text ) { return '' . esc_html( $text ) . ' '; } /* ------------------------------------------------------------------ */ private static function part_api() { AFPP_Admin::card_open( __( 'Part 1 · Create the WhatsApp Cloud API', 'afojet-new-post-alerts' ), __( 'The Cloud API is Meta\'s official, free-to-set-up way to send WhatsApp messages from a website. You pay Meta only for the messages you send.', 'afojet-new-post-alerts' ), 'api' ); echo '
    '; self::step( 1, __( 'Create a Meta Business portfolio', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'Open %s and create a business portfolio with your blog or company name. Skip this if you already have one.', 'afojet-new-post-alerts' ), self::link( 'https://business.facebook.com/overview', 'business.facebook.com' ) ) . '

    ' . '

    ' . __( 'Tip: verify your business (Settings → Security centre → Business verification) early. Without it you can message only 250 people a day.', 'afojet-new-post-alerts' ) . '

    ' ); self::step( 2, __( 'Create an app on Meta for Developers', 'afojet-new-post-alerts' ), '
      ' . '
    1. ' . sprintf( /* translators: %s link */ __( 'Go to %s and click Create app.', 'afojet-new-post-alerts' ), self::link( 'https://developers.facebook.com/apps', 'developers.facebook.com/apps' ) ) . '
    2. ' . '
    3. ' . __( 'Give it a name (e.g. "My Blog WhatsApp") and your email.', 'afojet-new-post-alerts' ) . '
    4. ' . '
    5. ' . __( 'Use case: choose Connect with customers through WhatsApp.', 'afojet-new-post-alerts' ) . '
    6. ' . '
    7. ' . __( 'Pick the business portfolio from step 1 and finish. In the app, open WhatsApp → API Setup.', 'afojet-new-post-alerts' ) . '
    8. ' . '
    ' ); self::step( 3, __( 'Add your phone number and copy the Phone number ID', 'afojet-new-post-alerts' ), '

    ' . __( 'Meta gives you a free test number to try things (it can only message up to 5 numbers you add under "To"). For real readers add your own number:', 'afojet-new-post-alerts' ) . '

    ' . '
      ' . '
    1. ' . __( 'In API Setup, click Add phone number.', 'afojet-new-post-alerts' ) . '
    2. ' . '
    3. ' . __( 'Enter a display name (your blog name – Meta reviews it), category and description.', 'afojet-new-post-alerts' ) . '
    4. ' . '
    5. ' . __( 'Enter the number and confirm it with the SMS or voice code. The number must not be active on the WhatsApp or WhatsApp Business app – delete that account first if needed.', 'afojet-new-post-alerts' ) . '
    6. ' . '
    7. ' . __( 'Back in API Setup, select your number in the From list and copy the Phone number ID shown under it.', 'afojet-new-post-alerts' ) . '
    8. ' . '
    ' . '

    ' . __( 'The Phone number ID is a long number like 1234567890123456. It is not your phone number and not the "WhatsApp Business Account ID".', 'afojet-new-post-alerts' ) . '

    ' ); self::step( 4, __( 'Create a permanent access token', 'afojet-new-post-alerts' ), '

    ' . __( 'The token shown in API Setup expires after 24 hours. Make one that never expires:', 'afojet-new-post-alerts' ) . '

    ' . '
      ' . '
    1. ' . sprintf( /* translators: %s link */ __( 'Open %s → Users → System users → Add. Name it "New Post Alerts" and choose role Admin.', 'afojet-new-post-alerts' ), self::link( 'https://business.facebook.com/settings/system-users', __( 'Business settings', 'afojet-new-post-alerts' ) ) ) . '
    2. ' . '
    3. ' . __( 'Click Assign assets: add your App (Full control) and your WhatsApp account (Full control).', 'afojet-new-post-alerts' ) . '
    4. ' . '
    5. ' . __( 'Click Generate new token, select your app, set expiry to Never.', 'afojet-new-post-alerts' ) . '
    6. ' . '
    7. ' . __( 'Tick the permissions whatsapp_business_messaging and whatsapp_business_management, then generate and copy the token. Meta shows it only once.', 'afojet-new-post-alerts' ) . '
    8. ' . '
    ' ); self::step( 5, __( 'Add a payment method', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'In %s → Payment settings, add a card. Post alerts are "marketing" messages; Meta charges per delivered message and the price depends on the reader\'s country.', 'afojet-new-post-alerts' ), self::link( 'https://business.facebook.com/wa/manage/home/', 'WhatsApp Manager' ) ) . ' ' . self::link( 'https://developers.facebook.com/docs/whatsapp/pricing', __( 'See prices', 'afojet-new-post-alerts' ) ) . '

    ' ); self::step( 6, __( 'Paste the details into New Post Alerts', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'Go to %s, paste the Phone number ID and the access token, and save. Then make the template in Part 2 and send a test.', 'afojet-new-post-alerts' ), '' . esc_html__( 'New Post Alerts → WhatsApp API', 'afojet-new-post-alerts' ) . '' ) . '

    ' ); echo '
'; AFPP_Admin::card_close(); } /* ------------------------------------------------------------------ */ /** Template body that matches the current settings. */ public static function sample_body() { $site = get_bloginfo( 'name' ); $n = 1; $lines = array( '📝 ' . sprintf( /* translators: 1 site name, 2 variable */ __( 'New on %1$s: *%2$s*', 'afojet-new-post-alerts' ), $site, '{{' . $n++ . '}}' ) ); if ( 'body' === AFPP_Settings::get( 'afpp_link_mode' ) ) { $lines[] = ''; $lines[] = sprintf( /* translators: %s variable */ __( 'Read it here: %s', 'afojet-new-post-alerts' ), '{{' . $n++ . '}}' ); } else { $lines[] = ''; $lines[] = __( 'Tap the button below to read it.', 'afojet-new-post-alerts' ); } if ( AFPP_Settings::enabled( 'afpp_unsub_var' ) ) { $lines[] = ''; $lines[] = sprintf( /* translators: %s variable */ __( 'Unsubscribe: %s', 'afojet-new-post-alerts' ), '{{' . $n++ . '}}' ); } $lines[] = ''; $lines[] = __( 'Thanks for reading!', 'afojet-new-post-alerts' ); return implode( "\n", $lines ); } public static function sample_values() { $latest = get_posts( array( 'numberposts' => 1, 'post_status' => 'publish', ) ); $title = $latest ? get_the_title( $latest[0] ) : __( '10 simple ways to grow your blog', 'afojet-new-post-alerts' ); $link = $latest ? get_permalink( $latest[0] ) : home_url( '/sample-post/' ); $vals = array( '{{1}}' => $title ); $n = 2; if ( 'body' === AFPP_Settings::get( 'afpp_link_mode' ) ) { $vals[ '{{' . $n++ . '}}' ] = $link; } if ( AFPP_Settings::enabled( 'afpp_unsub_var' ) ) { $vals[ '{{' . $n++ . '}}' ] = add_query_arg( 'afpp_unsub', 'abc123', home_url( '/' ) ); } return array( $vals, $link ); } private static function part_template() { $name = AFPP_Settings::get( 'afpp_template_name' ); $lang = AFPP_Settings::get( 'afpp_template_lang' ); list( $samples, $link ) = self::sample_values(); $button = 'button' === AFPP_Settings::get( 'afpp_link_mode' ); AFPP_Admin::card_open( __( 'Part 2 · Create the "new post" message template', 'afojet-new-post-alerts' ), __( 'WhatsApp only lets a business start a chat with a template that Meta has approved. New Post Alerts fills in the post title and link each time.', 'afojet-new-post-alerts' ), 'template' ); echo '
    '; self::step( 1, __( 'Open the template editor', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'Open %s and click Create template.', 'afojet-new-post-alerts' ), self::link( 'https://business.facebook.com/wa/manage/message-templates/', __( 'WhatsApp Manager → Message templates', 'afojet-new-post-alerts' ) ) ) . '

    ' ); self::step( 2, __( 'Choose category and name', 'afojet-new-post-alerts' ), '' . '' . '' . '' . '
    ' . esc_html__( 'Category', 'afojet-new-post-alerts' ) . 'Marketing → Default. ' . esc_html__( 'New-post alerts count as marketing. If you pick Utility, Meta will move it to Marketing or reject it.', 'afojet-new-post-alerts' ) . '
    ' . esc_html__( 'Name', 'afojet-new-post-alerts' ) . '' . esc_html( $name ) . ' ' . esc_html__( '(lowercase and underscores only – must match the plugin setting)', 'afojet-new-post-alerts' ) . '
    ' . esc_html__( 'Language', 'afojet-new-post-alerts' ) . '' . esc_html__( 'The language you write in. Its code must match the plugin setting:', 'afojet-new-post-alerts' ) . ' ' . esc_html( $lang ) . ' ' . esc_html__( '(English (US) = en_US, English (UK) = en_GB, Hindi = hi)', 'afojet-new-post-alerts' ) . '
    ' ); $header = AFPP_Settings::enabled( 'afpp_header_image' ) ? '

    ' . __( 'Header: choose Media → Image and upload any sample picture. New Post Alerts sends the post\'s featured image.', 'afojet-new-post-alerts' ) . '

    ' : '

    ' . __( 'Header: leave empty (or turn on "Template has an image header" in settings to show the featured image).', 'afojet-new-post-alerts' ) . '

    '; ob_start(); echo wp_kses_post( $header ); echo '

    ' . esc_html__( 'Body – copy this:', 'afojet-new-post-alerts' ) . '

    '; echo '
    ' . esc_html( self::sample_body() ) . '
    '; echo '

    ' . esc_html__( 'Click "Add variable" if the editor does not turn {{1}} into a variable by itself. Meta asks for sample values – use these:', 'afojet-new-post-alerts' ) . '

    '; echo ''; foreach ( $samples as $var => $val ) { echo ''; } echo '
    ' . esc_html( $var ) . '' . esc_html( $val ) . '
    '; echo '

    ' . esc_html__( 'Footer:', 'afojet-new-post-alerts' ) . ' ' . esc_html__( 'Reply STOP to unsubscribe', 'afojet-new-post-alerts' ) . '

    '; if ( $button ) { echo '

    ' . esc_html__( 'Button:', 'afojet-new-post-alerts' ) . ' ' . esc_html__( 'Add button → Visit website.', 'afojet-new-post-alerts' ) . '

    '; echo ''; echo ''; echo ''; echo '
    ' . esc_html__( 'Button text', 'afojet-new-post-alerts' ) . '' . esc_html__( 'Read post', 'afojet-new-post-alerts' ) . '
    ' . esc_html__( 'URL type', 'afojet-new-post-alerts' ) . 'Dynamic
    ' . esc_html__( 'Website URL', 'afojet-new-post-alerts' ) . '' . esc_html( trailingslashit( home_url() ) ) . '{{1}}
    ' . esc_html__( 'Sample', 'afojet-new-post-alerts' ) . '' . esc_html( $link ) . '
    '; } else { echo '

    ' . esc_html__( 'Buttons:', 'afojet-new-post-alerts' ) . ' ' . esc_html__( 'none needed. Meta may add a "Stop promotions" button by itself – New Post Alerts unsubscribes people who tap it (needs the webhook in Part 3).', 'afojet-new-post-alerts' ) . '

    '; } self::step( 3, __( 'Write the message', 'afojet-new-post-alerts' ), ob_get_clean() ); self::step( 4, __( 'Check the rules, then submit', 'afojet-new-post-alerts' ), '' . '

    ' . __( 'Click Submit. Approval usually takes a few minutes and at most 24 hours. Wait until the status is Active.', 'afojet-new-post-alerts' ) . '

    ' ); self::step( 5, __( 'Send a test', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'On %s, enter your own number under "Send a test". You should get your latest post on WhatsApp. If not, the error message tells you why – see Part 4.', 'afojet-new-post-alerts' ), '' . esc_html__( 'the WhatsApp API tab', 'afojet-new-post-alerts' ) . '' ) . '

    ' ); echo '
'; do_action( 'afpp_guide_templates' ); if ( ! has_action( 'afpp_guide_templates' ) ) { echo '

' . wp_kses_post( sprintf( /* translators: %s link */ __( 'New Post Alerts Pro uses two more templates (daily/weekly digest and a verification code). The Pro add-on adds their steps here. %s', 'afojet-new-post-alerts' ), '' . esc_html__( 'Learn about Pro', 'afojet-new-post-alerts' ) . '' ) ) . '

'; } AFPP_Admin::card_close(); } /* ------------------------------------------------------------------ */ private static function part_webhook() { AFPP_Admin::card_open( __( 'Part 3 · Connect the webhook', 'afojet-new-post-alerts' ), __( 'Lets WhatsApp tell your site when a reader replies STOP, taps "Stop promotions", or when a message is delivered and read.', 'afojet-new-post-alerts' ), 'webhook' ); echo '
    '; ob_start(); echo '

    ' . wp_kses_post( __( 'In your app on Meta for Developers open WhatsApp → Configuration, and under Webhook click Edit. Paste:', 'afojet-new-post-alerts' ) ) . '

    '; echo '
    ' . esc_html__( 'Callback URL', 'afojet-new-post-alerts' ) . ''; AFPP_Admin::copy_field( AFPP_Webhook::url() ); echo '
    ' . esc_html__( 'Verify token', 'afojet-new-post-alerts' ) . ''; AFPP_Admin::copy_field( (string) get_option( 'afpp_webhook_token' ) ); echo '

    ' . wp_kses_post( __( 'Click Verify and save.', 'afojet-new-post-alerts' ) ) . '

    '; self::step( 1, __( 'Add the callback URL', 'afojet-new-post-alerts' ), ob_get_clean() ); self::step( 2, __( 'Subscribe to messages', 'afojet-new-post-alerts' ), '

    ' . __( 'Under Webhook fields click Manage and subscribe to messages. That one field brings both replies and delivery receipts.', 'afojet-new-post-alerts' ) . '

    ' ); self::step( 3, __( 'Add the app secret', 'afojet-new-post-alerts' ), '

    ' . sprintf( /* translators: %s link */ __( 'Copy App settings → Basic → App secret into %s. New Post Alerts refuses every webhook call until it is saved, and then accepts only calls signed by Meta.', 'afojet-new-post-alerts' ), '' . esc_html__( 'the webhook settings', 'afojet-new-post-alerts' ) . '' ) . '

    ' ); self::step( 4, __( 'Check it works', 'afojet-new-post-alerts' ), '

    ' . __( 'Send any message to your business number from your phone. The "Webhook working" badge at the top of this page turns green.', 'afojet-new-post-alerts' ) . '

    ' . '

    ' . __( 'Meta can only reach a public HTTPS site. On a local site (localhost) the webhook will not verify – that is expected. Sending still works.', 'afojet-new-post-alerts' ) . '

    ' ); echo '
'; AFPP_Admin::card_close(); } /* ------------------------------------------------------------------ */ private static function part_live() { AFPP_Admin::card_open( __( 'Part 4 · Go live & fix common errors', 'afojet-new-post-alerts' ), '', 'live' ); echo '
    '; self::step( 1, __( 'Publish the app', 'afojet-new-post-alerts' ), '

    ' . __( 'In App settings → Basic, add a Privacy policy URL (your site\'s privacy page), then switch the app from Development to Live at the top of the dashboard.', 'afojet-new-post-alerts' ) . '

    ' ); self::step( 2, __( 'Send your first post', 'afojet-new-post-alerts' ), '

    ' . __( 'Open any published post. In the WhatsApp subscribers box click Send on WhatsApp. Results appear on the Broadcasts tab.', 'afojet-new-post-alerts' ) . '

    ' ); echo '
'; $errors = array( array( '190', __( 'Access token expired or wrong.', 'afojet-new-post-alerts' ), __( 'Make a permanent System User token (Part 1, step 4).', 'afojet-new-post-alerts' ) ), array( '131030', __( 'Recipient not in the allowed list.', 'afojet-new-post-alerts' ), __( 'You are using the test number. Add the reader under "To" in API Setup, or add your own number.', 'afojet-new-post-alerts' ) ), array( '132001', __( 'Template does not exist in this language.', 'afojet-new-post-alerts' ), __( 'Check the template name and language code match WhatsApp Manager exactly, and the template is Active.', 'afojet-new-post-alerts' ) ), array( '132000', __( 'Number of parameters does not match.', 'afojet-new-post-alerts' ), __( 'The template has a different number of {{n}} variables than the settings send. Compare with the list on the WhatsApp API tab.', 'afojet-new-post-alerts' ) ), array( '132012', __( 'Parameter format does not match.', 'afojet-new-post-alerts' ), __( 'Header image or button setting does not match the template. Check both toggles.', 'afojet-new-post-alerts' ) ), array( '131049', __( 'Meta chose not to deliver this marketing message.', 'afojet-new-post-alerts' ), __( 'WhatsApp limits how many marketing messages one person gets. Nothing to fix – it is not charged.', 'afojet-new-post-alerts' ) ), array( '131026', __( 'Message undeliverable.', 'afojet-new-post-alerts' ), __( 'The number is not on WhatsApp or uses an old app version. New Post Alerts marks it "Not on WhatsApp".', 'afojet-new-post-alerts' ) ), array( '131050', __( 'User stopped marketing messages.', 'afojet-new-post-alerts' ), __( 'The reader turned off your messages in WhatsApp. New Post Alerts stops sending to them.', 'afojet-new-post-alerts' ) ), array( '133010', __( 'Phone number not registered.', 'afojet-new-post-alerts' ), __( 'Finish adding your number in API Setup (verify it and set the 6-digit PIN).', 'afojet-new-post-alerts' ) ), array( '131056', __( 'Too many messages to one number.', 'afojet-new-post-alerts' ), __( 'You sent the same person many messages quickly. Wait a few minutes.', 'afojet-new-post-alerts' ) ), ); echo '

' . esc_html__( 'Error codes you may see on the Broadcasts tab', 'afojet-new-post-alerts' ) . '

'; echo ''; foreach ( $errors as $e ) { echo ''; } echo '
' . esc_html__( 'Code', 'afojet-new-post-alerts' ) . '' . esc_html__( 'Meaning', 'afojet-new-post-alerts' ) . '' . esc_html__( 'What to do', 'afojet-new-post-alerts' ) . '
' . esc_html( $e[0] ) . '' . esc_html( $e[1] ) . '' . esc_html( $e[2] ) . '
'; echo '

' . wp_kses_post( self::link( 'https://developers.facebook.com/docs/whatsapp/cloud-api/support/error-codes', __( 'All WhatsApp error codes', 'afojet-new-post-alerts' ) ) ) . '

'; AFPP_Admin::card_close(); } }