| @@ -1,0 +1,115 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Admin | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\Bluesky\Admin | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Shortcut function to get plugin options | |
| 14 | + * | |
| 15 | + * @since 1.0.0 | |
| 16 | + * | |
| 17 | + * @param string $option_name | |
| 18 | + * @param bool $default | |
| 19 | + * | |
| 20 | + * @return mixed | |
| 21 | + */ | |
| 22 | +function automatorwp_bluesky_get_option( $option_name, $default = false ) { | |
| 23 | + | |
| 24 | + $prefix = 'automatorwp_bluesky_'; | |
| 25 | + | |
| 26 | + return automatorwp_get_option( $prefix . $option_name, $default ); | |
| 27 | +} | |
| 28 | + | |
| 29 | +/** | |
| 30 | + * Register plugin settings sections | |
| 31 | + * | |
| 32 | + * @since 1.0.0 | |
| 33 | + * | |
| 34 | + * @return array | |
| 35 | + */ | |
| 36 | +function automatorwp_bluesky_settings_sections( $automatorwp_settings_sections ) { | |
| 37 | + | |
| 38 | + $automatorwp_settings_sections['bluesky'] = array( | |
| 39 | + 'title' => __( 'Bluesky', 'automatorwp' ), | |
| 40 | + 'icon' => 'dashicons-bluesky', | |
| 41 | + ); | |
| 42 | + | |
| 43 | + return $automatorwp_settings_sections; | |
| 44 | + | |
| 45 | +} | |
| 46 | +add_filter( 'automatorwp_settings_sections', 'automatorwp_bluesky_settings_sections' ); | |
| 47 | + | |
| 48 | +/** | |
| 49 | + * Register plugin settings meta boxes | |
| 50 | + * | |
| 51 | + * @since 1.0.0 | |
| 52 | + * | |
| 53 | + * @return array | |
| 54 | + */ | |
| 55 | +function automatorwp_bluesky_settings_meta_boxes( $meta_boxes ) { | |
| 56 | + | |
| 57 | + $prefix = 'automatorwp_bluesky_'; | |
| 58 | + | |
| 59 | + $meta_boxes['automatorwp-bluesky-settings'] = array( | |
| 60 | + 'title' => automatorwp_dashicon( 'bluesky' ) . __( 'Bluesky', 'automatorwp' ), | |
| 61 | + 'fields' => apply_filters( 'automatorwp_bluesky_settings_fields', array( | |
| 62 | + $prefix . 'user_handle' => array( | |
| 63 | + 'name' => __( 'Bluesky Handle:', 'automatorwp' ), | |
| 64 | + 'desc' => __( 'Your bluesky account handle.', 'automatorwp' ), | |
| 65 | + 'type' => 'text', | |
| 66 | + ), | |
| 67 | + $prefix . 'user_password' => array( | |
| 68 | + 'name' => __( 'Password:', 'automatorwp' ), | |
| 69 | + 'desc' => __( 'Your bluesky account password.', 'automatorwp' ), | |
| 70 | + 'type' => 'text', | |
| 71 | + ), | |
| 72 | + $prefix . 'authorize' => array( | |
| 73 | + 'type' => 'text', | |
| 74 | + 'render_row_cb' => 'automatorwp_bluesky_authorize_display_cb' | |
| 75 | + ), | |
| 76 | + ) ), | |
| 77 | + ); | |
| 78 | + | |
| 79 | + return $meta_boxes; | |
| 80 | + | |
| 81 | +} | |
| 82 | +add_filter( "automatorwp_settings_bluesky_meta_boxes", 'automatorwp_bluesky_settings_meta_boxes' ); | |
| 83 | + | |
| 84 | +/** | |
| 85 | + * Display callback for the authorize setting | |
| 86 | + * | |
| 87 | + * @since 1.0.0 | |
| 88 | + * | |
| 89 | + * @param array $field_args Array of field arguments. | |
| 90 | + * @param CMB2_Field $field The field object | |
| 91 | + */ | |
| 92 | +function automatorwp_bluesky_authorize_display_cb( $field_args, $field ) { | |
| 93 | + | |
| 94 | + $user_handle = automatorwp_bluesky_get_option( 'user_handle' ); | |
| 95 | + $user_password = automatorwp_bluesky_get_option( 'user_password' ); | |
| 96 | + | |
| 97 | + $field_id = $field_args['id']; | |
| 98 | + | |
| 99 | + ?> | |
| 100 | + | |
| 101 | + <div class="cmb-row cmb-type-custom cmb2-id-automatorwp-bluesky-authorize table-layout" data-fieldtype="custom"> | |
| 102 | + <div class="cmb-th"> | |
| 103 | + <label><?php echo __( 'Connect with bluesky:', 'automatorwp' ); ?></label> | |
| 104 | + </div> | |
| 105 | + <div class="cmb-td"> | |
| 106 | + <a id="<?php echo $field_id; ?>" class="button button-primary" href="#"><?php echo __( 'Save credentials', 'automatorwp' ); ?></a> | |
| 107 | + <p class="cmb2-metabox-description"><?php echo __( 'Add your User and Password and click on "Authorize" to connect.', 'automatorwp' ); ?></p> | |
| 108 | + <?php if ( ! empty( $user_handle ) && ! empty( $user_password ) ) : ?> | |
| 109 | + <div class="automatorwp-notice-success"><?php echo __( 'Site connected with Bluesky successfully.', 'automatorwp' ); ?></div> | |
| 110 | + <?php endif; ?> | |
| 111 | + </div> | |
| 112 | + </div> | |
| 113 | + | |
| 114 | + <?php | |
| 115 | +} | |