Skip to content

Commit

Permalink
Merge 9ac592d into 0c4622a
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Nov 4, 2022
2 parents 0c4622a + 9ac592d commit 267ff5e
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 48 deletions.
6 changes: 4 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
parameters:
level: 5 # Increase until "max"
level: 0 # Increase until "max"
paths:
- src/
scanFiles:
- vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php
- vendor/php-stubs/acf-pro-stubs/acf-pro-stubs.php
# ignoreErrors:
ignoreErrors:
- '#Instantiated class Twig\\CacheExtension\\CacheStrategy\\GenerationalCacheStrategy not found.#'
- '#Instantiated class Twig\\CacheExtension\\Extension not found.#'
# # Uses func_get_args()
# - '#^Function apply_filters invoked with [3456] parameters, 2 required\.$#'
# # TODO Do not create a static instance of a non-final class.
Expand Down
33 changes: 16 additions & 17 deletions src/CoreEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
/**
* Filters object meta data before it is fetched from the database.
*
* @since 2.0.0
*
* @example
* ```php
* // Disable fetching meta values.
Expand All @@ -126,15 +128,13 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
* }, 10, 3 );
* ```
*
* @since 2.0.0
*
* @param string $object_meta The field value. Default null. Passing a non-null
* @param string|null $object_meta The field value. Default null. Passing a non-null
* value will skip fetching the value from the database
* and will use the value from the filter instead.
* @param int $post_id The post ID.
* @param string $field_name The name of the meta field to get the value for.
* @param object $object The Timber object.
* @param array $args An array of arguments.
* @param int $post_id The post ID.
* @param string $field_name The name of the meta field to get the value for.
* @param object $object The Timber object.
* @param array $args An array of arguments.
*/
$object_meta = apply_filters(
"timber/{$object_type}/pre_meta",
Expand Down Expand Up @@ -200,6 +200,9 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
*
* This filter is used by the ACF Integration.
*
* @see \Timber\Post::meta()
* @since 2.0.0
*
* @example
* ```php
* add_filter( 'timber/post/meta', function( $post_meta, $post_id, $field_name, $post ) {
Expand All @@ -212,14 +215,11 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
* }, 10, 4 );
* ```
*
* @see \Timber\Post::meta()
* @since 2.0.0
*
* @param string $post_meta The field value.
* @param int $post_id The post ID.
* @param string $field_name The name of the meta field to get the value for.
* @param \Timber\Post $post The post object.
* @param array $args An array of arguments.
* @param string $post_meta The field value.
* @param int $post_id The post ID.
* @param string $field_name The name of the meta field to get the value for.
* @param \Timber\CoreEntity $post The post object.
* @param array $args An array of arguments.
*/
$object_meta = apply_filters(
"timber/{$object_type}/meta",
Expand Down Expand Up @@ -282,8 +282,7 @@ protected function fetch_meta($field_name = '', $args = [], $apply_filters = tru
* Finds any WP_Post objects and converts them to Timber\Posts
*
* @api
* @param array|WP_Post $data
* @param string $class
* @param array|\Timber\CoreEntity $data
*/
public function convert($data)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/PagesMenuFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ protected function get_menu_class($args): string
* } );
* ```
*
* @param array $class The pages menu class to use.
* @param array $args The arguments passed to `Timber::get_pages_menu()`.
* @param string $class The pages menu class to use.
* @param array $args The arguments passed to `Timber::get_pages_menu()`.
*/
$class = apply_filters('timber/pages_menu/class', PagesMenu::class, $args);

Expand Down
4 changes: 4 additions & 0 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ public function srcset($size = "full")
if ($this->is_image()) {
return wp_get_attachment_image_srcset($this->ID, $size);
}

return false;
}

/**
Expand All @@ -410,6 +412,8 @@ public function img_sizes($size = "full")
if ($this->is_image()) {
return wp_get_attachment_image_sizes($this->ID, $size);
}

return false;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Integration/AcfIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ public static function transform_user($value, $id, $field)
/**
* Gets meta value through ACF’s API.
*
* @param string $value
* @param int $id
* @param string $field_name
* @param array $args
* @param string $value
* @param int|string $id
* @param string $field_name
* @param array $args
* @return mixed|false
*/
private static function get_meta($value, $id, $field_name, $args)
Expand Down
6 changes: 2 additions & 4 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ public function get_loader()
*
* @link https://github.com/timber/timber/pull/1254
* @since 1.1.11
*
* @param array $paths
*/
$fs = apply_filters('timber/loader/loader', $fs);

Expand Down Expand Up @@ -333,7 +331,7 @@ public function get_twig()
* *
* * @link https://twig.symfony.com/doc/2.x/api.html#environment-options
* *
* * @param array $options An array of environment options.
* * \@param array $options An array of environment options.
* *
* * @return array
* *\/
Expand Down Expand Up @@ -479,7 +477,7 @@ public function get_twig()
* /**
* * Adds Twig functionality.
* *
* * @param \Twig\Environment $twig The Twig Environment to which you can add additional functionality.
* * \@param \Twig\Environment $twig The Twig Environment to which you can add additional functionality.
* *\/
* add_filter( 'timber/twig', function( $twig ) {
* // Make get_theme_file_uri() usable as {{ theme_file() }} in Twig.
Expand Down
4 changes: 3 additions & 1 deletion src/LocationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static function get_calling_script_file($offset = 0)
/**
* Get calling script dir.
* @api
* @return string
* @return string|null
*/
public static function get_calling_script_dir($offset = 0)
{
Expand All @@ -112,6 +112,8 @@ public static function get_calling_script_dir($offset = 0)
$dir = $pathinfo['dirname'];
return $dir;
}

return null;
}

/**
Expand Down
19 changes: 12 additions & 7 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,7 @@ public function teardown()
protected static function is_previewing()
{
global $wp_query;
if (isset($_GET['preview']) && isset($_GET['preview_nonce']) && wp_verify_nonce($_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id)) {
return true;
}
return isset($_GET['preview']) && isset($_GET['preview_nonce']) && wp_verify_nonce($_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id);
}

/**
Expand Down Expand Up @@ -478,9 +476,11 @@ public function preview()
}

/**
* Gets the link to a page number.
*
* @internal
* @param int $i
* @return string
* @return string|null Link to page number or `null` if link could not be read.
*/
protected static function get_wp_link_page($i)
{
Expand All @@ -489,6 +489,8 @@ protected static function get_wp_link_page($i)
if (isset($link['href'])) {
return $link['href'];
}

return null;
}

/**
Expand Down Expand Up @@ -705,8 +707,8 @@ public function field_object($field_name)
* @see \Timber\Post::field_object()
* @since 1.6.0
*
* @param array $value The field object array.
* @param int $post_id The post ID.
* @param mixed $value The value.
* @param int|null $post_id The post ID.
* @param string $field_name The ACF field name.
* @param \Timber\Post $post The post object.
*/
Expand Down Expand Up @@ -1480,13 +1482,16 @@ public function type()
* Returns the edit URL of a post if the user has access to it
*
* @api
* @return bool|string the edit URL of a post in the WordPress admin
* @return null|string The edit URL of a post in the WordPress admin. Null if user can’t edit a post or edit post
* link can’t be read.
*/
public function edit_link()
{
if ($this->can_edit()) {
return get_edit_post_link($this->ID);
}

return null;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/PostExcerpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,10 @@ protected function assemble($text, $args = [])
* Filters the link used for a read more text in an excerpt.
*
* @since 2.0.0
* @param string $link The HTML link.
* @param \Timber\Post $post Post instance.
* @param string $link The HTML link.
* @param \Timber\Post $post Post instance.
* @param string $linktext The link text.
* @param string $read_more_class The CSS class name.
*/
$link = apply_filters(
'timber/post/excerpt/read_more_link',
Expand Down
2 changes: 0 additions & 2 deletions src/Timber.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,6 @@ public static function fetch($filenames, $data = [], $expires = false, $cache_mo
* array, the first value is used for non-logged in visitors, the second for users.
* Default false.
* @param string $cache_mode Optional. Any of the cache mode constants defined in Timber\Loader.
* @return bool|string The echoed output.
*/
public static function render($filenames, $data = [], $expires = false, $cache_mode = Loader::CACHE_USE_DEFAULT)
{
Expand All @@ -1563,7 +1562,6 @@ public static function render($filenames, $data = [], $expires = false, $cache_m
* ```
* @param string $string A string with Twig variables.
* @param array $data An array of data to use in Twig template.
* @return bool|string
*/
public static function render_string($string, $data = [])
{
Expand Down
15 changes: 8 additions & 7 deletions tests/test-timber-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -1163,9 +1163,6 @@ public function testPathAndLinkWithPort()
*/
public function testEditUrl()
{
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");

global $current_user;
$current_user = [];

Expand All @@ -1178,13 +1175,17 @@ public function testEditUrl()
]);
$post = Timber::get_post($pid);
$edit_url = $post->edit_link();
$this->assertEquals('', $edit_url);
$this->assertFalse($post->can_edit());
$this->assertNull($edit_url);

$user = wp_set_current_user($uid);
$user->add_role('administrator');
$data = get_userdata($uid);

$this->assertTrue($post->can_edit());
$this->assertEquals('http://example.org/wp-admin/post.php?post=' . $pid . '&action=edit', $post->edit_link());
//
$this->assertEquals(
'http://example.org/wp-admin/post.php?post=' . $pid . '&action=edit',
$post->edit_link()
);
}

public function testPostThumbnailId()
Expand Down

0 comments on commit 267ff5e

Please sign in to comment.