michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

_getTheSetImageURL fails for media field type #241

Closed szepeviktor closed 8 years ago

szepeviktor commented 8 years ago
    private function _getTheSetImageURL(array $aField, $iCountAttributes) {
        $_sCaptureAttribute = $this->getAOrB($iCountAttributes, 'url', '');
        return $_sCaptureAttribute ? $this->getElement($aField, array('attributes', 'value', $_sCaptureAttribute), '') : $aField['attributes']['value'];
    }

https://github.com/michaeluno/admin-page-framework/blob/ce9d08d48ac4f6aacd476e316b8bf5e7e7cd7408/library/apf/factory/_common/form/field_type/AdminPageFramework_FieldType_media.php#L414-L416

What could we do?

szepeviktor commented 8 years ago

Maybe wp_get_attachment_url( $aField['attributes']['id'] );?

szepeviktor commented 8 years ago

This works for me

    private function _getTheSetImageURL(array $aField, $iCountAttributes) {
        $_sCaptureAttribute = $this->getAOrB($iCountAttributes, 'id', '');
        return $_sCaptureAttribute ? wp_get_attachment_url( $this->getElement($aField, array('attributes', 'value', $_sCaptureAttribute), '') ) : '';
    }
michaeluno commented 8 years ago

I hardly remember it but the saved value type becomes different (string vs array) when the attributes_to_store argument is set. When the user sets an attribute to save, the field value becomes an array and the image url gets stored in the url element of the array. Otherwise, it will store the url as a string and don't create an array so you won't see the url element.

Let me know if the attributes_to_store argument does not let you store expected values.

michaeluno commented 8 years ago

Closing the topic as the problem cannot be confirmed.

szepeviktor commented 8 years ago

OK.

Please take a look at my class for ultra simple options page maker: https://github.com/szepeviktor/wordpress-plugin-construction/blob/master/theme-options-page/one-theme-options-page-minimal-example.php

Thanks.