convertkit
/
includes
/
pre-publish-actions
/
class-convertkit-pre-publish-action-broadcast-export.php
class-convertkit-pre-publish-action-broadcast-export.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.5, at includes/pre-publish-actions/class-convertkit-pre-publish-action-broadcast-export.php
| 1 | <?php |
| 2 | /** |
| 3 | * ConvertKit Broadcast Export Pre-publish Action class. |
| 4 | * |
| 5 | * @package ConvertKit |
| 6 | * @author ConvertKit |
| 7 | */ |
| 8 | |
| 9 | /** |
| 10 | * ConvertKit Broadcast Export Pre-publish Action for Gutenberg and Shortcode. |
| 11 | * |
| 12 | * @package ConvertKit |
| 13 | * @author ConvertKit |
| 14 | */ |
| 15 | class ConvertKit_Pre_Publish_Action_Broadcast_Export extends ConvertKit_Pre_Publish_Action { |
| 16 | |
| 17 | /** |
| 18 | * Constructor |
| 19 | * |
| 20 | * @since 2.4.0 |
| 21 | */ |
| 22 | public function __construct() { |
| 23 | |
| 24 | // Bail if the Enable Export Actions setting is not enabled. |
| 25 | $broadcasts_settings = new ConvertKit_Settings_Broadcasts(); |
| 26 | if ( ! $broadcasts_settings->enabled_export() ) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | // Register action to export Post to ConvertKit Broadcast when published. |
| 31 | add_action( 'convertkit_pre_publish_action_run_' . $this->get_name(), array( $this, 'export_broadcast' ) ); |
| 32 | |
| 33 | // Call parent class constructor. |
| 34 | parent::__construct(); |
| 35 | |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Exports the given WordPress Post to a draft ConvertKit Broadcast, |
| 40 | * if the user has enabled this pre-publish action in the Post's settings, |
| 41 | * and the WordPress Post's status transitions to published from either |
| 42 | * draft or scheduled. |
| 43 | * |
| 44 | * @since 2.4.0 |
| 45 | * |
| 46 | * @param WP_Post $post Post. |
| 47 | */ |
| 48 | public function export_broadcast( $post ) { |
| 49 | |
| 50 | $broadcasts_exporter = WP_ConvertKit()->get_class( 'broadcasts_exporter' ); |
| 51 | $broadcasts_exporter->export_post_to_broadcast( $post->ID ); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns this action's programmatic name, excluding the convertkit- prefix. |
| 57 | * |
| 58 | * @since 2.4.0 |
| 59 | * |
| 60 | * @return string |
| 61 | */ |
| 62 | public function get_name() { |
| 63 | |
| 64 | /** |
| 65 | * This will register as: |
| 66 | * - a Classic Editor pre-publish action, displayed as a checkbox on a draft Post. |
| 67 | * - a Gutenberg pre-publish action, with the name convertkit-action-broadcast-export. |
| 68 | */ |
| 69 | return 'broadcast_export'; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns this action's label. |
| 75 | * |
| 76 | * @since 2.4.0 |
| 77 | * |
| 78 | * @return string |
| 79 | */ |
| 80 | public function get_label() { |
| 81 | |
| 82 | return __( 'Create Broadcast', 'convertkit' ); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns this action's description. |
| 88 | * |
| 89 | * @since 2.4.0 |
| 90 | * |
| 91 | * @return string |
| 92 | */ |
| 93 | public function get_description() { |
| 94 | |
| 95 | return __( 'If enabled, creates a draft Kit Broadcast using this Post\'s title, content and excerpt.', 'convertkit' ); |
| 96 | |
| 97 | } |
| 98 | |
| 99 | } |
| 100 |