coding standards

This commit is contained in:
Matthias Pfefferle 2023-01-23 19:43:34 +01:00
parent 16b52c0940
commit aec21a489c
2 changed files with 92 additions and 87 deletions

View file

@ -8,8 +8,8 @@ class Shortcodes {
* @param WP_Post $post A WordPress Post Object * @param WP_Post $post A WordPress Post Object
*/ */
public static function init() { public static function init() {
foreach( get_class_methods( 'Activitypub\Shortcodes' ) as $shortcode ) { foreach ( get_class_methods( 'Activitypub\Shortcodes' ) as $shortcode ) {
if( $shortcode != 'init' ) { if ( $shortcode != 'init' ) {
add_shortcode( 'ap_' . $shortcode, array( 'Activitypub\Shortcodes', $shortcode ) ); add_shortcode( 'ap_' . $shortcode, array( 'Activitypub\Shortcodes', $shortcode ) );
} }
} }
@ -27,7 +27,7 @@ class Shortcodes {
public static function hashtags( $atts, $content, $tag ) { public static function hashtags( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -58,11 +58,12 @@ class Shortcodes {
public static function title( $atts, $content, $tag ) { public static function title( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
return \get_the_title( $post->ID );; return \get_the_title( $post->ID );
} }
/** /**
@ -77,7 +78,7 @@ class Shortcodes {
public static function excerpt( $atts, $content, $tag ) { public static function excerpt( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -85,7 +86,8 @@ class Shortcodes {
$length = intval( $atts['length'] ); $length = intval( $atts['length'] );
if( $length == 0 ) { $length = ACTIVITYPUB_EXCERPT_LENGTH; } if ( $length == 0 ) {
$length = ACTIVITYPUB_EXCERPT_LENGTH; }
$excerpt = \get_post_field( 'post_excerpt', $post ); $excerpt = \get_post_field( 'post_excerpt', $post );
@ -176,7 +178,7 @@ class Shortcodes {
public static function content( $atts, $content, $tag ) { public static function content( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -197,22 +199,22 @@ class Shortcodes {
public static function permalink( $atts, $content, $tag ) { public static function permalink( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
$atts = shortcode_atts( array( 'type' => 'html' ), $atts, $tag ); $atts = shortcode_atts( array( 'type' => 'html' ), $atts, $tag );
if( is_array( $atts ) && array_key_exists( 'type', $atts ) ) { if ( is_array( $atts ) && array_key_exists( 'type', $atts ) ) {
if( $atts['type'] == 'raw' ) { if ( $atts['type'] == 'raw' ) {
return \get_permalink( $post->ID ); return \get_permalink( $post->ID );
} }
if( $atts['type'] == 'esc' ) { if ( $atts['type'] == 'esc' ) {
return \esc_url( \get_permalink( $post->ID ) ); return \esc_url( \get_permalink( $post->ID ) );
} }
if( $atts['type'] == 'blank' ) { if ( $atts['type'] == 'blank' ) {
return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \get_permalink( $post->ID ) ) ); return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \get_permalink( $post->ID ) ) );
} }
} }
@ -232,22 +234,22 @@ class Shortcodes {
public static function shortlink( $atts, $content, $tag ) { public static function shortlink( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
$atts = shortcode_atts( array( 'type' => 'html' ), $atts, $tag ); $atts = shortcode_atts( array( 'type' => 'html' ), $atts, $tag );
if( is_array( $atts ) && array_key_exists( 'type', $atts ) ) { if ( is_array( $atts ) && array_key_exists( 'type', $atts ) ) {
if( $atts['type'] == 'raw' ) { if ( $atts['type'] == 'raw' ) {
return \wp_get_shortlink( $post->ID ); return \wp_get_shortlink( $post->ID );
} }
if( $atts['type'] == 'esc' ) { if ( $atts['type'] == 'esc' ) {
return \esc_url( \wp_get_shortlink( $post->ID ) ); return \esc_url( \wp_get_shortlink( $post->ID ) );
} }
if( $atts['type'] == 'blank' ) { if ( $atts['type'] == 'blank' ) {
return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \wp_get_shortlink( $post->ID ) ) ); return \sprintf( '<a href="%1$s" target="_blank">%1$s</a>', \esc_url( \wp_get_shortlink( $post->ID ) ) );
} }
} }
@ -267,7 +269,7 @@ class Shortcodes {
public static function thumbnail( $atts, $content, $tag ) { public static function thumbnail( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -292,21 +294,22 @@ class Shortcodes {
public static function image( $atts, $content, $tag ) { public static function image( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
$atts = shortcode_atts( array( 'size' => 'full' ), $atts, $tag ); $atts = shortcode_atts( array( 'size' => 'full' ), $atts, $tag );
if( is_array( $atts ) && array_key_exists( 'size', $atts ) ) { if ( is_array( $atts ) && array_key_exists( 'size', $atts ) ) {
$registered_sizes = wp_get_registered_image_subsizes(); $registered_sizes = wp_get_registered_image_subsizes();
if( array_key_exists( $atts['size'], $registered_sizes ) ) { if ( array_key_exists( $atts['size'], $registered_sizes ) ) {
$size = intval( $atts['size'] ); $size = intval( $atts['size'] );
} }
} }
if( ! $size ) { $size = 'full'; } if ( ! $size ) {
$size = 'full'; }
$image = \get_the_post_thumbnail_url( $post->ID, $size ); $image = \get_the_post_thumbnail_url( $post->ID, $size );
@ -329,7 +332,7 @@ class Shortcodes {
public static function hashcats( $atts, $content, $tag ) { public static function hashcats( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -360,7 +363,7 @@ class Shortcodes {
public static function author( $atts, $content, $tag ) { public static function author( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -385,7 +388,7 @@ class Shortcodes {
public static function authorurl( $atts, $content, $tag ) { public static function authorurl( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -408,7 +411,7 @@ class Shortcodes {
* @return string * @return string
*/ */
public static function blogurl( $atts, $content, $tag ) { public static function blogurl( $atts, $content, $tag ) {
return \get_bloginfo('url'); return \get_bloginfo( 'url' );
} }
/** /**
@ -421,7 +424,7 @@ class Shortcodes {
* @return string * @return string
*/ */
public static function blogname( $atts, $content, $tag ) { public static function blogname( $atts, $content, $tag ) {
return \get_bloginfo('name'); return \get_bloginfo( 'name' );
} }
/** /**
@ -434,7 +437,7 @@ class Shortcodes {
* @return string * @return string
*/ */
public static function blogdesc( $atts, $content, $tag ) { public static function blogdesc( $atts, $content, $tag ) {
return \get_bloginfo('description'); return \get_bloginfo( 'description' );
} }
/** /**
@ -449,7 +452,7 @@ class Shortcodes {
public static function date( $atts, $content, $tag ) { public static function date( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -478,7 +481,7 @@ class Shortcodes {
public static function time( $atts, $content, $tag ) { public static function time( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }
@ -507,7 +510,7 @@ class Shortcodes {
public static function datetime( $atts, $content, $tag ) { public static function datetime( $atts, $content, $tag ) {
$post = get_post(); $post = get_post();
if( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) { if ( ! \is_object( $post ) || ( \is_object( $post ) && get_class( $post ) != 'WP_Post' ) ) {
return ''; return '';
} }

View file

@ -17,7 +17,7 @@ class Post {
private $object_type; private $object_type;
public function __construct( $post = null ) { public function __construct( $post = null ) {
if( $post ) { if ( $post ) {
$this->post = \get_post( $post ); $this->post = \get_post( $post );
$this->post_author = $this->post->post_author; $this->post_author = $this->post->post_author;
@ -298,7 +298,9 @@ class Post {
$need_update = false; $need_update = false;
// If the old contents is blank, use the defaults. // If the old contents is blank, use the defaults.
if( $old_content == "" ) { $old_content = ACTIVITYPUB_CUSTOM_POST_CONTENT; $need_update = true; } if ( $old_content == '' ) {
$old_content = ACTIVITYPUB_CUSTOM_POST_CONTENT;
$need_update = true; }
// Set the new content to be the old content. // Set the new content to be the old content.
$content = $old_content; $content = $old_content;
@ -313,7 +315,7 @@ class Post {
$content = \str_replace( '%tags%', '[ap_hashtags]', $content ); $content = \str_replace( '%tags%', '[ap_hashtags]', $content );
// Store the new template if required. // Store the new template if required.
if( $content != $old_content || $need_update ) { if ( $content != $old_content || $need_update ) {
\update_option( 'activitypub_custom_post_content', $content ); \update_option( 'activitypub_custom_post_content', $content );
} }