Trigger builds & share to mastodon properly

This commit is contained in:
Lewis Dale 2023-02-25 11:08:48 +00:00
parent 8e496a9909
commit bebac6cace

View File

@ -11,17 +11,9 @@ class Lewtilities {
public function init() {
add_action('admin_menu', array ( $this, 'submenu_page' ));
add_action('wp_print_styles', array( $this, 'enqueue_styles' ), 9999);
}
public function enqueue_styles() {
global $wp_styles;
global $enqueued_styles;
$enqueued_styles = array();
foreach( $wp_styles->queue as $handle ) {
$enqueued_styles[] = $wp_styles->registered[$handle]->src;
}
print_r($wp_styles->queue);
add_action('init', array ( $this, 'on_init' ));
add_action( 'rest_api_init', array( $this, 'add_md_to_rest' ));
add_filter( 'share_on_mastodon_status', array($this, 'format_post_for_mastodon'), 10, 2 );
}
public function submenu_page() {
@ -38,8 +30,6 @@ class Lewtilities {
public function admin_styles() {
echo "Admin styles section";
global $enqueued_styles;
echo var_dump($enqueued_styles);
}
public function admin_options_page() {
@ -55,4 +45,54 @@ class Lewtilities {
public function admin_options_page_display() {
echo "Options page";
}
}
public function rewrite_well_known() {
add_rewrite_rule('^\.well-known/webfinger$', 'https://dapchat.online/.well-known/webfinger?resource=acct:lewisdaleuk@dapchat.online');
}
public function add_md_to_rest() {
register_rest_field( 'post', 'markdown', array(
'get_callback' => function( $post_arr ) {
return $content = html_entity_decode(get_post_field('post_content_filtered', $post_arr['id'], 'edit'), ENT_QUOTES | ENT_HTML5, 'UTF-8');
},
'update_callback' => function( $karma, $comment_obj ) {
return true;
},
'schema' => array(
'description' => __( 'Markdown content.' ),
'type' => 'string'
),
) );
}
public function on_init() {
add_action('save_post', array( $this, 'trigger_frontend_build' ));
add_action('after_delete_post', array( $this, 'trigger_frontend_build' ));
add_action('lewtilities_build_hook', array( $this, 'build' ));
if ( ! wp_next_scheduled( 'lewtilities_build_hook' ) ) {
wp_schedule_event( time(), 'one_hour', 'lewtilities_build_hook' );
}
}
public function build() {
// Trigger build
$out = null;
$ret = null;
exec("./build.sh 2>&1", $out, $ret);
file_put_contents("build.output", $ret . "\n" . print_r($out, true));
}
public function trigger_frontend_build($post) {
if (get_post_status( $post ) === "publish") {
$this->build();
}
}
public function format_post_for_mastodon( $status, $post ) {
$status = "New post: " . $post->post_title . "\n\n";
$status .= html_entity_decode( get_the_excerpt($post) );
$status .= "\n\n" . get_permalink( $post );
return $status;
}
}