set up backward resolving of ids
This commit is contained in:
parent
8c9d8c02d6
commit
621b2b1cbe
|
@ -219,7 +219,7 @@ class ComicPressAdmin {
|
||||||
foreach ($_POST['attachments'] as $post_id => $settings) {
|
foreach ($_POST['attachments'] as $post_id => $settings) {
|
||||||
if (isset($settings['comicpress_management'])) {
|
if (isset($settings['comicpress_management'])) {
|
||||||
$media_post = get_post($post_id);
|
$media_post = get_post($post_id);
|
||||||
if (isset($media_post->post_parent)) {
|
if (isset($media_post->post_parent)) {
|
||||||
$media_post->post_parent = $settings['post_parent'];
|
$media_post->post_parent = $settings['post_parent'];
|
||||||
wp_update_post($media_post);
|
wp_update_post($media_post);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ComicPressBackend {
|
||||||
$extras = array_merge($extras, $dims);
|
$extras = array_merge($extras, $dims);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($extras as $field => $value) {
|
foreach ($extras as $field => $value) {
|
||||||
$extras[] = "${field}=\"${value}\" ";
|
$extras[] = "${field}=\"${value}\" ";
|
||||||
unset($extras[$field]);
|
unset($extras[$field]);
|
||||||
|
@ -18,4 +18,15 @@ class ComicPressBackend {
|
||||||
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url(), $this->alt(), $this->title(), implode("", $extras));
|
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url(), $this->alt(), $this->title(), implode("", $extras));
|
||||||
return apply_filters('comicpress_embed_image', $output, $this);
|
return apply_filters('comicpress_embed_image', $output, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generate_from_id($id) {
|
||||||
|
$comicpress = ComicPress::get_instance();
|
||||||
|
foreach ($comicpress->backends as $backend) {
|
||||||
|
$result = $backend->generate_from_id($id);
|
||||||
|
if ($result !== false) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -42,4 +42,25 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertTrue(preg_match($pattern, $result) > 0);
|
$this->assertTrue(preg_match($pattern, $result) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function providerTestGenerateFromID() {
|
||||||
|
return array(
|
||||||
|
array(null, false),
|
||||||
|
array('1', false),
|
||||||
|
array('attachment-1', (object)array('ID' => 1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTestGenerateFromID
|
||||||
|
*/
|
||||||
|
function testGenerateFromID($id, $expected_result) {
|
||||||
|
$backend = $this->getMock('ComicPressFakeBackend', array('generate_from_id'));
|
||||||
|
$backend->expects($this->once())->method('generate_from_id')->with($id)->will($this->returnValue($expected_result));
|
||||||
|
|
||||||
|
$comicpress = ComicPress::get_instance();
|
||||||
|
$comicpress->backends = array($backend);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_result, ComicPressBackend::generate_from_id($id));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue